From ee8e8a95b64ade76e423e4bdf7c273cb49611be3 Mon Sep 17 00:00:00 2001 From: Nikola Novakovic Date: Mon, 28 Mar 2022 05:40:35 -0400 Subject: [PATCH] Fix microphone issues with Firefox and Safari (#233) * Firefox can't open more than one microphone per process. When switching audio input device, we need to stop using current device before opening new one. This also somewhat affect safari, causing "A MediaStreamTrack ended due to a capture failure" error. * Remove overriding preffered codec profile with default. --- src/stream.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/stream.ts b/src/stream.ts index 17f55340..4b2bb131 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -253,10 +253,6 @@ export class LocalStream extends MediaStream { const cap = RTCRtpSender.getCapabilities(kind); if (!cap) return; let selCodec: RTCRtpCodecCapability | undefined; - // 42e01f for safari/chrome/firefox cross-browser compatibility - if (kind === 'video' && this.constraints.codec && this.constraints.codec.toLowerCase() === 'h264') { - this.constraints.preferredCodecProfile = '42e01f' - } if (this.constraints.preferredCodecProfile && kind === 'video') { const allCodecProfiles = cap.codecs.filter( (c) => c.mimeType.toLowerCase() === `video/${this.constraints.codec.toLowerCase()}`, @@ -302,8 +298,6 @@ export class LocalStream extends MediaStream { }); } } else { - this.addTrack(next); - if (this.pc) { this.publishTrack(next); } @@ -359,6 +353,8 @@ export class LocalStream extends MediaStream { }; const prev = this.getTrack(kind); + // Firefox/Safari have issues when multiple input devices are used by same origin. We need to stop previous track before creating new one. + if (prev) prev.stop() const next = await this.getNewTrack(kind); this.updateTrack(next, prev);