Macotron

macotron.bonjour

Browse the local network for Bonjour services, such as AirPlay receivers, printers, and file shares, and get each one's host, port, and TXT record.

// List AirPlay receivers on the network.
const found = await macotron.bonjour.browse("_airplay._tcp", { timeout: 2 });
macotron.notify.toast("AirPlay", found.map((s) => s.name).join(", ") || "None found");

Browsing

browse(type: string, opts?: { timeout?: number }): Promise<Array<{ name, type, host, port, txt }>>

Searches the local. domain for services of one type, such as "_airplay._tcp", "_ipp._tcp", or "_smb._tcp". A trailing .local. on the type is allowed and removed.

The search runs for the whole timeout, in seconds (default 1.5), then resolves with every service that resolved in that time. Each row has:

A service that does not resolve to a host and port before the timeout is left out, so a longer timeout finds slower devices. Nothing found resolves to an empty array.

macOS asks for Local Network permission the first time Macotron browses. Without it, browse finds nothing.

See also