Create decent server skeleton
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
import { Server } from "socket.io";
|
||||
import { PrismaClient } from "./generated/prisma";
|
||||
|
||||
/**
|
||||
* Server interfaces
|
||||
*/
|
||||
interface ServerToClientEvents {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -14,8 +23,12 @@ interface SocketData {
|
||||
token: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command interfaces
|
||||
*/
|
||||
interface CreateAlarmCommand {
|
||||
time:string
|
||||
time:string // HH:MM or HH:MM:SS
|
||||
groupId:number
|
||||
}
|
||||
|
||||
interface ListCommand {
|
||||
@@ -28,7 +41,7 @@ interface MakeGroupCommand {
|
||||
|
||||
interface RemoveCommand {
|
||||
groupId:number
|
||||
alarmId:number
|
||||
alarmId?:number
|
||||
}
|
||||
|
||||
interface SnoozeCommand {
|
||||
@@ -39,24 +52,47 @@ interface ShutoffCommand {
|
||||
groupId:number
|
||||
}
|
||||
|
||||
// Start program
|
||||
const key = process.env.SECRET_KEY;
|
||||
if (!key) {
|
||||
throw new Error("Secret key not defined");
|
||||
}
|
||||
|
||||
const io = new Server<
|
||||
ServerToClientEvents,
|
||||
ClientToServerEvents,
|
||||
ServerToClientEvents,
|
||||
InterServerEvents,
|
||||
SocketData
|
||||
>(3300);
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
io.on("connection", async (socket) => {
|
||||
if (socket.data.token !== key) {
|
||||
socket.disconnect();
|
||||
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);
|
||||
@@ -39,11 +39,12 @@ enum AlarmGroupState {
|
||||
}
|
||||
|
||||
model Alarm {
|
||||
id Int @id @default(autoincrement())
|
||||
time String
|
||||
secondsSinceMidnight Int
|
||||
nextRing DateTime
|
||||
|
||||
// AlarmGroup FK
|
||||
AlarmGroupId Int
|
||||
AlarmGroup AlarmGroup @relation(fields: [AlarmGroupId], references: [id])
|
||||
|
||||
@@id([secondsSinceMidnight, AlarmGroupId])
|
||||
}
|
||||
|
||||
4
alarm-snoozer/src/app/app.hpp
Normal file
4
alarm-snoozer/src/app/app.hpp
Normal file
@@ -0,0 +1,4 @@
|
||||
int admin(int argc, char** argv)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <iostream>
|
||||
#include "app/app.hpp"
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user