-
Notifications
You must be signed in to change notification settings - Fork 30
/
7-feedback-peoplecount.js
66 lines (54 loc) · 1.92 KB
/
7-feedback-peoplecount.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
59
60
61
62
63
64
65
66
//
// Copyright (c) 2018 Cisco Systems
// Licensed under the MIT License
//
/**
* Listen to realtime events via xAPI's feedback function
* In this example, we display people count changes as they happen
*
* /!\ This example only works when run against a 'RoomKit' type of device
*/
//
// Connect to the device
//
const jsxapi = require('jsxapi');
// Check args
if (!process.env.JSXAPI_DEVICE_URL || !process.env.JSXAPI_USERNAME) {
console.log("Please specify info to connect to your device as JSXAPI_DEVICE_URL, JSXAPI_USERNAME, JSXAPI_PASSWORD env variables");
console.log("Bash example: JSXAPI_DEVICE_URL='ssh://192.168.1.34' JSXAPI_USERNAME='integrator' JSXAPI_PASSWORD='integrator' node 7-feedback-peoplecount.js");
process.exit(1);
}
// Empty passwords are supported
const password = process.env.JSXAPI_PASSWORD ? process.env.JSXAPI_PASSWORD : "";
// Connect to the device
console.log("connecting to your device...");
const xapi = jsxapi.connect(process.env.JSXAPI_DEVICE_URL, {
username: process.env.JSXAPI_USERNAME,
password: password
});
xapi.on('error', (err) => {
console.error(`connexion failed: ${err}, exiting`);
process.exit(1);
});
//
// Code logic
//
xapi.on('ready', () => {
console.log("connexion successful");
// Fetch current count
xapi.status
.get('RoomAnalytics PeopleCount')
.then((count) => {
console.log(`Initial count is: ${count.Current}`);
// Listen to events
console.log('Adding feedback listener to: RoomAnalytics PeopleCount');
xapi.feedback.on('/Status/RoomAnalytics/PeopleCount', (count) => {
console.log(`Updated count to: ${count.Current}`);
});
})
.catch((err) => {
console.log(`Failed to fetch PeopleCount, err: ${err.message}`);
console.log(`Are you interacting with a RoomKit? exiting...`);
xapi.close();
});
});