Skip to content

Commit

Permalink
potential fix for unlimited waiting.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeken committed Nov 24, 2023
1 parent 89d28f7 commit c55b729
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class YarrboardClient
this.messageTimeout = 5000;

this.socket_retries = 0;
this.retry_time = 0;
this.retry_count = 0;
this.last_heartbeat = 0;
this.heartbeat_rate = 1000;
this.ota_started = false;
Expand Down Expand Up @@ -225,7 +225,7 @@ class YarrboardClient
//we are connected, reload
this.closed = false;
this.socket_retries = 0;
this.retry_time = 0;
this.retry_count = 0;
this.last_heartbeat = Date.now();
this.ota_started = false;
this.lastMessageId = 0;
Expand Down Expand Up @@ -356,17 +356,21 @@ class YarrboardClient
if (this.ws.readyState == ws.w3cwebsocket.CONNECTING)
{
console.log(`waiting for connection`);

this.retry_time++;

//tee it up.
setTimeout(this._retryConnection.bind(this), 1000);

return;
this.retry_count++;

//give it a little bit.
if (this.retry_count < 5)
{
setTimeout(this._retryConnection.bind(this), 1000);
return;
}
}

this.ws.close();
delete this

//keep track of stuff.
this.retry_time = 0;
this.retry_count = 0;
this.socket_retries++;

//reconnect!
Expand Down

0 comments on commit c55b729

Please sign in to comment.