Skip to content

Commit ee8e8a9

Browse files
authored
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.
1 parent f68cdde commit ee8e8a9

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

src/stream.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,6 @@ export class LocalStream extends MediaStream {
253253
const cap = RTCRtpSender.getCapabilities(kind);
254254
if (!cap) return;
255255
let selCodec: RTCRtpCodecCapability | undefined;
256-
// 42e01f for safari/chrome/firefox cross-browser compatibility
257-
if (kind === 'video' && this.constraints.codec && this.constraints.codec.toLowerCase() === 'h264') {
258-
this.constraints.preferredCodecProfile = '42e01f'
259-
}
260256
if (this.constraints.preferredCodecProfile && kind === 'video') {
261257
const allCodecProfiles = cap.codecs.filter(
262258
(c) => c.mimeType.toLowerCase() === `video/${this.constraints.codec.toLowerCase()}`,
@@ -302,8 +298,6 @@ export class LocalStream extends MediaStream {
302298
});
303299
}
304300
} else {
305-
this.addTrack(next);
306-
307301
if (this.pc) {
308302
this.publishTrack(next);
309303
}
@@ -359,6 +353,8 @@ export class LocalStream extends MediaStream {
359353
};
360354

361355
const prev = this.getTrack(kind);
356+
// Firefox/Safari have issues when multiple input devices are used by same origin. We need to stop previous track before creating new one.
357+
if (prev) prev.stop()
362358
const next = await this.getNewTrack(kind);
363359

364360
this.updateTrack(next, prev);

0 commit comments

Comments
 (0)