linx-simulator2/src/simulator.js

60 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-09-18 08:11:16 +00:00
const Asset = require('./asset');
const Request = require('request');
const async = require('async');
class Simulator {
constructor(configs) {
this.configs = configs;
this.assets = {};
// Read assets ids from configs
this.assetIds = configs.assets.ids;
this.apiEndpoint = this.configs.api.use_secure ? 'https' : 'http';
this.apiEndpoint += '://' + this.configs.api.host + (this.configs.api.port ? (':' + this.configs.api.port) : '');
async.waterfall([
this.unregisterAsstes.bind(this)
],
(err, result) => {
if(err) {
console.log(err)
return;
}
this._start();
});
}
_start() {
this.assetIds.forEach(id => {
console.log('Creating asset', id, '...');
this.assets[id] = new Asset(id, this.configs);
});
}
unregisterAsstes(callback) {
let url = this.apiEndpoint + '/audio/un-register/[' + this.assetIds + ']/';
console.log('url', url)
Request.post(
url,
{},
(error, response, body) => {
if (!error && (response.statusCode === 200 || response.statusCode === 201)) {
return callback();
} else {
return callback(error);
}
}
);
}
}
module.exports = Simulator;