-
Notifications
You must be signed in to change notification settings - Fork 7
/
RemoteSensors.js
36 lines (31 loc) · 982 Bytes
/
RemoteSensors.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
function RemoteSensors (params) {
this.fetch = function () {
while (script = document.getElementById('JSONP')) {
script.parentNode.removeChild(script);
for (var prop in script) {
delete script[prop];
}
}
var node = document.createElement('script');
node.setAttribute('language','javascript');
node.setAttribute('id','JSONP');
node.setAttribute('src', 'http://' + this.host + '/?jsonp=' + this.callback + '&rand=' + Math.random());
document.body.appendChild(node);
};
this.getHost = function () {
host = prompt("Please enter the host:port of the sensor server", "");
if (host) {
this.host = host;
} else {
this.getHost();
}
};
// Initial
this.callback = params.callback;
if (params.host) {
this.host = params.host;
} else {
this.getHost();
}
this.fetch();
}