2019-06-14 15:58:35 +00:00
|
|
|
'use strict';
|
2019-02-24 13:32:16 +00:00
|
|
|
class Intval {
|
2019-06-14 15:58:35 +00:00
|
|
|
constructor(url) {
|
|
|
|
this._baseUrl = `http://${url}`;
|
|
|
|
this.req = require('request');
|
|
|
|
}
|
|
|
|
async move() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const timeStart = +new Date();
|
|
|
|
const url = `${this._baseUrl}/frame`;
|
|
|
|
//console.log(url)
|
|
|
|
return this.req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart;
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
return resolve(ms);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
async setDir(dir) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const timeStart = +new Date();
|
|
|
|
const url = `${this._baseUrl}/dir?dir=${dir}`;
|
|
|
|
//console.log(url)
|
|
|
|
return this.req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart;
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
return resolve(ms);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
async setExposure(exposure, cb) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const timeStart = +new Date();
|
|
|
|
const url = `${this._baseUrl}/exposure?exposure=${exposure}`;
|
|
|
|
//console.log(url)
|
|
|
|
return this.req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart;
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
return resolve(ms);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
connect(cb) {
|
|
|
|
const timeStart = +new Date();
|
|
|
|
const url = `${this._baseUrl}/status`;
|
|
|
|
const opts = {
|
|
|
|
method: 'GET',
|
|
|
|
uri: url,
|
|
|
|
timeout: 5000
|
|
|
|
};
|
|
|
|
this.req(opts, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart;
|
|
|
|
if (err) {
|
|
|
|
//console.error(err)
|
|
|
|
return cb(err, ms);
|
|
|
|
}
|
|
|
|
cb(null, ms, body);
|
|
|
|
});
|
|
|
|
}
|
2019-02-24 13:32:16 +00:00
|
|
|
}
|
2019-06-14 15:58:35 +00:00
|
|
|
module.exports.Intval = Intval;
|
|
|
|
//# sourceMappingURL=index.js.map
|