mirror of
https://github.com/lichess-org/lila.git
synced 2026-05-26 13:51:00 +00:00
Merge pull request #20201 from Ijtihed/defer-audio-context-init
defer AudioContext creation in sound init via setTimeout(0)
This commit is contained in:
@@ -8,7 +8,7 @@ type Name = string;
|
||||
type Path = string;
|
||||
|
||||
export default new (class implements SoundI {
|
||||
ctx = makeAudioContext();
|
||||
ctx: AudioContext | undefined;
|
||||
listeners = new Set<SoundListener>();
|
||||
sounds = new Map<Path, Sound>(); // All loaded sounds and their instances
|
||||
paths = new Map<Name, Path>(); // sound names to paths
|
||||
@@ -27,7 +27,10 @@ export default new (class implements SoundI {
|
||||
|
||||
constructor() {
|
||||
this.primerEvents.forEach(e => window.addEventListener(e, this.primer, { capture: true }));
|
||||
window.speechSynthesis?.getVoices(); // preload
|
||||
requestIdleCallback(() => {
|
||||
this.ctx = makeAudioContext();
|
||||
window.speechSynthesis?.getVoices(); // preload
|
||||
});
|
||||
}
|
||||
|
||||
async load(name: Name, path?: Path): Promise<Sound | undefined> {
|
||||
|
||||
Reference in New Issue
Block a user