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

411 lines
16 KiB
CoffeeScript

$ = jQuery
context = window
logger = context.JK.logger
rest = context.JK.Rest()
EVENTS = context.JK.EVENTS
NAMED_MESSAGES = context.JK.NAMED_MESSAGES
VideoActions = @VideoActions
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)
this.onBringVideoToFront()
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()
# @videoEnabled = videoEnabled
# if videoEnabled
# currentDevice = context.jamClient.FTUECurrentSelectedVideoDevice()
# deviceNames = context.jamClient.FTUEGetVideoCaptureDeviceNames()
# #deviceCaps = context.jamClient.FTUEGetVideoCaptureDeviceCapabilities()
# captureResolutions = context.jamClient.FTUEGetCaptureResolution()
# currentCaptureResolution = context.jamClient.FTUEGetCurrentCaptureResolution()
# logger.debug("captureResolutions, currentCaptureResolution", captureResolutions, currentCaptureResolution)
# else
# @everDisabled = true
# # don't talk to the backend when video is disabled; avoiding crashes
# currentDevice = null
# deviceNames = {}
# captureResolutions: {}
# currentCaptureResolution: null
# frameRates: {}
# #deviceCaps: deviceCaps,
# @state = {
# currentDevice: currentDevice,
# deviceNames: deviceNames,
# captureResolutions: captureResolutions,
# currentCaptureResolution: currentCaptureResolution,
# videoShared: @videoShared
# videoOpen: @videoOpen,
# videoEnabled: videoEnabled,
# everDisabled: @everDisabled
# }
# this.trigger(@state)
onRefresh: `async function() {
let captureResolutions, currentCaptureResolution, currentDevice, deviceNames;
if (await context.jamClient.FTUECurrentSelectedVideoDevice() == null) { return; }
const videoEnabled = await context.jamClient.FTUEGetVideoShareEnable();
this.videoEnabled = videoEnabled;
if (videoEnabled) {
currentDevice = await context.jamClient.FTUECurrentSelectedVideoDevice();
deviceNames = await context.jamClient.FTUEGetVideoCaptureDeviceNames();
//deviceCaps = await context.jamClient.FTUEGetVideoCaptureDeviceCapabilities()
captureResolutions = await context.jamClient.FTUEGetCaptureResolution();
currentCaptureResolution = await context.jamClient.FTUEGetCurrentCaptureResolution();
logger.debug("captureResolutions, currentCaptureResolution", captureResolutions, currentCaptureResolution);
} else {
this.everDisabled = true;
currentDevice = null;
deviceNames = {};
({
captureResolutions: {},
currentCaptureResolution: null,
frameRates: {}
});
}
this.state = {
currentDevice,
deviceNames,
captureResolutions,
currentCaptureResolution,
videoShared: this.videoShared,
videoOpen: this.videoOpen,
videoEnabled,
externalVideoEnabled,
everDisabled: this.everDisabled
};
this.trigger(this.state);
}`
# onSetVideoEnabled: (enable) ->
# return unless context.jamClient.FTUESetVideoShareEnable?
# context.jamClient.FTUESetVideoShareEnable(enable)
# # keep state in sync
# @state.videoEnabled = enable
# @onRefresh()
onSetVideoEnabled: `async function(enable) {
if (await context.jamClient.FTUESetVideoShareEnable() == null) { return; }
await context.jamClient.FTUESetVideoShareEnable(enable);
// keep state in sync
this.state.videoEnabled = enable;
//return this.onRefresh();
}`
onSetExternalVideoEnabled: (enable) ->
console.log("onSetExternalVideoEnabled", enable)
if @state
console.log("setting externalVideoEnabled", enable)
@state.externalVideoEnabled = enable;
# onStartVideo: ->
# return unless context.jamClient.SessStartVideoSharing?
# 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)
onStartVideo: `async function() {
if (await context.jamClient.SessStartVideoSharing() == null) { return; }
if (this.howtoWindow != null) {
this.howtoWindow.close();
this.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')
this.logger.debug("SessStartVideoSharing()");
await context.jamClient.SessStartVideoSharing(0);
this.videoShared = true;
this.state.videoShared = this.videoShared;
return this.trigger(this.state);
}`
# onStopVideo: ->
# if @videoShared
# @logger.debug("SessStopVideoSharing()")
# context.jamClient.SessStopVideoSharing()
# @videoShared = false
# @state.videoShared = @videoShared
# this.trigger(@state)
onStopVideo: `async function() {
if (this.videoShared) {
this.logger.debug("SessStopVideoSharing()");
await context.jamClient.SessStopVideoSharing();
this.videoShared = false;
this.state.videoShared = this.videoShared;
return this.trigger(this.state);
}
}`
# onBringVideoToFront: ->
# if @videoShared
# @logger.debug("BringVideoToFront")
# context.jamClient.BringVideoWindowToFront();
onBringVideoToFront: `async function() {
if (this.videoShared) {
this.logger.debug("BringVideoToFront");
await context.jamClient.BringVideoWindowToFront(); }
}`
# 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"})
onTestVideo: `async function() {
const videoRender = await context.jamClient.testVideoRender();
if (videoRender == null) { return; }
const result = videoRender;
if (!result) {
return this.app.layout.notify({title: 'Unable to initialize video window', text: "Please contact support@jamkazam.com"});
}
}`
onToggleVideo: () ->
if @videoShared
@onBringVideoToFront()
else
@onStartVideo()
# onSetCaptureResolution: (resolution) ->
# @logger.debug("set capture resolution: #{resolution}")
# context.jamClient.FTUESetCaptureResolution(resolution)
# @state.currentCaptureResolution = resolution
# this.trigger(@state)
onSetCaptureResolution: `async function(resolution) {
this.logger.debug('set capture resolution: '+resolution);
await context.jamClient.FTUESetCaptureResolution(resolution);
this.state.currentCaptureResolution = resolution;
this.trigger(this.state);
}`
# onSetSendFrameRate: (frameRates) ->
# @logger.debug("set capture frame rate: #{frameRates}")
# context.jamClient.FTUESetSendFrameRates(frameRates)
# @state.currentFrameRate = frameRates
# this.trigger(@state)
onSetSendFrameRate: `async function(frameRates) {
this.logger.debug('set capture frame rate: '+frameRates);
await context.jamClient.FTUESetSendFrameRates(frameRates);
this.state.currentFrameRate = frameRates;
this.trigger(this.state);
}`
# onRefreshVideoState:()->
# @logger.debug("onRefreshVideoState")
# openVideoSources = context.jamClient.getOpenVideoSources()
# @logger.debug("onRefreshVideoState", openVideoSources)
# # possible keys, all bool values
# #"session_window", "webcam1", "webcam2", "screen_capture"
# # ex: with mac webcam open only: session_window: 2, webcam1: 1}
# # no webcam open: Object {}
# @openVideoSources = openVideoSources
# @anyVideoOpen = Object.keys(openVideoSources).length > 0
# @state.anyVideoOpen = Object.keys(openVideoSources).length > 0
# this.trigger(@state)
onRefreshVideoState: `async function(){
this.logger.debug("onRefreshVideoState");
const openVideoSources = await context.jamClient.getOpenVideoSources();
this.logger.debug("onRefreshVideoState", openVideoSources);
// possible keys, all bool values
//"session_window", "webcam1", "webcam2", "screen_capture"
// ex: with mac webcam open only: session_window: 2, webcam1: 1}
// no webcam open: Object {}
this.openVideoSources = openVideoSources;
this.anyVideoOpen = Object.keys(openVideoSources).length > 0;
this.state.anyVideoOpen = Object.keys(openVideoSources).length > 0;
return this.trigger(this.state);
}`
# onSelectDevice: (device, caps) ->
# # don't do anything if no video capabilities
# return unless context.jamClient.FTUESelectVideoCaptureDevice?
# 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)
onSelectDevice: `async function(device, caps) {
//do not do anything if no video capabilities
//if (await context.jamClient.FTUESelectVideoCaptureDevice() == null) { return; }
const result = await context.jamClient.FTUESelectVideoCaptureDevice(device, caps);
if(!result) {
this.logger.error('onSelectDevice failed with device '+ device);
return this.app.layout.notify({title: 'Unable to select webcam', text: "Please try reconnecting webcam."});
} else {
this.state.currentDevice = await context.jamClient.FTUECurrentSelectedVideoDevice();
this.trigger(this.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')
# )
#onCheckPromptConfigureVideo: `async function() {
#// do not do any check if this is a client with no video enabled
#if (await context.jamClient.FTUECurrentSelectedVideoDevice() == null) { return; }
#if (this.state == null) { this.onRefresh(); }
#this.logger.debug("checkPromptConfigureVideo", this.state.currentDevice, this.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 (((this.state.currentDevice == null) || (Object.keys(this.state.currentDevice).length === 0) || ((Object.keys(this.state.currentDevice).length === 1) && (this.state.currentDevice[''] === ''))) && (typeof gon !== 'undefined' && gon !== null ? gon.isNativeClient : undefined) && (Object.keys(this.state.deviceNames).length > 0)) {
# // and if they have not said stop bothering me about this
# context.JK.ModUtils.shouldShow(NAMED_MESSAGES.CONFIGURE_VIDEO_NOSHOW).done(shouldShow => {
# this.logger.debug("checking if user has 'should show' on video config: " + shouldShow);
# if (shouldShow) {
# return this.configureWindow = window.open("/popups/configure-video", 'Configure Video', 'scrollbars=yes,toolbar=no,status=no,height=395,width=444');
# }
# });
#}
#}`
isVideoEnabled:() ->
return @videoEnabled
}
)