2018-08-27 23:00:42 +08:00
|
|
|
require('dotenv').config();
|
|
|
|
const axios = require('axios');
|
2018-09-01 00:34:43 +08:00
|
|
|
const path = require('path');
|
2018-08-27 23:00:42 +08:00
|
|
|
const url = require('url');
|
|
|
|
const helper = require('./helper');
|
2018-10-13 02:46:26 +08:00
|
|
|
|
|
|
|
const httpPath = path.join(path.dirname(require.resolve('axios')), 'lib/adapters/http');
|
2018-09-01 00:34:43 +08:00
|
|
|
const http = require(httpPath);
|
2018-08-27 23:00:42 +08:00
|
|
|
|
2018-10-13 02:46:26 +08:00
|
|
|
(async () => {
|
|
|
|
const bbb = url.parse(process.env.BBB_SERVER_URL);
|
|
|
|
const check = `${bbb.protocol}//${bbb.hostname}/html5client/check`;
|
|
|
|
console.log(`HTML5 check URL: ${check}`);
|
2018-08-27 23:00:42 +08:00
|
|
|
const maxRetries = 20;
|
2018-08-31 03:21:49 +08:00
|
|
|
const retryDelay = 10000;
|
2018-10-13 02:46:26 +08:00
|
|
|
let retryCount = 0;
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
const response = await axios.get(check, { adapter: http });
|
|
|
|
const status = response.data.html5clientStatus;
|
2018-08-27 23:00:42 +08:00
|
|
|
console.log(response.data);
|
2018-10-13 02:46:26 +08:00
|
|
|
if (status === 'running') {
|
2018-08-27 23:00:42 +08:00
|
|
|
break;
|
2018-10-13 02:46:26 +08:00
|
|
|
} else if (retryCount < maxRetries) {
|
2018-08-27 23:00:42 +08:00
|
|
|
retryCount++;
|
2018-10-13 02:46:26 +08:00
|
|
|
} else {
|
|
|
|
console.log('Too many attempts. Exiting...');
|
2018-08-27 23:00:42 +08:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-10-13 02:46:26 +08:00
|
|
|
} catch (e) {
|
2018-08-27 23:00:42 +08:00
|
|
|
console.log(e.message);
|
2018-10-13 02:46:26 +08:00
|
|
|
if (retryCount < maxRetries) {
|
2018-08-27 23:00:42 +08:00
|
|
|
retryCount++;
|
2018-10-13 02:46:26 +08:00
|
|
|
} else {
|
|
|
|
console.log('Too many attempts. Exiting...');
|
2018-08-27 23:00:42 +08:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
2018-10-13 02:46:26 +08:00
|
|
|
console.log(`Retrying (attempt ${retryCount}/${maxRetries})...`);
|
2018-08-31 03:21:49 +08:00
|
|
|
await helper.sleep(retryDelay);
|
2018-08-27 23:00:42 +08:00
|
|
|
}
|
2018-10-13 02:46:26 +08:00
|
|
|
})();
|