-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
39 lines (39 loc) · 1.26 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
<html>
<head>
<script src="node_modules/binaryjs/dist/binary.min.js"></script>
<script type="application/javascript">
window.onload = function() {
var img = document.createElement("img");
document.body.appendChild(img);
// Connect to Binary.js server
var client = new BinaryClient('ws://'+location.hostname+':9000');
client.on('open', function (s) {
//console.log('client opened, created stream');
stream = client.createStream(s, 'toserver');
// data coming from the server...
});
// Received new stream from server!
client.on('stream', function(s, meta){
// console.log('recieved new stream');
// Buffer for parts
var parts = [];
// Got new data
s.on('data', function(data){
//console.log('pushing binary data to array');
parts.push(data);
});
// Display new data in browser!
s.on('end', function(){
// var img = document.getElementById("img");
//console.log('stream ended, binary data complete');
img.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
setTimeout(function() {client.send("ping")}, 500);
// console.log('pinging server to reinitiate stream');
});
});
}
</script>
</head>
<body>
</body>
</html>