mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
[ReactNative] Bring Chrome debugger to OSS. Part 2
This commit is contained in:
41
packager/webSocketProxy.js
Normal file
41
packager/webSocketProxy.js
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user