feat(events): add motion start/end flow with realtime client notifications

This commit is contained in:
2026-01-10 11:20:00 +00:00
parent 71401e1973
commit aa8b278c46
3 changed files with 230 additions and 0 deletions

View File

@@ -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();