diff --git a/http_server.ts b/http_server.ts index 6cbbf00..8a5b0af 100644 --- a/http_server.ts +++ b/http_server.ts @@ -4,7 +4,7 @@ import http from "node:http"; import { logger } from "./logger.js"; import { config } from "./settings.js"; import { discoverDevices } from "./discovery.js"; -import { DevSerial, SendDevStatus } from "./impl.js"; +import { DevSerial } from "./impl.js"; import { Handlers, makeSession, Session, startVideoStream } from "./session.js"; import { addExifToJpeg, createExifOrientation } from "./exif.js"; @@ -138,7 +138,6 @@ export const serveHttp = (port: number) => { let devEv = discoverDevices(config.discovery_ips); const startSession = (s: Session) => { - s.send(SendDevStatus(s)); startVideoStream(s); logger.info(`Camera ${s.devName} is now ready to stream`); }; @@ -152,7 +151,7 @@ export const serveHttp = (port: number) => { logger.info(`Discovered camera ${dev.devId} at ${rinfo.address}`); responses[dev.devId] = []; audioResponses[dev.devId] = []; - const s = makeSession(Handlers, dev, rinfo, startSession); + const s = makeSession(Handlers, dev, rinfo, startSession, 5000); sessions[dev.devId] = s; config.cameras[dev.devId] = { rotate: 0, mirror: false, audio: true, ...(config.cameras[dev.devId] || {}) }; diff --git a/session.ts b/session.ts index e6fa1b9..a2e2745 100644 --- a/session.ts +++ b/session.ts @@ -61,6 +61,7 @@ export const makeSession = ( dev: DevSerial, ra: RemoteInfo, onLogin: (s: Session) => void, + timeoutMs: number, ): Session => { let unackedDrw = {}; const sock = createSocket("udp4"); @@ -86,8 +87,7 @@ export const makeSession = ( let buf = create_P2pAlive(); session.send(buf); } - if (delta > 9000) { - // should depend on whether we are streaming video + if (delta > timeoutMs) { logger.warning(`Camera ${session.devName} timed out`); session.eventEmitter.emit("disconnect"); } @@ -161,9 +161,9 @@ export const makeSession = ( return session; }; -export const configureWifi = (ssid: string, password: string) => { +export const configureWifi = (ssid: string, password: string, channel: number) => { return (s: Session) => { - [SendWifiDetails(s, ssid, password, true)].forEach(s.send); + [SendWifiDetails(s, ssid, password, channel, true)].forEach(s.send); }; };