fix(tracks): mute tracks before using when created on device list change

This commit is contained in:
Leonard Kim 2018-09-04 08:29:50 -07:00
parent fe7652ec90
commit 3b754fa219
1 changed files with 17 additions and 6 deletions

View File

@ -2375,11 +2375,24 @@ export default {
createLocalTracksF, createLocalTracksF,
newDevices.videoinput, newDevices.videoinput,
newDevices.audioinput) newDevices.audioinput)
.then(tracks => .then(tracks => {
Promise.all(this._setLocalAudioVideoStreams(tracks))) // If audio or video muted before, or we unplugged current
// device and selected new one, then mute new track.
const muteSyncPromises = tracks.map(track => {
if ((track.isVideoTrack() && videoWasMuted)
|| (track.isAudioTrack() && audioWasMuted)) {
return track.mute();
}
return Promise.resolve();
});
return Promise.all(muteSyncPromises)
.then(() => Promise.all(
this._setLocalAudioVideoStreams(tracks)));
})
.then(() => { .then(() => {
// If audio was muted before, or we unplugged current device // Log and sync known mute state.
// and selected new one, then mute new audio track.
if (audioWasMuted) { if (audioWasMuted) {
sendAnalytics(createTrackMutedEvent( sendAnalytics(createTrackMutedEvent(
'audio', 'audio',
@ -2388,8 +2401,6 @@ export default {
muteLocalAudio(true); muteLocalAudio(true);
} }
// If video was muted before, or we unplugged current device
// and selected new one, then mute new video track.
if (!this.isSharingScreen && videoWasMuted) { if (!this.isSharingScreen && videoWasMuted) {
sendAnalytics(createTrackMutedEvent( sendAnalytics(createTrackMutedEvent(
'video', 'video',