How to use the faye-websocket.isWebSocket function in faye-websocket

To help you get started, we’ve selected a few faye-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 primus / primus / transformers / faye / server.js View on Github external
this.on('upgrade', (req, socket, head) => {
    if (!Faye.isWebSocket(req)) return socket.destroy();

    let websocket = new Faye(req, socket, head, null, options);

    //
    // The WebSocket handshake is complete only when the `open` event is fired.
    //
    websocket.on('open', () => {
      const spark = new this.Spark(
          req.headers               // HTTP request headers.
        , req                       // IP address location.
        , url.parse(req.url).query  // Optional query string.
        , null                      // We don't have an unique id.
        , req                       // Reference to the HTTP req.
        , websocket                 // Reference to the WebSocket.
      );
github obastemur / jxcore-android-basics / jxcore-droid-astd / app / build / intermediates / assets / debug / jxcore / node_modules / jxm / backend / jx_server.js View on Github external
var app = function (req, res) {

        if (!req.url) {
            res.end(0);
            return;
        }

        var socket = webSocket.isWebSocket(req);

        req.path = exports.getNormalizedPath(req.url.split('?')[0]);

        getSetCookies(req, res);

        if(helpers.emitEvent('request', req, res) === false){
            return;
        }

        if (serve(req, res)) {
            return;
        }

        req = fillReq(req, res);
        if (!req) {
            return;
github jxcore / jxm / backend / jx_server.js View on Github external
var app = function (req, res) {

        if (!req.url) {
            res.end(0);
            return;
        }

        var socket = webSocket.isWebSocket(req);

        req.path = exports.getNormalizedPath(req.url.split('?')[0]);

        getSetCookies(req, res);

        if(helpers.emitEvent('request', req, res) === false){
            return;
        }

        if (serve(req, res)) {
            return;
        }

        req = fillReq(req, res);
        if (!req) {
            return;
github microsoft / pxt / webapp / server.js View on Github external
wsserver.on('upgrade', function (request, socket, body) {
    if (WebSocket.isWebSocket(request)) {
        /^\/client/i.test(request.url)
            ? startws(request, socket, body, clients, servers)
            : startws(request, socket, body, servers, clients);
    }
});
github microsoft / pxt / cli / server.ts View on Github external
wsserver.on('upgrade', function (request: http.IncomingMessage, socket: WebSocket, body: any) {
        try {
            if (WebSocket.isWebSocket(request)) {
                console.log('ws connection at ' + request.url);
                if (request.url == "/" + serveOptions.localToken + "/serial")
                    startSerial(request, socket, body);
                else if (request.url == "/" + serveOptions.localToken + "/debug")
                    startDebug(request, socket, body);
                else if (request.url == "/" + serveOptions.localToken + "/hid")
                    startHID(request, socket, body);
                else if (request.url == "/" + serveOptions.localToken + "/tcp")
                    startTCP(request, socket, body);
                else {
                    console.log('refused connection at ' + request.url);
                    socket.close(403);
                }
            }
        } catch (e) {
            console.log('upgrade failed...')
github Curvytron / curvytron / bin / curvytron.js View on Github external
Server.prototype.authorizationHandler = function(request, socket, head)
{
    return WebSocket.isWebSocket(request) ? this.onSocketConnection(new WebSocket(request, socket, head, ['websocket'], {ping: 5})) : socket.end();
}
github octoblu / meshblu / lib / httpServer.js View on Github external
var setupWebsocket = function(request, socket, body) {
    if (WebSocket.isWebSocket(request) && request.url == '/ws/v2') {
      var meshbluEventEmitter = new MeshbluEventEmitter(config.uuid, config.forwardEventUuids, sendMessage);
      var ws = new WebSocket(request, socket, body);
      var websocketHandler = new MeshbluWebsocketHandler({
        sendMessage: sendMessage,
        meshbluEventEmitter: meshbluEventEmitter
      });
      websocketHandler.initialize(ws, request);
    }
  };
github taggon / livereload / lib / server.js View on Github external
this.app.on('upgrade', (request, socket, body) => {
      if (!WebSocket.isWebSocket(request)) return;
      var ws = new WebSocket(request, socket, body);

      ws.on('message', event => {
        var data = event.data, json;
        try {
          json = JSON.parse(event.data);
          if (typeof json.command === 'string') {
            this.handleCommand(json);
          }
        } catch(e) { }
      });

      ws.on('close', event => {
        this.sockets = this.sockets.filter( sock => (sock !== ws) );
        ws = null;
      });
github azer / prova / lib / browser.js View on Github external
server.on('upgrade', function(request, socket, body) {
    var ws;
    var ind;

    if (WebSocket.isWebSocket(request)) {
      ws = new WebSocket(request, socket, body);
      ind = sockets.push(ws) - 1;

      onSourceCodeChange.subscribe(notify);

      ws.send(JSON.stringify({ start: true, url: customFrameURL || '/run' }));
      ws.on('message', onMessage);
      ws.on('close', function(event) {
        ws = null;
        sockets[ind] = undefined;
        onSourceCodeChange.unsubscribe(notify);
      });
    }

    function notify () {
      ws.send(restartNotification);

faye-websocket

Standards-compliant WebSocket server and client

Apache-2.0
Latest version published 4 years ago

Package Health Score

73 / 100
Full package analysis