Plays the sounds of live events, which WSProvider triggers, and stores whether they are on. They are synthesised with Web Audio, so there's no file to ship: a soft blip for a chat message, and a rising two-note chime for a notification.

Functions

f
playChime(
kind: ChimeKind,
eventId: string
): void

Plays the chime for a live event, unless sounds are off, another tab already chimed for eventId, or a chat blip played less than 4 seconds ago. The caller must pass an id that is the same in every tab, such as the message's.

f
previewChime(kind: ChimeKind): void

Plays the chime kind whatever the setting, for the profile page's settings to preview it. It is called from a click, which unlocks the audio.

f
readSoundsEnabled(): boolean

Returns whether sounds are on in this browser, which they are unless turned off. playChime checks it on every play.

f
writeSoundsEnabled(enabled: boolean): void

Stores whether sounds are on, for useSoundsEnabled's setter.

Type Aliases

T
ChimeKind = "chat" | "notify"

Passed to playChime and previewChime to pick the sound.