abstract server a bit better

This commit is contained in:
DavidVentura
2024-01-31 11:56:33 +01:00
parent 0b2ac1a118
commit 9d671f18c9
2 changed files with 32 additions and 24 deletions
+1 -13
View File
@@ -2,23 +2,11 @@ import { RemoteInfo } from "node:dgram";
import { createWriteStream } from "node:fs";
import http from "node:http";
import { CommandsByValue } from "./datatypes.js";
import { hexdump } from "./hexdump.js";
import { create_LanSearch, create_P2pAlive } from "./impl.js";
import { Handlers, makeSession } from "./server.js";
const s = makeSession(
(session, msg, rinfo, options) => {
const ab = new Uint8Array(msg).buffer;
const dv = new DataView(ab);
const cmd = CommandsByValue[dv.readU16()];
if (options.debug) {
console.log(`<< ${cmd}`);
console.log(hexdump(msg.buffer, { ansi: options.ansi, ansiColor: 1 }));
}
Handlers[cmd](session, dv, rinfo);
session.lastReceivedPacket = Date.now();
},
Handlers,
(session) => {
// ther should be a better way of executing periodic status update
// requests per device