From d07ac009bf8c51126af9d16ff592e7d547b85de9 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 1 Sep 2015 08:11:35 -0500 Subject: [PATCH] * VRFS-3509 - case where no device is configured handled --- .../stores/VideoStore.js.coffee | 57 ++++++++++++++++++- .../stores/WebcamViewer.js.jsx.coffee | 47 +++++++-------- 2 files changed, 74 insertions(+), 30 deletions(-) diff --git a/web/app/assets/javascripts/react-components/stores/VideoStore.js.coffee b/web/app/assets/javascripts/react-components/stores/VideoStore.js.coffee index 540ca965b..c989d3972 100644 --- a/web/app/assets/javascripts/react-components/stores/VideoStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/VideoStore.js.coffee @@ -6,6 +6,24 @@ NAMED_MESSAGES = context.JK.NAMED_MESSAGES VideoActions = @VideoActions +BackendToFrontend = { + 1 : "CIF (352x288)", + 2 : "VGA (640x480)", + 3 : "4CIF (704x576)", + 4 : "1/2 720p HD (640x360)", + 5 : "720p HD (1280x720)", + 6 : "1080p HD (1920x1080)" +} + +BackendToFrontendFPS = { + + 0: 30, + 1: 24, + 2: 20, + 3: 15, + 4: 10 +} + @VideoStore = Reflux.createStore( { listenables: VideoActions @@ -22,6 +40,9 @@ VideoActions = @VideoActions # someone has requested us to refresh our config onRefresh: -> + # don't do any check if this is a client with no video enabled + return unless context.jamClient.FTUECurrentSelectedVideoDevice? + currentDevice = context.jamClient.FTUECurrentSelectedVideoDevice() deviceNames = context.jamClient.FTUEGetVideoCaptureDeviceNames() #deviceCaps = context.jamClient.FTUEGetVideoCaptureDeviceCapabilities() @@ -30,7 +51,29 @@ VideoActions = @VideoActions encodeResolutions = context.jamClient.FTUEGetAvailableEncodeVideoResolutions() frameRates = context.jamClient.FTUEGetSendFrameRates() - #deviceCaps: deviceCaps, + + autoSelect = false + if currentResolution == 0 + @logger.warn("current resolution not specified; defaulting to VGA") + autoSelect = true + currentResolution = 2 + + if currentFrameRate == 0 + autoSelect = true + @logger.warn("current frame rate not specified; defaulting to 30") + currentFrameRate = 30 + else + # backend accepts 10,20,30 etc for FPS, but returns an indexed value (1, 2, 3). + convertedFrameRate = BackendToFrontendFPS[currentFrameRate] + @logger.debug("translating FPS: backend numeric #{currentFrameRate} to #{convertedFrameRate}") + currentFrameRate = convertedFrameRate + + # backend needs to be same as frontend + if autoSelect + context.jamClient.FTUESetVideoEncodeResolution(currentResolution) + context.jamClient.FTUESetSendFrameRates(currentFrameRate) + + #deviceCaps: deviceCaps, @state = { currentDevice: currentDevice, @@ -75,10 +118,16 @@ VideoActions = @VideoActions @onStartVideo() onSetVideoEncodeResolution: (resolution) -> + @logger.debug("set capture resolution: #{resolution}") context.jamClient.FTUESetVideoEncodeResolution(resolution) + @state.currentResolution = resolution + this.trigger(@state) onSetSendFrameRate: (frameRates) -> + @logger.debug("set capture frame rate: #{frameRates}") context.jamClient.FTUESetSendFrameRates(frameRates) + @state.currentFrameRate = frameRates + this.trigger(@state) onSelectDevice: (device, caps) -> result = context.jamClient.FTUESelectVideoCaptureDevice(device, caps) @@ -135,12 +184,16 @@ VideoActions = @VideoActions # if the user passes all the safeguards, let's see if we should get them to configure video onCheckPromptConfigureVideo: () -> + # don't do any check if this is a client with no video enabled + return unless context.jamClient.FTUECurrentSelectedVideoDevice? + @onRefresh() unless @state? @logger.debug("checkPromptConfigureVideo", @state.currentDevice, @state.deviceNames) # if no device configured and this is the native client and if you have at least 1 video - if (!@state.currentDevice? || Object.keys(@state.currentDevice).length == 0) && gon?.isNativeClient && Object.keys(@state.deviceNames).length > 0 + # currentDevice, from the backend, is '{'':''}' in the case of no device configured. But we also check for an empty object, or null object. + if (!@state.currentDevice? || Object.keys(@state.currentDevice).length == 0 || (Object.keys(@state.currentDevice).length == 1 && @state.currentDevice[''] == '')) && gon?.isNativeClient && Object.keys(@state.deviceNames).length > 0 # and if they haven't said stop bothering me about this context.JK.ModUtils.shouldShow(NAMED_MESSAGES.CONFIGURE_VIDEO_NOSHOW).done((shouldShow) => @logger.debug("checking if user has 'should show' on video config: #{shouldShow}") diff --git a/web/app/assets/javascripts/react-components/stores/WebcamViewer.js.jsx.coffee b/web/app/assets/javascripts/react-components/stores/WebcamViewer.js.jsx.coffee index d9cb7210d..7da4b74a8 100644 --- a/web/app/assets/javascripts/react-components/stores/WebcamViewer.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/stores/WebcamViewer.js.jsx.coffee @@ -34,7 +34,6 @@ BackendNumericToBackendString = { BackendToFrontendFPS = { - 1: 30, 2: 24, 3: 20, @@ -53,6 +52,7 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) mixins: mixins logger: context.JK.logger + visible: false getInitialState: () -> { @@ -93,8 +93,7 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) # protect against non-video clients pointed at video-enabled server from getting into a session resolutions = @state.encodeResolutions frames = @state.frameRates - @logger.debug 'FOUND THESE RESOLUTIONS', resolutions - @logger.debug 'FOUND THESE FPS', frames + @logger.debug("Webcam state on render", @state) context._.each resolutions, (resolution, resolutionKey, obj) => #{1: "CIF (352X288)", 2: "VGA (640X480)", 3: "4CIF (704X576)", 4: "1/2WHD (640X360)", 5: "WHD (1280X720)", 6: "FHD (1920x1080)"} @@ -111,24 +110,6 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) captureResolutions.push `` - autoSelect = false - if currentResolution == 0 - @logger.warn("current resolution not specified; defaulting to VGA") - autoSelect = true - currentResolution = 2 - if currentFrameRate == 0 - autoSelect = true - @logger.warn("current frame rate not specified; defaulting to 30") - currentFrameRate = 30 - else - convertedFrameRate = BackendToFrontendFPS[currentFrameRate] - @logger.debug("translating FPS: backend numeric #{currentFrameRate} to #{convertedFrameRate}") - currentFrameRate = convertedFrameRate - - # backend needs to be same as frontend - if autoSelect - @updateBackend(currentResolution, currentFrameRate) - if @state.videoShared toggleText = 'STOP WEBCAM' else @@ -179,7 +160,7 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) if !@initialScan? @initialScan = true - else + else if @visible @findChangedWebcams(nextState.deviceNames, @state.deviceNames) componentWillReceiveProps:(nextProps) -> @@ -190,6 +171,7 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) beforeShow:() -> + @visible = true VideoActions.refresh() VideoActions.stopVideo() @@ -198,14 +180,15 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) beforeHide: () -> - context.JK.offBackendEvent(ALERT_NAMES.USB_CONNECTED, 'webcam-viewer', @onUsbDeviceConnected); - context.JK.offBackendEvent(ALERT_NAMES.USB_DISCONNECTED, 'webcam-viewer', @onUsbDeviceDisconnected); + @visible = false + context.JK.offBackendEvent(ALERT_NAMES.USB_CONNECTED, 'webcam-viewer', @onUsbDeviceConnected); + context.JK.offBackendEvent(ALERT_NAMES.USB_DISCONNECTED, 'webcam-viewer', @onUsbDeviceDisconnected); - if @rescanTimeout? - clearTimeout(@rescanTimeout) - @rescanTimeout = null + if @rescanTimeout? + clearTimeout(@rescanTimeout) + @rescanTimeout = null - @setVideoOff() + @setVideoOff() onUsbDeviceConnected: () -> @@ -256,6 +239,7 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) @logger.debug 'new capture resolution selected: ' + resolution if resolution? + bits = resolution.split('|') selectedResolution = bits[0] selectedFps = bits[1] @@ -270,6 +254,13 @@ mixins.push(Reflux.listenTo(VideoStore, 'onVideoStateChanged')) toggleWebcam:(e) -> e.preventDefault() $toggleBtn = $(e.target) + + # we should only do this if no device is currently selected + $root = $(@getDOMNode()) + $select = $root.find('.webcam-select-container select') + device = $select.val() + VideoActions.selectDevice(device, {}) + VideoActions.toggleVideo() #if this.isVideoShared()