2018-01-06 22:53:05 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const req = require('request')
|
|
|
|
|
|
|
|
class Intval {
|
2018-01-31 15:42:11 +00:00
|
|
|
constructor (url) {
|
|
|
|
this._baseUrl = `http://${url}`
|
2018-01-06 22:53:05 +00:00
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
async move () {
|
|
|
|
return new Promise ((resolve, reject) => {
|
|
|
|
const timeStart = +new Date()
|
|
|
|
const url = `${this._baseUrl}/frame`
|
|
|
|
//console.log(url)
|
|
|
|
return req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart
|
|
|
|
if (err) {
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
return resolve(ms)
|
|
|
|
})
|
2018-01-06 22:53:05 +00:00
|
|
|
})
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
async setDir (dir) {
|
|
|
|
return new Promise ((resolve, reject) => {
|
|
|
|
const timeStart = +new Date()
|
|
|
|
const url = `${this._baseUrl}/dir?dir=${dir}`
|
|
|
|
//console.log(url)
|
|
|
|
return req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart
|
|
|
|
if (err) {
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
return resolve(ms)
|
|
|
|
})
|
2018-01-06 22:53:05 +00:00
|
|
|
})
|
|
|
|
}
|
2018-03-03 05:27:49 +00:00
|
|
|
async setExposure (exposure, cb) {
|
2018-03-05 04:54:42 +00:00
|
|
|
return new Promise ((resolve, reject) => {
|
|
|
|
const timeStart = +new Date()
|
|
|
|
const url = `${this._baseUrl}/exposure?exposure=${exposure}`
|
|
|
|
//console.log(url)
|
|
|
|
return req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart
|
|
|
|
if (err) {
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
return resolve(ms)
|
|
|
|
})
|
2018-01-06 22:53:05 +00:00
|
|
|
})
|
|
|
|
}
|
2018-01-31 15:42:11 +00:00
|
|
|
connect (cb) {
|
|
|
|
const timeStart = +new Date()
|
|
|
|
const url = `${this._baseUrl}/status`
|
|
|
|
const opts = {
|
|
|
|
method : 'GET',
|
|
|
|
uri : url,
|
|
|
|
timeout: 5000
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Intval
|