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-01-31 15:42:11 +00:00
|
|
|
move (cb) {
|
2018-01-06 22:53:05 +00:00
|
|
|
const timeStart = +new Date()
|
2018-01-31 15:42:11 +00:00
|
|
|
const url = `${this._baseUrl}/frame`
|
2018-01-17 17:23:23 +00:00
|
|
|
//console.log(url)
|
2018-01-06 22:53:05 +00:00
|
|
|
req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
cb(ms)
|
|
|
|
})
|
|
|
|
}
|
2018-01-31 15:42:11 +00:00
|
|
|
setDir (dir, cb) {
|
2018-01-06 22:53:05 +00:00
|
|
|
const timeStart = +new Date()
|
2018-01-31 15:42:11 +00:00
|
|
|
const url = `${this._baseUrl}/dir?dir=${dir}`
|
2018-01-17 17:23:23 +00:00
|
|
|
//console.log(url)
|
2018-01-06 22:53:05 +00:00
|
|
|
req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
cb(ms)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
2018-01-31 15:42:11 +00:00
|
|
|
setExposure (exposure, cb) {
|
2018-01-06 22:53:05 +00:00
|
|
|
const timeStart = +new Date()
|
2018-01-31 15:42:11 +00:00
|
|
|
const url = `${this._baseUrl}/exposure?exposure=${exposure}`
|
2018-01-17 17:23:23 +00:00
|
|
|
//console.log(url)
|
2018-01-06 22:53:05 +00:00
|
|
|
req(url, (err, res, body) => {
|
|
|
|
let ms = (+new Date()) - timeStart
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
cb(ms)
|
|
|
|
})
|
|
|
|
}
|
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
|