@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import React , { useCallback , useEffect , useMemo , useState } from "react" ;
17
+ import React , { useCallback , useEffect , useState } from "react" ;
18
18
import { MatrixEvent } from "matrix-js-sdk/src/matrix" ;
19
19
import { Button , Tooltip } from "@vector-im/compound-web" ;
20
20
import { Icon as VideoCallIcon } from "@vector-im/compound-design-tokens/icons/video-call-solid.svg" ;
@@ -36,7 +36,7 @@ import AccessibleButton, { ButtonEvent } from "../components/views/elements/Acce
36
36
import { useDispatcher } from "../hooks/useDispatcher" ;
37
37
import { ActionPayload } from "../dispatcher/payloads" ;
38
38
import { Call } from "../models/Call" ;
39
- import { AudioID } from "../LegacyCallHandler" ;
39
+ import LegacyCallHandler , { AudioID } from "../LegacyCallHandler" ;
40
40
import { useEventEmitter } from "../hooks/useEventEmitter" ;
41
41
import { CallStore , CallStoreEvent } from "../stores/CallStore" ;
42
42
@@ -78,7 +78,6 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
78
78
const roomId = notifyEvent . getRoomId ( ) ! ;
79
79
const room = MatrixClientPeg . safeGet ( ) . getRoom ( roomId ) ?? undefined ;
80
80
const call = useCall ( roomId ) ;
81
- const audio = useMemo ( ( ) => document . getElementById ( AudioID . Ring ) as HTMLMediaElement , [ ] ) ;
82
81
const [ connectedCalls , setConnectedCalls ] = useState < Call [ ] > ( Array . from ( CallStore . instance . connectedCalls ) ) ;
83
82
useEventEmitter ( CallStore . instance , CallStoreEvent . ConnectedCalls , ( ) => {
84
83
setConnectedCalls ( Array . from ( CallStore . instance . connectedCalls ) ) ;
@@ -87,18 +86,18 @@ export function IncomingCallToast({ notifyEvent }: Props): JSX.Element {
87
86
// Start ringing if not already.
88
87
useEffect ( ( ) => {
89
88
const isRingToast = ( notifyEvent . getContent ( ) as unknown as { notify_type : string } ) [ "notify_type" ] == "ring" ;
90
- if ( isRingToast && audio . paused ) {
91
- audio . play ( ) ;
89
+ if ( isRingToast && ! LegacyCallHandler . instance . isPlaying ( AudioID . Ring ) ) {
90
+ LegacyCallHandler . instance . play ( AudioID . Ring ) ;
92
91
}
93
- } , [ audio , notifyEvent ] ) ;
92
+ } , [ notifyEvent ] ) ;
94
93
95
94
// Stop ringing on dismiss.
96
95
const dismissToast = useCallback ( ( ) : void => {
97
96
ToastStore . sharedInstance ( ) . dismissToast (
98
97
getIncomingCallToastKey ( notifyEvent . getContent ( ) . call_id ?? "" , roomId ) ,
99
98
) ;
100
- audio . pause ( ) ;
101
- } , [ audio , notifyEvent , roomId ] ) ;
99
+ LegacyCallHandler . instance . pause ( AudioID . Ring ) ;
100
+ } , [ notifyEvent , roomId ] ) ;
102
101
103
102
// Dismiss if session got ended remotely.
104
103
const onCall = useCallback (
0 commit comments