-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path10-autoanswer.js
88 lines (71 loc) · 2.49 KB
/
10-autoanswer.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Copyright (c) 2018 Cisco Systems
// Licensed under the MIT License
//
/**
* Auto-answer call example, filtering out not registered origens
*
* Integrator role: not supported, as tested as of June 2018
* - OK: registering a feedback for /Call
* - KO: accepting an incoming call
* *
*/
//
// 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.32' 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
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");
// Listen to call events
xapi.status
.on('Call', (call) => {
switch (call.Status) {
case "Ringing":
console.log(`NEW call: ${call.id}`);
// Filter depending the origen of the call
if ((call.Direction == "Incoming")
&& (call.Protocol == "Spark")
&& (call.DisplayName == "Salon")) {
// Accept incoming call
console.log(`Accepting incoming call: ${call.id}`);
xapi.command('Call Accept', {
CallId: call.id
});
}
return;
case "Connected":
console.log(`Connected call: ${call.id}`);
return;
case "Disconnecting":
console.log(`Disconnecting call: ${call.id}`);
return;
case "Idle":
console.log(`Idle call: ${call.id}`);
return;
default:
//console.log("DEBUG: ignoring event");
return;
}
})
});