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

Pause ringing more aggressively #6691

Merged
merged 3 commits into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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