connect method
void
connect()
Implementation
void connect() {
try {
connectionStatus = ConnectionStatus.connecting;
socket = WebSocket(url);
socket!.onOpen.listen((e) {
socketNotifier?.open();
_t = Timer?.periodic(ping, (t) {
socket!.send('');
});
connectionStatus = ConnectionStatus.connected;
});
socket!.onMessage.listen((event) {
socketNotifier!.notifyData(event.data);
});
socket!.onClose.listen((e) {
_t?.cancel();
connectionStatus = ConnectionStatus.closed;
socketNotifier!.notifyClose(Close(e.reason, e.code));
});
socket!.onError.listen((event) {
_t?.cancel();
socketNotifier!.notifyError(Close(event.toString(), 0));
connectionStatus = ConnectionStatus.closed;
});
} on Exception catch (e) {
_t?.cancel();
socketNotifier!.notifyError(Close(e.toString(), 500));
connectionStatus = ConnectionStatus.closed;
// close(500, e.toString());
}
}