added dapnet support

master
cheetah 4 years ago
parent 477cc42d52
commit a96b537f8c

@ -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",

@ -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 <transmitterGroup#callSign>'
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
Loading…
Cancel
Save