first commit
This commit is contained in:
38
node_modules/binaryjs/examples/imageshare/public/index.html
generated
vendored
Normal file
38
node_modules/binaryjs/examples/imageshare/public/index.html
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="http://cdn.binaryjs.com/0/binary.js"></script>
|
||||
</head>
|
||||
<body style="background-size:cover">
|
||||
|
||||
<input type="file" id="fileinput" accept="image/*" capture="camera" />
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
// connect to the same host this was served from
|
||||
var client = new BinaryClient('ws://' + document.location.host);
|
||||
|
||||
client.on('stream', function(stream, meta){
|
||||
|
||||
// collect stream data
|
||||
var parts = [];
|
||||
stream.on('data', function(data){
|
||||
parts.push(data);
|
||||
});
|
||||
|
||||
// when finished, set it as the background image
|
||||
stream.on('end', function(){
|
||||
var url = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
|
||||
document.body.style.backgroundImage = 'url(' + url + ')';
|
||||
});
|
||||
});
|
||||
|
||||
// listen for a file being chosen
|
||||
fileinput.addEventListener('change', function(event){
|
||||
var file = event.target.files[0];
|
||||
client.send(file);
|
||||
}, false);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
37
node_modules/binaryjs/examples/imageshare/server.js
generated
vendored
Normal file
37
node_modules/binaryjs/examples/imageshare/server.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
var fs = require('fs');
|
||||
var http = require('http');
|
||||
|
||||
// Serve client side statically
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
|
||||
var server = http.createServer(app);
|
||||
|
||||
// Start Binary.js server
|
||||
var BinaryServer = require('../../').BinaryServer;
|
||||
|
||||
// link it to express
|
||||
var bs = BinaryServer({server: server});
|
||||
|
||||
// Wait for new user connections
|
||||
bs.on('connection', function(client){
|
||||
|
||||
// Incoming stream from browsers
|
||||
client.on('stream', function(stream, meta){
|
||||
|
||||
// broadcast to all other clients
|
||||
for(var id in bs.clients){
|
||||
if(bs.clients.hasOwnProperty(id)){
|
||||
var otherClient = bs.clients[id];
|
||||
if(otherClient != client){
|
||||
var send = otherClient.createStream(meta);
|
||||
stream.pipe(send);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(9000);
|
||||
console.log('HTTP and BinaryJS server started on port 9000');
|
||||
Reference in New Issue
Block a user