File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1
- import StartAudioContext from ' startaudiocontext' ;
2
- import bowser from ' bowser' ;
1
+ import StartAudioContext from " startaudiocontext" ;
2
+ import bowser from " bowser" ;
3
3
4
4
let AUDIO_CONTEXT ;
5
5
@@ -8,7 +8,9 @@ if (!bowser.msie) {
8
8
* AudioContext can be initialized only when user interaction event happens
9
9
*/
10
10
const event =
11
- typeof document . ontouchend === 'undefined' ? 'mouseup' : 'touchend' ;
11
+ typeof document . ontouchstart === "undefined"
12
+ ? "mousedown"
13
+ : "touchstart" ;
12
14
const initAudioContext = ( ) => {
13
15
document . removeEventListener ( event , initAudioContext ) ;
14
16
AUDIO_CONTEXT = new ( window . AudioContext ||
Original file line number Diff line number Diff line change
1
+ import "web-audio-test-api" ;
2
+ import SharedAudioContext from "../../../src/lib/audio/shared-audio-context" ;
3
+
4
+ describe ( "Shared Audio Context" , ( ) => {
5
+ const audioContext = new AudioContext ( ) ;
6
+
7
+ test ( "returns empty object without user gesture" , ( ) => {
8
+ const sharedAudioContext = new SharedAudioContext ( ) ;
9
+ expect ( sharedAudioContext ) . toMatchObject ( { } ) ;
10
+ } ) ;
11
+
12
+ test ( "returns AudioContext when mousedown is triggered" , ( ) => {
13
+ const sharedAudioContext = new SharedAudioContext ( ) ;
14
+ const event = new Event ( "mousedown" ) ;
15
+ document . dispatchEvent ( event ) ;
16
+ expect ( sharedAudioContext ) . toMatchObject ( audioContext ) ;
17
+ } ) ;
18
+
19
+ test ( "returns AudioContext when touchstart is triggered" , ( ) => {
20
+ const sharedAudioContext = new SharedAudioContext ( ) ;
21
+ const event = new Event ( "touchstart" ) ;
22
+ document . dispatchEvent ( event ) ;
23
+ expect ( sharedAudioContext ) . toMatchObject ( audioContext ) ;
24
+ } ) ;
25
+ } ) ;
You can’t perform that action at this time.
0 commit comments