Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/room/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {

let publishDefaults: TrackPublishDefaults = {
audioBitrate: AudioPresets.speech.maxBitrate,
stopMicTrackOnMute: false,
};

let captureDefaults: TrackCaptureDefaults = {
Expand Down
3 changes: 3 additions & 0 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export default class LocalParticipant extends Participant {
if (opts.name) {
track.name = opts.name;
}
if (opts.stopMicTrackOnMute && track instanceof LocalAudioTrack) {
track.stopOnMute = true;
}

// handle track actions
track.on(TrackEvent.Muted, this.onTrackMuted);
Expand Down
20 changes: 13 additions & 7 deletions src/room/track/LocalAudioTrack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import log from '../../logger';
import LocalTrack from './LocalTrack';
import { CreateAudioTrackOptions } from './options';
import { Track } from './Track';

export default class LocalAudioTrack extends LocalTrack {
sender?: RTCRtpSender;

/** @internal */
stopOnMute: boolean = false;

constructor(
mediaTrack: MediaStreamTrack,
name?: string,
Expand All @@ -25,18 +29,20 @@ export default class LocalAudioTrack extends LocalTrack {

async mute(): Promise<LocalAudioTrack> {
// disabled special handling as it will cause BT headsets to switch communication modes
// if (this.source === Track.Source.Microphone) {
// // also stop the track, so that microphone indicator is turned off
// this.mediaStreamTrack.stop();
// }
if (this.source === Track.Source.Microphone && this.stopOnMute) {
log.debug('stopping mic track');
// also stop the track, so that microphone indicator is turned off
this.mediaStreamTrack.stop();
}
await super.mute();
return this;
}

async unmute(): Promise<LocalAudioTrack> {
// if (this.source === Track.Source.Microphone) {
// await this.restartTrack();
// }
if (this.source === Track.Source.Microphone && this.stopOnMute) {
log.debug('reacquiring mic track');
await this.restartTrack();
}
await super.unmute();
return this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/room/track/LocalVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class LocalVideoTrack extends LocalTrack {

async mute(): Promise<LocalVideoTrack> {
if (this.source === Track.Source.Camera) {
log.debug('stopping camera track');
// also stop the track, so that camera indicator is turned off
this.mediaStreamTrack.stop();
}
Expand All @@ -73,6 +74,7 @@ export default class LocalVideoTrack extends LocalTrack {

async unmute(): Promise<LocalVideoTrack> {
if (this.source === Track.Source.Camera) {
log.debug('reacquiring camera track');
await this.restartTrack();
}
await super.unmute();
Expand Down
10 changes: 10 additions & 0 deletions src/room/track/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export interface TrackPublishDefaults {
* at various resolutions.
*/
simulcast?: boolean;

/**
* For local tracks, stop the underlying MediaStreamTrack when the track is muted (or paused)
* on some platforms, this option is necessary to disable the microphone recording indicator.
* Note: when this is enabled, and BT devices are connected, they will transition between
* profiles (e.g. HFP to A2DP) and there will be an audible difference in playback.
*
* defaults to false
*/
stopMicTrackOnMute?: boolean;
}

export interface TrackCaptureDefaults {
Expand Down