-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 937 Bytes
/
index.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
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http, {
path: process.env.SIGNALING_PATH,
});
const debug = require('debug')('raven-signal');
io.on('connection', (socket) => {
debug('Received a new connection');
socket.on('join', (room) => {
debug(`User connected to room ${room}`);
const peers = io.nsps['/'].adapter.rooms[room]
? Object.keys(io.nsps['/'].adapter.rooms[room].sockets)
: [];
socket.emit('peers', peers);
socket.join(room);
});
socket.on('signal', (data) => {
debug(`Received signal: id [${data.id}], signal [${data.signal}]`);
const client = io.sockets.connected[data.id];
client && client.emit('signal', {
id: socket.id,
signal: data.signal,
});
});
});
const port = process.env.PORT || 3334;
http.listen(port, () => {
console.log('Signalling server listening on port:', port);
});