-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path2-environment.js
More file actions
75 lines (63 loc) · 2.01 KB
/
2-environment.js
File metadata and controls
75 lines (63 loc) · 2.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
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
67
68
69
70
71
72
73
74
75
//
// Copyright (c) 2018 Cisco Systems
// Licensed under the MIT License
//
/**
* Reads connection info from environment variables
*/
//
// Connect to the device
//
// Check args
if (!process.env.JSXAPI_DEVICE_URL || !process.env.JSXAPI_USERNAME) {
console.log("Please specify info to connect to your device as JSXAPI_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 example.js");
process.exit(1);
}
// Empty passwords are supported
const password = process.env.JSXAPI_PASSWORD ? process.env.JSXAPI_PASSWORD : "";
// Connect to the device
const jsxapi = require('jsxapi');
const xapi = jsxapi.connect(process.env.JSXAPI_DEVICE_URL, {
username: process.env.JSXAPI_USERNAME,
password: password
});
// Errors management
xapi.on('error', (err) => {
switch (err) {
case "client-socket":
console.error("Could not connect: invalid URL.");
process.exit(1);
case "client-authentication":
console.error("Could not connect: invalid credentials.");
process.exit(1);
case "client-timeout":
console.error("Could not connect: timeout.");
process.exit(1);
default:
console.error(`Encountered error: ${err}.`);
process.exit(1);
}
});
//
// Code logic
//
xapi.on('ready', () => {
console.log("connexion successful");
// Display current audio volume
xapi.status
.get('Audio Volume')
.then((level) => {
console.log(`Current volume level: ${level}`);
})
.then(() => {
// Gracefully ends after delay
const delay = process.env.DELAY || 5; // in seconds
setTimeout(() => {
// End
console.log('Exiting.');
xapi.close();
}, delay * 1000);
console.log(`Will exit gracefully in ${delay} seconds...`);
})
});