-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher.html
38 lines (38 loc) · 1 KB
/
publisher.html
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
<!DOCTYPE html>
<html>
<head>
<title>Crypto Publisher</title>
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.18.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
var pubnub = new PubNub({
publishKey: 'pub-c-3fed0d90-bc45-4217-bba5-9b65d527e3bf',
subscribeKey: 'sub-c-691e368e-05e7-11e8-8ec0-52bf6fff9f5d'
});
var xhr = new XMLHttpRequest();
function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
console.log(response);
pubnub.publish({
channel: 'bitcoin-feed',
message: {
eon: {
'BitCoin': response.BTC.USD.toFixed(2)
}
}
});
}
}
function mainApp() {
setInterval(function(){
xhr.open('GET', 'https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=USD', true)
xhr.send();
xhr.onreadystatechange = processRequest;
}, 10000)
};
mainApp();
</script>
</body>
</html>