-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
87 lines (70 loc) · 2.28 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Network</title>
<meta name="description" content="The network">
</head>
<body style="background-color: black; color: white;">
<code>
<h2><code id='address'></code></h2>
<h3>connections</h3>
<code id='connections'></code>
<h3>messages</h3>
<p>most recent message from: <code id='most-recent'></code></p>
<code id='messages'></code>
<h3>seen message id count</h3>
<code id='seen-messages'></code>
<br>
<br>
<button onclick='sendMessage(network.address + ": Hello there!")'>Say Hi</button>
</code>
<script src="/umd/network.js"></script>
<script src="//unpkg.com/@browser-network/crypto/umd/crypto.min.js"></script>
<script>
const APP_ID = 'Woohooo-this-is-our-test-app'
Network = Network.default
const network = window.network = new Network({
switchAddress: 'http://localhost:5678',
networkId: 'network-test-id',
secret: Bnc.generateSecret(),
config: {
respectSwitchboardVolunteerMessages: false
}
})
function sendMessage(message) {
network.broadcast({
type: 'helloooo',
appId: APP_ID,
data: message,
ttl: 6,
})
}
network.on('message', (message) => {
switch (message.type) {
case 'helloooo': {
console.log('got app message:', message)
const innerHTML = document.querySelector('#messages').innerHTML
document.querySelector('#messages').innerHTML = message.data + '</br>' + innerHTML
break;
}
default: {
document.querySelector('#most-recent').innerHTML = message.address
}
}
})
setInterval(function() {
document.querySelector('#address').innerHTML = JSON.stringify(network.address, 0, 2)
document.querySelector('#connections').innerHTML = network.connections.bind(network)().map(c => {
return '<br>' + JSON.stringify({
connectionId: c.id,
address: c.address
})
})
document.querySelector('#seen-messages').innerHTML = JSON.stringify(Object.keys(network._seenMessageIds).length, 0, 2)
}, 500)
window.DEBUG = 3
</script>
</body>
</html>