diff --git a/res/media/ring.mp3 b/res/media/ring.mp3 index 9b08ec7b36..386cce6998 100644 Binary files a/res/media/ring.mp3 and b/res/media/ring.mp3 differ diff --git a/res/media/ring.ogg b/res/media/ring.ogg index 41a22160b0..48c3f1c2ad 100644 Binary files a/res/media/ring.ogg and b/res/media/ring.ogg differ diff --git a/src/LegacyCallHandler.tsx b/src/LegacyCallHandler.tsx index e618fa62a0..33770fe4bf 100644 --- a/src/LegacyCallHandler.tsx +++ b/src/LegacyCallHandler.tsx @@ -390,6 +390,9 @@ export default class LegacyCallHandler extends TypedEventEmitter call.roomId !== roomId); - // Start ringing if not already. + const soundHasStarted = useRef(false); useEffect(() => { + // This section can race, so we use a ref to keep track of whether we have started trying to play. + // This is because `LegacyCallHandler.play` tries to load the sound and then play it asynchonously + // and `LegacyCallHandler.isPlaying` will not be `true` until the sound starts playing. const isRingToast = notificationContent.notification_type == "ring"; - if (isRingToast && !LegacyCallHandler.instance.isPlaying(AudioID.Ring)) { - LegacyCallHandler.instance.play(AudioID.Ring); + if (isRingToast && !soundHasStarted.current && !LegacyCallHandler.instance.isPlaying(AudioID.Ring)) { + // Start ringing if not already. + soundHasStarted.current = true; + void LegacyCallHandler.instance.play(AudioID.Ring); } - }, [notificationContent.notification_type]); + }, [notificationContent.notification_type, soundHasStarted]); // Stop ringing on dismiss. const dismissToast = useCallback((): void => {