-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,16 +342,18 @@ export class Call { | |
); | ||
|
||
this.leaveCallHooks.add( | ||
// watch for auto drop cancellation | ||
createSubscription(this.state.callingState$, (callingState) => { | ||
// cancel auto-drop when call is | ||
createSubscription(this.state.session$, (session) => { | ||
if (!this.ringing) return; | ||
if ( | ||
callingState === CallingState.JOINED || | ||
callingState === CallingState.JOINING || | ||
callingState === CallingState.LEFT | ||
) { | ||
clearTimeout(this.dropTimeout); | ||
this.dropTimeout = undefined; | ||
|
||
const receiverId = this.clientStore.connectedUser?.id; | ||
if (!receiverId) return; | ||
|
||
const isAcceptedByMe = Boolean(session?.accepted_by[receiverId]); | ||
const isRejectedByMe = Boolean(session?.rejected_by[receiverId]); | ||
|
||
if (isAcceptedByMe || isRejectedByMe) { | ||
this.cancelAutoDrop(); | ||
} | ||
}), | ||
); | ||
|
@@ -2000,28 +2002,36 @@ export class Call { | |
* Applicable only for ringing calls. | ||
*/ | ||
private scheduleAutoDrop = () => { | ||
clearTimeout(this.dropTimeout); | ||
this.leaveCallHooks.add( | ||
createSubscription(this.state.settings$, (settings) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (!settings) return; | ||
// ignore if the call is not ringing | ||
if (this.state.callingState !== CallingState.RINGING) return; | ||
|
||
const timeoutInMs = this.isCreatedByMe | ||
? settings.ring.auto_cancel_timeout_ms | ||
: settings.ring.incoming_call_timeout_ms; | ||
|
||
// 0 means no auto-drop | ||
if (timeoutInMs <= 0) return; | ||
this.cancelAutoDrop(); | ||
|
||
const settings = this.state.settings; | ||
if (!settings) return; | ||
// ignore if the call is not ringing | ||
if (this.state.callingState !== CallingState.RINGING) return; | ||
|
||
const timeoutInMs = this.isCreatedByMe | ||
? settings.ring.auto_cancel_timeout_ms | ||
: settings.ring.incoming_call_timeout_ms; | ||
|
||
// 0 means no auto-drop | ||
if (timeoutInMs <= 0) return; | ||
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An additional guard to prevent dropping a call that is no longer |
||
this.leave({ reject: true, reason: 'timeout' }).catch((err) => { | ||
this.logger('error', 'Failed to drop call', err); | ||
}); | ||
}, timeoutInMs); | ||
}; | ||
|
||
clearTimeout(this.dropTimeout); | ||
this.dropTimeout = setTimeout(() => { | ||
this.leave({ reject: true, reason: 'timeout' }).catch((err) => { | ||
this.logger('error', 'Failed to drop call', err); | ||
}); | ||
}, timeoutInMs); | ||
}), | ||
); | ||
/** | ||
* Cancels a scheduled auto-drop timeout. | ||
*/ | ||
private cancelAutoDrop = () => { | ||
clearTimeout(this.dropTimeout); | ||
this.dropTimeout = undefined; | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
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:
RINGING
.