hammerspoon2-docs
    Preparing search index...

    Class HSBonjourService

    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.

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

    IP address strings (IPv4 and/or IPv6) populated after resolve() completes.

    domain: string

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

    hostname: string | null

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

    identifier: string

    A unique identifier assigned to this service object.

    includesPeerToPeer: boolean

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

    name: string

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

    port: number

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

    txtRecord: Record<string, string> | null

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

    type: string

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

    • Starts monitoring the TXT record for changes. The callback fires whenever the TXT record is updated.

      Call stopMonitoring() to unsubscribe.

      Parameters

      • callback: (txtRecord: Record<string, string>) => void

        Called when TXT data changes with the updated record

      Returns HSBonjourService

      self, for chaining

    • Resolves the hostname, port, addresses, and TXT record of this service.

      The callback is called with (event) or (event, errorMessage):

      • "resolved" — resolution complete; read hostname, port, addresses, txtRecord
      • "stopped" — resolution stopped before completing
      • "error" — resolution failed; error message in second argument

      Parameters

      • timeout: number

        seconds before giving up; pass 0 for no timeout

      • callback: (event: string, error?: string) => void

        Called on status changes with event name and optional error message

      Returns HSBonjourService

      self, for chaining

      A resolving or monitored service, and its callbacks, stay alive until that finishes or is stopped, even if you don't keep a reference to it

    • Returns a plain object describing this service, for JSON serialisation

      JSON.stringify() calls this automatically, so you rarely need to call it yourself.

      Returns Record<string, any>

      An object with the service's name, type, domain, hostname, port, addresses, txtRecord and includesPeerToPeer. hostname and txtRecord are null until the service has been resolved