Files
openclaw/extensions/bonjour/index.ts
2026-04-26 10:47:36 +01:00

50 lines
1.5 KiB
TypeScript

import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
import {
registerUncaughtExceptionHandler,
registerUnhandledRejectionHandler,
} from "openclaw/plugin-sdk/runtime";
import { startGatewayBonjourAdvertiser } from "./src/advertiser.js";
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 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 };
},
});
},
});