refuse connections if no cameras are available

This commit is contained in:
DavidVentura
2024-01-30 13:46:52 +01:00
parent 550f805c62
commit 971f741d35
+17 -11
View File
@@ -3,9 +3,8 @@ import { createWriteStream } from "node:fs";
import http from "node:http"; import http from "node:http";
import { CommandsByValue } from "./datatypes.js"; import { CommandsByValue } from "./datatypes.js";
import { create_LanSearch } from "./func_replacements.js";
import { hexdump } from "./hexdump.js"; import { hexdump } from "./hexdump.js";
import { create_P2pAlive } from "./impl.js"; import { create_LanSearch, create_P2pAlive } from "./impl.js";
import { Handlers, makeSession } from "./server.js"; import { Handlers, makeSession } from "./server.js";
const s = makeSession( const s = makeSession(
@@ -23,11 +22,11 @@ const s = makeSession(
(session) => { (session) => {
// ther should be a better way of executing periodic status update // ther should be a better way of executing periodic status update
// requests per device // requests per device
let buf = create_LanSearch();
const int = setInterval(() => { const int = setInterval(() => {
let buf = new DataView(new Uint8Array(4).buffer);
create_LanSearch(buf);
session.broadcast(buf); session.broadcast(buf);
}, 1000); }, 2000);
session.broadcast(buf);
}, },
{ debug: false, ansi: false }, { debug: false, ansi: false },
); );
@@ -54,15 +53,22 @@ s.eventEmitter.on("connect", (name: string, rinfo: RemoteInfo) => {
s.outgoingCommandId = 0; s.outgoingCommandId = 0;
s.dst_ip = rinfo.address; s.dst_ip = rinfo.address;
const int = setInterval(() => { if (s.ticket.every((x) => x == 0)) {
let buf = create_P2pAlive(); const int = setInterval(() => {
if (Date.now() - s.lastReceivedPacket > 500) { let buf = create_P2pAlive();
s.send(buf); if (Date.now() - s.lastReceivedPacket > 600) {
} s.send(buf);
}, 1000); }
}, 400);
}
}); });
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
if (s.ticket.every((x) => x == 0)) {
res.writeHead(400);
res.end("Nothing online");
return;
}
res.setHeader("Content-Type", `multipart/x-mixed-replace; boundary="${BOUNDARY}"`); res.setHeader("Content-Type", `multipart/x-mixed-replace; boundary="${BOUNDARY}"`);
responses.push(res); responses.push(res);
}); });