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

fix: prevent auto-dropping already accepted or rejected calls #1619

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

myandrienko
Copy link
Contributor

@myandrienko myandrienko commented Dec 11, 2024

This PR compliments https://github.com/GetStream/chat/pull/7669 and prevents auto-rejection of a ringing call after it was accepted or rejected by the current user (on another device or in another tab).

Note that backend changes made in https://github.com/GetStream/chat/pull/7669 make this client update less critical, but it's still nice to avoid an extra API call.

@@ -2000,28 +2016,33 @@ export class Call {
* Applicable only for ringing calls.
*/
private scheduleAutoDrop = () => {
clearTimeout(this.dropTimeout);
this.leaveCallHooks.add(
createSubscription(this.state.settings$, (settings) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, a subscription on call settings was set up when scheduling auto-drop. I don't see a reason to set up the subscription here.

Call settings should be up-to-date at this point; and in case call settings were somehow update mid-ringing, this subscription didn't take updated timeouts into account correctly anyway.

So, to simplify things, we are just setting up a timeout using current call settings.

Comment on lines -348 to -352
if (
callingState === CallingState.JOINED ||
callingState === CallingState.JOINING ||
callingState === CallingState.LEFT
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cancelling auto-drop on calling state change is no longer required, since it's covered by two other checks:

  1. Auto-drop is cancelled if the call is either accepted or rejected by the current user.
  2. Auto-drop is a no-op if calling state changed to anything other than RINGING.

this.dropTimeout = setTimeout(() => {
// the call might have stopped ringing by this point,
// e.g. it was already accepted and joined
if (this.state.callingState !== CallingState.RINGING) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An additional guard to prevent dropping a call that is no longer RINGING (e.g. was accepted or rejected on the current device/tab).

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.

1 participant