jam-cloud/web/app/assets/javascripts/webcam_viewer.js.coffee

126 lines
4.2 KiB
CoffeeScript

$ = jQuery
context = window
context.JK ||= {};
context.JK.WebcamViewer = class WebcamViewer
constructor: (@root) ->
@client = context.jamClient
@logger = context.JK.logger
@initialScan = false
@toggleBtn = null
@webcamSelect = null
@resolutionSelect = null
@videoShared=false
@resolution=null
init: (root) =>
# the session usage of webcamViewer does not actually pass in anything
root = $() unless root?
@root = root
@toggleBtn = @root.find(".webcam-test-btn")
@webcamSelect = @root.find(".webcam-select-container select")
@resolutionSelect = @root.find(".webcam-resolution-select-container select")
@webcamSelect.on("change", this.selectWebcam)
@toggleBtn.on('click', @toggleWebcam)
@resolutionSelect.on("change", this.selectResolution)
#logger.debug("Initialed with (unique) select",@webcamSelect)
beforeShow:() =>
this.loadWebCams()
this.selectWebcam()
this.loadResolutions()
this.selectResolution()
@initialScan = true
# protect against non-video clients pointed at video-enabled server from getting into a session
if @client.SessStopVideoSharing
@client.SessStopVideoSharing()
#client.SessSetInsetPosition(5)
#client.SessSetInsetSize(1)
#client.FTUESetAutoSelectVideoLayout(false)
#client.SessSelectVideoDisplayLayoutGroup(1)
selectWebcam:(e, data) =>
device = @webcamSelect.val()
if device?
caps = @client.FTUEGetVideoCaptureDeviceCapabilities(device)
@logger.debug("Got capabilities from device", caps, device)
@client.FTUESelectVideoCaptureDevice(device, caps)
selectResolution:() =>
@logger.debug 'Selecting from res control: ', @resolutionSelect
@resolution = @resolutionSelect.val()
if @resolution?
@logger.debug 'Selecting webcam resolution: ', @resolution
@client.FTUESetVideoEncodeResolution @resolution
# if @isVideoShared
# this.setVideoOff()
# this.toggleWebcam()
setVideoOff:() =>
if this.isVideoShared()
@client.SessStopVideoSharing()
isVideoShared:() =>
@videoShared
setToggleState:() =>
available = @webcamSelect.find('option').size() > 0
shared = this.isVideoShared()
@toggleBtn.prop 'disabled', true
@toggleBtn.prop 'disabled', !available
toggleWebcam:() =>
@logger.debug 'Toggling webcam from: ', this.isVideoShared(), @toggleBtn
if this.isVideoShared()
@toggleBtn.removeClass("selected")
@client.SessStopVideoSharing()
@videoShared = false
else
@toggleBtn.addClass("selected")
@client.SessStartVideoSharing 0
@videoShared = true
selectedDeviceName:() =>
webcamName="None Configured"
# protect against non-video clients pointed at video-enabled server from getting into a session
webcam = if @client.FTUECurrentSelectedVideoDevice? then @client.FTUECurrentSelectedVideoDevice() else null
if (webcam? && Object.keys(webcam).length>0)
webcamName = _.values(webcam)[0]
webcamName
loadWebCams:() =>
# protect against non-video clients pointed at video-enabled server from getting into a session
devices = if @client.FTUEGetVideoCaptureDeviceNames? then @client.FTUEGetVideoCaptureDeviceNames() else []
selectedDevice = this.selectedDeviceName()
selectControl = @webcamSelect
context._.each devices, (device) ->
selected = device == selectedDevice
option = $('<option/>',
id: device
value: device
text: device)
selectControl.append option
selectControl.val selectedDevice
if devices.length == 0
@root.find('.no-webcam-msg').removeClass 'hidden'
else
@root.find('.no-webcam-msg').addClass 'hidden'
loadResolutions:() =>
# protect against non-video clients pointed at video-enabled server from getting into a session
resolutions = if @client.FTUEGetAvailableEncodeVideoResolutions? then @client.FTUEGetAvailableEncodeVideoResolutions() else {}
selectControl = @resolutionSelect
@logger.debug 'FOUND THESE RESOLUTIONS', resolutions, selectControl
context._.each resolutions, (value, key, obj) ->
option = $('<option/>',
value: value
text: value)
selectControl.append option
if @resolution != null and @resolution != ''
selectControl.val(@resolution)