2025-10-22 06:12:25 -04:00
|
|
|
import { Server } from "socket.io";
|
2025-10-22 01:18:32 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface ServerToClientEvents {
|
|
|
|
|
}
|
2025-10-22 01:18:32 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface ClientToServerEvents {
|
|
|
|
|
createAlarm: (cmd:CreateAlarmCommand) => void;
|
2025-10-22 06:12:25 -04:00
|
|
|
}
|
|
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface InterServerEvents {
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface SocketData {
|
|
|
|
|
token: string;
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface CreateAlarmCommand {
|
|
|
|
|
time:string
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface ListCommand {
|
|
|
|
|
groupId?:number
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface MakeGroupCommand {
|
|
|
|
|
name:string
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface RemoveCommand {
|
|
|
|
|
groupId:number
|
|
|
|
|
alarmId:number
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
interface SnoozeCommand {
|
|
|
|
|
groupId:number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ShutoffCommand {
|
|
|
|
|
groupId:number
|
|
|
|
|
}
|
2025-10-22 06:12:25 -04:00
|
|
|
|
2025-10-22 15:01:08 -04:00
|
|
|
const key = process.env.SECRET_KEY;
|
|
|
|
|
if (!key) {
|
|
|
|
|
throw new Error("Secret key not defined");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const io = new Server<
|
|
|
|
|
ServerToClientEvents,
|
|
|
|
|
ClientToServerEvents,
|
|
|
|
|
InterServerEvents,
|
|
|
|
|
SocketData
|
|
|
|
|
>(3300);
|
|
|
|
|
|
|
|
|
|
io.on("connection", (socket) => {
|
|
|
|
|
if (socket.data.token !== key) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.on("createAlarm", () => {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|