Skip to content

Commit c13b3be

Browse files
authored
Merge pull request matrix-org#6691 from SimonBrandner/fix/agressive-pausing/18588
Pause ringing more aggressively
2 parents 762fad0 + 242b4e7 commit c13b3be

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/CallHandler.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,15 @@ export default class CallHandler extends EventEmitter {
250250
* @returns {boolean}
251251
*/
252252
private areAnyCallsUnsilenced(): boolean {
253-
return this.calls.size > this.silencedCalls.size;
253+
for (const call of this.calls.values()) {
254+
if (
255+
call.state === CallState.Ringing &&
256+
!this.isCallSilenced(call.callId)
257+
) {
258+
return true;
259+
}
260+
}
261+
return false;
254262
}
255263

256264
private async checkProtocols(maxTries) {
@@ -878,6 +886,8 @@ export default class CallHandler extends EventEmitter {
878886
break;
879887
case 'hangup':
880888
case 'reject':
889+
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);
890+
881891
if (!this.calls.get(payload.room_id)) {
882892
return; // no call to hangup
883893
}
@@ -890,11 +900,15 @@ export default class CallHandler extends EventEmitter {
890900
// the hangup event away)
891901
break;
892902
case 'hangup_all':
903+
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);
904+
893905
for (const call of this.calls.values()) {
894906
call.hangup(CallErrorCode.UserHangup, false);
895907
}
896908
break;
897909
case 'answer': {
910+
this.stopRingingIfPossible(this.calls.get(payload.room_id).callId);
911+
898912
if (!this.calls.has(payload.room_id)) {
899913
return; // no call to answer
900914
}
@@ -929,6 +943,12 @@ export default class CallHandler extends EventEmitter {
929943
}
930944
};
931945

946+
private stopRingingIfPossible(callId: string): void {
947+
this.silencedCalls.delete(callId);
948+
if (this.areAnyCallsUnsilenced()) return;
949+
this.pause(AudioID.Ring);
950+
}
951+
932952
private async dialNumber(number: string) {
933953
const results = await this.pstnLookup(number);
934954
if (!results || results.length === 0 || !results[0].userid) {

0 commit comments

Comments
 (0)