Skip to content

Commit

Permalink
feat: emitting toggle device event for each device
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Dec 27, 2023
1 parent 03eac8b commit bb26d0e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/network/socket/routes/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import { updateDevices as ud } from 'database'
const realTimeDebug = debug(`${MAIN_TOPIC}:WebSockets:updateDevices`)

const updateDevices = (sensorData: SensorData, socket: Socket) => {
const { sensorId } = sensorData
const { id: clientId, sensorId } = sensorData

realTimeDebug(`Creating route: "${sensorId}/updateDevices"`)

socket.on(`${sensorId}/updateDevices`, (message: Device[]) => {
ud(message)
.then(() => {
message.forEach(({ id, status }) => {
__mqttClient__.publish(
`${MAIN_TOPIC}/toggleDevice`,
`${clientId}/${sensorId}/${id}/${status}`
)
})
socket.emit(`${sensorId}/updatedDevices`, true)
})
.catch(error => {
Expand Down

0 comments on commit bb26d0e

Please sign in to comment.