-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5444 from watilde/fix/audio-context
fix: initialize audio context only with user interaction
- Loading branch information
Showing
2 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'web-audio-test-api'; | ||
import SharedAudioContext from '../../../src/lib/audio/shared-audio-context'; | ||
|
||
describe('Shared Audio Context', () => { | ||
const audioContext = new AudioContext(); | ||
|
||
test('returns empty object without user gesture', () => { | ||
const sharedAudioContext = new SharedAudioContext(); | ||
expect(sharedAudioContext).toMatchObject({}); | ||
}); | ||
|
||
test('returns AudioContext when mousedown is triggered', () => { | ||
const sharedAudioContext = new SharedAudioContext(); | ||
const event = new Event('mousedown'); | ||
document.dispatchEvent(event); | ||
expect(sharedAudioContext).toMatchObject(audioContext); | ||
}); | ||
|
||
test('returns AudioContext when touchstart is triggered', () => { | ||
const sharedAudioContext = new SharedAudioContext(); | ||
const event = new Event('touchstart'); | ||
document.dispatchEvent(event); | ||
expect(sharedAudioContext).toMatchObject(audioContext); | ||
}); | ||
}); |