-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
46 lines (35 loc) · 1.18 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
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var resolve = require('path').resolve;
app.use(express.static(resolve('.')));
app.use('/app', express.static(resolve('../..', 'build')));
server.listen(3001);
io
.sockets
.on('connection', function (socket) {
socket.on('join', function(room) {
var people = io.sockets.clients(room).length;
socket.join(room);
if(people) {
console.log('people already create room');
// on envoit signal slave connected
socket.broadcast.emit('slave');
} else {
socket.emit('master');
console.log('room created you are the master');
}
});
socket.on('candidate', function(candidate) {
socket.broadcast.emit('candidate', candidate);
});
socket.on('master offer', function(offer) {
console.log('master offer and broadcast offer');
socket.broadcast.emit('master offer', offer);
});
socket.on('slave offer', function(offer) {
console.log('slave offer and broadcast offer', offer);
socket.broadcast.emit('slave offer', offer);
});
});