-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (29 loc) · 839 Bytes
/
Copy pathserver.js
File metadata and controls
34 lines (29 loc) · 839 Bytes
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
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('binaryjs').BinaryServer;
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){
//
var file = fs.createWriteStream(__dirname+ '/public/' + meta.name);
stream.pipe(file);
//
// Send progress back
stream.on('data', function(data){
stream.write({rx: data.length / meta.size});
});
//
});
});
//
//
server.listen(9000);
console.log('HTTP and BinaryJS server started on port 9000');