connect method Null safety
Starts a WebSocket connection with signaling server.
var response = await millicastSignaling.connect();
WebSocketChannel
Future object which represents the webSocket
{https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API}
of the establshed connection.
Implementation
Future<WebSocketChannel> connect() async {
{
_logger.i('Connecting to Signaling Server');
if (webSocket != null && transactionManager != null) {
_logger.i('Connected to server $wsUrl');
return webSocket!;
}
webSocket = WebSocketChannel.connect(Uri.parse(wsUrl));
transactionManager = TransactionManager(webSocket!);
_logger.i('WebSocket opened');
transactionManager?.on('event', this, (event, context) {
emit(SignalingEvents.broadcastEvent, this, event.eventData);
});
transactionManager?.on(SignalingEvents.connectionError, this,
(event, context) {
if (isMigrating == false) {
emit(SignalingEvents.connectionError, this, event);
throw Exception(event);
}
});
transactionManager?.on(SignalingEvents.connectionClose, this,
(event, context) {
webSocket = null;
transactionManager = null;
_logger.i('Connection closed with Signaling Server.');
emit(SignalingEvents.connectionClose, this, event);
});
emit(SignalingEvents.connectionSuccess, this,
{'ws': webSocket, 'tm': transactionManager});
return webSocket!;
}
}