-
Notifications
You must be signed in to change notification settings - Fork 0
/
gopro.js
45 lines (41 loc) · 1.21 KB
/
gopro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const querystring = require('querystring')
const superagent = require('superagent')
const URL = require('url')
const goproIp = '10.5.5.9'
const goProStreamingPort = '8080'
module.exports.getStreamingData = (request, response) => {
superagent
.get(`http://${goproIp}:${goProStreamingPort}${request.url}`)
.pipe(response)
}
module.exports.sendStartStopCmd = (request, response) => {
const queryData = URL.parse(request.url, true).query
const pathName = URL.parse(request.url).pathname
const newQuery = querystring.stringify(queryData, null, null, { encodeURIComponent: uri => uri })
superagent
.get(`http://${goproIp}${pathName}?${newQuery}`)
.then(() => {
setTimeout(() =>{
response.writeHead(302, {
'Location': '/'
})
response.end()
}, 8000)
})
}
module.exports.getGoProPassword = () => {
return superagent.get(`http://${goproIp}/bacpac/sd`)
.buffer()
.parse(binaryParser)
.then(res => res.body.substring(2))
}
const binaryParser = (res, callback) => {
res.setEncoding('binary');
res.data = '';
res.on('data', function (chunk) {
res.data += chunk;
});
res.on('end', function () {
callback(null, res.data.toString());
});
}