HSBonjourService
TypeA 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
txtRecord
The TXT record as a {key: value} object, or null if none is available.
Populated after resolve() completes or when updated via monitor().
Methods
resolve(timeout, callback) -> HSBonjourService
Resolves the hostname, port, addresses, and TXT record of this service.
The callback is called with (event) or (event, errorMessage):
"resolved"— resolution complete; readhostname,port,addresses,txtRecord"stopped"— resolution stopped before completing"error"— resolution failed; error message in second argument
resolve(timeout, callback) -> HSBonjourService
| Name | Type | Description |
|---|---|---|
| timeout | number | seconds before giving up; pass 0 for no timeout |
| callback | function | Called on status changes with event name and optional error message |
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 | function | Called when TXT data changes with the updated record |
service.monitor(txt => console.log('TXT updated:', txt))
stop() -> HSBonjourService
Stops any active resolution.
stop() -> HSBonjourService
service.stop()
stopMonitoring() -> HSBonjourService
Stops TXT record monitoring started by monitor().
stopMonitoring() -> HSBonjourService
service.stopMonitoring()
toJSON() -> {[key: string]: any}
Returns a plain object describing this service, for JSON serialisation
JSON.stringify() calls this automatically, so you rarely need to call it yourself.
toJSON() -> {[key: string]: any}
name, type, domain, hostname, port, addresses, txtRecord and includesPeerToPeer. hostname and txtRecord are null until the service has been resolvedconsole.log(JSON.stringify(service))