File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " livekit-client " : patch
3+ ---
4+
5+ Automatically attempt to resume suspended audio contexts on click
Original file line number Diff line number Diff line change @@ -133,7 +133,21 @@ export function getNewAudioContext(): AudioContext | void {
133133 // @ts -ignore
134134 typeof window !== 'undefined' && ( window . AudioContext || window . webkitAudioContext ) ;
135135 if ( AudioContext ) {
136- return new AudioContext ( { latencyHint : 'interactive' } ) ;
136+ const audioContext = new AudioContext ( { latencyHint : 'interactive' } ) ;
137+ // If the audio context is suspended, we need to resume it when the user clicks on the page
138+ if (
139+ audioContext . state === 'suspended' &&
140+ typeof window !== 'undefined' &&
141+ window . document ?. body
142+ ) {
143+ const handleResume = ( ) => {
144+ audioContext . resume ( ) . then ( ( ) => {
145+ window . document . body ?. removeEventListener ( 'click' , handleResume ) ;
146+ } ) ;
147+ } ;
148+ window . document . body . addEventListener ( 'click' , handleResume ) ;
149+ }
150+ return audioContext ;
137151 }
138152}
139153
Original file line number Diff line number Diff line change @@ -433,6 +433,7 @@ export function createAudioAnalyser(
433433 if ( ! audioContext ) {
434434 throw new Error ( 'Audio Context not supported on this browser' ) ;
435435 }
436+
436437 const streamTrack = opts . cloneTrack ? track . mediaStreamTrack . clone ( ) : track . mediaStreamTrack ;
437438 const mediaStreamSource = audioContext . createMediaStreamSource ( new MediaStream ( [ streamTrack ] ) ) ;
438439 const analyser = audioContext . createAnalyser ( ) ;
You can’t perform that action at this time.
0 commit comments