Skip to content

Commit

Permalink
🐛 [Sound] Disconnect and empty only after emitting ended event
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Dec 22, 2023
1 parent fcee531 commit 7b50b9c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ export class Sound extends EmittenCommon<SoundEventMap> {
this.#handleEnded();
}

// Should `disconnect` and `empty` be moved into `#handleEnded`?
// Would this actually matter?
this.#source.disconnect();
this.empty();

return this;
}

Expand All @@ -168,5 +163,11 @@ export class Sound extends EmittenCommon<SoundEventMap> {
source: this.#source,
neverStarted: !this.#started,
});

// This needs to happen AFTER our artifical `ended` event is emitted.
// Otherwise, the native `ended` event may not be called in time
// after triggering `source.stop()`.
this.#source.disconnect();
this.empty();
};
}

0 comments on commit 7b50b9c

Please sign in to comment.