diff --git a/package.json b/package.json index 6521277..f7dc130 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "amqp-connection-manager": "^3.2.2", "amqplib": "^0.7.0", "async-mqtt": "^2.6.1", + "axios": "^0.21.1", "body-parser": "^1.19.0", "express": "^4.17.1", "md5": "^2.3.0", diff --git a/types/connectors/DAPNETConnector.js b/types/connectors/DAPNETConnector.js index a292848..aae14b7 100644 --- a/types/connectors/DAPNETConnector.js +++ b/types/connectors/DAPNETConnector.js @@ -1,4 +1,6 @@ const Connector = require("./Connector") +const config = require('../../config.json') +const axios = require('axois') class DAPNETConnector extends Connector { constructor (amqpConnMngr) { @@ -6,5 +8,31 @@ class DAPNETConnector extends Connector { this.name = "dapnet" this.duplexCapable = false } + async transmitMessage(msg, params) { + const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) + if (params.length < 1) return false + const target = params[0] + if (target.split('#').length !== 2) throw 'No valid DAPNET Parameter ' + const transmitterGroup = target.split('#')[ 0 ], callsign = target.split('#')[ 1 ] + const dapnetRequest = { + text: msg.payload, + callSignNames: [ callsign ], + transmitterGroupNames: [ transmitterGroup ] + } + const extraParameters = { + auth: { + username: config.connectors.dapnet.username, + password: config.connectors.dapnet.password + } + } + return axios.post(config.connectors.dapnet.endpoint, dapnetRequest, extraParameters) + .then(() => { + this.connectorRegistry.reportState(msg, UUID, 'routed') + return true + }).catch((err) => { + this.connectorRegistry.reportFail(msg, UUID) + return false + }) + } } module.exports = DAPNETConnector \ No newline at end of file