From cf2e2e87f499028f9c9b2211466af8a7e22d2c68 Mon Sep 17 00:00:00 2001 From: beefchimi Date: Sun, 8 Dec 2024 15:02:38 -0500 Subject: [PATCH] :recycle: [Earwurm] Initialize private state to be AudioContext.state --- pkg/earwurm/src/Earwurm.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/earwurm/src/Earwurm.ts b/pkg/earwurm/src/Earwurm.ts index ef22d15..c33c543 100644 --- a/pkg/earwurm/src/Earwurm.ts +++ b/pkg/earwurm/src/Earwurm.ts @@ -14,21 +14,21 @@ import type { } from './types'; export class Earwurm extends EmittenCommon { - private _vol = 1; - private _mute = false; - private _trans = false; - private _playing = false; - private _keys: StackId[] = []; - private _state: ManagerState = 'suspended'; - readonly #context = new AudioContext(); readonly #gainNode = this.#context.createGain(); readonly #request: ManagerConfig['request']; #library: Stack[] = []; + private _vol = 1; + private _mute = false; + private _trans = false; + private _playing = false; + private _keys: StackId[] = []; + // If the `AudioContext` is `running` upon initialization, // then it should be safe to mark audio as “unlocked”. + private _state: ManagerState = this.#context.state || 'suspended'; private _unlocked = this.#context.state === 'running'; constructor(config?: ManagerConfig) { @@ -140,6 +140,7 @@ export class Earwurm extends EmittenCommon { const existingStack = this.get(id); const identicalStack = existingStack?.path === path; + // Only skip updating the `Stack` if both `id + path` are the same. if (identicalStack) return collection; newKeys.push(id);