connect method
- @Deprecated('Use connect with token or credential login i.e connectWithCredential(..) or connectWithToken(..)')
Connects to the WebSocket with a previously provided Config
Implementation
@Deprecated(
'Use connect with token or credential login i.e connectWithCredential(..) or connectWithToken(..)',
)
/// Connects to the WebSocket with a previously provided [Config]
void connect() {
GlobalLogger().i('connect()');
if (isConnected()) {
GlobalLogger().i('WebSocket $_storedHostAddress is already connected');
return;
}
GlobalLogger().i('connecting to WebSocket $_storedHostAddress');
try {
if (_pushMetaData != null) {
txSocket.hostAddress =
'$_storedHostAddress?voice_sdk_id=${_pushMetaData?.voiceSdkId}';
GlobalLogger().i(
'Connecting to WebSocket with voice_sdk_id :: ${_pushMetaData?.voiceSdkId}',
);
} else {
txSocket.hostAddress = _storedHostAddress;
GlobalLogger().i('connecting to WebSocket $_storedHostAddress');
}
txSocket
..onOpen = () {
_closed = false;
_updateConnectionState(true);
GlobalLogger().i('Web Socket is now connected');
_onOpen();
}
..onMessage = (dynamic data) {
_onMessage(data);
}
..onClose = (int closeCode, String closeReason) {
GlobalLogger().i('Closed [$closeCode, $closeReason]!');
_updateConnectionState(false);
final bool wasClean =
WebSocketUtils.isCleanClose(closeCode, closeReason);
_onClose(wasClean, closeCode, closeReason);
}
..onPing = (SocketConnectionMetrics metrics) {
onConnectionMetricsUpdate?.call(metrics);
}
..connect();
} catch (e) {
GlobalLogger().e(e.toString());
_updateConnectionState(false);
GlobalLogger().e('WebSocket $_storedHostAddress error: $e');
}
}