-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
35 lines (27 loc) · 906 Bytes
/
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>P2P-peer Example</title>
</head>
<body>
<script type="module" charset="utf-8">
import PeerNetwork from './src/index.ts';
window.addEventListener('DOMContentLoaded', async (event) => {
const peerNet = window.peerNet = new PeerNetwork();
peerNet.connect('http://sig.amar.io');
peerNet.on('connection', peer => {
console.log('Peer', peer.uid, 'connected');
peer.on('greeting', msg => console.log('Peer', peer.uid + ':', msg));
peer.on('disconnect', () => console.log('Peer', peer.uid, 'disconnected'));
peer.send('greeting', 'Hi from ' + peerNet.ownUID + '!');
});
peerNet.on('uid', async uid => {
console.log(uid);
await peerNet.join('test');
});
});
</script>
</body>
</html>