Create decent server skeleton

This commit is contained in:
2025-10-22 15:20:13 -04:00
parent 390f637c48
commit 520c0a8280
4 changed files with 53 additions and 10 deletions

View File

@@ -1,10 +1,19 @@
import { Server } from "socket.io"; import { Server } from "socket.io";
import { PrismaClient } from "./generated/prisma";
/**
* Server interfaces
*/
interface ServerToClientEvents { interface ServerToClientEvents {
} }
interface ClientToServerEvents { interface ClientToServerEvents {
createAlarm: (cmd:CreateAlarmCommand) => void; create: (cmd:CreateAlarmCommand) => void;
ls: (cmd:ListCommand) => void;
mkgrp: (cmd:MakeGroupCommand) => void;
rm: (cmd:RemoveCommand) => void;
snooze: (cmd:SnoozeCommand) => void;
shutoff: (cmd:ShutoffCommand) => void;
} }
interface InterServerEvents { interface InterServerEvents {
@@ -14,8 +23,12 @@ interface SocketData {
token: string; token: string;
} }
/**
* Command interfaces
*/
interface CreateAlarmCommand { interface CreateAlarmCommand {
time:string time:string // HH:MM or HH:MM:SS
groupId:number
} }
interface ListCommand { interface ListCommand {
@@ -28,7 +41,7 @@ interface MakeGroupCommand {
interface RemoveCommand { interface RemoveCommand {
groupId:number groupId:number
alarmId:number alarmId?:number
} }
interface SnoozeCommand { interface SnoozeCommand {
@@ -39,24 +52,47 @@ interface ShutoffCommand {
groupId:number groupId:number
} }
// Start program
const key = process.env.SECRET_KEY; const key = process.env.SECRET_KEY;
if (!key) { if (!key) {
throw new Error("Secret key not defined"); throw new Error("Secret key not defined");
} }
const io = new Server< const io = new Server<
ServerToClientEvents,
ClientToServerEvents, ClientToServerEvents,
ServerToClientEvents,
InterServerEvents, InterServerEvents,
SocketData SocketData
>(3300); >(3300);
io.on("connection", (socket) => { const prisma = new PrismaClient();
io.on("connection", async (socket) => {
if (socket.data.token !== key) { if (socket.data.token !== key) {
socket.disconnect();
return; return;
} }
socket.on("createAlarm", () => { socket.on("create", async (cmd:CreateAlarmCommand) => {
});
socket.on("ls", async (cmd:ListCommand) => {
});
socket.on("mkgrp", async (cmd:MakeGroupCommand) => {
});
socket.on("rm", async (cmd:RemoveCommand) => {
});
socket.on("snooze", async (cmd:SnoozeCommand) => {
});
socket.on("shutoff", async (cmd:ShutoffCommand) => {
}); });
}); });
setInterval(async () => {
// Process alarms constantly to announce alarm state to "groupstate-alert" on a change or when the client reports a differing state
}, 1);

View File

@@ -39,11 +39,12 @@ enum AlarmGroupState {
} }
model Alarm { model Alarm {
id Int @id @default(autoincrement()) secondsSinceMidnight Int
time String nextRing DateTime
nextRing DateTime
// AlarmGroup FK // AlarmGroup FK
AlarmGroupId Int AlarmGroupId Int
AlarmGroup AlarmGroup @relation(fields: [AlarmGroupId], references: [id]) AlarmGroup AlarmGroup @relation(fields: [AlarmGroupId], references: [id])
@@id([secondsSinceMidnight, AlarmGroupId])
} }

View File

@@ -0,0 +1,4 @@
int admin(int argc, char** argv)
{
}

View File

@@ -1,6 +1,8 @@
#include <iostream> #include <iostream>
#include "app/app.hpp"
int main() { int main() {
std::cout << "Hello, World!" << std::endl; std::cout << "Hello, World!" << std::endl;
return 0; return 0;
} }