Skip to content

Commit

Permalink
additional guard against dropping not ringing call
Browse files Browse the repository at this point in the history
  • Loading branch information
myandrienko committed Dec 11, 2024
1 parent c5fb1b9 commit ff04987
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions packages/client/src/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export class Call {
);

this.leaveCallHooks.add(
// cancel auto-drop when call is
createSubscription(this.state.session$, (session) => {
if (!this.ringing) return;

Expand All @@ -357,21 +358,6 @@ export class Call {
}),
);

this.leaveCallHooks.add(
// watch for auto drop cancellation
createSubscription(this.state.callingState$, (callingState) => {
if (!this.ringing) return;
if (
callingState === CallingState.JOINED ||
callingState === CallingState.JOINING ||
callingState === CallingState.LEFT
) {
clearTimeout(this.dropTimeout);
this.dropTimeout = undefined;
}
}),
);

this.leaveCallHooks.add(
// "ringing" mode effects and event handlers
createSubscription(this.ringingSubject, (isRinging) => {
Expand Down Expand Up @@ -2031,6 +2017,9 @@ export class Call {
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;
this.leave({ reject: true, reason: 'timeout' }).catch((err) => {
this.logger('error', 'Failed to drop call', err);
});
Expand Down

0 comments on commit ff04987

Please sign in to comment.