Add new and improved ringtone (#30761)

* Fix racy ringing sound

* Add new ringtone from ECall

* Drop use of promise

* Add a comment.

* lint
This commit is contained in:
Will Hunt 2025-09-17 13:02:57 +01:00 committed by GitHub
parent db2e958823
commit b4ba350770
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -390,6 +390,9 @@ export default class LegacyCallHandler extends TypedEventEmitter<LegacyCallHandl
const [urlPrefix, loop] = audioInfo[audioId]; const [urlPrefix, loop] = audioInfo[audioId];
const source = await this.backgroundAudio.pickFormatAndPlay(urlPrefix, ["mp3", "ogg"], loop); const source = await this.backgroundAudio.pickFormatAndPlay(urlPrefix, ["mp3", "ogg"], loop);
if (this.playingSources[audioId]) {
logger.warn(`${logPrefix} Already playing audio ${audioId}!`);
}
this.playingSources[audioId] = source; this.playingSources[audioId] = source;
logger.debug(`${logPrefix} playing audio successfully`); logger.debug(`${logPrefix} playing audio successfully`);
} }

View File

@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details. Please see LICENSE files in the repository root for full details.
*/ */
import React, { type JSX, useCallback, useEffect, useState } from "react"; import React, { type JSX, useCallback, useEffect, useRef, useState } from "react";
import { type Room, type MatrixEvent, type RoomMember, RoomEvent, EventType } from "matrix-js-sdk/src/matrix"; import { type Room, type MatrixEvent, type RoomMember, RoomEvent, EventType } from "matrix-js-sdk/src/matrix";
import { Button, ToggleInput, Tooltip, TooltipProvider } from "@vector-im/compound-web"; import { Button, ToggleInput, Tooltip, TooltipProvider } from "@vector-im/compound-web";
import VideoCallIcon from "@vector-im/compound-design-tokens/assets/web/icons/video-call-solid"; import VideoCallIcon from "@vector-im/compound-design-tokens/assets/web/icons/video-call-solid";
@ -147,13 +147,18 @@ export function IncomingCallToast({ notificationEvent }: Props): JSX.Element {
setConnectedCalls(Array.from(CallStore.instance.connectedCalls)); setConnectedCalls(Array.from(CallStore.instance.connectedCalls));
}); });
const otherCallIsOngoing = connectedCalls.find((call) => call.roomId !== roomId); const otherCallIsOngoing = connectedCalls.find((call) => call.roomId !== roomId);
// Start ringing if not already. const soundHasStarted = useRef<boolean>(false);
useEffect(() => { 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"; const isRingToast = notificationContent.notification_type == "ring";
if (isRingToast && !LegacyCallHandler.instance.isPlaying(AudioID.Ring)) { if (isRingToast && !soundHasStarted.current && !LegacyCallHandler.instance.isPlaying(AudioID.Ring)) {
LegacyCallHandler.instance.play(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. // Stop ringing on dismiss.
const dismissToast = useCallback((): void => { const dismissToast = useCallback((): void => {