EndpointStreamChannel extension

An extensions for generic EndpointRefs that allows to access the endpoints websocket connection via a StreamChannel.

This basically wraps serverpod's stream APIs into endpoint-bound stream channels. Most of it happens automatically, but the following should be considered:

  1. The endpoint is not responsible for managing the underlying websocket connection. This is done by the client. Use ServerpodClientShared.openStreamingConnection to connect to the server before accessing the endpoints stream channel. Likewise, use ServerpodClientShared.closeStreamingConnection to close it once finished.
  2. If any side closes the connection, the StreamChannel.stream will emit the done event and adding more messages to theStreamChannel.sink will have no effect.
  3. Closing the StreamChannel.sink will also close the StreamChannel.stream, but it will not close the websocket connection! This is because multiple endpoints could be using the same connection. If you need to close the connection, use
  4. It is allowed to call createStreamChannel before ServerpodClientShared.openStreamingConnection. However, in that case you must not add any messages to the StreamChannel.sink before doing so. ServerpodClientShared.closeStreamingConnection. Please note that closing the sink will not notify the server at all. Further messages received from the server will be silently dropped.
on

Methods

createStreamChannel() → StreamChannel<SerializableEntity>
Creates a new StreamChannel for the endpoint.