-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path12a-primary.js
More file actions
40 lines (31 loc) · 1.15 KB
/
12a-primary.js
File metadata and controls
40 lines (31 loc) · 1.15 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
//
// Copyright (c) 2019 Cisco Systems
// Licensed under the MIT License
//
/**
* Pushes an event to a remote Codec using the Message command and an HttpClient POST
* This code needs a listener: install the secondary.js macro on the remote Codec
*
*/
const xapi = require('xapi');
const SECONDARY_IP = "192.168.1.32";
const SECONDARY_BASICAUTH = "bG9jYWxhZG1pbjpjaXNjb3BzZHQ=";
var EVENTURL = `http://${SECONDARY_IP}/putxml`;
var HEADERS = ['Content-Type: text/xml', `Authorization: Basic ${SECONDARY_BASICAUTH}`];
function postRequest(url, payload, headers) {
xapi.command('HttpClient Post', {
Url: url,
Header: headers
}, payload).then((response) => { console.log(JSON.stringify(response)) });
console.log(payload);
}
function sendEvent(event) {
event = event.replace(/"/g, "\'");
var payload = "<XmlDoc internal='True'><Command><Message><Send><Text>" + event + "</Text></Send></Message></Command></XmlDoc>";
postRequest(EVENTURL, payload, HEADERS);
}
function volumeSync(volume) {
sendEvent(JSON.stringify({ "Audio Volume Set": { "Level": volume } }));
}
xapi.status.on('Audio Volume', volumeSync);
console.log('primary started')