-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2p.html
49 lines (43 loc) · 1.35 KB
/
p2p.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
<!DOCTYPE html>
<html
<body>
<script src="http://cdn.peerjs.com/0.3.9/peer.js"></script>
<script src="utility.js"></script>
<script>
var peer = new Peer('p2p', {key: '8o0fs765i5dn29'});
var latency_iterations = 100;
var bandwidth_iterations = 1;
var receivings = 0;
var start, stop;
peer.on('connection', function(connection) {
connection.on('data', function(data) {
var bw_recv = receivings - latency_iterations;
if (receivings == 0
|| receivings > latency_iterations
&& bw_recv % bandwidth_iterations == 0)
{
start = timeMs();
}
receivings++;
if (receivings == latency_iterations) {
console.log('latency ' + (timeMs() - start)
/latency_iterations);
start = timeMs();
} else {
if (receivings > latency_iterations
&& bw_recv % bandwidth_iterations == 0)
{
var time_s = (timeMs() - start)/bandwidth_iterations/1000;
var exp = bw_recv / bandwidth_iterations;
var size_mb = Math.pow(2, exp) / 1024 / 1024;
var bw = size_mb/time_s;
console.log('bw ' + size_mb + 'MB ' + bw +
' (' + time_s + 's)');
start = timeMs();
}
}
});
});
</script>
</body>
</html>