connect method
Connects to the Hub and authenticates.
Throws AuthException if authentication fails, or TransportException if the connection cannot be established.
Implementation
Future<void> connect() async {
final auth = _auth = Completer<void>();
final WebSocketConnection connection;
try {
connection = await WebSocketConnection.connect(
config.hubUri,
securityContext: config.securityContext,
onBadCertificate: config.onBadCertificate,
);
} on Object catch (e) {
throw TransportException('Failed to connect to Hub: $e');
}
_connection = connection;
final mux = _mux = ChannelMultiplexer(connection, firstChannelId: 1);
_controlSub = mux.control.listen(
_onControl,
onDone: _onDisconnected,
cancelOnError: false,
);
unawaited(connection.done.then((_) => _onDisconnected()));
await auth.future;
}