forked from binaryjs/binaryjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (29 loc) · 910 Bytes
/
server.js
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
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');