-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (32 loc) · 1.02 KB
/
app.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
/**
* Module dependencies.
*/
var express = require('express')
, app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, path = require('path');
// Change to acceptible port
server.listen(3000);
app.use(express.static(path.join(__dirname, 'public')));
var isInitiator = false;
// Fall back to xhr-polling for hosts that don't support Web Sockets. Not needed for those that do.
io.configure('development', function(){
io.set('transports', ['xhr-polling']);
});
io.sockets.on('connection', function(socket) {
if(!isInitiator)
{
isInitiator = true;
socket.emit('initiatorFound', {setInitiator: isInitiator});
} else {
socket.emit('initiatorFound', {setInitiator: !isInitiator});
}
// Signaling Channel
socket.on('message', function(message) {
if(message.type == 'streamAdd') {
console.log('Got message: ' + message);
}
socket.broadcast.emit('message' ,message);
});
});