-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.js
More file actions
executable file
·61 lines (56 loc) · 1.72 KB
/
Copy pathapi.js
File metadata and controls
executable file
·61 lines (56 loc) · 1.72 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const http = require('http');
const {getImacHostName} = require('./utils');
module.exports = {
getSessionStatus: (sessionId, event) => {
return new Promise((resolve, reject) => {
const options = {
protocol: 'http:',
host: getImacHostName(),
port: 5000,
path: `/api/webcam/verify?sessionId=${sessionId}&event=${event}`,
method: 'GET',
timeout: 3000
};
const req = http.request(options, res => {
let data = '';
res.setEncoding('utf8');
res.on('data', chunk => data += chunk);
res.on('end', () => resolve(JSON.parse(data)));
});
req.on('error', error => reject(error));
req.on('timeout', () => {
req.abort();
});
req.on('abort', () => reject(new Error('Request was aborted by timeout')));
req.end();
})
},
forceLogout: sessionId => {
return new Promise((resolve, reject) => {
const options = {
protocol: 'http:',
host: getImacHostName(),
port: 5000,
path: `/api/webcam/force_logout`,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
timeout: 3000
};
const req = http.request(options, res => {
let data = '';
res.setEncoding('utf8');
res.on('data', chunk => data += chunk);
res.on('end', () => resolve(JSON.parse(data)));
});
req.on('error', error => reject(error));
req.on('timeout', () => {
req.abort();
});
req.on('abort', () => reject(new Error('Request was aborted by timeout')));
req.write(JSON.stringify({sessionId}));
req.end();
})
}
}