Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6691 from SimonBrandner/fix/agressive-pausing/18588
Browse files Browse the repository at this point in the history
Pause ringing more aggressively
  • Loading branch information
dbkr authored Aug 26, 2021
2 parents 762fad0 + 242b4e7 commit c13b3be
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/CallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,15 @@ export default class CallHandler extends EventEmitter {
* @returns {boolean}
*/
private areAnyCallsUnsilenced(): boolean {
return this.calls.size > this.silencedCalls.size;
for (const call of this.calls.values()) {
if (
call.state === CallState.Ringing &&
!this.isCallSilenced(call.callId)
) {
return true;
}
}
return false;
}

private async checkProtocols(maxTries) {
Expand Down Expand Up @@ -878,6 +886,8 @@ export default class CallHandler extends EventEmitter {
break;
case 'hangup':
case 'reject':
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);

if (!this.calls.get(payload.room_id)) {
return; // no call to hangup
}
Expand All @@ -890,11 +900,15 @@ export default class CallHandler extends EventEmitter {
// the hangup event away)
break;
case 'hangup_all':
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);

for (const call of this.calls.values()) {
call.hangup(CallErrorCode.UserHangup, false);
}
break;
case 'answer': {
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);

if (!this.calls.has(payload.room_id)) {
return; // no call to answer
}
Expand Down Expand Up @@ -929,6 +943,12 @@ export default class CallHandler extends EventEmitter {
}
};

private stopRingingIfPossible(callId: string): void {
this.silencedCalls.delete(callId);
if (this.areAnyCallsUnsilenced()) return;
this.pause(AudioID.Ring);
}

private async dialNumber(number: string) {
const results = await this.pstnLookup(number);
if (!results || results.length === 0 || !results[0].userid) {
Expand Down

0 comments on commit c13b3be

Please sign in to comment.