From 57a876e28d7488ce704a7da7fc05a17ba48be35e Mon Sep 17 00:00:00 2001 From: Moe Date: Sat, 13 Jun 2020 11:46:20 -0700 Subject: [PATCH] minor cleanup for PTZ handling --- libs/control/ptz.js | 53 +++++++++++++++++------------------ libs/events.js | 2 +- web/libs/js/dash2.elements.js | 2 +- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/libs/control/ptz.js b/libs/control/ptz.js index 5e74a071..74131022 100644 --- a/libs/control/ptz.js +++ b/libs/control/ptz.js @@ -105,42 +105,41 @@ module.exports = function(s,config,lang,app,io){ break; } } - const ptzControl = async function(e,callback){ - s.checkDetails(e) - if(!s.group[e.ke] || !s.group[e.ke].activeMonitors[e.id]){return} - const monitorConfig = s.group[e.ke].rawMonitorConfigurations[e.id] + const ptzControl = async function(options,callback){ + if(!s.group[options.ke] || !s.group[options.ke].activeMonitors[options.id]){return} + const monitorConfig = s.group[options.ke].rawMonitorConfigurations[options.id] const controlUrlMethod = monitorConfig.details.control_url_method || 'GET' const controlBaseUrl = monitorConfig.details.control_base_url || s.buildMonitorUrl(monitorConfig, true) if(monitorConfig.details.control !== "1"){ s.userLog(e,{type:lang['Control Error'],msg:lang.ControlErrorText1}); return } - if(monitorConfig.details.control_url_stop_timeout === '0' && monitorConfig.details.control_stop === '1' && s.group[e.ke].activeMonitors[e.id].ptzMoving === true){ - e.direction = 'stopMove' - s.group[e.ke].activeMonitors[e.id].ptzMoving = false + if(monitorConfig.details.control_url_stop_timeout === '0' && monitorConfig.details.control_stop === '1' && s.group[options.ke].activeMonitors[options.id].ptzMoving === true){ + options.direction = 'stopMove' + s.group[options.ke].activeMonitors[options.id].ptzMoving = false }else{ - s.group[e.ke].activeMonitors[e.id].ptzMoving = true + s.group[options.ke].activeMonitors[options.id].ptzMoving = true } if(controlUrlMethod === 'ONVIF'){ try{ //create onvif connection if( - !s.group[e.ke].activeMonitors[e.id].onvifConnection || - !s.group[e.ke].activeMonitors[e.id].onvifConnection.current_profile || - !s.group[e.ke].activeMonitors[e.id].onvifConnection.current_profile.token + !s.group[options.ke].activeMonitors[options.id].onvifConnection || + !s.group[options.ke].activeMonitors[options.id].onvifConnection.current_profile || + !s.group[options.ke].activeMonitors[options.id].onvifConnection.current_profile.token ){ const response = await s.createOnvifDevice({ - ke: e.ke, - id: e.id, + ke: options.ke, + id: options.id, }) if(response.ok){ moveCamera({ - ke: e.ke, - id: e.id, - direction: e.direction, - axis: e.axis, + ke: options.ke, + id: options.id, + direction: options.direction, + axis: options.axis, },(msg) => { - msg.msg = e.direction + msg.msg = options.direction callback(msg) }) }else{ @@ -148,12 +147,12 @@ module.exports = function(s,config,lang,app,io){ } }else{ moveCamera({ - ke: e.ke, - id: e.id, - direction: e.direction, - axis: e.axis, + ke: options.ke, + id: options.id, + direction: options.direction, + axis: options.axis, },(msg) => { - if(!msg.msg)msg.msg = {direction: e.direction} + if(!msg.msg)msg.msg = {direction: options.direction} callback(msg) }) } @@ -164,14 +163,14 @@ module.exports = function(s,config,lang,app,io){ msg: { msg: lang.ControlErrorText2, error: err, - direction: e.direction + direction: options.direction } }) } }else{ const controlUrlStopTimeout = parseInt(monitorConfig.details.control_url_stop_timeout) || 1000 var stopCamera = function(){ - var stopURL = controlBaseUrl + monitorConfig.details['control_url_'+e.direction+'_stop'] + var stopURL = controlBaseUrl + monitorConfig.details[`control_url_${options.direction}_stop`] var options = s.cameraControlOptionsFromUrl(stopURL,monitorConfig) var requestOptions = { url : stopURL, @@ -194,7 +193,7 @@ module.exports = function(s,config,lang,app,io){ s.userLog(e,msg); }) } - if(e.direction === 'stopMove'){ + if(options.direction === 'stopMove'){ stopCamera() }else{ var requestOptions = { @@ -213,7 +212,7 @@ module.exports = function(s,config,lang,app,io){ callback({ok:false,type:'Control Error',msg:err}) return } - if(monitorConfig.details.control_stop == '1' && e.direction !== 'center' ){ + if(monitorConfig.details.control_stop == '1' && options.direction !== 'center' ){ s.userLog(e,{type:'Control Triggered Started'}); if(controlUrlStopTimeout > 0){ setTimeout(function(){ diff --git a/libs/events.js b/libs/events.js index c0d88ddf..0193a846 100644 --- a/libs/events.js +++ b/libs/events.js @@ -105,7 +105,7 @@ module.exports = function(s,config,lang){ s.cameraControl({ axis: axis, // axis: [{direction: 'x', amount: 1.0}], - mid: event.id, + id: event.id, ke: event.ke },(msg) => { s.userLog(event,msg) diff --git a/web/libs/js/dash2.elements.js b/web/libs/js/dash2.elements.js index 1222b79a..fdcdcbc0 100644 --- a/web/libs/js/dash2.elements.js +++ b/web/libs/js/dash2.elements.js @@ -435,7 +435,7 @@ $(document).ready(function(e){ break; case'control': e.a=e.e.attr('control') - $.ccio.cx({f:'monitor',ff:'control',direction:e.a,mid:e.mid,ke:e.ke},user) + $.ccio.cx({f:'monitor',ff:'control',direction:e.a,id:e.mid,ke:e.ke},user) break; case'videos_table':case'calendar':case'video_grid'://call videos table or calendar or video grid $.vidview.launcher=$(this);