LAPI-588: Update simulator to make short PTT calls in a period of time
This commit is contained in:
83
src/asset.js
83
src/asset.js
@ -28,6 +28,8 @@ class Asset {
|
||||
this.pttEndSuccessfully = false;
|
||||
this.assetProps = {};
|
||||
this.murmurPassword = '';
|
||||
this.startTime = null; // Will be set at the initialization of ptt(_start -> on_tt)
|
||||
this.endTime = +new Date() + (this.configs.settings.testing_duration * 1000)
|
||||
|
||||
utils.writeLog(`Creating asset ${id}`)
|
||||
|
||||
@ -54,22 +56,8 @@ class Asset {
|
||||
|
||||
_processConfigs() {
|
||||
let apiConfig = this.configs.api;
|
||||
|
||||
this.apiEndpoint = apiConfig.use_secure ? 'https' : 'http';
|
||||
this.apiEndpoint += '://' + apiConfig.host + (apiConfig.port ? (':' + apiConfig.port) : '');
|
||||
|
||||
this.soundPath = currentPath;
|
||||
// this.soundPath += '/sounds/sound.mp3';
|
||||
this.soundPath += '/sounds/' + this.configs.sounds['sound'];
|
||||
// if (this.configs.sounds['custom' + this.id]) {
|
||||
|
||||
// // Custom path sound.
|
||||
// this.soundPath += '/sounds/' + this.configs.sounds['custom' + this.id];
|
||||
// } else {
|
||||
|
||||
// // Normal path sound.
|
||||
// this.soundPath += '/sounds/sample' + (this.id % this.configs.sounds.sounds_total_number) + '.mp3';
|
||||
// }
|
||||
}
|
||||
|
||||
_getDataFromApi(callback) {
|
||||
@ -186,6 +174,7 @@ class Asset {
|
||||
});
|
||||
|
||||
hub.once('connect', () => {
|
||||
console.log('11111111111111111111')
|
||||
return callback();
|
||||
});
|
||||
hub.on('connect', () => {
|
||||
@ -233,7 +222,7 @@ class Asset {
|
||||
// return callback();
|
||||
setTimeout(()=> {
|
||||
return callback();
|
||||
}, 1000);
|
||||
}, 400);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -307,22 +296,36 @@ class Asset {
|
||||
}
|
||||
|
||||
_start() {
|
||||
if(this.configs.settings.send_voice) {
|
||||
this._makePtt(() => {
|
||||
if(this.pttEndSuccessfully) {
|
||||
this._verifyRecorder();
|
||||
}
|
||||
});
|
||||
this.startTime = +new Date();
|
||||
if(this.endTime > this.startTime) {
|
||||
if(this.configs.settings.send_voice) {
|
||||
this._makePtt(() => {
|
||||
if(this.pttEndSuccessfully) {
|
||||
this._verifyRecorder();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(this.configs.settings.send_gps) {
|
||||
this._sendGPS();
|
||||
}
|
||||
} else {
|
||||
const assetIds = this.configs.assets.ids;
|
||||
if(Math.max(...assetIds) == this.id) {
|
||||
setTimeout(() => {
|
||||
utils.writeLog('STOP')
|
||||
.then(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.configs.settings.send_gps) {
|
||||
this._sendGPS();
|
||||
}
|
||||
}
|
||||
|
||||
_verifyRecorder(callback) {
|
||||
console.log(chalk.green(`Check to see if a record was created for the unit id: ${this.id} | name: ${this.assetProps.name}`));
|
||||
let startDate = parseInt(this.startTime) - 5000;
|
||||
let startDate = parseInt(this.startTime) - 3000;
|
||||
let stopDate = parseInt(+new Date() + 30 * 1000);
|
||||
setTimeout(() => { this._getRecord(startDate, stopDate, this.configs); }, 3000);
|
||||
}
|
||||
@ -365,27 +368,7 @@ class Asset {
|
||||
}
|
||||
let assetIds = configs.assets.ids;
|
||||
|
||||
// console.log('id', this.id, 'total', assetIds)
|
||||
// console.log('assetIds[0]', assetIds[0])
|
||||
// console.log('max', Math.max(...assetIds))
|
||||
if(Math.max(...assetIds) == this.id) {
|
||||
setTimeout(() => {
|
||||
utils.writeLog('STOP')
|
||||
.then(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
}, 7000);
|
||||
}
|
||||
// const settings = configs.settings;
|
||||
// let testing_period = 1000;
|
||||
// if(settings.hasOwnProperty('testing_period')) { testing_period = parseInt(settings.testing_period, 10); }
|
||||
// const exit_time = 13000 + testing_period;
|
||||
// setTimeout(() => {
|
||||
// utils.writeLog('STOP')
|
||||
// .then(() => {
|
||||
// process.exit(0);
|
||||
// });
|
||||
// }, exit_time);
|
||||
this._start();
|
||||
|
||||
}
|
||||
);
|
||||
@ -408,12 +391,14 @@ class Asset {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// Ptt accepted. We can send voice.
|
||||
// Select a random track from sounds.tracks
|
||||
this.soundPath = `${currentPath}/sounds/${Math.floor(Math.random() * (this.configs.sounds.tracks.length) + 1)}.mp3`
|
||||
|
||||
// Ptt accepted. We can send voice.
|
||||
// Mp3 read stream.
|
||||
var mp3 = fs.createReadStream(this.soundPath);
|
||||
mp3.on('error', (e) => {
|
||||
utils.writeErrorLog(`Error _makePtt asset ${this.id}`, e);
|
||||
utils.writeErrorLog(`Error _makePtt asset ${this.id}`, JSON.stringify(e));
|
||||
});
|
||||
|
||||
mp3.on('data', (data) => {
|
||||
@ -486,7 +471,7 @@ class Asset {
|
||||
lameDecoder
|
||||
|
||||
// Make 4096 chunks to be like the microphone stream.
|
||||
.pipe(chunker(4096, {flush: true, align: true}))
|
||||
// .pipe(chunker(4096, {flush: true, align: true}))
|
||||
|
||||
// Resample to 48000 hz.
|
||||
.pipe(resampler)
|
||||
|
@ -37,21 +37,17 @@ class Simulator {
|
||||
const settings = this.configs.settings;
|
||||
|
||||
this.assetIds.forEach((id, i) => {
|
||||
let testing_period = 500;
|
||||
if(settings.hasOwnProperty('testing_period')) {
|
||||
testing_period = parseInt(settings.testing_period, 10);
|
||||
let delay_between_clients = 500;
|
||||
if(settings.hasOwnProperty('delay_between_clients')) {
|
||||
delay_between_clients = parseInt(settings.delay_between_clients, 10);
|
||||
}
|
||||
console.log('id', id, i * testing_period+'ms')
|
||||
console.log('id', id, i * delay_between_clients+'ms')
|
||||
|
||||
testing_period = this._getRandomInt(testing_period);
|
||||
delay_between_clients = this._getRandomInt(delay_between_clients);
|
||||
setTimeout(() => {
|
||||
new Asset(id, this.configs, this.token);
|
||||
}, i * testing_period);
|
||||
|
||||
// const amount = 15;
|
||||
// for(let i = 0; i < amount; i++) {
|
||||
// new Asset(id, this.configs, this.token);
|
||||
// }
|
||||
// console.log('id, this.configs, this.token', id, this.configs, this.token)
|
||||
}, i * delay_between_clients);
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user