mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-24 15:16:44 -06:00
chore: create AudioContext when it is needed (#12460)
This commit is contained in:
parent
755ca97857
commit
ccb951f11e
2 changed files with 8 additions and 2 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
|
|
||||||
const ctx = new AudioContext();
|
let ctx: AudioContext;
|
||||||
const cache = new Map<string, AudioBuffer>();
|
const cache = new Map<string, AudioBuffer>();
|
||||||
let canPlay = true;
|
let canPlay = true;
|
||||||
|
|
||||||
|
@ -65,6 +65,9 @@ export const soundsTypes = [
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export async function loadAudio(file: string, useCache = true) {
|
export async function loadAudio(file: string, useCache = true) {
|
||||||
|
if (ctx == null) {
|
||||||
|
ctx = new AudioContext();
|
||||||
|
}
|
||||||
if (useCache && cache.has(file)) {
|
if (useCache && cache.has(file)) {
|
||||||
return cache.get(file)!;
|
return cache.get(file)!;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ import { useStream } from '@/stream.js';
|
||||||
import number from '@/filters/number.js';
|
import number from '@/filters/number.js';
|
||||||
import * as sound from '@/scripts/sound.js';
|
import * as sound from '@/scripts/sound.js';
|
||||||
import { deepClone } from '@/scripts/clone.js';
|
import { deepClone } from '@/scripts/clone.js';
|
||||||
|
import { defaultStore } from '@/store.js';
|
||||||
|
|
||||||
const name = 'jobQueue';
|
const name = 'jobQueue';
|
||||||
|
|
||||||
|
@ -102,7 +103,9 @@ const prev = reactive({} as typeof current);
|
||||||
let jammedAudioBuffer: AudioBuffer | null = $ref(null);
|
let jammedAudioBuffer: AudioBuffer | null = $ref(null);
|
||||||
let jammedSoundNodePlaying: boolean = $ref(false);
|
let jammedSoundNodePlaying: boolean = $ref(false);
|
||||||
|
|
||||||
sound.loadAudio('syuilo/queue-jammed').then(buf => jammedAudioBuffer = buf);
|
if (defaultStore.state.sound_masterVolume) {
|
||||||
|
sound.loadAudio('syuilo/queue-jammed').then(buf => jammedAudioBuffer = buf);
|
||||||
|
}
|
||||||
|
|
||||||
for (const domain of ['inbox', 'deliver']) {
|
for (const domain of ['inbox', 'deliver']) {
|
||||||
prev[domain] = deepClone(current[domain]);
|
prev[domain] = deepClone(current[domain]);
|
||||||
|
|
Loading…
Reference in a new issue