-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.handler.js
More file actions
33 lines (27 loc) · 794 Bytes
/
Copy pathsocket.handler.js
File metadata and controls
33 lines (27 loc) · 794 Bytes
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
module.exports = (socket, io) => {
socket.on('join', (id) => {
const roomClients = io.sockets.adapter.rooms[id] || { length: 0 };
if (roomClients.length > 1) socket.emit('full_room', id);
else {
socket.join(id);
socket.emit('join', id);
}
})
socket.on('offer', event => {
socket.broadcast.to(event.id).emit('offer', event.offer)
});
socket.on('answer', event => {
socket.broadcast.to(event.id).emit('answer', event.answer)
});
socket.on('end', event => {
io.to(event.id).emit('end');
io.in(event.id).clients(function (error, ids) {
ids.forEach(id => {
io.sockets.sockets[id].leave(event.id);
})
})
});
socket.on('candidate', event => {
socket.broadcast.to(event.id).emit('candidate', event)
})
}