Commit 86ba7b9e authored by D1plo1d's avatar D1plo1d

Throttling the DOM writes of pronserve inspector and stopping dom writes...

Throttling the DOM writes of pronserve inspector and stopping dom writes entirely when the window looses focus.
parent ad4c7153
console.log("w00t!"); (function() {
var $console;
var $console; var windowFocus;
var connect = function() { $(window).focus(function() {
windowFocus = true;
if ($console) $console.append("Window refocused, restarting log.\n");
$(".focus-lost-overlay").addClass("out").removeClass("in");
}).blur(function() {
windowFocus = false;
if ($console) $console.append("Window's focus, lost stopping logging...\n");
$(".focus-lost-overlay").addClass("in").removeClass("out");
}.debounce());
var connect = function() {
// Let us open a web socket // Let us open a web socket
var url = "ws://localhost:8888/socket?user=admin&password=admin"; var url = "ws://localhost:8888/socket?user=admin&password=admin";
console.log(url); console.log(url);
...@@ -10,25 +21,28 @@ var connect = function() { ...@@ -10,25 +21,28 @@ var connect = function() {
$(function () { $(function () {
$consoleWrapper = $(".console"); $consoleWrapper = $(".console");
$console = $(".console pre"); $console = $(".console pre");
$console.html("Connecting...") $console.html("Connecting...\n")
onConnect(ws) onConnect(ws)
}); });
}; };
var updateSensors = function() { var updateSensorsUi = function() {
$(".sensors .val").each(function() { $(".sensors .val").each(function() {
$(this).html($(this).data("val")||"xx.x"); $(this).html($(this).data("val")||"xx.x");
}) })
}.throttle(800); }.throttle(800);
var graph = null; var graph = null;
var graphData = []; var graphData = [];
var graphResolution = 40; var graphResolution = 40;
var updateGraph = function(current) { var updateGraphData = function(current) {
current.time = Date.now(); current.time = Date.now();
if(graphData.length == graphResolution) graphData.shift(); if(graphData.length == graphResolution) graphData.shift();
graphData.push(current); graphData.push(current);
}
var updateGraphUi = function(current) {
if(graph == null) if(graph == null)
{ {
graph = new Morris.Line({ graph = new Morris.Line({
...@@ -55,12 +69,21 @@ var updateGraph = function(current) { ...@@ -55,12 +69,21 @@ var updateGraph = function(current) {
{ {
graph.setData(graphData); graph.setData(graphData);
} }
} }
var onConnect = function(ws) { var updateUi = function(msg) {
if(windowFocus == false) return;
updateSensorsUi();
updateGraphUi();
$console.append($console.data("toBeWritten"));
$console.data("toBeWritten", "");
$consoleWrapper.scrollTop($console.innerHeight());
}
var onConnect = function(ws) {
ws.onopen = function() ws.onopen = function()
{ {
$console.append("\nConnected."); $console.append("Connected.\n");
// Web Socket is connected, send data using send() // Web Socket is connected, send data using send()
}; };
...@@ -78,25 +101,29 @@ var onConnect = function(ws) { ...@@ -78,25 +101,29 @@ var onConnect = function(ws) {
values[name] = val; values[name] = val;
$("."+name+" .val").data("val", val.format(1)) $("."+name+" .val").data("val", val.format(1))
} }
updateSensors(); if(windowFocus)
updateGraph(values); {
var previous = $console.data("toBeWritten") || "";
$console.data("toBeWritten", previous + evt.data + "\n");
}
updateGraphData(values);
requestAnimationFrame(updateUi);
} }
$console.append("\n"+evt.data);
$consoleWrapper.scrollTop($console.innerHeight());
}; };
ws.onclose = function() ws.onclose = function()
{ {
// websocket is closed. // websocket is closed.
$console.append("\nConnection closed."); $console.append("\nConnection closed.");
}; };
}; };
if ("WebSocket" in window) if ("WebSocket" in window)
{ {
connect(); connect();
} }
else else
{ {
// The browser doesn't support WebSocket // The browser doesn't support WebSocket
alert("Error: WebSocket NOT supported by your Browser!"); alert("Error: WebSocket NOT supported by your Browser!");
} }
\ No newline at end of file })();
\ No newline at end of file
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<body> <body>
<div class="container"> <div class="container-fluid">
<div class="row"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<h1> <h1>
Pronserve Inspector Pronserve Inspector
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
</div> </div>
<div class="focus-lost-overlay modal-backdrop fade out"></div>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script> <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sugar/1.3.9/sugar.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/sugar/1.3.9/sugar.min.js"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment