Skip to content

Commit

Permalink
♻️ [Earwurm] Initialize private state to be AudioContext.state
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Dec 8, 2024
1 parent dd04449 commit cf2e2e8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/earwurm/src/Earwurm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ import type {
} from './types';

export class Earwurm extends EmittenCommon<ManagerEventMap> {
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) {
Expand Down Expand Up @@ -140,6 +140,7 @@ export class Earwurm extends EmittenCommon<ManagerEventMap> {
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);
Expand Down

0 comments on commit cf2e2e8

Please sign in to comment.