This commit is contained in:
Timo K
2026-06-02 11:27:59 +02:00
parent ea4144ccc7
commit e05af09c28
3 changed files with 11 additions and 11 deletions

View File

@@ -248,7 +248,7 @@ test.skip("GroupCallView plays a leave sound synchronously in widget mode", asyn
expect(leaveRTCSession).toHaveBeenCalledOnce(); expect(leaveRTCSession).toHaveBeenCalledOnce();
}); });
test.skip("Should close widget when all other left and have time to play a sound", async () => { test("Should close widget when all other left and have time to play a sound", async () => {
const user = userEvent.setup(); const user = userEvent.setup();
const widgetClosedCalled = Promise.withResolvers<void>(); const widgetClosedCalled = Promise.withResolvers<void>();
const widgetSendMock = vi.fn().mockImplementation((action: string) => { const widgetSendMock = vi.fn().mockImplementation((action: string) => {
@@ -284,8 +284,9 @@ test.skip("Should close widget when all other left and have time to play a sound
resolvePlaySound.resolve(); resolvePlaySound.resolve();
await flushPromises(); await flushPromises();
expect(playSound).toHaveBeenCalledWith("left"); // Expect the leave sound to be played but silent (volumeOverwrite = 0)
// The allOthersLeft effect should already play a leave sound for the last user in the call.
expect(playSound).toHaveBeenCalledWith("left", 0);
await widgetClosedCalled.promise; await widgetClosedCalled.promise;
await flushPromises(); await flushPromises();
expect(widgetStopMock).toHaveBeenCalledOnce(); expect(widgetStopMock).toHaveBeenCalledOnce();

View File

@@ -57,10 +57,7 @@ import {
} from "../UrlParams"; } from "../UrlParams";
import { E2eeType } from "../e2ee/e2eeType"; import { E2eeType } from "../e2ee/e2eeType";
import { useAudioContext } from "../useAudioContext"; import { useAudioContext } from "../useAudioContext";
import { import { callEventAudioSounds } from "./CallEventAudioRenderer";
callEventAudioSounds,
type CallEventSounds,
} from "./CallEventAudioRenderer";
import { useLatest } from "../useLatest"; import { useLatest } from "../useLatest";
import { usePageTitle } from "../usePageTitle"; import { usePageTitle } from "../usePageTitle";
import { import {
@@ -323,7 +320,9 @@ export const GroupCallView: FC<Props> = ({
case "allOthersLeft": case "allOthersLeft":
// When "allOthersLeft", the leaveSoundEffect$ in CallEventAudioRenderer // When "allOthersLeft", the leaveSoundEffect$ in CallEventAudioRenderer
// already plays the "left" sound when the remote participant's media // already plays the "left" sound when the remote participant's media
// disappears. Playing it here too would cause the sound to play twice. // disappears. We play it here silenced (volumeOverwrite = 0) so we have the right duration in the audioPromise.
// (used to destory the widget)
audioPromise = leaveSoundContext.current?.playSound("left", 0);
break; break;
case "timeout": case "timeout":
case "decline": case "decline":

View File

@@ -114,7 +114,7 @@ interface Props<S extends string> {
} }
interface UseAudioContext<S extends string> { interface UseAudioContext<S extends string> {
playSound(soundName: S): Promise<void>; playSound(soundName: S, volumeOverwrite?: number): Promise<void>;
playSoundLooping(soundName: S, delayS?: number): () => Promise<void>; playSoundLooping(soundName: S, delayS?: number): () => Promise<void>;
/** /**
* Map of sound name to duration in seconds. * Map of sound name to duration in seconds.
@@ -195,7 +195,7 @@ export function useAudioContext<S extends string>(
} }
return { return {
playSound: async (name): Promise<void> => { playSound: async (name, volumeOverwrite?: number): Promise<void> => {
if (!audioBuffers[name]) { if (!audioBuffers[name]) {
logger.debug(`Tried to play a sound that wasn't buffered (${name})`); logger.debug(`Tried to play a sound that wasn't buffered (${name})`);
return; return;
@@ -203,7 +203,7 @@ export function useAudioContext<S extends string>(
return playSound( return playSound(
audioContext, audioContext,
audioBuffers[name], audioBuffers[name],
soundEffectVolume * earpieceVolume, volumeOverwrite ?? soundEffectVolume * earpieceVolume,
earpiecePan, earpiecePan,
); );
}, },