Skip to content

Commit

Permalink
fix: web sockets issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Dec 26, 2023
1 parent 9d15527 commit f6c5093
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/network/socket/routes/takePhoto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { Server } from 'socket.io'
import { Socket } from 'socket.io'
import debug from 'debug'

const takePhoto = (sensorData: SensorData, io: Server) => {
import { MAIN_TOPIC } from 'utils'

const realTimeDebug = debug(`${MAIN_TOPIC}:WebSockets:takePhoto`)

const takePhoto = (sensorData: SensorData, socket: Socket) => {
const { id, moduleId, sensorId } = sensorData

io.on(`${sensorId}/takePhoto`, () => {
global.__mqttClient__.publish('takePhoto', `${id}/${moduleId}/${sensorId}`)
realTimeDebug(`Creating route: "${sensorId}/takePhoto"`)

socket.on(`${sensorId}/takePhoto`, () => {
realTimeDebug(`Taking photo for: ${id}/${moduleId}/${sensorId}`)

global.__mqttClient__.publish(
`${MAIN_TOPIC}/takePhoto`,
`${id}/${moduleId}/${sensorId}`
)
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/network/socket/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const socketConnection = (d: Debugger) => ({

socket.emit(`${sensorId}/initialData`, data)
;(Object.keys(routes) as (keyof typeof routes)[]).forEach(route => {
routes[route]({ id, moduleId, sensorId }, global.__io__)
d(`Applying route: ${route} for ${id}/${moduleId}/${sensorId}`)
routes[route]({ id, moduleId, sensorId }, socket)
})
})

Expand Down

0 comments on commit f6c5093

Please sign in to comment.