forked from ericz/ascam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (35 loc) · 1.04 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
var express = require('express');
var fs = require('fs');
var app = express.createServer();
// Initialize main server
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');
app.get('/', function(req, res){
res.render('index');
});
app.get('/view/:room', function(req, res){
res.render('view', {room: req.params.room});
});
app.get('/broadcast/:room', function(req, res){
res.render('broadcast', {room: req.params.room});
});
app.listen(80);
var BinaryServer = require('binaryjs').BinaryServer;
var rooms = {};
// Start Binary.js server
var server = BinaryServer({port: 9001});
// Wait for new user connections
server.on('connection', function(client){
client.on('error', function(e) {
console.log(e.stack, e.message);
});
client.on('stream', function(stream, meta){
if(meta.type == 'write') {
rooms[meta.room] = stream;
} else if (meta.type == 'read' && rooms[meta.room]) {
rooms[meta.room].pipe(stream);
}
});
});