-
Notifications
You must be signed in to change notification settings - Fork 104
/
realtime-telemetry-plugin.js
32 lines (29 loc) · 1.08 KB
/
realtime-telemetry-plugin.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
/**
* Basic Realtime telemetry plugin using websockets.
*/
function RealtimeTelemetryPlugin() {
return function (openmct) {
var socket = new WebSocket(location.origin.replace(/^http/, 'ws') + '/realtime/');
var listener = {};
socket.onmessage = function (event) {
point = JSON.parse(event.data);
if (listener[point.id]) {
listener[point.id](point);
}
};
var provider = {
supportsSubscribe: function (domainObject) {
return domainObject.type === 'example.telemetry';
},
subscribe: function (domainObject, callback) {
listener[domainObject.identifier.key] = callback;
socket.send('subscribe ' + domainObject.identifier.key);
return function unsubscribe() {
delete listener[domainObject.identifier.key];
socket.send('unsubscribe ' + domainObject.identifier.key);
};
}
};
openmct.telemetry.addProvider(provider);
}
}