From 8767edd37a70bf75533edd9a5df476f20ffe03ef Mon Sep 17 00:00:00 2001 From: Brad Date: Tue, 4 Mar 2014 10:52:04 -0800 Subject: [PATCH] updating main.js --- cmd/droned/assets/js/main.js | 37 +++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/cmd/droned/assets/js/main.js b/cmd/droned/assets/js/main.js index d16ae68f0..5863899f2 100644 --- a/cmd/droned/assets/js/main.js +++ b/cmd/droned/assets/js/main.js @@ -8,7 +8,6 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } var url = [(window.location.protocol == 'https:' ? 'wss' : 'ws'), '://', window.location.host, - '/', socket].join('') this.socket = new WebSocket(url); } else { @@ -30,14 +29,20 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } this.el = el; } - this.updateScreen(); + if(!this.reqId) { + this.updateScreen(); + } + }, + + stopOutput: function() { + this.stoppingRefresh = true; }, attach: function() { - this.socket.onopen = this.onOpen; - this.socket.onerror = this.onError; + this.socket.onopen = this.onOpen; + this.socket.onerror = this.onError; this.socket.onmessage = this.onMessage.bind(this); - this.socket.onclose = this.onClose; + this.socket.onclose = this.onClose; }, 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() { @@ -67,7 +76,7 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } onClose: function(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); }; + window.cancelRequestAnimationFrame = window.cancelRequestAnimationFrame || + window.cancelWebkitRequestAnimationFrame || + function(fn) { + window.clearTimeout(fn); + }; + })(); ;// Format ANSI to HTML @@ -100,7 +115,7 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } var output = ""; var current = 0; 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; var token = s.substr(m.index, this.regex.lastIndex - m.index); @@ -112,9 +127,9 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } switch (code) { case 'm': case '0m': - var len = styles.length; + var len = this.styles.length; for (var i=0; i < len; i++) { - styles.pop(); + this.styles.pop(); post += "" } break; @@ -135,7 +150,7 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } } if (pre !== "") { - styles.push(pre); + this.styles.push(pre); } output += part + pre + post;