Showing
2 changed files
with
27 additions
and
0 deletions
socket.js
0 → 100644
1 | +const SocketIO = require('socket.io'); | ||
2 | + | ||
3 | +module.exports = (server, app) => { | ||
4 | + const io = SocketIO(server, { path: '/socket.io' }); | ||
5 | + | ||
6 | + app.set('io', io); | ||
7 | + | ||
8 | + io.on('connection', (socket) => { | ||
9 | + const req = socket.request; | ||
10 | + const { headers: { referer } } = req; | ||
11 | + const roomId = referer.split('/')[referer.split('/').length - 1]; | ||
12 | + socket.join(roomId); | ||
13 | + socket.on('disconnect', () => { | ||
14 | + socket.leave(roomId); | ||
15 | + }); | ||
16 | + }); | ||
17 | +}; |
-
Please register or login to post a comment