Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor livekit disconnect to use an effect hook. #1925

Merged
merged 6 commits into from
Nov 28, 2023

Conversation

toger5
Copy link
Contributor

@toger5 toger5 commented Nov 28, 2023

No description provided.

Signed-off-by: Timo K <toger5@hotmail.de>
@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (712f320) 24.67% compared to head (8b09ad4) 24.67%.

Additional details and impacted files
@@           Coverage Diff            @@
##           livekit    #1925   +/-   ##
========================================
  Coverage    24.67%   24.67%           
========================================
  Files           48       48           
  Lines         2383     2383           
  Branches       438      438           
========================================
  Hits           588      588           
  Misses        1744     1744           
  Partials        51       51           
Flag Coverage Δ
unittests 24.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 110 to 118
const cleanup = useCallback(() => {
if (connState === ConnectionState.Connected) {
livekitRoom?.disconnect();
}
}, [livekitRoom, connState]);

useEffect(() => {
return cleanup;
}, [cleanup, livekitRoom]);
Copy link
Contributor

@daniel-abramov daniel-abramov Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that:

  1. This clean-up function may be called multiple times.
  2. The connection state could also be Reconnecting or Connecting in which case the disconnect() will not be called (meaning that we will connect to the room despite unmounting the ActiveCall leading to an unexpected bug for this edge-case).

I think the cleanest way to fix the problem is to do a clean effect that just disconnects the room on unmount without any further actions and checks (I don't think we need connState here), similarly to how LiveKit does it. I checked the LiveKit Meet example and how they do it. They use the LiveKitRoom component that relies on LkRoomContext. Here is how the clean-up is done: link which is just a typical React idiom for these sort of cases. Are there any strong reasons why we don't want to do it this way? 🙂

Copy link
Contributor Author

@toger5 toger5 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this initially. But was seeing it beeing called in the beginning, thats why I added: if (connState === ConnectionState.Connected) {. But that was because i let copilot + tooling add the dependencies...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now use exactly what you propose.

Signed-off-by: Timo K <toger5@hotmail.de>
(we had an error because onLeave gets called with the button)

Signed-off-by: Timo K <toger5@hotmail.de>
Signed-off-by: Timo K <toger5@hotmail.de>
@toger5 toger5 merged commit db859d4 into livekit Nov 28, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants