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:
- 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.
- If any side closes the connection, the
StreamChannel.streamwill emit the done event and adding more messages to theStreamChannel.sinkwill have no effect. - Closing the
StreamChannel.sinkwill also close theStreamChannel.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 - It is allowed to call createStreamChannel before
ServerpodClientShared.openStreamingConnection. However, in that case you
must not add any messages to the
StreamChannel.sinkbefore 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> -
Available on EndpointRef, provided by the EndpointStreamChannel extension
Creates a newStreamChannelfor the endpoint.