|
|
@ -1609,22 +1609,27 @@ function tr(key) { return _tr[key] || '?'+key+'?'; } |
|
|
|
w.startScanning = startScanning; |
|
|
|
w.startScanning = startScanning; |
|
|
|
})(window.WiFi = {}); |
|
|
|
})(window.WiFi = {}); |
|
|
|
/** Handle connections */ |
|
|
|
/** Handle connections */ |
|
|
|
var Conn = (function() { |
|
|
|
var Conn = (function () { |
|
|
|
var ws; |
|
|
|
var ws; |
|
|
|
var heartbeatTout; |
|
|
|
var heartbeatTout; |
|
|
|
var pingIv; |
|
|
|
var pingIv; |
|
|
|
var xoff = false; |
|
|
|
var xoff = false; |
|
|
|
var autoXoffTout; |
|
|
|
var autoXoffTout; |
|
|
|
|
|
|
|
var reconTout; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var pageShown = false; |
|
|
|
|
|
|
|
|
|
|
|
function onOpen(evt) { |
|
|
|
function onOpen(evt) { |
|
|
|
console.log("CONNECTED"); |
|
|
|
console.log("CONNECTED"); |
|
|
|
|
|
|
|
doSend("i"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onClose(evt) { |
|
|
|
function onClose(evt) { |
|
|
|
console.warn("SOCKET CLOSED, code "+evt.code+". Reconnecting..."); |
|
|
|
console.warn("SOCKET CLOSED, code " + evt.code + ". Reconnecting..."); |
|
|
|
setTimeout(function() { |
|
|
|
clearTimeout(reconTout); |
|
|
|
|
|
|
|
reconTout = setTimeout(function () { |
|
|
|
init(); |
|
|
|
init(); |
|
|
|
}, 200); |
|
|
|
}, 2000); |
|
|
|
// this happens when the buffer gets fucked up via invalid unicode.
|
|
|
|
// this happens when the buffer gets fucked up via invalid unicode.
|
|
|
|
// we basically use polling instead of socket then
|
|
|
|
// we basically use polling instead of socket then
|
|
|
|
} |
|
|
|
} |
|
|
@ -1637,12 +1642,18 @@ var Conn = (function() { |
|
|
|
case 'T': |
|
|
|
case 'T': |
|
|
|
case 'S': |
|
|
|
case 'S': |
|
|
|
Screen.load(evt.data); |
|
|
|
Screen.load(evt.data); |
|
|
|
|
|
|
|
if(!pageShown) { |
|
|
|
|
|
|
|
showPage(); |
|
|
|
|
|
|
|
pageShown = true; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case '-': |
|
|
|
case '-': |
|
|
|
//console.log('xoff');
|
|
|
|
//console.log('xoff');
|
|
|
|
xoff = true; |
|
|
|
xoff = true; |
|
|
|
autoXoffTout = setTimeout(function(){xoff=false;}, 250); |
|
|
|
autoXoffTout = setTimeout(function () { |
|
|
|
|
|
|
|
xoff = false; |
|
|
|
|
|
|
|
}, 250); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case '+': |
|
|
|
case '+': |
|
|
@ -1652,7 +1663,7 @@ var Conn = (function() { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
heartbeat(); |
|
|
|
heartbeat(); |
|
|
|
} catch(e) { |
|
|
|
} catch (e) { |
|
|
|
console.error(e); |
|
|
|
console.error(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1691,24 +1702,16 @@ var Conn = (function() { |
|
|
|
showPage(); |
|
|
|
showPage(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
heartbeat(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws = new WebSocket("ws://"+_root+"/term/update.ws"); |
|
|
|
clearTimeout(reconTout); |
|
|
|
|
|
|
|
clearTimeout(heartbeatTout); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws = new WebSocket("ws://" + _root + "/term/update.ws"); |
|
|
|
ws.onopen = onOpen; |
|
|
|
ws.onopen = onOpen; |
|
|
|
ws.onclose = onClose; |
|
|
|
ws.onclose = onClose; |
|
|
|
ws.onmessage = onMessage; |
|
|
|
ws.onmessage = onMessage; |
|
|
|
|
|
|
|
|
|
|
|
console.log("Opening socket."); |
|
|
|
console.log("Opening socket."); |
|
|
|
|
|
|
|
|
|
|
|
// Ask for initial data
|
|
|
|
|
|
|
|
$.get('http://'+_root+'/term/init', function(resp, status) { |
|
|
|
|
|
|
|
if (status !== 200) location.reload(true); |
|
|
|
|
|
|
|
console.log("Data received!"); |
|
|
|
|
|
|
|
Screen.load(resp); |
|
|
|
|
|
|
|
heartbeat(); |
|
|
|
heartbeat(); |
|
|
|
|
|
|
|
|
|
|
|
showPage(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function heartbeat() { |
|
|
|
function heartbeat() { |
|
|
@ -1718,9 +1721,9 @@ var Conn = (function() { |
|
|
|
|
|
|
|
|
|
|
|
function heartbeatFail() { |
|
|
|
function heartbeatFail() { |
|
|
|
console.error("Heartbeat lost, probing server..."); |
|
|
|
console.error("Heartbeat lost, probing server..."); |
|
|
|
pingIv = setInterval(function() { |
|
|
|
pingIv = setInterval(function () { |
|
|
|
console.log("> ping"); |
|
|
|
console.log("> ping"); |
|
|
|
$.get('http://'+_root+'/system/ping', function(resp, status) { |
|
|
|
$.get('http://' + _root + '/system/ping', function (resp, status) { |
|
|
|
if (status == 200) { |
|
|
|
if (status == 200) { |
|
|
|
clearInterval(pingIv); |
|
|
|
clearInterval(pingIv); |
|
|
|
console.info("Server ready, reloading page..."); |
|
|
|
console.info("Server ready, reloading page..."); |
|
|
@ -1729,7 +1732,7 @@ var Conn = (function() { |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
timeout: 100, |
|
|
|
timeout: 100, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, 500); |
|
|
|
}, 1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|