-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path1-connect.js
More file actions
63 lines (52 loc) · 1.64 KB
/
1-connect.js
File metadata and controls
63 lines (52 loc) · 1.64 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
//
// Copyright (c) 2018 Cisco Systems
// Licensed under the MIT License
//
/**
* Script that connects to a device, and checks for errors at connection
* then displays current volume level, and attempts to change level if authorized
* and finally exists gracefully.
*
* /!\ Changing the volume level requires admin priviledges (not authorized from the integrator role)
*/
// Connect to the device
const jsxapi = require('jsxapi');
const xapi = jsxapi.connect("ssh://192.168.1.34", {
username: 'admin',
password: ''
});
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);
}
});
xapi.on('ready', () => {
console.log("connexion successful");
// Display current audio volume
xapi.status
.get('Audio Volume')
.then((level) => {
console.log(`Current volume level: ${level}`);
});
// Reset volume to 50
xapi.command('Audio Volume Set', { Level: "50" })
.then((result) => {
console.log(`Reset volume: ${result.status}`);
// Ending script
xapi.close();
})
.catch((err) => {
console.error(`Cannot reset volume, reason: ${err.message}`)
});
});