console.log(`[CONNECT] New client connected with ID ${me}`);
- socket.on('join', (data) => {
+ socket.on('join', async (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)
+ const sockets = await server.in(data.url).fetchSockets()
+ console.log(sockets);
+ 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(peerId, true));
+ socket.emit(events.types.ADD_PEER, events.addPeer(peer.id, true));
}
});
console.log(`[CONNECT] Client ${me} added to room ${data.url}`);
console.log(`[DISCONNECT] Client ${me} has disconnected and has been removed from all rooms`);
});
- socket.on('relayICECandidate', (data) => {
- const sockets = [...server.of(data.url).sockets.keys()];
- sockets.forEach((peerId) => {
- const peer = server.sockets.sockets.get(peerId)
+ socket.on('relayICECandidate', async (data) => {
+ const sockets = await server.in(data.url).fetchSockets()
+ console.log(sockets);
+ sockets.forEach((peer) => {
peer.emit(events.types.ICE_CANDIDATE_RECEIVED, events.ICECandidateReceived(me, data.ice_candidate))
});
console.log(`[RELAY_ICE_CANDIDATE] ICE candidate for client ${me} has been relayed to all peers`);
});
- socket.on('relaySessionDescription', (data) => {
- const sockets = [...server.of(data.url).sockets.keys()];
- sockets.forEach((peerId) => {
- const peer = server.sockets.sockets.get(peerId)
+ socket.on('relaySessionDescription', async (data) => {
+ const sockets = await server.in(data.url).fetchSockets()
+ console.log(sockets);
+ sockets.forEach((peer) => {
peer.emit(events.types.SESSION_DESCRIPTION_RECEIVED, events.SessionDescriptionReceived(me, data.session_description))
});