UNPKG

iotagent-node-lib

Version:

IoT Agent library to interface with NGSI Context Broker

63 lines (58 loc) 2.67 kB
/* * Copyright 2020 Telefonica Investigación y Desarrollo, S.A.U * * This file is part of fiware-iotagent-lib * * fiware-iotagent-lib is free software: you can redistribute it and/or * modify it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * fiware-iotagent-lib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public * License along with fiware-iotagent-lib. * If not, see http://www.gnu.org/licenses/. * * For those usages not covered by the GNU Affero General Public License * please contact with::daniel.moranjimenez@telefonica.com * * Modified by: Jason Fox - FIWARE Foundation */ const config = require('../../commonConfig'); const subscriptionHandlerLD = require('./subscription-NGSI-LD'); const subscriptionHandlerV2 = require('./subscription-NGSI-v2'); /** * Makes a subscription for the given device's entity using NGSI-LD, triggered by the given attributes. * The contents of the notification can be selected using the "content" array (that can be left blank * to notify the complete entity). * * @param {Object} device Object containing all the information about a particular device. * @param {Object} triggers Array with the names of the attributes that would trigger the subscription * @param {Object} content Array with the names of the attributes to retrieve in the notification. */ function subscribeNgsiMixed(device, triggers, content, attrsFormat, callback) { if (config.checkNgsiLD(device)) { subscriptionHandlerLD.subscribe(device, triggers, content, attrsFormat, callback); } else { subscriptionHandlerV2.subscribe(device, triggers, content, attrsFormat, callback); } } /** * Remove the subscription with the given ID from the Context Broker and from the device repository using NGSI-LD. * * @param {Object} device Object containing all the information about a particular device. * @param {String} id ID of the subscription to remove. */ function unsubscribeNgsiMixed(device, id, callback) { if (config.checkNgsiLD(device)) { subscriptionHandlerLD.unsubscribe(device, id, callback); } else { subscriptionHandlerV2.unsubscribe(device, id, callback); } } exports.subscribe = subscribeNgsiMixed; exports.unsubscribe = unsubscribeNgsiMixed;