VRFS-1844 : A webcam component to initialize, and manage the state of, the webcam setup pane. Since this is accessed in several places, this javascript needed generifying.

This commit is contained in:
Steven Miers 2015-02-11 11:10:25 -06:00
parent 17b4b1aeca
commit 1081efffdd
1 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,104 @@
$ = 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) =>
console.log 'root', 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)
console.log 'webcamSelect', @webcamSelect
beforeShow:() =>
this.loadWebCams()
this.selectWebcam()
this.loadResolutions()
this.selectResolution()
@initialScan = true
#client.SessSetInsetPosition(5)
#client.SessSetInsetSize(1)
#client.FTUESetAutoSelectVideoLayout(false)
#client.SessSelectVideoDisplayLayoutGroup(1)
selectWebcam:(e, data) =>
console.log 'Selecting control: ', @webcamSelect
device = @webcamSelect.val()
if device != null and device != ''
console.log 'Selecting webcam: ', device
selectResolution:() =>
console.log 'Selecting res control: ', @resolutionSelect
@resolution = @resolutionSelect.val()
if @resolution != null and @resolution != ''
console.log 'Selecting res: ', @resolution
@client.FTUESetVideoEncodeResolution @resolution
setVideoOff:() =>
if this.isVideoShared()
@client.SessStopVideoSharing()
isVideoShared:() =>
@videoShared
setToggleState:() =>
available = @webcamSelect.find('option').size() > 0
shared = this.isVideoShared()
console.log 'Setting toggle from : ', shared
@toggleBtn.prop 'disabled', true
@toggleBtn.prop 'disabled', !available
toggleWebcam:() =>
console.log 'Toggling webcam from: ', this.isVideoShared()
if this.isVideoShared()
@client.SessStopVideoSharing()
@videoShared = false
else
@client.SessStartVideoSharing 0
@videoShared = true
loadWebCams:() =>
devices = @client.FTUEGetVideoCaptureDeviceNames()
selectedDevice = @client.FTUECurrentSelectedVideoDevice()
selectControl = @webcamSelect
context._.each devices, (device) ->
selected = device == selectedDevice
option = $('<option/>',
id: device
value: device
text: device)
console.log("Appending ", option, selectControl)
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:() =>
resolutions = @client.FTUEGetAvailableEncodeVideoResolutions()
selectControl = @resolutionSelect
console.log 'FOUND THESE RESOLUTIONS', resolutions, selectControl
context._.each resolutions, (value, key, obj) ->
console.log 'RRR', key, value
option = $('<option/>',
value: value
text: value)
selectControl.append option
if @resolution != null and @resolution != ''
selectControl.val(@resolution)