Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
next();
}));
});
});
app.listen(cfg.port, '0.0.0.0');
var wsServer = new WebSocketServer({
httpServer: app,
// Firefox 7 alpha has a bug that drops the
// connection on large fragmented messages
fragmentOutgoingMessages: false
});
var router = new WebSocketRouter();
router.attachServer(wsServer);
function originIsAllowed(url) {
// put logic here to detect whether the specified origin is allowed.
return true;
}
/*
wsServer.on('request', function(request) {
var url = request.httpRequest.url;
if (!originIsAllowed(url)) {
request.reject();
console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
return;
}
disconnected: 'cms:client:disconnect'
}
};
//Store a list of the connected clients
connections = [];
var serverConfig = {
httpServer: app,
};
wsserver = new WebSocketServer();
wsserver.mount(serverConfig);
router = new WebSocketRouter();
router.attachServer(wsserver);
/**
* Echo Protocol
*/
router.mount('*', 'echo-protocol', function (request) {
console.log('mounted to echo protocol');
var conn = request.accept(request.origin);
conn.on('message', function (message) {
console.log('routed message', util.inspect(message, {colors: true}));
});
conn.send('hey');
});
var serverConfig = {
httpServer: server,
autoAcceptConnections: false
};
/**
* Create Socket Server
* @type {WebSocketServer}
*/
var wsserver = jsWebSocketServer(serverConfig).getInstance();
var wsrouter = new WebSocketRouter();
wsrouter.attachServer(wsserver);
/**
* On Connect
*/
wsserver.on('connect', function (connection) {
connection.send('WebSocketServer: Connected!');
console.log('Connected to WebSocket Server!');
});
/**
* On Close
*/
wsserver.on('close', function (connection, reason, description) {
connection.send('WebSocketServer: Disconnected!');
console.log('Disconnected to WebSocket Server!', reason, description);
});