This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
forked from emerging-tech/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
73 lines (56 loc) · 1.55 KB
/
index.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Emerging tech</title>
<style type="text/css">body{font-family: sans-serif;} label{display:block;}</style>
</head>
<body>
<h1>Emerging tech, yo!</h1>
<h2 id="data">-</h2>
<form>
<label>
Node
<input name="node" value="dc42">
</label>
<label>
Payload
<input name="payload" value="0">
</label>
<input type="submit">
</form>
<script src="bower_components/pubnub/web/pubnub.min.js"></script>
<script type="text/javascript">
var pubnub = PUBNUB.init({
subscribe_key: 'sub-c-9c92c072-698f-11e4-97dd-02ee2ddab7fe',
publish_key: 'pub-c-10a63f9f-359c-472b-a6ba-d55766a60e69'
});
pubnub.subscribe({
channel: 'dc42',
backfill: true,
callback: function(message){
if(message.value){
var v = message.value;
document.body.style.backgroundColor = 'rgb('+v+','+v+','+v+')';
document.body.style.color = v < 127 ? '#fff' : '#000';
document.getElementById('data').innerText = v;
}
}
});
document.querySelector('form').onsubmit = function(e){
e.preventDefault();
var message = {
node: document.querySelector('[name=node]').value,
payload: document.querySelector('[name=payload]').value.split(',').map(function(n){
return parseInt(n, 10)
})
}
pubnub.publish({
channel:'inbound',
message:message
})
console.log(">>", message)
}
</script>
</body>
</html>