onWebSocket method

void onWebSocket(
  1. SocketConnect connect
)

Called upon a ws.io connection.

Implementation

void onWebSocket(SocketConnect connect) {
  if (connect.request.connectionInfo == null) {
    return;
  }
  // get client id
  var id = connect.request.uri.queryParameters['sid'];

  if (id != null) {
    var client = clients[id];

    if (client == null) {
      connect.websocket?.close();
    } else if (client.upgrading == true) {
      connect.websocket?.close();
    } else if (client.upgraded == true) {
      connect.websocket?.close();
    } else {
      var req = connect.request;
      var transport = Transports.newInstance(
          req.uri.queryParameters['transport'] as String, connect);
      // ignore: unrelated_type_equality_checks
      if (req.uri.queryParameters['b64'] == true) {
        transport.supportsBinary = false;
      } else {
        transport.supportsBinary = true;
      }
      transport.perMessageDeflate = perMessageDeflate;
      client.maybeUpgrade(transport);
    }
  } else {
    handshake(
        connect.request.uri.queryParameters['transport'] as String, connect);
  }
}