livekit / client-sdk-js

LiveKit browser client SDK (javascript)
https://livekit.io
Apache License 2.0
334 stars 143 forks source link

Room Reconnected event doesn't get emitted #1163

Closed revertiz closed 2 months ago

revertiz commented 2 months ago

Describe the bug

When i have a bad internet connection the room reconnect event is not completely reliable

Reproduction

Reproducibility <50%:

  1. Turn off internet for a longer period, get the reconnecting event
  2. Turn on internet for a short duration (1-3s), get the reconnected event
  3. Turn off internet for a longer period, get the reconnecting event
  4. Turn on internet, i can see other participant, but don't get the reconnected event

Logs

client-ignasp-local.front-4877.pr.meedio.pro-1718225459290.log server-ignasp-local.front-4877.pr.meedio.pro-1718225459290.json

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1
    Memory: 106.47 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    Yarn: 4.0.2 - ~/.yarn/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
    pnpm: 8.14.2 - ~/.nvm/versions/node/v18.17.0/bin/pnpm
  Browsers:
    Brave Browser: 117.1.58.137
    Chrome: 125.0.6422.142
    Safari: 17.4.1
  npmPackages:
    livekit-client: ^2.2.0 => 2.2.0

Severity

annoyance

Additional Information

In the client logs there's my added log "timer ran out roomStateRef.current: disconnected"(timer runs out, because it didn't receive the reconnected event and didn't get cleared). It seems that the room ConnectionState is 'disconnected' even though both participants can see each other.

lukasIO commented 2 months ago

How are you disabling your internet connection? And is your server running locally?

revertiz commented 2 months ago

How are you disabling your internet connection? And is your server running locally?

lukasIO commented 2 months ago

Thanks. In the logs you shared, I can see both

23:50:11.361 livekit-client.esm.mjs:21326 room event reconnected {room: '!NeGhSXJYtaMmIgxgIk:matrix.meedio.pro', roomID: 'RM_o4Tt2VegfDwU', participant: '@cw4s1ohjnb:matrix.meedio.pro:VSIPQLWNPN', pID: 'PA_DJBmpTmFjqGG', event: 'reconnected', …}

and, a little earlier

23:50:11.361 useHandleLivekitReconnection.ts:54 ConnectionStateChanged event connected

which sounds like your logic around this picked up on connectionState changing back to connected

edit: Ah, I see, the second time it doesn't work the same anymore. It seems to get stuck at some point, probably with the PeerConnection status. Will take a closer look

lukasIO commented 2 months ago

This should be fixed as a side effect of https://github.com/livekit/client-sdk-js/pull/1158. However I also opened a separate PR, before realising that, which would address this issue more specifically. I'll leave #1164 as a draft for now. But if you could try with the changes in #1158 applied and see if you can still repro, that would be great!

revertiz commented 2 months ago

This should be fixed as a side effect of #1158. However I also opened a separate PR, before realising that, which would address this issue more specifically. I'll leave #1164 as a draft for now. But if you could try with the changes in #1158 applied and see if you can still repro, that would be great!

Hey, i've tested and can confirm that this PR indeed fixes it: https://github.com/livekit/client-sdk-js/pull/1158. You can close the issue, thank you very much!