Add support for playing a sound when the user exits a call. (#2860)

* Refactor to use AudioContext

* Remove unused audio format.

* Reduce update frequency for volume

* Port to useAudioContext

* Port reactionaudiorenderer to useAudioContext

* Integrate raise hand sound into call event renderer.

* Simplify reaction sounds

* only play one sound per reaction type

* Start to build out tests

* fixup tests / comments

* Fix reaction sound

* remove console line

* Remove another debug line.

* fix lint

* Use testing library click

* lint

* Add support for playing a sound when the user exits a call.

* Port GroupCallView to useAudioContext

* Remove debug bits.

* asyncify

* lint

* lint

* lint

* tidy

* Add test for group call view

* Test widget mode too.

* fix ?.

* Format

* Lint

* Lint

---------

Co-authored-by: Hugh Nimmo-Smith <hughns@element.io>
This commit is contained in:
Will Hunt
2024-12-12 07:33:47 +00:00
committed by GitHub
parent 6c81f69590
commit 77facd01e4
9 changed files with 242 additions and 38 deletions

View File

@@ -22,18 +22,21 @@ import { type PrefetchedSounds } from "./soundUtils";
* @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(
async function playSound(
ctx: AudioContext,
buffer: AudioBuffer,
volume: number,
): void {
): Promise<void> {
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<void>((r) => src.addEventListener("ended", () => r()));
src.start();
return p;
}
interface Props<S extends string> {
@@ -47,7 +50,7 @@ interface Props<S extends string> {
}
interface UseAudioContext<S> {
playSound(soundName: S): void;
playSound(soundName: S): Promise<void>;
}
/**
@@ -113,7 +116,7 @@ export function useAudioContext<S extends string>(
return null;
}
return {
playSound: (name): void => {
playSound: async (name): Promise<void> => {
if (!audioBuffers[name]) {
logger.debug(`Tried to play a sound that wasn't buffered (${name})`);
return;