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