diff --git a/definitions/base.js b/definitions/base.js index 0ee5258f..087b7f23 100644 --- a/definitions/base.js +++ b/definitions/base.js @@ -3142,6 +3142,14 @@ module.exports = function(s,config,lang){ } ] }, + { + "name": "detail=detector_chosen", + "field": lang["Chosen Plugin"], + "description": lang.fieldTextChosenPlugin, + "attribute": `multiple`, + "fieldType": "select", + "possible": [] + }, { "name": "detail=detector_object_ignore_not_move", "field": lang["Ignore Non-Moving"], diff --git a/languages/en_CA.json b/languages/en_CA.json index 40b2c242..91d205a6 100644 --- a/languages/en_CA.json +++ b/languages/en_CA.json @@ -18,6 +18,8 @@ "accountEditError": "Account Edit Error", "Monitor Map": "Monitor Map", "Geolocation": "Geolocation", + "Chosen Plugin": "Chosen Plugin", + "fieldTextChosenPlugin": "Detector Plugin to use. Select none to send to all. This field is inactive when Plugins are used in Cluster Mode.", "fieldTextGeolocation": "The map coordinates of this camera in the real world. This will plot a point for your camera on the Monitor Map.", "playUntilVideoEnd": "Play until video end", "Monitor Saved": "Monitor Saved", diff --git a/libs/plugins.js b/libs/plugins.js index 9cd51d87..0ba6a9a9 100644 --- a/libs/plugins.js +++ b/libs/plugins.js @@ -164,6 +164,18 @@ module.exports = function(s,config,lang,app,io){ }) } } + function sendToSpecificDetector(data, chosenDetectorPlugins){ + if(s.connectedPlugins[name]){ + s.connectedPlugins[name].tx(data) + }else{ + console.error('Plugin Not Connected',name, 'used by',data.id) + } + } + s.sendToSpecificDetectors = function(data, chosenDetectorPlugins){ + chosenDetectorPlugins.forEach(function(name){ + sendToSpecificDetector(data, name) + }) + } s.sendDetectorInfoToClient = function(data,txFunction){ s.detectorPluginArray.forEach(function(name){ var detectorData = Object.assign(data,{ diff --git a/libs/plugins/webPaths.js b/libs/plugins/webPaths.js new file mode 100644 index 00000000..b6d2d4ec --- /dev/null +++ b/libs/plugins/webPaths.js @@ -0,0 +1,21 @@ + +module.exports = function(s,config,lang,app,io){ + /** + * API : Get Available Plugins + */ + app.get(config.webPaths.apiPrefix+':auth/plugins/:ke',function (req,res){ + var response = {ok: true}; + res.setHeader('Content-Type', 'application/json'); + s.auth(req.params,function(user){ + response.plugins = [ + ...s.detectorPluginArray.map(item => { + return { + "name": item, + "value": item + } + }) + ]; + res.end(s.prettyPrint(response)); + },res,req); + }) +} diff --git a/web/assets/js/bs5.monitorSettings.js b/web/assets/js/bs5.monitorSettings.js index 5ec616c6..a47059c7 100644 --- a/web/assets/js/bs5.monitorSettings.js +++ b/web/assets/js/bs5.monitorSettings.js @@ -700,6 +700,14 @@ function importIntoMonitorEditor(options){ theAction(monitorConfig) }) } + +function getAvailablePlugins(){ + return new Promise((resolve) => { + $.get(getApiPrefix()+'/plugins/'+monitorConfig.ke+'/',function(data){ + resolve(data) + }) + }) +} //parse "Automatic" field in "Input" Section monitorEditorWindow.on('change','.auto_host_fill input,.auto_host_fill select',function(e){ var theSwitch = monitorEditorWindow.find('[detail="auto_host_enable"]').val() @@ -1327,11 +1335,12 @@ editorForm.find('[name="type"]').change(function(e){ sideMenuCollapsePoint.collapse('show') } } - function onTabMove(){ + async function onTabMove(){ var theSelected = `${monitorsList.val() || ''}` drawMonitorListToSelector(monitorsList.find('optgroup'),false,'host') monitorsList.val(theSelected) checkToOpenSideMenu() + monitorEditorWindow.find('[detail="detector_chosen"]').val(await getAvailablePlugins()) } addOnTabAway('monitorSettings', function(){ if(isSideBarMenuCollapsed()){