Skip to content

Commit

Permalink
Remove experimental hint for webAudioMix and enable it by default (#1013
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lukasIO authored Jan 31, 2024
1 parent 4fe4389 commit 8603746
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-cows-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": major
---

Remove experimental hint for webAudioMix and enable it by default
7 changes: 3 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ export interface InternalRoomOptions {
expSignalLatency?: number;

/**
* @internal
* @experimental
* experimental flag, mix all audio tracks in web audio
* mix all audio tracks in web audio, helps to tackle some audio auto playback issues
* allows for passing in your own AudioContext instance, too
*/

expWebAudioMix: boolean | WebAudioSettings;
webAudioMix: boolean | WebAudioSettings;

/**
* @experimental
Expand Down
19 changes: 8 additions & 11 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,8 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
}
} else if (kind === 'audiooutput') {
if (
(!supportsSetSinkId() && !this.options.expWebAudioMix) ||
(this.options.expWebAudioMix && this.audioContext && !('setSinkId' in this.audioContext))
(!supportsSetSinkId() && !this.options.webAudioMix) ||
(this.options.webAudioMix && this.audioContext && !('setSinkId' in this.audioContext))
) {
throw new Error('cannot switch audio output, setSinkId not supported');
}
Expand All @@ -1034,7 +1034,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
deviceHasChanged = prevDeviceId !== deviceConstraint;

try {
if (this.options.expWebAudioMix) {
if (this.options.webAudioMix) {
// @ts-expect-error setSinkId is not yet in the typescript type of AudioContext
this.audioContext?.setSinkId(deviceId);
} else {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
this.remoteParticipants.clear();
this.sidToIdentity.clear();
this.activeSpeakers = [];
if (this.audioContext && typeof this.options.expWebAudioMix === 'boolean') {
if (this.audioContext && typeof this.options.webAudioMix === 'boolean') {
this.audioContext.close();
this.audioContext = undefined;
}
Expand Down Expand Up @@ -1497,12 +1497,9 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
};

private async acquireAudioContext() {
if (
typeof this.options.expWebAudioMix !== 'boolean' &&
this.options.expWebAudioMix.audioContext
) {
if (typeof this.options.webAudioMix !== 'boolean' && this.options.webAudioMix.audioContext) {
// override audio context with custom audio context if supplied by user
this.audioContext = this.options.expWebAudioMix.audioContext;
this.audioContext = this.options.webAudioMix.audioContext;
} else if (!this.audioContext || this.audioContext.state === 'closed') {
// by using an AudioContext, it reduces lag on audio elements
// https://stackoverflow.com/questions/9811429/html5-audio-tag-on-safari-has-a-delay/54119854#54119854
Expand All @@ -1519,7 +1516,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
}
}

if (this.options.expWebAudioMix) {
if (this.options.webAudioMix) {
this.remoteParticipants.forEach((participant) =>
participant.setAudioContext(this.audioContext),
);
Expand All @@ -1544,7 +1541,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
loggerName: this.options.loggerName,
});
}
if (this.options.expWebAudioMix) {
if (this.options.webAudioMix) {
participant.setAudioContext(this.audioContext);
}
if (this.options.audioOutput?.deviceId) {
Expand Down
2 changes: 1 addition & 1 deletion src/room/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const roomOptionDefaults: InternalRoomOptions = {
stopLocalTrackOnUnpublish: true,
reconnectPolicy: new DefaultReconnectPolicy(),
disconnectOnPageLeave: true,
expWebAudioMix: false,
webAudioMix: true,
} as const;

export const roomConnectOptionDefaults: InternalRoomConnectOptions = {
Expand Down

0 comments on commit 8603746

Please sign in to comment.