$ = jQuery context = window logger = context.JK.logger EVENTS = context.JK.EVENTS 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 logger: context.JK.logger videoShared: false videoOpen : false state : null everDisabled : false init: -> this.listenTo(context.AppStore, this.onAppInit) onAppInit: (@app) -> # 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? videoEnabled = context.jamClient.FTUEGetVideoShareEnable() if videoEnabled currentDevice = context.jamClient.FTUECurrentSelectedVideoDevice() deviceNames = context.jamClient.FTUEGetVideoCaptureDeviceNames() #deviceCaps = context.jamClient.FTUEGetVideoCaptureDeviceCapabilities() currentResolution = context.jamClient.GetCurrentVideoResolution() currentFrameRate = context.jamClient.GetCurrentVideoFrameRate() encodeResolutions = context.jamClient.FTUEGetAvailableEncodeVideoResolutions() frameRates = context.jamClient.FTUEGetSendFrameRates() 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) else @everDisabled = true # don't talk to the backend when video is disabled; avoiding crashes currentDevice = null deviceNames = {} currentResolution: 0 currentFrameRate: 0 encodeResolutions: {} frameRates: {} #deviceCaps: deviceCaps, @state = { currentDevice: currentDevice, deviceNames: deviceNames, currentResolution: currentResolution, currentFrameRate: currentFrameRate, encodeResolutions: encodeResolutions, frameRates: frameRates, videoShared: @videoShared videoOpen: @videoOpen, videoEnabled: videoEnabled, everDisabled: @everDisabled } this.trigger(@state) onSetVideoEnabled: (enable) -> return unless context.jamClient.FTUESetVideoShareEnable? context.jamClient.FTUESetVideoShareEnable(enable) # keep state in sync @state.videoEnabled = enable @onRefresh() onStartVideo: -> if @howtoWindow? @howtoWindow.close() @howtoWindow = null #else # TESTING # @howtoWindow = window.open("/popups/how-to-use-video", 'How to Use Video', 'scrollbars=yes,toolbar=no,status=no,height=315,width=320') @logger.debug("SessStartVideoSharing()") context.jamClient.SessStartVideoSharing(0) @videoShared = true @state.videoShared = @videoShared this.trigger(@state) onStopVideo: -> if @videoShared @logger.debug("SessStopVideoSharing()") context.jamClient.SessStopVideoSharing() @videoShared = false @state.videoShared = @videoShared this.trigger(@state) onTestVideo: () -> return unless context.jamClient.testVideoRender? result = context.jamClient.testVideoRender() if !result @app.layout.notify({title: 'Unable to initialize video window', text: "Please contact support@jamkazam.com"}) onToggleVideo: () -> if @videoShared @onStopVideo() else @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) if(!result) @logger.error("onSelectDevice failed with device #{device}") @app.layout.notify({title: 'Unable to select webcam', text: "Please try reconnecting webcam."}) else @state.currentDevice = context.jamClient.FTUECurrentSelectedVideoDevice(); this.trigger(@state) onVideoWindowOpened: () -> @onRefresh() unless @state? @logger.debug("in session? #{context.SessionStore.inSession()}, currentDevice? #{@state?.currentDevice?}, videoShared? #{@videoShared}") if context.SessionStore.inSession() && @state.currentDevice? && Object.keys(@state.currentDevice).length > 0 && !@videoShared context.JK.ModUtils.shouldShow(NAMED_MESSAGES.HOWTO_USE_VIDEO_NOSHOW).done((shouldShow) => @logger.debug("checking if user has 'should show' on video howto: #{shouldShow}") if shouldShow @howtoWindow = window.open("/popups/how-to-use-video", 'How to Use Video', 'scrollbars=yes,toolbar=no,status=no,height=315,width=320') ) #@howtoWindo.ParentRecordingStore = context.RecordingStore #@howtoWindo.ParentIsRecording = @recordingModel.isRecording() @videoOpen = true @state.videoOpen = @videoOpen this.trigger(@state) onVideoWindowClosed: () -> @onRefresh() unless @state? if @howtoWindow? @howtoWindow.close() @howtoWindow = null @videoOpen = false @state.videoOpen = @videoOpen @videoShared = false @state.videoShared = @videoShared this.trigger(@state) onHowToUseVideoPopupClosed: (dontShow) -> if (dontShow) @logger.debug("requesting that user no longer see how-to-use-video") context.JK.ModUtils.updateNoShow(NAMED_MESSAGES.HOWTO_USE_VIDEO_NOSHOW); logger.debug("how-to-use-video popup closed") @howtoWindow = null onConfigureVideoPopupClosed: (dontShow) -> if (dontShow) @logger.debug("requesting that user no longer see configure-video") context.JK.ModUtils.updateNoShow(NAMED_MESSAGES.CONFIGURE_VIDEO_NOSHOW); logger.debug("configure-video popup closed") @configureWindow = null # 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 # 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}") if shouldShow @configureWindow = window.open("/popups/configure-video", 'Configure Video', 'scrollbars=yes,toolbar=no,status=no,height=395,width=444') ) } )