Merge branch 'master' of bitbucket.org:cybafelo/r3-websocket
commit
65c957f3a6
59
index.js
59
index.js
|
@ -2,15 +2,70 @@ const WebSocket = require('ws');
|
|||
const config = require('./config');
|
||||
const http = require('http');
|
||||
|
||||
var server = http.createServer();
|
||||
var wss = null;
|
||||
|
||||
const wss = new WebSocket.Server(
|
||||
var server = http.createServer(
|
||||
|
||||
function(req, res) {
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
|
||||
wss.clients.forEach(
|
||||
function(client){
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
var cache = [];
|
||||
|
||||
res.write(
|
||||
|
||||
JSON.stringify(client,
|
||||
|
||||
function(key, value) {
|
||||
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (cache.indexOf(value) !== -1) {
|
||||
// Duplicate reference found
|
||||
try {
|
||||
// If this value does not reference a parent it can be deduped
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
} catch (error) {
|
||||
// discard key if value cannot be deduped
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Store value in our collection
|
||||
cache.push(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
cache = null;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
res.end();
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
wss = new WebSocket.Server(
|
||||
{
|
||||
server : server,
|
||||
perMessageDeflate: false
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
server.on(
|
||||
'listening',
|
||||
function() {
|
||||
|
|
Loading…
Reference in New Issue