LINXD-2396: Get Hub address from asset configuration; Take default main group if not specified in config; Update config to not declare hub address and voice server #6
@ -1,10 +1,3 @@
|
|||||||
[mumble]
|
|
||||||
port = '5668'
|
|
||||||
host = 'dev.linx.safemobile.com'
|
|
||||||
|
|
||||||
[hub]
|
|
||||||
address = 'https://hub.dev.linx.safemobile.com/'
|
|
||||||
|
|
||||||
[elogs]
|
[elogs]
|
||||||
name = 'dev'
|
name = 'dev'
|
||||||
|
|
||||||
|
4
index.js
4
index.js
@ -6,8 +6,8 @@ const Simulator = require('./src/simulator');
|
|||||||
|
|
||||||
// Read configs.
|
// Read configs.
|
||||||
let configs = {
|
let configs = {
|
||||||
mumble: config.get('mumble'),
|
// mumble: config.get('mumble'),
|
||||||
hub: config.get('hub'),
|
// hub: config.get('hub'),
|
||||||
api: config.get('api'),
|
api: config.get('api'),
|
||||||
assets: config.get('assets'),
|
assets: config.get('assets'),
|
||||||
sounds: config.get('sounds'),
|
sounds: config.get('sounds'),
|
||||||
|
146
src/asset.js
146
src/asset.js
@ -21,9 +21,14 @@ class Asset {
|
|||||||
constructor(asset, configs, token) {
|
constructor(asset, configs, token) {
|
||||||
|
|
||||||
this.id = asset.asset_id;
|
this.id = asset.asset_id;
|
||||||
|
this.mumbleHost = null;
|
||||||
|
this.mumblePort = null;
|
||||||
|
this.murmurUser = null;
|
||||||
|
this.murmurPassword = null;
|
||||||
|
this.hubAddress = null;
|
||||||
this.group_id = asset.group_id;
|
this.group_id = asset.group_id;
|
||||||
this.generate_voice = asset.generate_voice;
|
this.generate_voice = asset.generate_voice || false;
|
||||||
this.generate_gps = asset.generate_gps;
|
this.generate_gps = asset.generate_gps || false;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.configs = configs
|
this.configs = configs
|
||||||
this._processConfigs();
|
this._processConfigs();
|
||||||
@ -36,7 +41,9 @@ class Asset {
|
|||||||
|
|
||||||
// Do async work: Init asset.
|
// Do async work: Init asset.
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
this._getConfiguration.bind(this),
|
||||||
this._getDataFromApi.bind(this),
|
this._getDataFromApi.bind(this),
|
||||||
|
this._checkGroupToJoin.bind(this),
|
||||||
this._connectToHub.bind(this),
|
this._connectToHub.bind(this),
|
||||||
this._connectToMurmur.bind(this),
|
this._connectToMurmur.bind(this),
|
||||||
this._register.bind(this),
|
this._register.bind(this),
|
||||||
@ -56,12 +63,70 @@ class Asset {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_processConfigs() {
|
_processConfigs(callback) {
|
||||||
let apiConfig = this.configs.api;
|
let apiConfig = this.configs.api;
|
||||||
this.apiEndpoint = apiConfig.use_secure ? 'https' : 'http';
|
this.apiEndpoint = apiConfig.use_secure ? 'https' : 'http';
|
||||||
this.apiEndpoint += '://' + apiConfig.host + (apiConfig.port ? (':' + apiConfig.port) : '');
|
this.apiEndpoint += '://' + apiConfig.host + (apiConfig.port ? (':' + apiConfig.port) : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getConfiguration(callback) {
|
||||||
|
console.log('_getConfiguration', this.id);
|
||||||
|
Request.get(
|
||||||
|
this.apiEndpoint + '/asset/' + this.id + '/account',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error, response, body) => {
|
||||||
|
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
|
||||||
|
const bodyObj = JSON.parse(body);
|
||||||
|
const data = bodyObj.data;
|
||||||
|
// console.log('_getConfiguration', data);
|
||||||
|
this.mumbleHost = data.configuration.mumble_address;
|
||||||
|
this.mumblePort = data.configuration.voice_rtp_port;
|
||||||
|
this.murmurUser = bodyObj.data.configuration.mumble_username;
|
||||||
|
this.murmurPassword = bodyObj.data.configuration.mumble_password;
|
||||||
|
this.hubAddress = data.configuration.hub_address;
|
||||||
|
return callback();
|
||||||
|
} else {
|
||||||
|
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
|
||||||
|
utils.writeErrorLog(`ERROR_API`);
|
||||||
|
return callback(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_checkGroupToJoin(callback) {
|
||||||
|
console.log('_getConfiguration', this.id);
|
||||||
|
Request.get(
|
||||||
|
this.apiEndpoint + '/assets/' + this.id + '/groups',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error, response, body) => {
|
||||||
|
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
|
||||||
|
const bodyObj = JSON.parse(body);
|
||||||
|
const data = bodyObj.data.map(group => group.group_id);
|
||||||
|
if (data.includes(this.group_id)) {
|
||||||
|
utils.writeLog(`Asset ${this.id} have group ${this.group_id}`);
|
||||||
|
return callback();
|
||||||
|
} else {
|
||||||
|
utils.writeLog(`ERROR Asset ${this.id} is not in group ${this.group_id}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
|
||||||
|
utils.writeErrorLog(`ERROR_API`);
|
||||||
|
return callback(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
_getDataFromApi(callback) {
|
_getDataFromApi(callback) {
|
||||||
utils.writeLog(`Get informations about asset ${this.id}`);
|
utils.writeLog(`Get informations about asset ${this.id}`);
|
||||||
Request.get(
|
Request.get(
|
||||||
@ -74,35 +139,7 @@ class Asset {
|
|||||||
(error, response, body) => {
|
(error, response, body) => {
|
||||||
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
|
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
|
||||||
let bodyObj = JSON.parse(body);
|
let bodyObj = JSON.parse(body);
|
||||||
// Here are the asset fields.
|
|
||||||
this.assetProps = bodyObj.data;
|
this.assetProps = bodyObj.data;
|
||||||
// console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!', this.assetProps)
|
|
||||||
return this._getMumblePassword(callback);
|
|
||||||
} else {
|
|
||||||
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
|
|
||||||
utils.writeErrorLog(`ERROR_API`);
|
|
||||||
return callback(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_getMumblePassword(callback) {
|
|
||||||
utils.writeLog(`Get Mumble password for asset ${this.id}`);
|
|
||||||
Request.get(
|
|
||||||
this.apiEndpoint + '/asset/' + this.id + '/account',
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${this.token}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(error, response, body) => {
|
|
||||||
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
|
|
||||||
let bodyObj = JSON.parse(body);
|
|
||||||
|
|
||||||
// Here are the asset fields.
|
|
||||||
this.murmurPassword = bodyObj.data.configuration.mumble_password;
|
|
||||||
// console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!', this.assetProps)
|
|
||||||
return this._getGroupsFromApi(callback);
|
return this._getGroupsFromApi(callback);
|
||||||
} else {
|
} else {
|
||||||
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
|
utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
|
||||||
@ -129,17 +166,28 @@ class Asset {
|
|||||||
|
|
||||||
this.groups = bodyObj.data;
|
this.groups = bodyObj.data;
|
||||||
|
|
||||||
// Find what group this asset is monitoring.
|
if (this.group_id) {
|
||||||
this.groups.forEach((g) => {
|
this.groups.forEach((g) => {
|
||||||
if (g.id === this.group_id) {
|
if (g.id === this.group_id) {
|
||||||
this.groupSipId = g.sip_id;
|
this.groupSipId = g.sip_id;
|
||||||
this.groupName = g.name;
|
this.groupName = g.name;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.groups.forEach((g) => {
|
||||||
|
if (g.is_talk_group && g.monitoring.indexOf(this.id) != -1) {
|
||||||
|
this.groupSipId = g.sip_id;
|
||||||
|
this.groupName = g.name;
|
||||||
|
this.group_id = g.id;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// if (!this.groupId) {
|
if (!this.group_id) {
|
||||||
// return callback('No talk group assigned to ' + this.id);
|
utils.writeErrorLog(`Group/Default voice group not found for asset: ${this.group_id}`);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
utils.writeLog(`Group: ${this.group_id} found for asset: ${this.id}`);
|
||||||
utils.writeLog(`Informations about asset ${this.id} received | groupId: ${this.group_id} | groupName: ${this.groupName}`);
|
utils.writeLog(`Informations about asset ${this.id} received | groupId: ${this.group_id} | groupName: ${this.groupName}`);
|
||||||
return callback();
|
return callback();
|
||||||
} else {
|
} else {
|
||||||
@ -152,10 +200,8 @@ class Asset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_connectToHub(callback) {
|
_connectToHub(callback) {
|
||||||
|
|
||||||
let hubAddress = this.configs.hub.address;
|
|
||||||
let options = {rejectUnauthorized: false, secure: true};
|
let options = {rejectUnauthorized: false, secure: true};
|
||||||
let hub = io(hubAddress, options);
|
let hub = io(this.hubAddress, options);
|
||||||
this.hub = hub;
|
this.hub = hub;
|
||||||
|
|
||||||
// Disconnect event
|
// Disconnect event
|
||||||
@ -210,10 +256,16 @@ class Asset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_connectToMurmur(callback) {
|
_connectToMurmur(callback) {
|
||||||
|
!this.group_id && return callback();
|
||||||
|
|
||||||
console.log(`Asset ${this.id} connecting to Murmur`);
|
console.log(`Asset ${this.id} connecting to Murmur`);
|
||||||
this.configs.murmurPassword = this.murmurPassword;
|
const murmurConnectionDetails = {
|
||||||
|
mumbleHost: this.mumbleHost,
|
||||||
this.mumble = new Mumble(this.id, this.configs, (err) => {
|
mumblePort: this.mumblePort,
|
||||||
|
murmurUser: this.murmurUser,
|
||||||
|
murmurPassword: this.murmurPassword
|
||||||
|
};
|
||||||
|
this.mumble = new Mumble(this.id, murmurConnectionDetails, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
utils.writeLog(`Asset ${this.id} Murmur connection error`, err);
|
utils.writeLog(`Asset ${this.id} Murmur connection error`, err);
|
||||||
utils.writeErrorLog(`ERROR_MURMUR`);
|
utils.writeErrorLog(`ERROR_MURMUR`);
|
||||||
|
@ -11,12 +11,19 @@ const OpusEncoder = require('node-opus').OpusEncoder;
|
|||||||
|
|
||||||
class Mumble {
|
class Mumble {
|
||||||
|
|
||||||
constructor(id, configs, connectedCallback) {
|
constructor(id, murmurConnectionDetails, connectedCallback) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.configs = configs;
|
this.mumbleHost = murmurConnectionDetails.mumbleHost;
|
||||||
let mumble = configs.mumble;
|
this.mumblePort = murmurConnectionDetails.mumblePort;
|
||||||
|
this.murmurUser = murmurConnectionDetails.murmurUser;
|
||||||
|
this.murmurPassword = murmurConnectionDetails.murmurPassword;
|
||||||
|
console.log('mumbleHost', this.mumbleHost)
|
||||||
|
console.log('mumblePort', this.mumblePort)
|
||||||
|
console.log('murmurUser', this.murmurUser)
|
||||||
|
console.log('murmurPassword', this.murmurPassword)
|
||||||
|
|
||||||
this._createCertificatesForUser(id, () => {
|
this._createCertificatesForUser(id, () => {
|
||||||
this._makeMumbleConnection(id, mumble.port, mumble.host, id, this.configs.murmurPassword, connectedCallback);
|
this._makeMumbleConnection(id, this.mumblePort, this.mumbleHost, id, this.murmurPassword, connectedCallback);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user