private static async Task PerformHandshakeAsync(IPC ipc) { // Do a two-way handshake with the browser, this ensures that the appropriate // interop handlers have been set up before control returns to the user. // // The handshake sequence looks like this: // // 1. dotnet starts listening for components:init // 2. dotnet sends components:init repeatedly // 3. JS starts listening for components:init // 4. JS sends a components:init once it has received one from dotnet - it's ready // 5. dotnet receives components:init - it's ready // // Because either side might take any amount of time to start listening, // step 3 can occur at any point prior to step 4. The whole process works // because steps 1, 2, 4, and 5 can only occur in that order var cts = new CancellationTokenSource(); var incomingHandshakeCancellationToken = cts.Token; ipc.Once("components:init", args => { var argsArray = (object[])args; InitialUriAbsolute = ((JsonElement)argsArray[0]).GetString(); BaseUriAbsolute = ((JsonElement)argsArray[1]).GetString(); cts.Cancel(); }); Log("Waiting for interop connection"); while (!incomingHandshakeCancellationToken.IsCancellationRequested) { ipc.Send("components:init"); try { await Task.Delay(100, incomingHandshakeCancellationToken); } catch (TaskCanceledException) { } } Log("Interop connected"); }
protected override void BeginInvokeJS(long asyncHandle, string identifier, string argsJson) { _ipc.Send("JS.BeginInvokeJS", asyncHandle, identifier, argsJson); }