2019-06-14 15:58:35 +00:00
|
|
|
'use strict';
|
2018-01-06 22:53:05 +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);
|
|
|
|
});
|
|
|
|
}
|
2018-01-06 22:53:05 +00:00
|
|
|
}
|
2019-06-14 15:58:35 +00:00
|
|
|
module.exports.Intval = Intval;
|
|
|
|
//# sourceMappingURL=index.js.map
|