connect method
void
connect(
- {required PusherChannelsConnectionOnDoneCallback onDoneCallback,
- required PusherChannelsConnectionOnErrorCallback onErrorCallback,
- required PusherChannelsConnectionOnEventCallback onEventCallback}
override
Tries to establish connection.
onDoneCallback
must be called when connection is closed.onErrorCallback
must be called when a connection error is thrown.onEventCallback
must be called when an event is received.
Implementation
@override
void connect({
required PusherChannelsConnectionOnDoneCallback onDoneCallback,
required PusherChannelsConnectionOnErrorCallback onErrorCallback,
required PusherChannelsConnectionOnEventCallback onEventCallback,
}) {
if (_isClosed) {
throw const PusherChannelsWebSocketConnectionWasClosedException();
}
_webSocketChannel ??= WebSocketChannel.connect(uri);
_webSocketEventsSubscription ??= _webSocketChannel?.stream.listen(
(event) => _onEvent(event.toString(), onEventCallback),
cancelOnError: true,
onDone: () => _onDone(onDoneCallback),
onError: (exception, trace) => _onError(
exception: exception,
trace: trace,
callback: onErrorCallback,
),
);
}