getConnectionSocket method

Future<WebSocket> getConnectionSocket({
  1. Duration? duration,
})

Implementation

Future<WebSocket> getConnectionSocket({Duration? duration}) async {
  HttpClient? customCient;
  if (credentials.isSecure) {
    customCient = HttpClient(context: credentials.securityContext);
    customCient.badCertificateCallback = (cert, host, port) {
      if (credentials.onBadCertificate != null) {
        return credentials.onBadCertificate!(
          cert,
          credentials.authority ?? _host,
        );
      }
      return false;
    };
  }
  if (log) {
    loger.log(
      "${credentials.isSecure ? "wss" : "ws"}://$_host:$_port$_path",
      name: "ws",
    );
  }
  // var channel = IOWebSocketChannel.connect(Uri.parse('ws://localhost:1234'));
  // channel.stream.listen((event) { })
  var _tmpSocket = await WebSocket.connect(
    "${credentials.isSecure ? "wss" : "ws"}://$_host:$_port$_path",
    protocols: protocols,
    // headers: {
    //   "host": credentials.authority,
    // },
    customClient: customCient,
  );

  return _tmpSocket;
}