Closed draeder closed 2 years ago
It looks like "timeout" and "left" events did eventually fire, but I'm not sure when they happened.
I've had an instance running since I posted this issue a couple days ago, and a client connection running against it since then also. I just checked the logging, and do see both events. First the "left" event, followed by the "timeout" event.
I was hoping to use it as a way to see if someone closed their browser tab. Since the remote peer addresses change every time a tab reloads, I expected to see the "left" event upon browser close / reload. Is this an incorrect assumption?
@draeder if the timeout
option is not passed, the "unseen peer" timeout defaults to 5 minutes.
If you want peers to know when the other peer has closed the browser tab then you should use the beforeunload event in the client and explicitly call b.destroy()
when that happens. This should hopefully cause the client to send the "left" message as the browser tab is closed, but I haven't tested this myself. Code to try this:
window.addEventListener('beforeunload', function (e) {
b.destroy();
delete e['returnValue'];
});
In this code b
should be your bugout instance. Let me know if it works for you.
PS you could also just shorten the timeout
to e.g. 30 seconds = 30000
.
I've been experimenting with the beforeunload event you suggested using, but it doesn't seem to work. I also set the timeout to 15 seconds b.heartbeat(15000)
, but did not get the "left" or timeout" events for about 50 minutes. If it matters, I'm testing this in Chrome.
@draeder ok thanks for reporting this and for the detail. Seems like the "left" event doesn't make it out before the Bugout node is destroyed. Will investigate when I get some time.
Within the past couple of days, the "left" and "timeout" events appear to be occurring in a more timely fashion. But they still don't coincide with the passed timeout
option.
I have the following code:
I'm pretty sure I'm handling the "left" event correctly--please correct me if I'm not.
I'm wondering if the recent refactor affected it because I never receive the event. This is also true of the "timeout" event, when I have
heartbeat
enabled.Using
b.on("connections", function(c){ console.log("Connections: " + c) })
shows the correct connections count.