connect method

void connect()

Connects to the WebSocket server

Implementation

void connect() async {
  try {
    webSocket = await WebSocket.connect(getWebSocketAddress(),
        customClient: customClient);

    webSocket!.listen((data) {
      onTextMessage(data);
    }, onError: (error) {
      onError(error.toString());
    }, onDone: () {
      onDisconnected();
    });

    onConnected();
  } catch (e) {
    onError(e.toString());
    websocketCancelled = true;
  }
}