/** * 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 };