jam-cloud/web/app/assets/javascripts/react-components/stores/VideoStore.js.coffee

205 lines
7.2 KiB
CoffeeScript
Raw Normal View History

$ = 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
init: ->
this.listenTo(context.SessionStore, this.onSessionChange)
# 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()
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)
#deviceCaps: deviceCaps,
@state = {
currentDevice: currentDevice,
deviceNames: deviceNames,
currentResolution: currentResolution,
currentFrameRate: currentFrameRate,
encodeResolutions: encodeResolutions,
frameRates: frameRates,
videoShared: @videoShared
videoOpen: @videoOpen
}
this.trigger(@state)
onSessionChange: (@session) ->
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)
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}")
onVideoWindowOpened: () ->
@onRefresh() unless @state?
@logger.debug("in session? #{@session.inSession()}, currentDevice? #{@state?.currentDevice?}, videoShared? #{@videoShared}")
if @session.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')
)
}
)