abstract server a bit better
This commit is contained in:
+1
-30
@@ -1,23 +1,9 @@
|
||||
import { RemoteInfo } from "node:dgram";
|
||||
import { createWriteStream } from "node:fs";
|
||||
import http from "node:http";
|
||||
|
||||
import { create_LanSearch, create_P2pAlive } from "./impl.js";
|
||||
import { Handlers, makeSession } from "./server.js";
|
||||
|
||||
const s = makeSession(
|
||||
Handlers,
|
||||
(session) => {
|
||||
// ther should be a better way of executing periodic status update
|
||||
// requests per device
|
||||
let buf = create_LanSearch();
|
||||
const int = setInterval(() => {
|
||||
session.broadcast(buf);
|
||||
}, 2000);
|
||||
session.broadcast(buf);
|
||||
},
|
||||
{ debug: false, ansi: false },
|
||||
);
|
||||
const s = makeSession(Handlers, { debug: false, ansi: false });
|
||||
|
||||
let BOUNDARY = "a very good boundary line";
|
||||
let responses = [];
|
||||
@@ -36,21 +22,6 @@ s.eventEmitter.on("audio", (frame: Buffer) => {
|
||||
audioFd.write(frame);
|
||||
});
|
||||
|
||||
s.eventEmitter.on("connect", (name: string, rinfo: RemoteInfo) => {
|
||||
console.log(`Connected to ${name} - ${rinfo.address}`);
|
||||
s.outgoingCommandId = 0;
|
||||
s.dst_ip = rinfo.address;
|
||||
|
||||
if (s.ticket.every((x) => x == 0)) {
|
||||
const int = setInterval(() => {
|
||||
let buf = create_P2pAlive();
|
||||
if (Date.now() - s.lastReceivedPacket > 600) {
|
||||
s.send(buf);
|
||||
}
|
||||
}, 400);
|
||||
}
|
||||
});
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
if (s.ticket.every((x) => x == 0)) {
|
||||
res.writeHead(400);
|
||||
|
||||
Reference in New Issue
Block a user