Skip to content

Commit e6dde20

Browse files
committed
Change socket event names for consistency
1 parent 8e808a1 commit e6dde20

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/controllers/locationController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function emitAction(
1818
locations: locations,
1919
}
2020

21-
io.to(`user_${userId.toString()}`).emit("locations_change", data)
22-
io.to(`admin`).emit("admin_locations_change", data)
21+
io.to(`user_${userId.toString()}`).emit("locations-change", data)
22+
io.to(`admin`).emit("admin-locations-change", data)
2323
}
2424

2525
export const createLocation = async (

src/socket.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,50 @@ export function createIO(
2626

2727
console.log(`New client connected: ${socket.id}`)
2828

29-
socket.on("register-device", async ({ deviceId }) => {
29+
socket.on("register-device", async ({ device_id }) => {
3030
const device = await prisma.device.findUnique({
31-
where: { id: deviceId },
31+
where: { id: device_id },
3232
})
3333
if (!device) return socket.emit("error", "Device not found")
3434
if (device.user_id !== user.id) {
3535
return socket.emit("error", "You do not own this device")
3636
}
3737

38-
socket.join(`device-${deviceId}`)
39-
io!.to(`user_${user.id}`).emit("connections_change")
40-
console.log(`Device ${deviceId} joined room`)
38+
socket.join(`device-${device_id}`)
39+
io!.to(`user_${user.id}`).emit("connections-change")
40+
console.log(`Device ${device_id} joined room`)
4141

4242
// Ring the device if it's in the queue
43-
const formattedDeviceId = BigInt(deviceId)
43+
const formattedDeviceId = BigInt(device_id)
4444
if (ringQueue.has(formattedDeviceId)) {
4545
io!.to(`device-${formattedDeviceId}`).emit("ring-command")
4646
console.log(`Sent queued ring to ${formattedDeviceId}`)
4747
ringQueue.remove(formattedDeviceId)
4848
}
4949
})
5050

51-
socket.on("unregister-device", async ({ deviceId }) => {
51+
socket.on("unregister-device", async ({ device_id }) => {
5252
const device = await prisma.device.findUnique({
53-
where: { id: deviceId },
53+
where: { id: device_id },
5454
})
5555
if (!device) return socket.emit("error", "Device not found")
5656

57-
socket.leave(`device-${deviceId}`)
58-
io!.to(`user_${user.id}`).emit("connections_change")
59-
console.log(`Device ${deviceId} left room`)
57+
socket.leave(`device-${device_id}`)
58+
io!.to(`user_${user.id}`).emit("connections-change")
59+
console.log(`Device ${device_id} left room`)
6060
})
6161

62-
socket.on("ring", async ({ deviceId }) => {
62+
socket.on("ring", async ({ device_id }) => {
6363
const device = await prisma.device.findUnique({
64-
where: { id: deviceId },
64+
where: { id: device_id },
6565
})
6666
if (!device) return socket.emit("error", "Device not found")
6767
if (device.user_id !== user.id) {
6868
return socket.emit("error", "You do not own this device")
6969
}
7070

71-
io!.to(`device-${deviceId}`).emit("ring-command")
72-
console.log(`Sent ring to device ${deviceId}`)
71+
io!.to(`device-${device_id}`).emit("ring-command")
72+
console.log(`Sent ring to device ${device_id}`)
7373
})
7474

7575
socket.on("disconnect", () => {

0 commit comments

Comments
 (0)