Skip to content

Commit f7796ee

Browse files
lukasIOsvajunas-budrys
authored andcommitted
Fix applying default processors from captureDefaults (livekit#1416)
1 parent 29388bc commit f7796ee

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

.changeset/sharp-avocados-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Fix applying default processors from captureDefaults

src/room/participant/LocalParticipant.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,17 @@ export default class LocalParticipant extends Participant {
602602
*/
603603
async createTracks(options?: CreateLocalTracksOptions): Promise<LocalTrack[]> {
604604
options ??= {};
605-
const { audioProcessor, videoProcessor, optionsWithoutProcessor } =
606-
extractProcessorsFromOptions(options);
607605

608-
const mergedOptions = mergeDefaultOptions(
609-
optionsWithoutProcessor,
606+
const mergedOptionsWithProcessors = mergeDefaultOptions(
607+
options,
610608
this.roomOptions?.audioCaptureDefaults,
611609
this.roomOptions?.videoCaptureDefaults,
612610
);
613611

614-
const constraints = constraintsForOptions(mergedOptions);
612+
const { audioProcessor, videoProcessor, optionsWithoutProcessor } =
613+
extractProcessorsFromOptions(mergedOptionsWithProcessors);
614+
615+
const constraints = constraintsForOptions(optionsWithoutProcessor);
615616
let stream: MediaStream | undefined;
616617
try {
617618
stream = await navigator.mediaDevices.getUserMedia(constraints);
@@ -639,10 +640,6 @@ export default class LocalParticipant extends Participant {
639640
return Promise.all(
640641
stream.getTracks().map(async (mediaStreamTrack) => {
641642
const isAudio = mediaStreamTrack.kind === 'audio';
642-
let trackOptions = isAudio ? mergedOptions!.audio : mergedOptions!.video;
643-
if (typeof trackOptions === 'boolean' || !trackOptions) {
644-
trackOptions = {};
645-
}
646643
let trackConstraints: MediaTrackConstraints | undefined;
647644
const conOrBool = isAudio ? constraints.audio : constraints.video;
648645
if (typeof conOrBool !== 'boolean') {

src/room/track/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export function mergeDefaultOptions(
2121
const { optionsWithoutProcessor, audioProcessor, videoProcessor } = extractProcessorsFromOptions(
2222
options ?? {},
2323
);
24+
const defaultAudioProcessor = audioDefaults?.processor;
25+
const defaultVideoProcessor = videoDefaults?.processor;
2426
const clonedOptions: CreateLocalTracksOptions = cloneDeep(optionsWithoutProcessor) ?? {};
2527
if (clonedOptions.audio === true) clonedOptions.audio = {};
2628
if (clonedOptions.video === true) clonedOptions.video = {};
@@ -32,8 +34,8 @@ export function mergeDefaultOptions(
3234
audioDefaults as Record<string, unknown>,
3335
);
3436
clonedOptions.audio.deviceId ??= 'default';
35-
if (audioProcessor) {
36-
clonedOptions.audio.processor = audioProcessor;
37+
if (audioProcessor || defaultAudioProcessor) {
38+
clonedOptions.audio.processor = audioProcessor ?? defaultAudioProcessor;
3739
}
3840
}
3941
if (clonedOptions.video) {
@@ -42,8 +44,8 @@ export function mergeDefaultOptions(
4244
videoDefaults as Record<string, unknown>,
4345
);
4446
clonedOptions.video.deviceId ??= 'default';
45-
if (videoProcessor) {
46-
clonedOptions.video.processor = videoProcessor;
47+
if (videoProcessor || defaultVideoProcessor) {
48+
clonedOptions.video.processor = videoProcessor ?? defaultVideoProcessor;
4749
}
4850
}
4951
return clonedOptions;

0 commit comments

Comments
 (0)