Skip to content

Commit

Permalink
stop reconnecting websocket after NetworkAdapter.destroy() was called (
Browse files Browse the repository at this point in the history
  • Loading branch information
chschnell authored Dec 20, 2024
1 parent 8f5d58b commit 0612c6c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/browser/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function NetworkAdapter(url, bus, id)
this.reconnect_interval = 10000;
this.last_connect_attempt = Date.now() - this.reconnect_interval;
this.send_queue_limit = 64;
this.destroyed = false;

this.bus.register("net" + this.id + "-send", function(data)
{
Expand All @@ -44,8 +45,11 @@ NetworkAdapter.prototype.handle_close = function(e)
{
//console.log("onclose", e);

this.connect();
setTimeout(this.connect.bind(this), this.reconnect_interval);
if(!this.destroyed)
{
this.connect();
setTimeout(this.connect.bind(this), this.reconnect_interval);
}
};

NetworkAdapter.prototype.handle_open = function(e)
Expand All @@ -67,6 +71,7 @@ NetworkAdapter.prototype.handle_error = function(e)

NetworkAdapter.prototype.destroy = function()
{
this.destroyed = true;
if(this.socket)
{
this.socket.close();
Expand Down

0 comments on commit 0612c6c

Please sign in to comment.