How to use the sockjs.createServer function in sockjs

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 sockjs / sockjs-client / tests / support / sockjs_app.js View on Github external
d.slice(0, 64) +
                  ((d.length > 64) ? '...' : ''));
      conn.write(m);
    });
  });

  var sjs_close = sockjs.createServer(opts);
  sjs_close.on('connection', function(conn) {
    debug('    [+] close open    ' + conn);
    conn.close(3000, 'Go away!');
    conn.on('close', function() {
      debug('    [-] close close   ' + conn);
    });
  });

  var sjs_ticker = sockjs.createServer(opts);
  sjs_ticker.on('connection', function(conn) {
    debug('    [+] ticker open   ' + conn);
    var tref;
    var schedule = function() {
      conn.write('tick!');
      tref = setTimeout(schedule, 1000);
    };
    tref = setTimeout(schedule, 1000);
    conn.on('close', function() {
      clearTimeout(tref);
      debug('    [-] ticker close   ' + conn);
    });
  });

  var broadcast = {};
  var sjs_broadcast = sockjs.createServer(opts);
github sockjs / sockjs-client / tests / support / sockjs_app.js View on Github external
exports.install = function(opts, server) {
  var sjs_echo = sockjs.createServer(opts);
  sjs_echo.on('connection', function(conn) {
    debug('    [+] echo open    ' + conn);
    conn.on('close', function() {
      debug('    [-] echo close   ' + conn);
    });
    conn.on('data', function(m) {
      var d = JSON.stringify(m);
      debug('    [ ] echo message ' + conn,
                  d.slice(0, 64) +
                  ((d.length > 64) ? '...' : ''));
      conn.write(m);
    });
  });

  var sjs_close = sockjs.createServer(opts);
  sjs_close.on('connection', function(conn) {
github iliakan / chat / socket / index.js View on Github external
module.exports = function(sessionConfig) {

  var server = sockjs.createServer({
    sockjs_url: "http://cdn.sockjs.org/sockjs-0.3.min.js",
    log: log.log.bind(log)
  });

  server.on('connection', function(connection) {
    connection = new Connection(connection, sessionConfig);

    connection.on('message', function(message) {
      log.debug(message);
    });
  });

  return server;
};

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