API Docs

A discovered Bonjour service record. Call resolve() to look up its hostname, port, and addresses.

Instances are delivered by an HSBonjourSearch callback. Call resolve() to discover their hostname, port, and addresses, and optionally monitor() to watch for TXT record changes.

Callback events

Method Event Extra data
resolve() "resolved" (none)
resolve() "stopped" (none)
resolve() "error" error message string
monitor() "txtRecord" updated TXT record dict

Properties

identifier

string
A unique identifier assigned to this service object.

name

string
The service name (e.g. `"My Web Server"`).

type

string
The service type string (e.g. `"_http._tcp."`).

domain

string
The mDNS domain (almost always `"local."`).

hostname

string
The resolved hostname, or `null` before `resolve()` completes.

port

number
The service port. `-1` until `resolve()` completes.

addresses

string[]
IP address strings (IPv4 and/or IPv6) populated after `resolve()` completes.

txtRecord

[String: String]
The TXT record as a `{key: value}` object, or `null` if none is available. Populated after `resolve()` completes or when updated via `monitor()`.

includesPeerToPeer

boolean
Whether peer-to-peer Bluetooth/Wi-Fi is included in resolution.

Methods

resolve(timeout, callback) -> HSBonjourService

Resolves the hostname, port, addresses, and TXT record of this service.
resolve(timeout, callback) -> HSBonjourService
Name Type Description
timeout number seconds before giving up; pass `0` for no timeout
callback JSValue `function(event, data?)` called on status changes
HSBonjourService
self, for chaining
service.resolve(5, (ev, err) => {
    if (ev === 'resolved') console.log(service.hostname, service.port)
    else console.error('Resolve failed:', err)
})

monitor(callback) -> HSBonjourService

Starts monitoring the TXT record for changes. The callback fires whenever the TXT record is updated. Call `stopMonitoring()` to unsubscribe.
monitor(callback) -> HSBonjourService
Name Type Description
callback JSValue `function(txtRecord)` called when TXT data changes
HSBonjourService
self, for chaining
service.monitor(txt => console.log('TXT updated:', txt))

stop() -> HSBonjourService

Stops any active resolution.
stop() -> HSBonjourService
HSBonjourService
self, for chaining
service.stop()

stopMonitoring() -> HSBonjourService

Stops TXT record monitoring started by `monitor()`.
stopMonitoring() -> HSBonjourService
HSBonjourService
self, for chaining
service.stopMonitoring()