- socket.on('join', (data) => {
- socket.join(data.url);
- const sockets = [...server.of(data.url).sockets.keys()];
- sockets.forEach((peerId) => {
- if (peerId !== me) {
- const peer = server.sockets.sockets.get(peerId)
- peer.emit(events.types.ADD_PEER, events.addPeer(me, false));
- socket.emit(events.types.ADD_PEER, events.addPeer(peerId, true));
- }
- });
- console.log(`[CONNECT] Client ${me} added to room ${data.url}`);
+ socket.on('join', async (data) => {
+ const room = data.room;
+ socket.join(room);
+
+ if (!rooms[room]) {
+ rooms[room] = {};
+ }
+
+ rooms[room].push(socket.id);
+
+ const sockets = await server.in(data.url).fetchSockets()
+ sockets.forEach((peer) => {
+ if (peer.id !== me) {
+ peer.emit(events.types.ADD_PEER, events.addPeer(me, false));
+ socket.emit(events.types.ADD_PEER, events.addPeer(peer.id, true));
+ }
+ });
+ console.log(`[CONNECT] Client ${me} added to room ${data.url}`);