Files
openclaw/extensions/bonjour/index.ts
2026-05-02 15:05:33 +01:00

52 lines
1.6 KiB
TypeScript

import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
function formatBonjourInstanceName(displayName: string) {
const trimmed = displayName.trim();
if (!trimmed) {
return "OpenClaw";
}
if (/openclaw/i.test(trimmed)) {
return trimmed;
}
return `${trimmed} (OpenClaw)`;
}
export default definePluginEntry({
id: "bonjour",
name: "Bonjour Gateway Discovery",
description: "Advertise the local OpenClaw gateway over Bonjour/mDNS.",
register(api) {
api.registerGatewayDiscoveryService({
id: "bonjour",
advertise: async (ctx) => {
const [
{ startGatewayBonjourAdvertiser },
{ registerUncaughtExceptionHandler, registerUnhandledRejectionHandler },
] = await Promise.all([
import("./src/advertiser.js"),
import("openclaw/plugin-sdk/runtime"),
]);
const advertiser = await startGatewayBonjourAdvertiser(
{
instanceName: formatBonjourInstanceName(ctx.machineDisplayName),
gatewayPort: ctx.gatewayPort,
gatewayTlsEnabled: ctx.gatewayTlsEnabled,
gatewayTlsFingerprintSha256: ctx.gatewayTlsFingerprintSha256,
canvasPort: ctx.canvasPort,
sshPort: ctx.sshPort,
tailnetDns: ctx.tailnetDns,
cliPath: ctx.cliPath,
minimal: ctx.minimal,
},
{
logger: api.logger,
registerUncaughtExceptionHandler,
registerUnhandledRejectionHandler,
},
);
return { stop: advertiser.stop };
},
});
},
});