Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {}
});
'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");
'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.
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;
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;
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.');
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);
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) {
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;
};