[react-native] enable react devtools from JavascriptCore

This commit is contained in:
Jared Forsyth 2015-07-23 16:56:23 -07:00
parent fa6c4dde65
commit c90d79fe01
1 changed files with 14 additions and 0 deletions

View File

@ -17,7 +17,19 @@ function attachToServer(server, path) {
}); });
var clients = []; var clients = [];
function sendSpecial(message) {
clients.forEach(function (cn) {
try {
cn.send(JSON.stringify(message));
} catch(e) {
console.warn('WARN: ' + e.message);
}
});
}
wss.on('connection', function(ws) { wss.on('connection', function(ws) {
var id = Math.random().toString(15).slice(10, 20);
sendSpecial({$open: id});
clients.push(ws); clients.push(ws);
var allClientsExcept = function(ws) { var allClientsExcept = function(ws) {
@ -26,10 +38,12 @@ function attachToServer(server, path) {
ws.onerror = function() { ws.onerror = function() {
clients = allClientsExcept(ws); clients = allClientsExcept(ws);
sendSpecial({$error: id});
}; };
ws.onclose = function() { ws.onclose = function() {
clients = allClientsExcept(ws); clients = allClientsExcept(ws);
sendSpecial({$close: id});
}; };
ws.on('message', function(message) { ws.on('message', function(message) {