WebSocketAuthenticator typedef

WebSocketAuthenticator = Future<void> Function(WsRequestSender send, StreamApiException? previousError)

A function that authenticates a newly opened connection.

Called while the state is Authenticating, to send the credentials the connection requires.

previousError is the error the server closed the previous attempt with, and null when there was none, once a connection has been established, or once the caller has disconnected. Only the next attempt after a refusal sees it. Use it to replace credentials that were refused.

Throw when the credentials did not go out, whether because sending failed or because this function chose not to send them. The connection is then closed with AuthenticationFailed carrying what was thrown, and reconnected only when that says the network was at fault rather than the credentials — so pass a failed WsRequestSender's error on rather than replacing it.

Implementation

typedef WebSocketAuthenticator = Future<void> Function(WsRequestSender send, StreamApiException? previousError);