-
Notifications
You must be signed in to change notification settings - Fork 0
/
joinSound.ts
34 lines (30 loc) · 831 Bytes
/
joinSound.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* simple join sound
* @packageDocumentation
*/
import type { VerseModuleBase } from "./VerseModuleBase";
import { PlayerSessionIdData } from "./playerSessionId";
import { createCachedAudio } from "./util/cachedAudio";
/** @internal */
const { getAudio, createAudio } = createCachedAudio();
const ids = new Set<string>();
/** @internal */
export function handleJoinSound(id: string) {
if (ids.has(id)) return;
ids.add(id);
getAudio()?.play();
}
/**
* simple join sound
*/
export default ({
addTextDataChangedListener,
domRoot,
}: VerseModuleBase<{}, PlayerSessionIdData>) => ({
initialize(options: { audioSrc: string; volume?: number }) {
createAudio(domRoot, options.audioSrc, options.volume);
addTextDataChangedListener((_, data) => {
handleJoinSound(data.playerSessionId);
});
},
});