|
1 | 1 | /* |
2 | 2 | Copyright 2015, 2016 OpenMarket Ltd |
3 | 3 | Copyright 2017, 2018 New Vector Ltd |
4 | | -Copyright 2019, 2020 The Matrix.org Foundation C.I.C. |
| 4 | +Copyright 2019 - 2021 The Matrix.org Foundation C.I.C. |
| 5 | +Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com> |
5 | 6 |
|
6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 8 | you may not use this file except in compliance with the License. |
@@ -85,6 +86,8 @@ import { randomUppercaseString, randomLowercaseString } from "matrix-js-sdk/src/ |
85 | 86 | import EventEmitter from 'events'; |
86 | 87 | import SdkConfig from './SdkConfig'; |
87 | 88 | import { ensureDMExists, findDMForUser } from './createRoom'; |
| 89 | +import { IPushRule, RuleId, TweakName, Tweaks } from "matrix-js-sdk/src/@types/PushRules"; |
| 90 | +import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor'; |
88 | 91 | import { WidgetLayoutStore, Container } from './stores/widgets/WidgetLayoutStore'; |
89 | 92 | import { getIncomingCallToastKey } from './toasts/IncomingCallToast'; |
90 | 93 | import ToastStore from './stores/ToastStore'; |
@@ -479,14 +482,28 @@ export default class CallHandler extends EventEmitter { |
479 | 482 | } |
480 | 483 |
|
481 | 484 | switch (newState) { |
482 | | - case CallState.Ringing: |
483 | | - this.play(AudioID.Ring); |
| 485 | + case CallState.Ringing: { |
| 486 | + const incomingCallPushRule = ( |
| 487 | + new PushProcessor(MatrixClientPeg.get()).getPushRuleById(RuleId.IncomingCall) as IPushRule |
| 488 | + ); |
| 489 | + const pushRuleEnabled = incomingCallPushRule?.enabled; |
| 490 | + const tweakSetToRing = incomingCallPushRule?.actions.some((action: Tweaks) => ( |
| 491 | + action.set_tweak === TweakName.Sound && |
| 492 | + action.value === "ring" |
| 493 | + )); |
| 494 | + |
| 495 | + if (pushRuleEnabled && tweakSetToRing) { |
| 496 | + this.play(AudioID.Ring); |
| 497 | + } else { |
| 498 | + this.silenceCall(call.callId); |
| 499 | + } |
484 | 500 | break; |
485 | | - case CallState.InviteSent: |
| 501 | + } |
| 502 | + case CallState.InviteSent: { |
486 | 503 | this.play(AudioID.Ringback); |
487 | 504 | break; |
488 | | - case CallState.Ended: |
489 | | - { |
| 505 | + } |
| 506 | + case CallState.Ended: { |
490 | 507 | const hangupReason = call.hangupReason; |
491 | 508 | Analytics.trackEvent('voip', 'callEnded', 'hangupReason', hangupReason); |
492 | 509 | this.removeCallForRoom(mappedRoomId); |
|
0 commit comments