Skip to content

Commit

Permalink
Fix microphone issues with Firefox and Safari (#233)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dreamerns authored Mar 28, 2022
1 parent f68cdde commit ee8e8a9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
Expand Down Expand Up @@ -302,8 +298,6 @@ export class LocalStream extends MediaStream {
});
}
} else {
this.addTrack(next);

if (this.pc) {
this.publishTrack(next);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ee8e8a9

Please sign in to comment.