public sealed class DesktopBridgeTransport : IBridgeConnectionTransport, IBridgeTransport, IDisposable Carries the Views protocol of one window over a Desktop surface.
Remarks
Requests arrive on one capability, __runicViews, which runic-desktop-views.js calls with each request's JSON. Pushes travel as raw data to the page's bridge, to every page of the surface or to one connection, and reach the listeners of __runicBridge.onMessage without evaluating script, so a Content-Security-Policy without 'unsafe-eval' receives them. A connection is one authenticated WebSocket: its key is the Desktop connection id, which is also its client key, and a reconnect is a new connection.
The requests of one connection are admitted in the order the page sent them. Disposing the transport removes the capability and stops pushes, while the surface itself stays open. A window uses this to close its Views before accepted operations have drained.
Constructors
DesktopBridgeTransport
public DesktopBridgeTransport(DesktopSurface surface) Creates a transport for surface.
Methods
BroadcastAsync
public ValueTask BroadcastAsync(ReadOnlyMemory<byte> message, CancellationToken cancellationToken = default) Sends one push to every connection of the window.
Parameters
messageThe push, one JSON object as UTF-8. It is valid until the returned task completes.
cancellationTokenStops waiting for the send; the push may still be delivered.
Returns
A task that completes once the transport has handed the push to every connection.
Remarks
The window awaits each call before it sends the next push, so a transport sends pushes in call order without coalescing them. A push sent after the transport was disposed is dropped.
Documentation from IBridgeTransport.BroadcastAsync.
Dispose
public void Dispose() Removes the capability and stops pushes; the surface stays open.
SendAsync
public ValueTask<bool> SendAsync(string connectionKey, ReadOnlyMemory<byte> message, CancellationToken cancellationToken = default) Sends one push to the connection connectionKey.
Parameters
connectionKeyThe connection's key, as the transport supplied it in
BridgeRequest.ConnectionKey.messageThe push, one JSON object as UTF-8. It is valid until the returned task completes.
cancellationTokenStops waiting for the send; the push may still be delivered.
Returns
true when the transport handed the push to the connection; false when the connection is not open.
Remarks
The window looks up the open connection and calls this with its transport key outside its own lock, so a send can be in flight while the connection closes. A transport must not give that key to a new connection while a send to it is in flight: complete or fail the send first, so the push never reaches the connection that came next.
Documentation from IBridgeConnectionTransport.SendAsync.
Serve
public IDisposable Serve(IBridgeRequestHandler handler) Delivers the requests of every connection of this transport to handler.
Parameters
handlerThe window's request handler.
Returns
A lease that stops delivering requests to handler.
Exceptions
InvalidOperationExceptionThe transport already serves a handler.
ObjectDisposedExceptionThe transport was disposed.
Remarks
A transport serves one handler at a time. It calls IBridgeRequestHandler.HandleAsync for the requests of one connection in the order they arrived, without waiting for a reply before it passes the next request: some requests, such as receive and awaited commands, stay open for a long time. The handler admits a request before its returned task first yields, so calling it in arrival order keeps the connection's admission order. A transport reports each connection that closes with IBridgeRequestHandler.ConnectionClosed.
A request that arrives while no handler is served, or after the lease was disposed, is answered with the released reply of the Views protocol, or not at all when the page's connection is closing.
Documentation from IBridgeTransport.Serve.