Merge pull request #2077 from jitsi/device-changes

Fixes few changes around changing devices
This commit is contained in:
virtuacoplenny 2017-10-20 15:55:43 -07:00 committed by GitHub
commit 205822ac31
2 changed files with 28 additions and 14 deletions

View File

@ -2176,6 +2176,8 @@ export default {
APP.UI.addListener( APP.UI.addListener(
UIEvents.VIDEO_DEVICE_CHANGED, UIEvents.VIDEO_DEVICE_CHANGED,
cameraDeviceId => { cameraDeviceId => {
const videoWasMuted = this.isLocalVideoMuted();
sendAnalyticsEvent('settings.changeDevice.video'); sendAnalyticsEvent('settings.changeDevice.video');
createLocalTracksF({ createLocalTracksF({
devices: [ 'video' ], devices: [ 'video' ],
@ -2183,7 +2185,9 @@ export default {
micDeviceId: null micDeviceId: null
}) })
.then(([ stream ]) => { .then(([ stream ]) => {
if (this.isAudioOnly()) { // if we are in audio only mode or video was muted before
// changing device, then mute
if (this.isAudioOnly() || videoWasMuted) {
return stream.mute() return stream.mute()
.then(() => stream); .then(() => stream);
} }
@ -2191,7 +2195,14 @@ export default {
return stream; return stream;
}) })
.then(stream => { .then(stream => {
this.useVideoStream(stream); // if we are screen sharing we do not want to stop it
if (this.isSharingScreen) {
return Promise.resolve();
}
return this.useVideoStream(stream);
})
.then(() => {
logger.log('switched local video device'); logger.log('switched local video device');
APP.settings.setCameraDeviceId(cameraDeviceId, true); APP.settings.setCameraDeviceId(cameraDeviceId, true);
}) })
@ -2204,6 +2215,8 @@ export default {
APP.UI.addListener( APP.UI.addListener(
UIEvents.AUDIO_DEVICE_CHANGED, UIEvents.AUDIO_DEVICE_CHANGED,
micDeviceId => { micDeviceId => {
const audioWasMuted = this.isLocalAudioMuted();
sendAnalyticsEvent( sendAnalyticsEvent(
'settings.changeDevice.audioIn'); 'settings.changeDevice.audioIn');
createLocalTracksF({ createLocalTracksF({
@ -2212,6 +2225,16 @@ export default {
micDeviceId micDeviceId
}) })
.then(([ stream ]) => { .then(([ stream ]) => {
// if audio was muted before changing the device, mute
// with the new device
if (audioWasMuted) {
return stream.mute()
.then(() => stream);
}
return stream;
})
.then(stream => {
this.useAudioStream(stream); this.useAudioStream(stream);
logger.log('switched local audio device'); logger.log('switched local audio device');
APP.settings.setMicDeviceId(micDeviceId, true); APP.settings.setMicDeviceId(micDeviceId, true);
@ -2408,10 +2431,6 @@ export default {
const promises = []; const promises = [];
const audioWasMuted = this.isLocalAudioMuted(); const audioWasMuted = this.isLocalAudioMuted();
const videoWasMuted = this.isLocalVideoMuted(); const videoWasMuted = this.isLocalVideoMuted();
const availableAudioInputDevices
= mediaDeviceHelper.getDevicesFromListByKind(devices, 'audioinput');
const availableVideoInputDevices
= mediaDeviceHelper.getDevicesFromListByKind(devices, 'videoinput');
if (typeof newDevices.audiooutput !== 'undefined') { if (typeof newDevices.audiooutput !== 'undefined') {
// Just ignore any errors in catch block. // Just ignore any errors in catch block.
@ -2430,9 +2449,7 @@ export default {
.then(() => { .then(() => {
// If audio was muted before, or we unplugged current device // If audio was muted before, or we unplugged current device
// and selected new one, then mute new audio track. // and selected new one, then mute new audio track.
if (audioWasMuted if (audioWasMuted) {
|| currentDevices.audioinput.length
> availableAudioInputDevices.length) {
sendAnalyticsEvent('deviceListChanged.audio.muted'); sendAnalyticsEvent('deviceListChanged.audio.muted');
logger.log('Audio mute: device list changed'); logger.log('Audio mute: device list changed');
muteLocalAudio(true); muteLocalAudio(true);
@ -2440,10 +2457,7 @@ export default {
// If video was muted before, or we unplugged current device // If video was muted before, or we unplugged current device
// and selected new one, then mute new video track. // and selected new one, then mute new video track.
if (!this.isSharingScreen if (!this.isSharingScreen && videoWasMuted) {
&& (videoWasMuted
|| currentDevices.videoinput.length
> availableVideoInputDevices.length)) {
sendAnalyticsEvent('deviceListChanged.video.muted'); sendAnalyticsEvent('deviceListChanged.video.muted');
logger.log('Video mute: device list changed'); logger.log('Video mute: device list changed');
muteLocalVideo(true); muteLocalVideo(true);

View File

@ -165,7 +165,7 @@ export function replaceLocalTrack(oldTrack, newTrack, conference) {
logger.log(`Replace ${newTrack.getType()} track - ${ logger.log(`Replace ${newTrack.getType()} track - ${
isMuted ? 'muted' : 'unmuted'}`); isMuted ? 'muted' : 'unmuted'}`);
return dispatch(setMuted()); return dispatch(setMuted(isMuted));
} }
}) })
.then(() => { .then(() => {