How to use sockjs - 10 common examples

To help you get started, we’ve selected a few sockjs 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 dbusjs / node-dbus-next / examples / dbusproxy / server.js View on Github external
const http = require('http');
const sockjs = require('sockjs');
const node_static = require('node-static');
const dbus = require('../../index');

// 1. Echo sockjs server
var sockjs_opts = {
  sockjs_url: 'https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js'
};

var sockjs_echo = sockjs.createServer(sockjs_opts);
sockjs_echo.on('connection', function(conn) {
  var dbusConn = dbus.sessionBus().connection;
  conn.on('data', function(message) {
    //conn.write(message);
    try {
      //console.log('about to parse', message)
      var o = JSON.parse(message);
      //console.log('after parse', [o]);
      try {
        dbusConn.message(o);
      } catch (ee) {
        console.log(ee);
      }
      //console.log('sent to dbus');
    } catch (e) {}
  });
github squaremo / dolt / server / server.js View on Github external
'use strict';

var express = require('express');
var mu = require('mu2');
var when = require('when');
var Session = require('./session');
var misc = require('./misc');
var SockJS = require('sockjs');

var path = process.env.PWD + "/../client";
var host = process.env.VCAP_APP_HOST || '0.0.0.0';
var port = process.env.VCAP_APP_PORT || 8000;

var app = express();
var server = require('http').createServer(app);
var sockjs = SockJS.createServer();
sockjs.installHandlers(server, {prefix: '/eval'});

app.configure(function(){
    app.use(express.logger());
    app.use(app.router);
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
    app.use(express.static(path));
});

// Utility to hook a promise up to a SockJS connection
function respond(connection, p) {
    when(p, function(out) {
        connection.write(out);
    }, function (err) {
        if (err.stack) { console.log(err.stack); }
        connection.close(500, err.toString()+"\r\n");
github primus / primus / transformers / sockjs / server.js View on Github external
'Please run the following command and try again:',
        '',
        '  npm install --save permessage-deflate',
        ''
      ].forEach((line) => console.error(`Primus: ${line}`));

      throw new PrimusError(
        'Missing dependencies for transformer: "sockjs"',
        this.primus
      );
    }
  }

  if (prefix.charAt(prefix.length - 1) !== '/') prefix += '(?:[^/]+)?';

  this.service = sockjs.createServer();

  //
  // We've received a new connection, create a new Spark. The Spark will
  // automatically announce it self as a new connection once it's created (after
  // the next tick).
  //
  this.service.on('connection', (socket) => {
    const headers = socket.headers.via;

    headers.via = headers._via;
    socket.headers.via = null;

    const spark = new this.Spark(
        headers                      // HTTP request headers.
      , socket                       // IP address location.
      , url.parse(socket.url).query  // Optional query string.
github Graphite-Docs / graphite / node_modules / webpack-dev-server / lib / Server.js View on Github external
const returnValue = this.listeningApp.listen(port, hostname, (err) => {
    const sockServer = sockjs.createServer({
      // Use provided up-to-date sockjs-client
      sockjs_url: '/__webpack_dev_server__/sockjs.bundle.js',
      // Limit useless logs
      log(severity, line) {
        if (severity === 'error') {
          log(line);
        }
      }
    });

    sockServer.on('connection', (conn) => {
      if (!conn) return;
      if (!this.checkHost(conn.headers)) {
        this.sockWrite([conn], 'error', 'Invalid Host header');
        conn.close();
        return;
github pump-io / pump.io / lib / pumpsocket.js View on Github external
if (err) {
                                conn.log.error({err: err}, "Error finishing object");
                            } else {
                                tosend = _.pick(msg, "cmd", "url");
                                tosend.activity = act;
                                conn.log.info({activity: msg.activity.id}, "Delivering activity");
                                conn.write(JSON.stringify(tosend));
                            }
                        }
                    );
                });
            }
        }
    });

    server = sockjs.createServer(options);

    // Note this is a utility for us; SockJS uses the log() function
    // we pass in through options

    server.log = slog;

    server.log.debug("Setting up sockjs server.");

    // snatch the provider

    server.provider = app.provider;

    server.on("connection", function(conn) {
        if (conn === null) {
            server.log.info("Connection event without a connection.");
            return;
github sx1989827 / DOClever / Desktop / node_modules / sockjs / examples / multiplex / server.js View on Github external
var express             = require('express');
var sockjs              = require('sockjs');

var websocket_multiplex = require('websocket-multiplex');


// 1. Setup SockJS server
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
var service = sockjs.createServer(sockjs_opts);


// 2. Setup multiplexing
var multiplexer = new websocket_multiplex.MultiplexServer(service);

var ann = multiplexer.registerChannel('ann');
ann.on('connection', function(conn) {
    conn.write('Ann says hi!');
    conn.on('data', function(data) {
        conn.write('Ann nods: ' + data);
    });
});

var bob = multiplexer.registerChannel('bob');
bob.on('connection', function(conn) {
    conn.write('Bob doesn\'t agree.');
github lintopher0315 / Quick-Math / node_modules / webpack-dev-server / lib / Server.js View on Github external
const webpackDevMiddleware = require('webpack-dev-middleware');

const createLogger = require('./utils/createLogger');
const createCertificate = require('./utils/createCertificate');

const validateOptions = require('schema-utils');
const schema = require('./options.json');

// Workaround for sockjs@~0.3.19
// sockjs will remove Origin header, however Origin header is required for checking host.
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
{
  // eslint-disable-next-line global-require
  const SockjsSession = require('sockjs/lib/transport').Session;
  const decorateConnection = SockjsSession.prototype.decorateConnection;
  SockjsSession.prototype.decorateConnection = function(req) {
    decorateConnection.call(this, req);
    const connection = this.connection;
    if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) {
      connection.headers.origin = req.headers.origin;
    }
  };
}

// Workaround for node ^8.6.0, ^9.0.0
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
// breaking connection when certificate is not signed with prime256v1
// change it to auto allows OpenSSL to select the curve automatically
// See https://github.com/nodejs/node/issues/16196 for more infomation
if (semver.satisfies(process.version, '8.6.0 - 9')) {
  tls.DEFAULT_ECDH_CURVE = 'auto';
}
github lintopher0315 / Quick-Math / node_modules / webpack-dev-server / lib / Server.js View on Github external
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');

const createLogger = require('./utils/createLogger');
const createCertificate = require('./utils/createCertificate');

const validateOptions = require('schema-utils');
const schema = require('./options.json');

// Workaround for sockjs@~0.3.19
// sockjs will remove Origin header, however Origin header is required for checking host.
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
{
  // eslint-disable-next-line global-require
  const SockjsSession = require('sockjs/lib/transport').Session;
  const decorateConnection = SockjsSession.prototype.decorateConnection;
  SockjsSession.prototype.decorateConnection = function(req) {
    decorateConnection.call(this, req);
    const connection = this.connection;
    if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) {
      connection.headers.origin = req.headers.origin;
    }
  };
}

// Workaround for node ^8.6.0, ^9.0.0
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
// breaking connection when certificate is not signed with prime256v1
// change it to auto allows OpenSSL to select the curve automatically
// See https://github.com/nodejs/node/issues/16196 for more infomation
if (semver.satisfies(process.version, '8.6.0 - 9')) {
  tls.DEFAULT_ECDH_CURVE = 'auto';
github eschirtz / Computer-Science-Series / node_modules / webpack-dev-server / lib / Server.js View on Github external
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');

const createLogger = require('./utils/createLogger');
const createCertificate = require('./utils/createCertificate');

const validateOptions = require('schema-utils');
const schema = require('./options.json');

// Workaround for sockjs@~0.3.19
// sockjs will remove Origin header, however Origin header is required for checking host.
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
{
  // eslint-disable-next-line global-require
  const SockjsSession = require('sockjs/lib/transport').Session;
  const decorateConnection = SockjsSession.prototype.decorateConnection;
  SockjsSession.prototype.decorateConnection = function(req) {
    decorateConnection.call(this, req);
    const connection = this.connection;
    if (connection.headers && !('origin' in connection.headers) && 'origin' in req.headers) {
      connection.headers.origin = req.headers.origin;
    }
  };
}

// Workaround for node ^8.6.0, ^9.0.0
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
// breaking connection when certificate is not signed with prime256v1
// change it to auto allows OpenSSL to select the curve automatically
// See https://github.com/nodejs/node/issues/16196 for more infomation
if (semver.satisfies(process.version, '8.6.0 - 9')) {
  tls.DEFAULT_ECDH_CURVE = 'auto';
github flaviuse / mern-authentication / client / node_modules / webpack-dev-server / lib / Server.js View on Github external
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');

const createLogger = require('./utils/createLogger');
const createCertificate = require('./utils/createCertificate');

const validateOptions = require('schema-utils');
const schema = require('./options.json');

// Workaround for sockjs@~0.3.19
// sockjs will remove Origin header, however Origin header is required for checking host.
// See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
{
  // eslint-disable-next-line global-require
  const SockjsSession = require('sockjs/lib/transport').Session;
  const decorateConnection = SockjsSession.prototype.decorateConnection;
  SockjsSession.prototype.decorateConnection = function(req) {
    decorateConnection.call(this, req);
    const connection = this.connection;
    if (
      connection.headers &&
      !('origin' in connection.headers) &&
      'origin' in req.headers
    ) {
      connection.headers.origin = req.headers.origin;
    }
  };
}

// Workaround for node ^8.6.0, ^9.0.0
// DEFAULT_ECDH_CURVE is default to prime256v1 in these version
// breaking connection when certificate is not signed with prime256v1

sockjs

SockJS-node is a server counterpart of SockJS-client a JavaScript library that provides a WebSocket-like object in the browser. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication

MIT
Latest version published 3 years ago

Package Health Score

76 / 100
Full package analysis