diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-08-14 18:36:22 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-08-14 18:36:22 +0900 |
| commit | f95d5701a22757f73ddb3e56cc99153de4146be5 (patch) | |
| tree | b47eded7d8a9c9341bf0d072569356bba9f37265 /src/client/scripts/sound.ts | |
| parent | add sound (diff) | |
| download | sharkey-f95d5701a22757f73ddb3e56cc99153de4146be5.tar.gz sharkey-f95d5701a22757f73ddb3e56cc99153de4146be5.tar.bz2 sharkey-f95d5701a22757f73ddb3e56cc99153de4146be5.zip | |
feat(client): ジョブキューウィジェットに警報音を鳴らす設定を追加
Diffstat (limited to 'src/client/scripts/sound.ts')
| -rw-r--r-- | src/client/scripts/sound.ts | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/client/scripts/sound.ts b/src/client/scripts/sound.ts index d3422bfff2..c51fa8f215 100644 --- a/src/client/scripts/sound.ts +++ b/src/client/scripts/sound.ts @@ -2,6 +2,23 @@ import { ColdDeviceStorage } from '@client/store'; const cache = new Map<string, HTMLAudioElement>(); +export function getAudio(file: string, useCache = true): HTMLAudioElement { + let audio: HTMLAudioElement; + if (useCache && cache.has(file)) { + audio = cache.get(file); + } else { + audio = new Audio(`/static-assets/client/sounds/${file}.mp3`); + if (useCache) cache.set(file, audio); + } + return audio; +} + +export function setVolume(audio: HTMLAudioElement, volume: number): HTMLAudioElement { + const masterVolume = ColdDeviceStorage.get('sound_masterVolume'); + audio.volume = masterVolume - ((1 - volume) * masterVolume); + return audio; +} + export function play(type: string) { const sound = ColdDeviceStorage.get('sound_' + type as any); if (sound.type == null) return; @@ -12,13 +29,6 @@ export function playFile(file: string, volume: number) { const masterVolume = ColdDeviceStorage.get('sound_masterVolume'); if (masterVolume === 0) return; - let audio: HTMLAudioElement; - if (cache.has(file)) { - audio = cache.get(file); - } else { - audio = new Audio(`/static-assets/client/sounds/${file}.mp3`); - cache.set(file, audio); - } - audio.volume = masterVolume - ((1 - volume) * masterVolume); + const audio = setVolume(getAudio(file), volume); audio.play(); } |