diff options
Diffstat (limited to 'backend/src/socket/handlers.js')
-rw-r--r-- | backend/src/socket/handlers.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/backend/src/socket/handlers.js b/backend/src/socket/handlers.js new file mode 100644 index 0000000..7e110b5 --- /dev/null +++ b/backend/src/socket/handlers.js @@ -0,0 +1,51 @@ +/** + * Register all event handlers for a socket connection + * @param {object} io - Socket.IO server instance + * @param {object} socket - Socket connection instance + */ +const registerHandlers = (io, socket) => { + // Handle joining a room (e.g., for orders or staff notifications) + socket.on('join-room', (room) => { + socket.join(room); + console.log(`Client ${socket.id} joined room: ${room}`); + }); + + // Handle order updates + socket.on('order-update', (data) => { + // Broadcast order updates to all clients in the room + io.to('staff-notifications').emit('order-status-changed', data); + io.to(`user-${data.userId}`).emit('order-status-changed', data); + console.log(`Order update: ${JSON.stringify(data)}`); + }); + + // Handle table reservation updates + socket.on('reservation-update', (data) => { + // Broadcast reservation updates to staff + io.to('staff-notifications').emit('reservation-changed', data); + console.log(`Reservation update: ${JSON.stringify(data)}`); + }); + + // Handle staff notifications + socket.on('staff-notification', (data) => { + // Broadcast to specific staff members or all staff + io.to('staff-notifications').emit('new-notification', data); + console.log(`Staff notification: ${JSON.stringify(data)}`); + }); + + // Handle customer notifications + socket.on('customer-notification', (data) => { + // Send notification to specific customer + io.to(`user-${data.userId}`).emit('new-notification', data); + console.log(`Customer notification: ${JSON.stringify(data)}`); + }); + + // Leave room + socket.on('leave-room', (room) => { + socket.leave(room); + console.log(`Client ${socket.id} left room: ${room}`); + }); +}; + +module.exports = { + registerHandlers +};
\ No newline at end of file |