How to use faye-websocket - 10 common examples

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 apifytech / proxy-chain / test / server.js View on Github external
return new Promise((resolve, reject) => {
                const wsUrl = `${useSsl ? 'wss' : 'ws'}://127.0.0.1:${targetServerPort}`;
                const ws = new WebSocket.Client(wsUrl, [], {
                    proxy: {
                        origin: mainProxyUrl,
                        tls: useSsl ? { cert: sslCrt } : null,
                    }
                });

                ws.on('error', (err) => {
                    ws.close();
                    reject(err);
                });
                ws.on('open', () => {
                    ws.send('hello world');
                });
                ws.on('message', (event) => {
                    ws.close();
                    resolve(event.data);
github apifytech / proxy-chain / test / server.js View on Github external
return new Promise((resolve, reject) => {
                const wsUrl = `${useSsl ? 'wss' : 'ws'}://127.0.0.1:${targetServerPort}`;
                const ws = new WebSocket.Client(wsUrl, [], {
                    proxy: {
                        origin: mainProxyUrl,
                        tls: useSsl ? { cert: sslCrt } : null,
                    }
                });

                ws.on('error', (err) => {
                    ws.close();
                    reject(err);
                });
                ws.on('open', () => {
                    ws.send('hello world');
                });
                ws.on('message', (event) => {
                    ws.close();
                    resolve(event.data);
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 tisunov / InstacabDispatcher / driver-app.js View on Github external
epoch: Math.round(new Date().getTime() / 1000.0)
};

var tripCoordinates = [
  [51.681520, 39.183383],
  [51.675932, 39.169736],
  [51.670715, 39.161153],
  [51.672419, 39.153171],
  [51.675719, 39.143300],
  [51.677901, 39.136691],
  [51.680296, 39.129653],
  [51.683448, 39.122151],
];

var WebSocket = require('faye-websocket'),
    client    = new WebSocket.Client('ws://localhost:9000/');

client.on('open', function(event) {
  console.log('WebSocket client connected');
  
  client.sendWithLog = function(message) {
    console.log('Sending ' + message.messageType);
    console.log(message);
    this.send(JSON.stringify(message));
  };

  client.sendWithLog(login1);
});


client.on('close', function(event) {
  console.log('Connection Closed', event.code, event.reason);
github redcap3000 / crypto-socket / index.js View on Github external
makeSocket: function(url, title, onMessage, send) {
        if (typeof url != "string" || typeof title != "string") {
            return false;
        }
        if (typeof Sockets[title] == "undefined" || !Sockets[title]) {
            Sockets[title] = {};
        }
        Sockets[title] = new WebSocket.Client(url);

        try {
            Sockets[title].on('open', function(event) {
                console.log(title + ' open');
                if (typeof Exchanges[title] == "undefined" && title != "gemini2") {
                    Exchanges[title] = {};
                }
            })
        } catch (error) {
            console.log(error);
            return false;

        }
        try {
            Sockets[title].on('close', function(event) {
                console.log(title + ' close');
github tisunov / InstacabDispatcher / client-app.js View on Github external
region: "Коминтерновский район",
    city: "Воронеж",
    longitude: 39.122151,
    latitude: 51.683448    
  }
};

cancelPickup = {
  messageType: "PickupCanceledClient",
  longitude: 39.122151,
  latitude: 51.683448,
  app: 'client',
};

var WebSocket = require('faye-websocket'),
    client    = new WebSocket.Client('ws://localhost:9000/');

var timeId;

client.on('open', function(event) {
  console.log('WebSocket client connected');
  
  client.sendWithLog = function(message) {
    console.log('Sending ' + message.messageType);
    console.log(message);
    this.send(JSON.stringify(message));
  };

  client.sendWithLog(login);

  if (timeId) clearInterval(timerId);

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