-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (31 loc) · 1.01 KB
/
test.js
File metadata and controls
36 lines (31 loc) · 1.01 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
var Api = require('./lib/src/index').default;
const EventEmitter = require('events');
const main = async () => {
var api = new Api();
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
let grpcTransport;
let mydevice;
myEmitter.on('ATTACH', (device) => {
mydevice = device;
api.getValidatedTransport(device)
.then((transport) => {
grpcTransport = transport;
grpcClient = transport.grpcClient;
// TODO: Perform actions
console.log('We can perform actions on the device now');
console.log(mydevice);
}).catch((e) => {
console.log('Unable to get transport for device');
console.error(e);
})
});
myEmitter.on('DETACH', (device) => {
if (mydevice && mydevice.equals(device)) {
console.log('Closing grpc channel on device');
grpcTransport.close();
}
});
api.registerForHotplugEvents(myEmitter);
}
main();