mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 04:14:14 +00:00
refactor(infra): reuse lan ip picker
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import os from "node:os";
|
||||
import { pickPrimaryLanIPv4 } from "../gateway/net.js";
|
||||
|
||||
export type SystemPresence = {
|
||||
host?: string;
|
||||
@@ -43,25 +44,7 @@ function normalizePresenceKey(key: string | undefined): string | undefined {
|
||||
}
|
||||
|
||||
function resolvePrimaryIPv4(): string | undefined {
|
||||
const nets = os.networkInterfaces();
|
||||
const prefer = ["en0", "eth0"];
|
||||
const pick = (names: string[]) => {
|
||||
for (const name of names) {
|
||||
const list = nets[name];
|
||||
const entry = list?.find((n) => n.family === "IPv4" && !n.internal);
|
||||
if (entry?.address) {
|
||||
return entry.address;
|
||||
}
|
||||
}
|
||||
for (const list of Object.values(nets)) {
|
||||
const entry = list?.find((n) => n.family === "IPv4" && !n.internal);
|
||||
if (entry?.address) {
|
||||
return entry.address;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
return pick(prefer) ?? os.hostname();
|
||||
return pickPrimaryLanIPv4() ?? os.hostname();
|
||||
}
|
||||
|
||||
function initSelfPresence() {
|
||||
|
||||
Reference in New Issue
Block a user