-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (48 loc) · 1.34 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
import process from 'node:process';
import {HaloGateway} from "@arx-research/libhalo/api/web.js";
import QRCode from 'qrcode';
import websocket from 'websocket';
// list of HaLo commands that will be executed
// once the tag is detected by the reader
let commands = [
{
"name": "sign",
"message": "010203",
"keyNo": 1
},
{
"name": "sign",
"message": "05050505",
"keyNo": 1
}
];
let gate = new HaloGateway('wss://s1.halo-gateway.arx.org', {
createWebSocket: (url) => new websocket.w3cwebsocket(url)
});
let pairInfo = await gate.startPairing();
QRCode.toString(pairInfo.execURL, {type: 'terminal'}, function (err, qrtext) {
console.log('Please scan the following QR code using your smartphone:');
console.log('');
console.log(qrtext);
console.log('');
})
console.log('Waiting for smartphone to connect...');
try {
await gate.waitConnected();
} catch (e) {
console.error('caught error when waitConnected()');
console.log(e);
process.exit(1);
}
for (let cmd of commands) {
console.log('Executing command:', cmd);
try {
let res = await gate.execHaloCmd(cmd);
console.log('Command result:', res);
} catch (e) {
console.log('caught error when execHaloCmd');
console.log(e);
process.exit(1);
}
}
process.exit(0);