Compare commits

..

No commits in common. "master" and "simulator-custom-group-join" have entirely different histories.

32 changed files with 160 additions and 1090 deletions

6
.gitignore vendored
View File

@ -1,6 +1,6 @@
node_modules node_modules
.vscode .vscode
config/default.toml
certs
logs/* logs/*
!logs !logs
config/default.toml
certs

View File

@ -1,440 +0,0 @@
[elogs]
name = 'dev'
[api]
port = ''
host = 'node.dev.linx.safemobile.com/api'
use_secure = true
accept_untrusted_certs = true
[settings]
max_fails = 3
send_group_monitoring_before_each_call = 'false'
gps_report_interval = ''
gps_min_interval = 1000
gps_max_interval = 10000
gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126
delay_between_clients = 500
testing_duration = 240 # seconds
# group 1 / 1 send / 10 listen
[[assets]]
asset_id = 7516
group_id = 2561
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7517
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7518
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7519
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7520
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7521
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7522
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7523
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7524
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7525
group_id = 2561
generate_voice = false
[[assets]]
asset_id = 7526
group_id = 2561
generate_voice = false
# group 2 / 1 send / 10 listen
[[assets]]
asset_id = 7536
group_id = 2560
generate_voice = true
[[assets]]
asset_id = 7537
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7538
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7539
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7540
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7541
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7542
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7543
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7544
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7545
group_id = 2560
generate_voice = false
[[assets]]
asset_id = 7546
group_id = 2560
generate_voice = false
# group 3 / 1 send / 10 listen
[[assets]]
asset_id = 7556
group_id = 2559
generate_voice = true
[[assets]]
asset_id = 7557
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7558
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7559
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7560
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7561
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7562
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7563
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7564
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7565
group_id = 2559
generate_voice = false
[[assets]]
asset_id = 7566
group_id = 2559
generate_voice = false
# group 4 / 1 send / 10 listen
[[assets]]
asset_id = 7576
group_id = 2558
generate_voice = true
[[assets]]
asset_id = 7577
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7578
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7579
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7580
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7581
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7582
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7583
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7584
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7585
group_id = 2558
generate_voice = false
[[assets]]
asset_id = 7586
group_id = 2558
generate_voice = false
# group 5 / 1 send / 10 listen
# group 6 / 1 send / 10 listen
# group 7 / 1 send / 10 listen
# group 8 / 1 send / 10 listen
# group 9 / 1 send / 10 listen
# group 10 / 1 send / 10 listen
[[assets]]
asset_id = 7715
group_id = 2552
generate_voice = true
[[assets]]
asset_id = 7714
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7713
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7712
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7711
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7710
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7709
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7708
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7707
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7706
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7705
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7704
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7703
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7702
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7701
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7700
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7699
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7698
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7697
group_id = 2552
generate_voice = false
[[assets]]
asset_id = 7696
group_id = 2552
generate_voice = false
[sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -1,28 +0,0 @@
[elogs]
name = 'dev'
[api]
port = ''
host = 'node.dev.linx.safemobile.com/api'
use_secure = true
accept_untrusted_certs = true
[settings]
max_fails = 3
send_group_monitoring_before_each_call = 'false'
gps_report_interval = ''
gps_min_interval = 500
gps_max_interval = 1000
gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126
delay_between_clients = 500
testing_duration = 10 # seconds
[[assets]]
asset_id = 60
group_id = 1
generate_voice = true
generate_gps = true
[sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -1,440 +1,40 @@
[mumble]
port = '5668'
host = 'dev.linx.safemobile.com'
[hub]
address = 'https://hub.dev.linx.safemobile.com/'
[elogs] [elogs]
name = 'dev' name = 'dev'
[api] [api]
port = '' port = ''
host = 'node.dev.linx.safemobile.com/api' host = 'dev.linx.safemobile.com/api'
use_secure = true use_secure = true
accept_untrusted_certs = true accept_untrusted_certs = true
[settings] [settings]
max_fails = 3 max_fails = 3
send_group_monitoring_before_each_call = 'false' send_group_monitoring_before_each_call = 'true'
gps_report_interval = '' gps_report_interval = 1000 # The interval in which the GPS is sent
gps_min_interval = 1000
gps_max_interval = 10000
gps_lat_start_point = 46.217802 gps_lat_start_point = 46.217802
gps_lng_start_point = 24.776126 gps_lng_start_point = 24.776126
delay_between_clients = 500 delay_between_clients = 300
testing_duration = 240 # seconds testing_duration = 40 # seconds
# group 1 / 1 send / 10 listen
[[assets]] [[assets]]
asset_id = 7516 asset_id = 63
group_id = 2561 group_id = 1
generate_voice = true generate_voice = true
generate_gps = true generate_gps = true
[[assets]]
asset_id = 7517
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7518
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7519
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7520
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7521
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7522
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7523
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7524
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7525
group_id = 2561
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7526
group_id = 2561
generate_voice = false
generate_gps = true
# group 2 / 1 send / 10 listen
[[assets]]
asset_id = 7536
group_id = 2560
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7537
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7538
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7539
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7540
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7541
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7542
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7543
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7544
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7545
group_id = 2560
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7546
group_id = 2560
generate_voice = false
generate_gps = true
# group 3 / 1 send / 10 listen
[[assets]]
asset_id = 7556
group_id = 2559
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7557
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7558
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7559
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7560
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7561
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7562
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7563
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7564
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7565
group_id = 2559
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7566
group_id = 2559
generate_voice = false
generate_gps = true
# group 4 / 1 send / 10 listen
[[assets]]
asset_id = 7576
group_id = 2558
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7577
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7578
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7579
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7580
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7581
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7582
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7583
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7584
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7585
group_id = 2558
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7586
group_id = 2558
generate_voice = false
generate_gps = true
# group 5 / 1 send / 10 listen
# group 6 / 1 send / 10 listen
# group 7 / 1 send / 10 listen
# group 8 / 1 send / 10 listen
# group 9 / 1 send / 10 listen
# group 10 / 1 send / 10 listen
[[assets]]
asset_id = 7715
group_id = 2552
generate_voice = true
generate_gps = true
[[assets]]
asset_id = 7714
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7713
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7712
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7711
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7710
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7709
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7708
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7707
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7706
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7705
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]] [[assets]]
asset_id = 7704 asset_id = 64
group_id = 2552 group_id = 1
generate_voice = false generate_voice = false
generate_gps = true generate_gps = true
[[assets]]
asset_id = 7703
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7702
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7701
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7700
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7699
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7698
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7697
group_id = 2552
generate_voice = false
generate_gps = true
[[assets]]
asset_id = 7696
group_id = 2552
generate_voice = false
generate_gps = true
[sounds] [sounds]
tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3'] tracks = ['1.mp3','2.mp3','3.mp3','4.mp3','5.mp3','6.mp3','7.mp3','8.mp3','9.mp3','10.mp3','11.mp3','12.mp3','13.mp3','14.mp3','15.mp3','16.mp3','17.mp3','18.mp3','19.mp3']

View File

@ -1,6 +1,4 @@
#!/bin/sh #!/bin/sh
OPENSSL_PATH="/usr/bin" #default install path
#OPENSSL_PATH="/usr/local/ssl/bin" #workaround for dual openssl install
DAYS=$((10*365)) DAYS=$((10*365))
LEVELS=1 LEVELS=1
@ -14,10 +12,10 @@ OPENSSL_CNF="/etc/ssl/openssl.cnf"
mkdir -p $CERTS_PATH mkdir -p $CERTS_PATH
#generate root key pair #generate root key pair
$OPENSSL_PATH/openssl genrsa -out "$CERTS_PATH/root-key.pem" 4096 openssl genrsa -out "$CERTS_PATH/root-key.pem" 4096
#generate root self-signed cert #generate root self-signed cert
$OPENSSL_PATH/openssl req -new -x509 -days $DAYS -key "$CERTS_PATH/root-key.pem" -subj "$DN/CN=Root" -out "$CERTS_PATH/root-cert.pem" openssl req -new -x509 -days $DAYS -key "$CERTS_PATH/root-key.pem" -subj "$DN/CN=Root" -out "$CERTS_PATH/root-cert.pem"
cat "$CERTS_PATH/root-cert.pem" > $CHAIN cat "$CERTS_PATH/root-cert.pem" > $CHAIN
@ -32,17 +30,17 @@ for i in `seq 1 $LEVELS`; do
fi fi
#generate key pair #generate key pair
$OPENSSL_PATH/openssl genrsa -out "$CERTS_PATH/ca$i-key.pem" 4096 openssl genrsa -out "$CERTS_PATH/ca$i-key.pem" 4096
#generate signing request #generate signing request
$OPENSSL_PATH/openssl req -new -key "$CERTS_PATH/ca$i-key.pem" -subj "$DN/CN=Level$i" -out "$CERTS_PATH/ca$i-csr.pem" openssl req -new -key "$CERTS_PATH/ca$i-key.pem" -subj "$DN/CN=Level$i" -out "$CERTS_PATH/ca$i-csr.pem"
echo "-------------" echo "-------------"
echo ">>>>>>>>>>>>>>>>>"$SIGNER_CERT echo ">>>>>>>>>>>>>>>>>"$SIGNER_CERT
echo ">>>>>>>>>>>>>>>>>"$SIGNER_KEY echo ">>>>>>>>>>>>>>>>>"$SIGNER_KEY
#sign new cert #sign new cert
$OPENSSL_PATH/openssl x509 -req -days $DAYS -in "$CERTS_PATH/ca$i-csr.pem" -CA $SIGNER_CERT -CAkey $SIGNER_KEY \ openssl x509 -req -days $DAYS -in "$CERTS_PATH/ca$i-csr.pem" -CA $SIGNER_CERT -CAkey $SIGNER_KEY \
-set_serial $i -out "$CERTS_PATH/ca$i-cert.pem" -extfile $OPENSSL_CNF -extensions v3_ca -set_serial $i -out "$CERTS_PATH/ca$i-cert.pem" -extfile $OPENSSL_CNF -extensions v3_ca
cat "$CERTS_PATH/ca$i-cert.pem" >> $CHAIN cat "$CERTS_PATH/ca$i-cert.pem" >> $CHAIN
echo "-------------" echo "-------------"

View File

@ -1,6 +1,5 @@
#!/bin/sh #!/bin/sh
OPENSSL_PATH="/usr/bin" #default install path
#OPENSSL_PATH="/usr/local/ssl/bin" #workaround for dual openssl install
if test "$#" -ne 1; then if test "$#" -ne 1; then
echo "Error: Wrong parameters --> You must provide the certificate name." echo "Error: Wrong parameters --> You must provide the certificate name."
echo "Please use: ./createCerts.sh 18" echo "Please use: ./createCerts.sh 18"
@ -14,11 +13,11 @@ ID=$1
CERTS_PATH=certs CERTS_PATH=certs
#generate key pair #generate key pair
$OPENSSL_PATH/openssl genrsa -out "$CERTS_PATH/$ID-key.pem" 4096 openssl genrsa -out "$CERTS_PATH/$ID-key.pem" 4096
#generate signing request #generate signing request
$OPENSSL_PATH/openssl req -new -key "$CERTS_PATH/$ID-key.pem" -subj "$DN/CN=$ID" -out "$CERTS_PATH/$ID-csr.pem" openssl req -new -key "$CERTS_PATH/$ID-key.pem" -subj "$DN/CN=$ID" -out "$CERTS_PATH/$ID-csr.pem"
#sign new cert #sign new cert
$OPENSSL_PATH/openssl x509 -req -days $DAYS -in "$CERTS_PATH/$ID-csr.pem" -CA "$CERTS_PATH/ca1-cert.pem" \ openssl x509 -req -days $DAYS -in "$CERTS_PATH/$ID-csr.pem" -CA "$CERTS_PATH/ca1-cert.pem" \
-CAkey "$CERTS_PATH/ca1-key.pem" -set_serial 500 -out "$CERTS_PATH/$ID-cert.pem" -CAkey "$CERTS_PATH/ca1-key.pem" -set_serial 500 -out "$CERTS_PATH/$ID-cert.pem"

View File

@ -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'),

View File

@ -1,10 +0,0 @@
#!/bin/sh
cd /usr/local/
wget https://www.openssl.org/source/openssl-1.0.2g.tar.gz
tar -xzvf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g/
./config
make install
/usr/local/ssl/bin/openssl version

View File

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,14 +21,9 @@ 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 || false; this.generate_voice = asset.generate_voice;
this.generate_gps = asset.generate_gps || false; this.generate_gps = asset.generate_gps;
this.token = token; this.token = token;
this.configs = configs this.configs = configs
this._processConfigs(); this._processConfigs();
@ -41,9 +36,7 @@ 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),
@ -63,72 +56,12 @@ class Asset {
}); });
} }
_processConfigs(callback) { _processConfigs() {
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 | _getConfiguration | response ${JSON.stringify(response)} | body: ${JSON.stringify(body)}`)
utils.writeLog(`ERROR | _getConfiguration | Getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _getConfiguration`);
return callback(error);
}
}
);
}
_checkGroupToJoin(callback) {
console.log('_checkGroupToJoin', 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(`_checkGroupToJoin | response ${JSON.stringify(response)} | body: ${JSON.stringify(body)}`)
utils.writeLog(`ERROR | _checkGroupToJoin | Getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _checkGroupToJoin`);
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(
@ -141,11 +74,39 @@ 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 | _getDataFromApi | Getting informations about asset ${this.id}`, error); utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _getDataFromApi`); utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }
@ -168,33 +129,22 @@ class Asset {
this.groups = bodyObj.data; this.groups = bodyObj.data;
if (this.group_id) { // Find what group this asset is monitoring.
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.group_id) { // if (!this.groupId) {
utils.writeLog(`Group/Default voice group not found for asset: ${this.group_id}`); // return callback('No talk group assigned to ' + this.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 {
utils.writeLog(`ERROR | _getGroupsFromApi | Getting informations about asset ${this.id}`, error); utils.writeLog(`Error getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API | _getGroupsFromApi`); utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }
@ -202,8 +152,10 @@ 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(this.hubAddress, options); let hub = io(hubAddress, options);
this.hub = hub; this.hub = hub;
// Disconnect event // Disconnect event
@ -213,12 +165,12 @@ class Asset {
hub.on('connect_timeout', () => { hub.on('connect_timeout', () => {
utils.writeLog(`Asset ${this.id} connect_timeout from HUB`); utils.writeLog(`Asset ${this.id} connect_timeout from HUB`);
utils.writeErrorLog(`ERROR_HUB | _connectToHub`); utils.writeErrorLog(`ERROR_HUB`);
}); });
hub.on('connect_error', () => { hub.on('connect_error', () => {
utils.writeLog(`Asset ${this.id} connect_error from HUB`); utils.writeLog(`Asset ${this.id} connect_error from HUB`);
utils.writeErrorLog(`ERROR_HUB | _connectToHub`); utils.writeErrorLog(`ERROR_HUB`);
}); });
hub.once('connect', () => { hub.once('connect', () => {
@ -258,24 +210,19 @@ class Asset {
} }
_connectToMurmur(callback) { _connectToMurmur(callback) {
if (!this.group_id) { return callback(); }
console.log(`Asset ${this.id} connecting to Murmur`); console.log(`Asset ${this.id} connecting to Murmur`);
const murmurConnectionDetails = { this.configs.murmurPassword = this.murmurPassword;
mumbleHost: this.mumbleHost,
mumblePort: this.mumblePort, this.mumble = new Mumble(this.id, this.configs, (err) => {
murmurUser: this.murmurUser,
murmurPassword: this.murmurPassword
};
this.mumble = new Mumble(this.id, murmurConnectionDetails, (err) => {
if (err) { if (err) {
utils.writeLog(`ERROR | _connectToMurmur | Asset ${this.id} Murmur connection error`, err); utils.writeLog(`Asset ${this.id} Murmur connection error`, err);
utils.writeErrorLog(`ERROR_MURMUR | _connectToMurmur`); utils.writeErrorLog(`ERROR_MURMUR`);
return callback(err); return callback(err);
} else { } else {
// return callback();
setTimeout(()=> { setTimeout(()=> {
return callback(); return callback();
}, 500); }, 400);
} }
}); });
} }
@ -294,9 +241,13 @@ class Asset {
utils.writeLog(`Asset ${this.id} audio registered`); utils.writeLog(`Asset ${this.id} audio registered`);
return callback(); return callback();
} else { } else {
utils.writeLog(`ERROR | _register | Asset ${this.id} audio registered error`, error); console.log('_register--------------------')
utils.writeErrorLog(`ERROR_AUDIO | _register`); console.log('error---', error)
return callback(error); // console.log('response---', response)
console.log('body---', body)
// utils.writeLog(`Asset ${this.id} audio registered error`, error);
// utils.writeErrorLog(`ERROR_API`);
// return callback(error);
} }
} }
); );
@ -335,26 +286,21 @@ class Asset {
if (callback) return callback('Cannot send group-monitoring: Hub not connected'); if (callback) return callback('Cannot send group-monitoring: Hub not connected');
} }
} else { } else {
utils.writeLog(`ERROR | _moveToChannel | Asset ${this.id} audio enter group error`, error); console.log('_moveToChannel--------------------')
utils.writeErrorLog(`ERROR_AUDIO | _moveToChannel`); console.log('error---', error)
return callback(error); // console.log('response---', response)
console.log('body---', body)
// utils.writeLog(`Asset ${this.id} audio enter group error`, error);
// utils.writeErrorLog(`ERROR_API`);
// return callback(error);
} }
} }
); );
} }
_start() { _start() {
this.generate_voice && this._makePtt(); // Generate voce this.generate_voice && this._makePtt();
this.generate_gps && this._sendGPS(); // Generate GPS this.generate_gps && this._sendGPS();
this._measuringTestTime(); // Process exit base on this.endTime and current date
}
_measuringTestTime() {
setInterval(() => {
if(Date.now() > this.endTime + 18000) {
process.exit(0)
}
}, 1000);
} }
_verifyRecorder(callback) { _verifyRecorder(callback) {
@ -397,8 +343,8 @@ class Asset {
console.log(chalk.yellow(`[RECORDER] for asset ${this.id} not found`)); console.log(chalk.yellow(`[RECORDER] for asset ${this.id} not found`));
} }
} else { } else {
utils.writeLog(`ERROR | _getRecord | Error getting record for asset ${this.id} | ${error}`); utils.writeLog(`Error getting record for asset ${this.id} | ${error}`);
utils.writeErrorLog(`ERROR_RECORDER | _getRecord`); utils.writeErrorLog(`ERROR_RECORDER`);
} }
let assetIds = configs.assets.ids; let assetIds = configs.assets.ids;
@ -467,12 +413,19 @@ class Asset {
this.pttEndSuccessfully = true; this.pttEndSuccessfully = true;
setTimeout(() => { setTimeout(() => {
this._sendPttRelease(); this._sendPttRelease();
if(this.endTime > +new Date()) { const now = +new Date();
this._makePtt(callback); if(this.endTime > now) {
this._makePtt();
} else { } else {
utils.writeLog(`Asset ${this.id} Voice sleeping...`);
setTimeout(() => {
utils.writeLog(`Asset: ${this.id} - STOP`)
.then(() => {
process.exit(0);
});
}, 10000);
} }
}, 1500); // Hangtime }, 1800); // Hangtime
}); });
// @TODO: Ugly hack for the voice to work with mp3 (The fix is to remove float32ToInt16 conversion). It is the _transform function from OpusEncoderStream class (mumble-client-codecs-node project). // @TODO: Ugly hack for the voice to work with mp3 (The fix is to remove float32ToInt16 conversion). It is the _transform function from OpusEncoderStream class (mumble-client-codecs-node project).
@ -534,45 +487,42 @@ class Asset {
}) })
} }
_sendGPS() { _sendGPS(callback) {
let hub = this.hub; let hub = this.hub;
if (hub && hub.connected) { if (hub && hub.connected) {
let lat = this.configs.settings.gps_lat_start_point; let lat = this.configs.settings.gps_lat_start_point;
let lng = this.configs.settings.gps_lng_start_point; let lng = this.configs.settings.gps_lng_start_point;
const max = this.configs.settings.gps_max_interval;
const min = this.configs.settings.gps_min_interval;
let interval = null; setInterval(() => {
if (!this.configs.settings.gps_report_interval) { const now = +new Date();
interval = Math.floor(Math.random() * (max - min + 1) + min); if(this.endTime > now) {
} else { var new_lat = this._randomCoordinates(lat);
interval = this.configs.settings.gps_report_interval; var new_lng = this._randomCoordinates(lng);
}
const now = +new Date(); hub.emit('gps', JSON.stringify(
if(this.endTime > now) { {
var new_lat = this._randomCoordinates(lat); unix_time: 1467126677000,
var new_lng = this._randomCoordinates(lng); asset_id: this.assetProps.id,
asset_sip_id: this.assetProps.sip_id,
hub.emit('gps', JSON.stringify( speed_kmh: 16,
{ lat: new_lat,
unix_time: 1467126677000, lng: new_lng,
asset_id: this.assetProps.id, accuracy: 20.3,
asset_sip_id: this.assetProps.sip_id, activity_type: "driving",
speed_kmh: 16, activity_confidence: 90
lat: new_lat, }
lng: new_lng, ));
accuracy: 20.3, lat = new_lat;
activity_type: "driving", lng = new_lng;
activity_confidence: 90 } else {
} setTimeout(() => {
)); utils.writeLog(`Asset: ${this.id} - STOP`)
lat = new_lat; .then(() => {
lng = new_lng; process.exit(0);
setTimeout(() => { this._sendGPS(); }, interval); });
} else { }, 11000);
utils.writeLog(`Asset ${this.id} GPS sleeping...`); }
} }, this.configs.settings.gps_report_interval);
} }
} }

View File

@ -11,19 +11,12 @@ const OpusEncoder = require('node-opus').OpusEncoder;
class Mumble { class Mumble {
constructor(id, murmurConnectionDetails, connectedCallback) { constructor(id, configs, connectedCallback) {
this.id = id; this.id = id;
this.mumbleHost = murmurConnectionDetails.mumbleHost; this.configs = configs;
this.mumblePort = murmurConnectionDetails.mumblePort; let mumble = configs.mumble;
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, this.mumblePort, this.mumbleHost, id, this.murmurPassword, connectedCallback); this._makeMumbleConnection(id, mumble.port, mumble.host, id, this.configs.murmurPassword, connectedCallback);
}) })
} }

View File

@ -36,11 +36,19 @@ class Simulator {
_start() { _start() {
const settings = this.configs.settings; const settings = this.configs.settings;
// this.assetIds.forEach((id, i) => {
this.assets.forEach((asset, i) => { this.assets.forEach((asset, i) => {
console.log('asset_id', asset.asset_id, i * settings.delay_between_clients + 'ms'); let delay_between_clients = 500;
if(settings.hasOwnProperty('delay_between_clients')) {
delay_between_clients = parseInt(settings.delay_between_clients, 10);
}
console.log('asset_id', asset.asset_id, i * delay_between_clients+'ms')
delay_between_clients = this._getRandomInt(delay_between_clients);
setTimeout(() => { setTimeout(() => {
new Asset(asset, this.configs, this.token); new Asset(asset, this.configs, this.token);
}, i * settings.delay_between_clients); // console.log('id, this.configs, this.token', id, this.configs, this.token)
}, i * delay_between_clients);
}) })
} }