diff --git a/src/room/CallEventAudioRenderer.tsx b/src/room/CallEventAudioRenderer.tsx index 0e410ffb..2d17fbb8 100644 --- a/src/room/CallEventAudioRenderer.tsx +++ b/src/room/CallEventAudioRenderer.tsx @@ -24,7 +24,7 @@ import { useLatest } from "../useLatest"; export const MAX_PARTICIPANT_COUNT_FOR_SOUND = 8; export const THROTTLE_SOUND_EFFECT_MS = 500; -const Sounds = prefetchSounds({ +export const CallEventAudioSounds = prefetchSounds({ join: { mp3: joinCallSoundMp3, ogg: joinCallSoundOgg, @@ -45,7 +45,7 @@ export function CallEventAudioRenderer({ vm: CallViewModel; }): ReactNode { const audioEngineCtx = useAudioContext({ - sounds: Sounds, + sounds: CallEventAudioSounds, latencyHint: "interactive", }); const audioEngineRef = useLatest(audioEngineCtx); diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index a4f32e23..0b185b07 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -226,7 +226,6 @@ export const GroupCallView: FC = ({ // In embedded/widget mode the iFrame will be killed right after the call ended prohibiting the posthog event from getting sent, // therefore we want the event to be sent instantly without getting queued/batched. const sendInstantly = !!widget; - console.log("hangup!", sendInstantly); setLeaveError(leaveError); PosthogAnalytics.instance.eventCallEnded.track( rtcSession.room.roomId, diff --git a/src/useAudioContext.tsx b/src/useAudioContext.tsx index 4b3b9b2c..61d0d96e 100644 --- a/src/useAudioContext.tsx +++ b/src/useAudioContext.tsx @@ -24,18 +24,21 @@ type SoundDefinition = { mp3?: string; ogg: string }; * @param volume The volume to play at. * @param ctx The context to play through. * @param buffer The buffer to play. + * @returns A promise that resolves when the sound has finished playing. */ function playSound( ctx: AudioContext, buffer: AudioBuffer, volume: number, -): void { +): Promise { const gain = ctx.createGain(); gain.gain.setValueAtTime(volume, 0); const src = ctx.createBufferSource(); src.buffer = buffer; src.connect(gain).connect(ctx.destination); + const p = new Promise((r) => src.addEventListener("ended", () => r())); src.start(); + return p; } /** @@ -163,7 +166,7 @@ export function useAudioContext( return null; } return { - playSound: (name): void => { + playSound: (name): Promise => { if (!audioBuffers[name]) { logger.debug(`Tried to play a sound that wasn't buffered (${name})`); return;