~james/core

core/web/src/lib/components/landing/sound.ts -rw-r--r-- 470 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import type { PlayOptions, SoundName } from "cuelume";

/** The interaction sounds (cuelume) play at this volume. */
const VOLUME = 0.7;

let cuelume: Promise<typeof import("cuelume")> | undefined;

export const loadSounds = () =>
	(cuelume ??= import("cuelume").then((module) => {
		module.setVolume(VOLUME);
		return module;
	}));

export const play = (sound: SoundName, options?: PlayOptions) => {
	void loadSounds().then((module) => module.play(sound, options));
};