add slow-startup flag
This commit is contained in:
+4
-2
@@ -13,8 +13,9 @@ yargs(hideBin(process.argv))
|
||||
return yargs
|
||||
.option("debug", { describe: "Log debug messages", default: false })
|
||||
.option("ansi", { default: false })
|
||||
.option("slow_startup", { default: false })
|
||||
.option("audio", { describe: "Also stream audio from camera", default: true })
|
||||
.boolean(["debug", "ansi", "audio"])
|
||||
.boolean(["debug", "ansi", "audio", "slow_startup"])
|
||||
.option("discovery_ip", { describe: "Camera discovery IP address", default: "192.168.1.255" })
|
||||
.option("attempt_to_fix_packet_loss", { default: false })
|
||||
.option("port", { describe: "HTTP Port to listen on", default: 5000 })
|
||||
@@ -33,7 +34,8 @@ yargs(hideBin(process.argv))
|
||||
return yargs
|
||||
.option("debug", { describe: "Log debug messages", default: false })
|
||||
.option("ansi", { default: false })
|
||||
.boolean(["debug", "ansi"])
|
||||
.option("slow_startup", { default: false })
|
||||
.boolean(["debug", "ansi", "slow_startup"])
|
||||
.option("discovery_ip", { describe: "Camera discovery IP address", default: "192.168.1.255" })
|
||||
.option("attempt_to_fix_packet_loss", { default: false })
|
||||
.option("ssid", { describe: "Wifi network for the camera to connect to" })
|
||||
|
||||
@@ -2,5 +2,6 @@ export type opt = {
|
||||
debug: boolean;
|
||||
ansi: boolean;
|
||||
discovery_ip: string;
|
||||
slow_startup: boolean;
|
||||
attempt_to_fix_packet_loss: boolean;
|
||||
};
|
||||
|
||||
+23
-11
@@ -21,6 +21,7 @@ export type Session = {
|
||||
rcvSeqId: number;
|
||||
frame_is_bad: boolean;
|
||||
frame_was_fixed: boolean;
|
||||
started: boolean;
|
||||
options: opt;
|
||||
};
|
||||
|
||||
@@ -62,23 +63,33 @@ export const makeSession = (
|
||||
sock.on("message", (msg, rinfo) => handleIncoming(session, handlers, msg, rinfo));
|
||||
|
||||
sock.on("listening", () => {
|
||||
const buf = makeP2pRdy(dev);
|
||||
session.send(buf);
|
||||
// The YsxLite sends a P2PAlive message immediately after P2PRdy
|
||||
const alive_buf = create_P2pAlive();
|
||||
session.send(alive_buf);
|
||||
const startup = () => {
|
||||
const buf = makeP2pRdy(dev);
|
||||
session.send(buf);
|
||||
// The YsxLite sends a P2PAlive message immediately after P2PRdy
|
||||
const alive_buf = create_P2pAlive();
|
||||
session.send(alive_buf);
|
||||
session.started = true;
|
||||
};
|
||||
if (options.slow_startup) {
|
||||
setTimeout(startup, 3000);
|
||||
} else {
|
||||
startup();
|
||||
}
|
||||
});
|
||||
|
||||
const SEND_PORT = 32108;
|
||||
sock.bind();
|
||||
const sessTimer = setInterval(() => {
|
||||
const delta = Date.now() - session.lastReceivedPacket;
|
||||
if (delta > 600) {
|
||||
let buf = create_P2pAlive();
|
||||
session.send(buf);
|
||||
}
|
||||
if (delta > 8000) {
|
||||
session.eventEmitter.emit("disconnect");
|
||||
if (session.started) {
|
||||
if (delta > 600) {
|
||||
let buf = create_P2pAlive();
|
||||
session.send(buf);
|
||||
}
|
||||
if (delta > 8000) {
|
||||
session.eventEmitter.emit("disconnect");
|
||||
}
|
||||
}
|
||||
}, 400);
|
||||
|
||||
@@ -90,6 +101,7 @@ export const makeSession = (
|
||||
connected: true,
|
||||
timers: [sessTimer],
|
||||
devName: dev.devId,
|
||||
started: false,
|
||||
send: (msg: DataView) => {
|
||||
const raw = msg.readU16();
|
||||
const cmd = CommandsByValue[raw];
|
||||
|
||||
Reference in New Issue
Block a user