Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-pandas-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Don't hang on audio context trying to resume
19 changes: 10 additions & 9 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
isReactNative,
isSafari,
isWeb,
sleep,
supportsSetSinkId,
toHttpUrl,
unpackStreamId,
Expand Down Expand Up @@ -1771,24 +1772,24 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
this.audioContext = getNewAudioContext() ?? undefined;
}

if (this.options.webAudioMix) {
this.remoteParticipants.forEach((participant) =>
participant.setAudioContext(this.audioContext),
);
}

this.localParticipant.setAudioContext(this.audioContext);

if (this.audioContext && this.audioContext.state === 'suspended') {
// for iOS a newly created AudioContext is always in `suspended` state.
// we try our best to resume the context here, if that doesn't work, we just continue with regular processing
try {
await this.audioContext.resume();
await Promise.race([this.audioContext.resume(), sleep(200)]);
} catch (e: any) {
this.log.warn('Could not resume audio context', { ...this.logContext, error: e });
}
}

if (this.options.webAudioMix) {
this.remoteParticipants.forEach((participant) =>
participant.setAudioContext(this.audioContext),
);
}

this.localParticipant.setAudioContext(this.audioContext);

const newContextIsRunning = this.audioContext?.state === 'running';
if (newContextIsRunning !== this.canPlaybackAudio) {
this.audioEnabled = newContextIsRunning;
Expand Down
Loading