fix(engine): defer AudioContext creation to first user gesture#3
Merged
Conversation
Constructing the AudioContext inside init() trips Chrome's autoplay-policy
warning ("AudioContext was not allowed to start") because init() typically
runs at module load, outside any user gesture. The context was then born
suspended, which silently dropped the very first sound — most visibly the
hover sound on pointerenter, which is not itself a qualifying gesture.
Move construction into the existing gesture-unlock path so the context
is created inside a real pointerdown / touchstart / mousedown / keydown.
The context comes up running and the next pointerenter plays as expected.
playSound bails silently when no context exists yet (no warning, no node).
Closes #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2.
tiks.init()constructed anAudioContextimmediately, which trips Chrome's autoplay-policy warning (The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page) and leaves the contextsuspended. The first hover sound triggered viaonPointerEnterthen silently drops, becausepointerenteris not a qualifying user gesture.This change moves construction into the existing gesture-unlock listener so the
AudioContextis born inside a realpointerdown/touchstart/mousedown/keydownevent. The context comes uprunning, no warning fires, and post-gesture hovers play immediately.Test plan
npm test— 70/70 passnpm run typecheck— cleannpm run build— clean