How to use the websocket.request function in websocket

To help you get started, we’ve selected a few websocket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FE-Kits / Holo-Web / server / modules / websocket-compat.js View on Github external
options.httpServer.on('upgrade', function(req, socket, head) {
    if (typeof req.headers['sec-websocket-version'] !== 'undefined') {

      // WebSocket hybi-08/-09/-10 connection (WebSocket-Node)
      wsRequest = new WebSocketRequest(socket, req, wsServerConfig);
      try {
        wsRequest.readHandshake();
      } catch (e) {
        wsRequest.reject(
          e.httpCode ? e.httpCode : 400,
          e.message,
          e.headers
        );
        return;
      }
      wsRequest.once('requestAccepted', function(connection) {
        wsRequest.handleRequestAccepted(connection);
      });
      self.emit('request', wsRequest);

    } else {
github soundanalogous / Breakout / server / server_old.js View on Github external
httpServer.on('upgrade', function(req, socket, head) {

    if (typeof req.headers['sec-websocket-version'] !== 'undefined') {

        // WebSocket hybi-08/-09/-10 connection (WebSocket-Node)
        var wsRequest = new WebSocketRequest(socket, req, wsServerConfig);
        try {
            wsRequest.readHandshake();
            var wsConnection = wsRequest.accept(wsRequest.requestedProtocols[0], wsRequest.origin);
            handleConnection(wsConnection);
        }
        catch(e) {
            console.log("WebSocket Request unsupported by WebSocket-Node: " + e.toString());
            return;
        }

    } else {

        // WebSocket hixie-75/-76/hybi-00 connection (node-websocket-server)
        if (req.method === 'GET' &&
            (req.headers.upgrade && req.headers.connection) &&
            req.headers.upgrade.toLowerCase() === 'websocket' &&
github ascetictoolbox / ascetictoolbox / paas / application-monitor.removeme / etc / old / cube / lib / cube / server.js View on Github external
primary.on("upgrade", function(request, socket, head) {
    if ("sec-websocket-version" in request.headers) {
      request = new websocket.request(socket, request, wsOptions);
      request.readHandshake();
      connect(request.accept(request.requestedProtocols[0], request.origin), request.httpRequest);
    } else if (request.method === "GET"
        && /^websocket$/i.test(request.headers.upgrade)
        && /^upgrade$/i.test(request.headers.connection)) {
      new websprocket.Connection(secondary.manager, secondary.options, request, socket, head);
    }
  });
github square / cube / lib / cube / server.js View on Github external
function auth_ok(perms) {
      if (is_sec_ws_initiation(request)) {
        request = new websocket.request(socket, request, wsOptions);
        request.readHandshake();
        connect(request.accept(request.requestedProtocols[0], request.origin), request.httpRequest);
      } else if (is_ws_initiation(request)) {
        new websprocket.Connection(secondary.manager, secondary.options, request, socket, head);
      }
    }
    function auth_no(perms) {
github square / cube / lib / cube / server.js View on Github external
function auth_no(perms) {
      if (is_sec_ws_initiation(request)) {
        request = new websocket.request(socket, request, wsOptions);
        request.readHandshake();
        request.reject();
      } else if (is_ws_initiation(request)) {
        res = 'HTTP/1.1 403 Forbidden\r\nConnection: close';
        socket.end(res + '\r\n\r\n', 'ascii');
      }
    }
    return authenticator.check(request, auth_ok, auth_no);