connectSocket method

Future<void> connectSocket(
  1. dynamic projectid,
  2. dynamic completeAddress
)

Implementation

Future<void> connectSocket(projectid, completeAddress) async {
  //completeAddress = "wss://r-signalling.vdotok.dev:8443/call";
  //completeAddress = "wss://r-stun2.vdotok.dev:8443/call";

  await getInternetStatus().then((value) async {
    print("this is valuuueee $value $isUnRegistered");
    if ( isUnRegistered == false && value) {
      try {

        _socket = WebSocketConnection(url: completeAddress);

        _socket?.onOpen = () {
          register();

          onConnect?.call("connected");
        };
      } catch (e) {
        closeSocket();
        print("this is error in socket opening  $e");
      }

      _socket?.onMessage = (message) {
        print("this is messageeeeee ${message.runtimeType}");
        if(message == null)
        {
print("nulll");
        }
        _onMessage(json.decode(message));
      };

      _socket?.onClose = (dynamic code, String? reason) {
        print("this is onclose socket $_socket");
        //   closeSocket();
        timer?.cancel();

        if (reason == null) {
          onError?.call(code, "no reason");

          reConnectSocketConnectTimer();
        } else {
          onError?.call(code, reason);

          reConnectSocketConnectTimer();
        }
      };
      try {
        await _socket?.connect();
      } catch (e) {
        closeSocket();
        print("this is exception");
      }
    } else {
      print("here in falseeee $_socket");
      // onError?.call()
      //internetConnectivityCallBack?.call("Disconnected");
      //onError?.call(1000,"no internet connection");
    }
  }).catchError((onError) {
    print("this is onError of internet connection $onError");
  });
}