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