blob: 7e110b5b89e61fc92cbe93bdf25ea1a5cb0a6d5b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
};
|