This message was deleted.
# helpdesk
s
This message was deleted.
b
I might be missing something, but could it be possible that no
beforeunload
event is triggered with this codebase to disconnect from a room ?
d
hmm, this should be happening automatically as it's a function within our JS SDK: https://github.com/livekit/client-sdk-js/blob/main/src/room/Room.ts#L391 if it's not, it's probably a bug
b
In Next.js, because of how the routing is handled, I think there is a missing piece.
Copy code
useEffect(() => {
    router.events.on("routeChangeStart", handleDisconnect);
    return () => {
      router.events.off("routeChangeStart", handleDisconnect);
    };
  }, []);
I had to implement the following. Id say this could probably be added to the LiveKitRoom Component or something similar.
p
that’s a good point. with the client side router the js sdk won’t pick up the route change. but as this is next specific, best we can probably do is supply a next specific helper method that does exactly what your workaround is doing. However we already try to disconnect on whenever <LiveKitRoom /> unmounts. this should also be happening on client route changes.
@brief-refrigerator-69901 are you seeing this also when navigating to a page that does not have a LiveKitRoom in it? In my tests the LiveKitRoom automatically disconnects when unmounted. Would be super helpful if you could provide a minimal reproduction for this
b
Id need to test some more without my implementation... one of the thing I was seeing is the delay from the other participants window.. still seeing that participant.. for the 10-15mins.. because that "disconnected" participant never sent out the disconnect message. I think this is where everything gets out of sync
@polite-kilobyte-67570, you might be right that it auto disconnects, but the participant never sends the disconnect message to the server, so the server needs to handle that disconnection through the timeout process which I think is around 1-15mins delay. I hope Im making sense for you here 🙂
p
1-15mins definitely sounds too long. the client will attempt to send the leave when dismounting, it’s not guaranteed that it will make it to the server. does the issue disappear entirely with your dicsonnect on route change workaround?
b
Yes, it is instant