[ReactNative] Bring Chrome debugger to OSS. Part 2

This commit is contained in:
Alex Kotliarskyi
2015-03-19 12:10:41 -07:00
parent da2b122e21
commit 8dea55618d
5 changed files with 229 additions and 2 deletions

View File

@@ -0,0 +1,41 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*/
'use strict';
var WebSocketServer = require('ws').Server;
function attachToServer(server, path) {
var wss = new WebSocketServer({
server: server,
path: path
});
var clients = [];
wss.on('connection', function(ws) {
clients.push(ws);
var allClientsExcept = function(ws) {
return clients.filter(function(cn) { return cn !== ws; });
};
ws.onerror = function() {
clients = allClientsExcept(ws);
};
ws.onclose = function() {
clients = allClientsExcept(ws);
};
ws.on('message', function(message) {
allClientsExcept(ws).forEach(function(cn) {
cn.send(message);
});
});
});
}
module.exports = {
attachToServer: attachToServer
};