-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
36 lines (29 loc) · 1.17 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
/*
This code was developed by @ArinSime and WebRTC.ventures for a WebRTC blog post.
You are welcome to use it at your own risk as starter code for your applications,
but please be aware that this is not a complete code example with all the necessary
security and privacy considerations implemented that a production app would require.
It is for educational purposes only, and any other use is done at your own risk.
*/
//Server.js: This is the core Node.js configuration code, and also used for
//setting up signaling channels to be used by socket.io
var express = require('express.io');
var app = express();
app.http().io();
var PORT = 3000;
console.log('server started on port ' + PORT);
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.render('index.ejs');
});
app.listen(process.env.PORT || PORT);
app.io.route('ready', function(req) {
req.io.join(req.data.signal_room);
})
app.io.route('signal', function(req) {
//Note the use of req here for broadcasting so only the sender doesn't receive their own messages
req.io.room(req.data.room).broadcast('signaling_message', {
type: req.data.type,
message: req.data.message
});
})