/
crestron_dm_nvx_discovered_streams.js
130 lines (121 loc) · 3.41 KB
/
crestron_dm_nvx_discovered_streams.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* This driver extracts information for Crestron DM-NVX devices.
* Communication protocol is https
* Communicate with https api using USERNAME and PASSWORD
* Create a tables for Discovered Streaming information ('Discovered Streams').
* Return a table with these columns:
* -------------------------------------
* Session name: The session name.
* Bitrate: The stream bitrate in Mbps.
* Resolution: The stream resolution.
* Multicast adress: The multicast address.
* -----------------------------------------
*/
var discoveredStreams;
var table = D.createTable(
"Discovered Streams",
[
{ label: "Session name" },
{ label: "Bitrate" },
{ label: "Resolution" },
{ label: "Multicast adress" },
]
);
/**
* @returns a promise containing the body of the login page.
*/
function login() {
var d = D.q.defer();
D.device.http.post({
url: "/userlogin.html",
protocol: "https",
form: {
login: D.device.username(),
passwd: D.device.password(),
},
jar: true,
rejectUnauthorized: false
}, function (err, res, body) {
d.resolve(body);
});
return d.promise;
}
/**
* @returns a promise containing the body of the response.
*/
function httpGet(url) {
var d = D.q.defer();
var config = {
url: url,
protocol: "https",
jar: true,
rejectUnauthorized: false
};
D.device.http.get(config, function (error, response, body) {
if (response.statusCode && response.statusCode === 200 && body)
d.resolve(body);
});
return d.promise;
}
/**
* @returns promise for http response body containig discoveres streaams informations.
*/
function getDiscoveredStreams() {
return httpGet("/Device/DiscoveredStreams")
.then(JSON.parse)
.then(function (data) {
discoveredStreams = data.Device.DiscoveredStreams;
});
}
//Fill the table with data related to discovered streams
function fillTable() {
var stream = discoveredStreams.Streams;
for (var uuid in stream) {
var sessionName = stream[uuid].SessionName;
var bitrate = stream[uuid].Bitrate;
var resolution = stream[uuid].Resolution;
var multicastAddress = stream[uuid].MulticastAddress;
var recordId = stream[uuid].UniqueId;
table.insertRecord(recordId, [
sessionName,
bitrate,
resolution,
multicastAddress
]);
}
}
//Indicate the successful execution for the get status and returns the table data
function success() {
D.success(table);
}
/**
* @remote_procedure
* @label Validate DM-NVX Device
* @documentation This procedure is used to validate if the data needed for the retrieval is accessible
*/
function validate() {
login()
.then(getDiscoveredStreams)
.then(function () {
D.success();
})
.catch(function (err) {
console.error(err);
D.failure(D.errorType.GENERIC_ERROR);
});
}
/**
* @remote_procedure
* @label Get Discovered Streams
* @documentation This procedure is used to extract monitoring parameters from Crestron API.
*/
function get_status() {
login()
.then(getDiscoveredStreams)
.then(fillTable)
.then(success)
.catch(function (err) {
console.error(err);
D.failure(D.errorType.PARSING_ERROR);
});
}