Updates from Fri July 17th

This commit is contained in:
Spencer Ahrens 2015-07-17 14:14:30 +02:00
commit 0e7ebfeec5
1 changed files with 40 additions and 27 deletions

View File

@ -27,6 +27,11 @@ window.onbeforeunload = function() {
}
};
// Alias native implementations needed by the debugger before platform-specific
// implementations are loaded into the global namespace
var debuggerSetTimeout = window.setTimeout;
var DebuggerWebSocket = window.WebSocket;
function setStatus(status) {
document.getElementById('status').innerHTML = status;
}
@ -58,9 +63,10 @@ var messageHandlers = {
sendReply(JSON.stringify(returnValue));
}
}
}
};
var ws = new WebSocket('ws://' + window.location.host + '/debugger-proxy');
function connectToDebuggerProxy() {
var ws = new DebuggerWebSocket('ws://' + window.location.host + '/debugger-proxy');
ws.onopen = function() {
if (sessionID) {
@ -69,25 +75,32 @@ ws.onopen = function() {
} else {
setStatus('Waiting, press ⌘R in simulator to reload and connect');
}
}
};
ws.onmessage = function(message) {
var object = JSON.parse(message.data);
var sendReply = function(result) {
ws.send(JSON.stringify({replyID: object.id, result: result}));
}
};
var handler = messageHandlers[object.method];
if (handler) {
handler(object, sendReply);
} else {
console.warn('Unknown method: ' + object.method);
}
}
};
ws.onclose = function() {
setStatus('Disconnected from proxy. Is node server running?');
setStatus('Disconnected from proxy. Attempting reconnection. Is node server running?');
sessionID = null;
window.localStorage.removeItem('sessionID');
debuggerSetTimeout(connectToDebuggerProxy, 100);
};
}
connectToDebuggerProxy();
function loadScript(src, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';