-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocketIO.js
29 lines (28 loc) · 1.03 KB
/
socketIO.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
module.exports = function (io) {
io.on('connection', (socket) => {
socket.on('join', async (data) => {
let rooms = Object.keys(socket.rooms);
console.log(rooms);
await socket.leave(rooms)
await socket.join(data.room, () => {
io.in(data.room).emit('join', { msg: `${data.name} has join ${data.room}` })
});
console.log(room);
})
io.in(socket.rooms).emit('newMessage', { msg: `${socket.id} has join ${socket.room}` })
socket.on('close', (data) => {
io.in(data.room).emit('join', { msg: `${data.name} has leave ` })
});
socket.on('newMessage', (data) => {
io.in(data.room).emit('newMessage', data);
console.log(data);
});
socket.on('typing', (data) => {
socket.broadcast.to(data.room).emit('typing', data);
})
});
// setInterval(function () {
// console.clear()
// console.log(io.sockets.adapter.rooms)
// }, 1000);
}