aboutsummaryrefslogtreecommitdiffstats
path: root/backend/src/socket/index.js
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswa Kalyan Bhuyan <[email protected]> 2025-04-29 10:47:43 +0530
committerLibravatarLibravatar Biswa Kalyan Bhuyan <[email protected]> 2025-04-29 10:47:43 +0530
commita2e0a65b2599267efe94d665d6305f59b225bbd5 (patch)
treee2cef2031e3f7655e0c5f419020a3f1064c3b7b8 /backend/src/socket/index.js
parent570bf0f3f065d583d6f94ecfc61aae93ba3e43de (diff)
downloadrestaurant-master.tar.gz
restaurant-master.tar.bz2
restaurant-master.zip
feat: added initlaized the frontend and backendHEADmaster
Diffstat (limited to 'backend/src/socket/index.js')
-rw-r--r--backend/src/socket/index.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/backend/src/socket/index.js b/backend/src/socket/index.js
new file mode 100644
index 0000000..0c25ed4
--- /dev/null
+++ b/backend/src/socket/index.js
@@ -0,0 +1,42 @@
+const socketIO = require('socket.io');
+const handlers = require('./handlers');
+
+/**
+ * Initialize Socket.IO
+ * @param {object} server - HTTP server instance
+ * @returns {object} Socket.IO instance
+ */
+const initializeSocket = (server) => {
+ const io = socketIO(server, {
+ cors: {
+ origin: '*',
+ methods: ['GET', 'POST']
+ }
+ });
+
+ // Authentication middleware for socket connections
+ io.use((socket, next) => {
+ // Simple authentication can be added here if needed
+ // const token = socket.handshake.auth.token;
+ // if (token validation logic) next();
+ // else next(new Error('Authentication error'));
+ next();
+ });
+
+ // Handle connection
+ io.on('connection', (socket) => {
+ console.log(`New client connected: ${socket.id}`);
+
+ // Register event handlers
+ handlers.registerHandlers(io, socket);
+
+ // Handle disconnection
+ socket.on('disconnect', () => {
+ console.log(`Client disconnected: ${socket.id}`);
+ });
+ });
+
+ return io;
+};
+
+module.exports = initializeSocket; \ No newline at end of file