From 7f6f40edc4525a8337445076b3f31509bd0b73a2 Mon Sep 17 00:00:00 2001 From: heyhiru Date: Sat, 11 Nov 2023 14:49:32 +0530 Subject: [PATCH] created connection in backend Signed-off-by: heyhiru --- server/index.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/index.js b/server/index.js index e69de29..97b2dbd 100644 --- a/server/index.js +++ b/server/index.js @@ -0,0 +1,23 @@ +const { Server, Socket } = require('socket.io'); + +const io = new Server(8080, { + cors: true +}); + + +const emailToSocket = new Map(); +const socketToEmail = new Map(); + +io.on("connection", (socket) => { + console.log(`Socket Connected: ${socket.id}`); + + socket.on('room:join', data => { + const { email, room } = data; + emailToSocket.set(email, socket.id); + socketToEmail.set(socket.id, email); + + // emits a 'room:joined' event back to the client + // that just joined the room. + io.to(socket.id).emit('room:join', data); + }) +}) \ No newline at end of file