fix(discovery): lazy-load bonjour; add tests

This commit is contained in:
Peter Steinberger
2025-12-13 03:55:32 +00:00
parent 47b4d245aa
commit 4b608117a2
5 changed files with 273 additions and 5 deletions

View File

@@ -1,7 +1,5 @@
import os from "node:os";
import { type CiaoService, getResponder, Protocol } from "@homebridge/ciao";
export type GatewayBonjourAdvertiser = {
stop: () => Promise<void>;
};
@@ -26,6 +24,11 @@ function safeServiceName(name: string) {
return trimmed.length > 0 ? trimmed : "Clawdis";
}
type BonjourService = {
advertise: () => Promise<void>;
destroy: () => Promise<void>;
};
export async function startGatewayBonjourAdvertiser(
opts: GatewayBonjourAdvertiseOpts,
): Promise<GatewayBonjourAdvertiser> {
@@ -33,6 +36,7 @@ export async function startGatewayBonjourAdvertiser(
return { stop: async () => {} };
}
const { getResponder, Protocol } = await import("@homebridge/ciao");
const responder = getResponder();
const hostname = os.hostname().replace(/\.local$/i, "");
@@ -53,7 +57,7 @@ export async function startGatewayBonjourAdvertiser(
txtBase.tailnetDns = opts.tailnetDns.trim();
}
const services: CiaoService[] = [];
const services: BonjourService[] = [];
// Master beacon: used for discovery (auto-fill SSH/direct targets).
// We advertise a TCP service so clients can resolve the host; the port itself is informational.