feat(events): add motion start/end flow with realtime client notifications
This commit is contained in:
@@ -31,6 +31,21 @@ const countSocketsForDevice = (deviceId: string): number => {
|
||||
return io.sockets.adapter.rooms.get(roomForDevice(deviceId))?.size ?? 0;
|
||||
};
|
||||
|
||||
export const isDeviceOnline = (deviceId: string): boolean => countSocketsForDevice(deviceId) > 0;
|
||||
|
||||
export const sendRealtimeToDevice = (
|
||||
deviceId: string,
|
||||
eventName: string,
|
||||
payload: Record<string, unknown>,
|
||||
): boolean => {
|
||||
if (!io || !isDeviceOnline(deviceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
io.to(roomForDevice(deviceId)).emit(eventName, payload);
|
||||
return true;
|
||||
};
|
||||
|
||||
const markDevicePresence = async (deviceId: string, status: 'online' | 'offline') => {
|
||||
const now = new Date();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user