From 21f2018e718ab7b97e6dec481fe60fbd4b04f5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Fri, 22 May 2020 16:06:24 +0200 Subject: [PATCH] Handle device change properly based on paused status. --- app/src/RoomClient.js | 40 ++++++++++--------- app/src/components/Containers/Me.js | 12 +++--- .../components/Controls/ButtonControlBar.js | 6 +-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index b2fe424..7f5a6ce 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -402,7 +402,7 @@ export default class RoomClient } else { - this.updateMic({ restart: true }); + this.updateMic({ start: true }); store.dispatch(requestActions.notify( { @@ -421,7 +421,7 @@ export default class RoomClient if (this._webcamProducer) this.disableWebcam(); else - this.updateWebcam({ restart: true }); + this.updateWebcam({ start: true }); break; } @@ -969,7 +969,7 @@ export default class RoomClient if (!this._micProducer) { - this.updateMic({ restart: true }); + this.updateMic({ start: true }); } else { @@ -1153,10 +1153,11 @@ export default class RoomClient meActions.setAudioOutputInProgress(false)); } - async updateMic({ restart = false, newDeviceId = null } = {}) + async updateMic({ start = false, restart = false, newDeviceId = null } = {}) { logger.debug( - 'updateMic() [restart:"%s", newDeviceId:"%s"]', + 'updateMic() [start:"%s", restart:"%s", newDeviceId:"%s"]', + start, restart, newDeviceId ); @@ -1192,12 +1193,13 @@ export default class RoomClient sampleSize } = store.getState().settings; - if (restart) + if ( + (restart && this._micProducer) || + start + ) { this.disconnectLocalHark(); - store.dispatch(settingsActions.setSelectedAudioDevice(deviceId)); - if (this._micProducer) await this.disableMic(); @@ -1325,6 +1327,7 @@ export default class RoomClient } async updateWebcam({ + start = false, restart = false, newDeviceId = null, newResolution = null, @@ -1332,7 +1335,8 @@ export default class RoomClient } = {}) { logger.debug( - 'updateWebcam() [restart:"%s", newDeviceId:"%s", newResolution:"%s", newFrameRate:"%s"]', + 'updateWebcam() [start:"%s", restart:"%s", newDeviceId:"%s", newResolution:"%s", newFrameRate:"%s"]', + start, restart, newDeviceId, newResolution, @@ -1371,10 +1375,11 @@ export default class RoomClient frameRate } = store.getState().settings; - if (restart) + if ( + (restart && this._webcamProducer) || + start + ) { - store.dispatch(settingsActions.setSelectedWebcamDevice(deviceId)); - if (this._webcamProducer) await this.disableWebcam(); @@ -1439,7 +1444,6 @@ export default class RoomClient store.dispatch(producerActions.addProducer( { id : this._webcamProducer.id, - deviceLabel : device.label, source : 'webcam', paused : this._webcamProducer.paused, track : this._webcamProducer.track, @@ -3226,7 +3230,7 @@ export default class RoomClient if (this._mediasoupDevice.canProduce('audio')) if (!this._muted) { - await this.updateMic({ restart: true }); + await this.updateMic({ start: true }); let autoMuteThreshold = 4; if ('autoMuteThreshold' in window.config) @@ -3238,7 +3242,7 @@ export default class RoomClient } if (joinVideo) - this.updateWebcam({ restart: true }); + this.updateWebcam({ start: true }); } await this._updateAudioOutputDevices(); @@ -3585,12 +3589,12 @@ export default class RoomClient } async updateScreenSharing({ - restart = false, + start = false, newResolution = null, newFrameRate = null } = {}) { - logger.debug('updateScreenSharing() [restart:"%s"]', restart); + logger.debug('updateScreenSharing() [start:"%s"]', start); let track; @@ -3617,7 +3621,7 @@ export default class RoomClient screenSharingFrameRate } = store.getState().settings; - if (restart) + if (start) { const stream = await this._screenSharing.start({ ...VIDEO_CONSTRAINS[screenSharingResolution], diff --git a/app/src/components/Containers/Me.js b/app/src/components/Containers/Me.js index 450dd96..d475b8b 100644 --- a/app/src/components/Containers/Me.js +++ b/app/src/components/Containers/Me.js @@ -466,7 +466,7 @@ const Me = (props) => onClick={() => { if (micState === 'off') - roomClient.updateMic({ restart: true }); + roomClient.updateMic({ start: true }); else if (micState === 'on') roomClient.muteMic(); else @@ -500,7 +500,7 @@ const Me = (props) => onClick={() => { if (micState === 'off') - roomClient.updateMic({ restart: true }); + roomClient.updateMic({ start: true }); else if (micState === 'on') roomClient.muteMic(); else @@ -538,7 +538,7 @@ const Me = (props) => { webcamState === 'on' ? roomClient.disableWebcam() : - roomClient.updateWebcam({ restart: true }); + roomClient.updateWebcam({ start: true }); }} > { webcamState === 'on' ? @@ -563,7 +563,7 @@ const Me = (props) => { webcamState === 'on' ? roomClient.disableWebcam() : - roomClient.updateWebcam({ restart: true }); + roomClient.updateWebcam({ start: true }); }} > { webcamState === 'on' ? @@ -599,7 +599,7 @@ const Me = (props) => onClick={() => { if (screenState === 'off') - roomClient.updateScreenSharing({ restart: true }); + roomClient.updateScreenSharing({ start: true }); else if (screenState === 'on') roomClient.disableScreenSharing(); }} @@ -631,7 +631,7 @@ const Me = (props) => onClick={() => { if (screenState === 'off') - roomClient.updateScreenSharing({ restart: true }); + roomClient.updateScreenSharing({ start: true }); else if (screenState === 'on') roomClient.disableScreenSharing(); }} diff --git a/app/src/components/Controls/ButtonControlBar.js b/app/src/components/Controls/ButtonControlBar.js index 2ba9efa..50df0d2 100644 --- a/app/src/components/Controls/ButtonControlBar.js +++ b/app/src/components/Controls/ButtonControlBar.js @@ -192,7 +192,7 @@ const ButtonControlBar = (props) => onClick={() => { if (micState === 'off') - roomClient.updateMic({ restart: true }); + roomClient.updateMic({ start: true }); else if (micState === 'on') roomClient.muteMic(); else @@ -220,7 +220,7 @@ const ButtonControlBar = (props) => { webcamState === 'on' ? roomClient.disableWebcam() : - roomClient.updateWebcam({ restart: true }); + roomClient.updateWebcam({ start: true }); }} > { webcamState === 'on' ? @@ -243,7 +243,7 @@ const ButtonControlBar = (props) => onClick={() => { if (screenState === 'off') - roomClient.updateScreenSharing({ restart: true }); + roomClient.updateScreenSharing({ start: true }); else if (screenState === 'on') roomClient.disableScreenSharing(); }}