public interface IBridgeTransport Carries the Views protocol between one window and the pages connected to it: the requests of each connection with their replies, and pushes to every connection.
Remarks
The window serves its requests through IBridgeTransport.Serve and sends its pushes through IBridgeTransport.BroadcastAsync. Every message is one JSON object, encoded as UTF-8 without a byte order mark (specs/application/README.md, "Transport"). A transport carries messages without reading them.
A transport that can push to one connection also implements IBridgeConnectionTransport. Without it, the window queues each connection's targeted pushes, and the host script drains them with receive requests.
The replies and pushes of one connection must arrive in the order the window sent them. Runic Desktop, WPF (DesktopBridgeTransport), CS-WebUI (CreateBridgeSession) and the in-memory transport of Runic.Application.Testing implement this interface.
Methods
BroadcastAsync
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.
Serve
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.