Skip to content

Commit

Permalink
Don't register extra timeout callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
malloch committed May 29, 2019
1 parent 980fb15 commit c2932d3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions js/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var command = {
var msg = JSON.parse(text);
if (msg && msg['id'] != null)
command.requests.take(msg['id']);
command.maintain_requests();
command.maintain_requests(false);
if (msg['cmd']) {
var hs = command.handlers[msg['cmd']];
if (hs)
Expand All @@ -34,15 +34,16 @@ var command = {

/* Called to make sure the required number of connections are
* still active. */
maintain_requests: function() {
maintain_requests: function(repeat) {
if (command.ws) {
if (command.ws.is_closed)
command.open_websocket();
}
else if (!command.ws || !command.ws.is_opened)
while (command.requests.contents.length < command.num_requests)
command.message_request();
setTimeout(function() {command.maintain_requests();}, 1000);
if (repeat)
setTimeout(function() {command.maintain_requests(true);}, 1000);
},

/* Register a handler for a particular message address. Returns a
Expand Down Expand Up @@ -80,7 +81,7 @@ var command = {
/* Start the command service. */
start: function() {
command.open_websocket();
setTimeout(function() {command.maintain_requests();}, 100);
setTimeout(function() {command.maintain_requests(true);}, 100);
},

/* Send a message. */
Expand All @@ -105,9 +106,9 @@ var command = {

if (command.num_ws_tries == 10) {
document.title = 'mapperGUI: error connecting to server after 10 tries';
setTimeout(function(){
// document.title = 'mapperGUI (connecting...)';
}, 10000);
// setTimeout(function(){
//// document.title = 'mapperGUI (connecting...)';
// }, 10000);
command.num_ws_tries ++;
return;
}
Expand Down

0 comments on commit c2932d3

Please sign in to comment.