updating main.js

This commit is contained in:
Brad 2014-03-04 10:52:04 -08:00
parent cecef21d4f
commit 8767edd37a

View file

@ -8,7 +8,6 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
var url = [(window.location.protocol == 'https:' ? 'wss' : 'ws'), var url = [(window.location.protocol == 'https:' ? 'wss' : 'ws'),
'://', '://',
window.location.host, window.location.host,
'/',
socket].join('') socket].join('')
this.socket = new WebSocket(url); this.socket = new WebSocket(url);
} else { } else {
@ -30,14 +29,20 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
this.el = el; this.el = el;
} }
this.updateScreen(); if(!this.reqId) {
this.updateScreen();
}
},
stopOutput: function() {
this.stoppingRefresh = true;
}, },
attach: function() { attach: function() {
this.socket.onopen = this.onOpen; this.socket.onopen = this.onOpen;
this.socket.onerror = this.onError; this.socket.onerror = this.onError;
this.socket.onmessage = this.onMessage.bind(this); this.socket.onmessage = this.onMessage.bind(this);
this.socket.onclose = this.onClose; this.socket.onclose = this.onClose;
}, },
updateScreen: function() { updateScreen: function() {
@ -50,7 +55,11 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
} }
} }
requestAnimationFrame(this.updateScreen.bind(this)); if(this.stoppingRefresh) {
this.stoppingRefresh = false;
} else {
window.requestAnimationFrame(this.updateScreen.bind(this));
}
}, },
onOpen: function() { onOpen: function() {
@ -67,7 +76,7 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
onClose: function(e) { onClose: function(e) {
console.log('output websocket closed: ' + JSON.stringify(e)); console.log('output websocket closed: ' + JSON.stringify(e));
//window.location.reload(); window.location.reload();
} }
}; };
@ -80,6 +89,12 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
}, 1000 / 60); }, 1000 / 60);
}; };
window.cancelRequestAnimationFrame = window.cancelRequestAnimationFrame ||
window.cancelWebkitRequestAnimationFrame ||
function(fn) {
window.clearTimeout(fn);
};
})(); })();
;// Format ANSI to HTML ;// Format ANSI to HTML
@ -100,7 +115,7 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
var output = ""; var output = "";
var current = 0; var current = 0;
while (m = this.regex.exec(s)) { while (m = this.regex.exec(s)) {
var part = s.substring(current, m.index+1); var part = s.substring(current, m.index);
current = this.regex.lastIndex; current = this.regex.lastIndex;
var token = s.substr(m.index, this.regex.lastIndex - m.index); var token = s.substr(m.index, this.regex.lastIndex - m.index);
@ -112,9 +127,9 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
switch (code) { switch (code) {
case 'm': case 'm':
case '0m': case '0m':
var len = styles.length; var len = this.styles.length;
for (var i=0; i < len; i++) { for (var i=0; i < len; i++) {
styles.pop(); this.styles.pop();
post += "</span>" post += "</span>"
} }
break; break;
@ -135,7 +150,7 @@ if(typeof(Drone) === 'undefined') { Drone = {}; }
} }
if (pre !== "") { if (pre !== "") {
styles.push(pre); this.styles.push(pre);
} }
output += part + pre + post; output += part + pre + post;