From 091ad77179844c7883b88d409bca120dedfc7f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Fri, 12 Apr 2019 09:10:05 +0200 Subject: [PATCH] Added resolution setting. --- app/src/RoomClient.js | 83 +++++++++++++++++++++++-- app/src/actions/stateActions.js | 8 +++ app/src/components/Settings/Settings.js | 70 ++++++++++++++------- app/src/reducers/settings.js | 10 ++- 4 files changed, 144 insertions(+), 27 deletions(-) diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index 943cb69..4a90984 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -29,8 +29,31 @@ let ROOM_OPTIONS = const VIDEO_CONSTRAINS = { - width : { ideal: 1280 }, - aspectRatio : 1.334 + 'low' : + { + width : { ideal: 320 }, + aspectRatio : 1.334 + }, + 'medium' : + { + width : { ideal: 640 }, + aspectRatio : 1.334 + }, + 'high' : + { + width : { ideal: 1280 }, + aspectRatio : 1.334 + }, + 'veryhigh' : + { + width : { ideal: 1920 }, + aspectRatio : 1.334 + }, + 'ultra' : + { + width : { ideal: 3840 }, + aspectRatio : 1.334 + } }; let store; @@ -839,6 +862,56 @@ export default class RoomClient stateActions.setAudioInProgress(false)); } + async changeVideoResolution(resolution) + { + logger.debug('changeVideoResolution() [resolution: %s]', resolution); + + store.dispatch( + stateActions.setWebcamInProgress(true)); + + try + { + const deviceId = await this._getWebcamDeviceId(); + + const device = this._webcams[deviceId]; + + if (!device) + throw new Error('no webcam devices'); + + logger.debug('changeVideoResolution() | calling getUserMedia()'); + + const stream = await navigator.mediaDevices.getUserMedia( + { + video : + { + deviceId : { exact: device.deviceId }, + ...VIDEO_CONSTRAINS[resolution] + } + }); + + const track = stream.getVideoTracks()[0]; + + const newTrack = await this._webcamProducer.replaceTrack(track); + + track.stop(); + + store.dispatch( + stateActions.setProducerTrack(this._webcamProducer.id, newTrack)); + + store.dispatch(stateActions.setSelectedWebcamDevice(deviceId)); + store.dispatch(stateActions.setVideoResolution(resolution)); + + await this._updateWebcams(); + } + catch (error) + { + logger.error('changeVideoResolution() failed: %o', error); + } + + store.dispatch( + stateActions.setWebcamInProgress(false)); + } + async changeWebcam(deviceId) { logger.debug('changeWebcam() [deviceId: %s]', deviceId); @@ -849,6 +922,7 @@ export default class RoomClient try { const device = this._webcams[deviceId]; + const resolution = store.getState().settings.resolution; if (!device) throw new Error('no webcam devices'); @@ -864,7 +938,7 @@ export default class RoomClient video : { deviceId : { exact: device.deviceId }, - ...VIDEO_CONSTRAINS + ...VIDEO_CONSTRAINS[resolution] } }); @@ -1666,6 +1740,7 @@ export default class RoomClient const deviceId = await this._getWebcamDeviceId(); const device = this._webcams[deviceId]; + const resolution = store.getState().settings.resolution; if (!device) throw new Error('no webcam devices'); @@ -1681,7 +1756,7 @@ export default class RoomClient video : { deviceId : { exact: deviceId }, - ...VIDEO_CONSTRAINS + ...VIDEO_CONSTRAINS[resolution] } }); diff --git a/app/src/actions/stateActions.js b/app/src/actions/stateActions.js index d97ccb2..d81d433 100644 --- a/app/src/actions/stateActions.js +++ b/app/src/actions/stateActions.js @@ -113,6 +113,14 @@ export const setSelectedWebcamDevice = (deviceId) => }; }; +export const setVideoResolution = (resolution) => +{ + return { + type : 'SET_VIDEO_RESOLUTION', + payload : { resolution } + }; +}; + export const setFileSharingSupported = (supported) => { return { diff --git a/app/src/components/Settings/Settings.js b/app/src/components/Settings/Settings.js index 60f254f..843d548 100644 --- a/app/src/components/Settings/Settings.js +++ b/app/src/components/Settings/Settings.js @@ -59,13 +59,33 @@ const styles = (theme) => label : 'Filmstrip view' } ]; */ +const resolutions = [ { + value : 'low', + label : 'Low' +}, +{ + value : 'medium', + label : 'Medium' +}, +{ + value : 'high', + label : 'High (HD)' +}, +{ + value : 'veryhigh', + label : 'Very high (FHD)' +}, +{ + value : 'ultra', + label : 'Ultra (UHD)' +} ]; + const Settings = ({ roomClient, room, me, settings, onToggleAdvancedMode, - // handleChangeMode, handleCloseSettings, classes }) => @@ -156,32 +176,38 @@ const Settings = ({ +
+ + + + Select your video resolution + + +
} label='Advanced mode' /> - { /*
- - - - Select room layout - - -
*/ }