#
hs.bonjour.service
Represents the service records that are discovered or published by the hs.bonjour module.
This module allows you to explore the details of discovered services including ip addresses and text records, and to publish your own multicast DNS advertisements for services on your computer. This can be useful to advertise network services provided by other Hammerspoon modules or other applications on your computer which do not publish their own advertisements already.
This module will not allow you to publish proxy records for other hosts on your local network. Additional submodules which may address this limitation as well as provide additional functions available with Apple's dns-sd library are being considered but there is no estimated timeframe at present.
#
API Overview
Constants - Useful values which cannot be changed
serviceTypes
Constructors - API calls which return an object, typically one that offers API methods
new remote
Methods - API calls which can only be made on an object returned by a constructor
addresses domain hostname includesPeerToPeer monitor name port publish resolve stop stopMonitoring txtRecord type
#
API Documentation
#
Constants
#
serviceTypes
#
Constructors
#
new
#
remote
#
Methods
#
addresses
#
domain
#
hostname
#
includesPeerToPeer
#
monitor
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.bonjour.service:monitor([callback]) -> serviceObject
|
| Type | Method |
| Description | Monitor the service for changes to its associated text records. |
| Parameters |
callback
- an optional callback function which should expect 3 arguments: the serviceObject userdata the string "txtRecord" a table containing key-value pairs specifying the new text records for the service
- the serviceObject
- When monitoring is active,
hs.bonjour.service:txtRecord will return the most recent text records observed. If this is the only method by which you check the text records, but you wish to ensure you have the most recent values, you should invoke this method without specifying a callback. - When
hs.bonjour.service:resolve is invoked, the text records at the time of resolution are captured for retrieval withhs.bonjour.service:txtRecord . Subsequent changes to the text records will not be reflected byhs.bonjour.service:txtRecord unless this method has been invoked (with or without a callback function) and is currently active. - You can monitor for text changes on local serviceObjects that were created by
hs.bonjour.service.new and that you are publishing. This can be used to invoke a callback when one portion of your code makes changes to the text records you are publishing and you need another portion of your code to be aware of this change.
#
name
#
port
#
publish
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.bonjour.service:publish([allowRename], [callback]) -> serviceObject
|
| Type | Method |
| Description | Begin advertising the specified local service. |
| Parameters |
allowRename
- an optional boolean, default true, specifying whether to automatically rename the service if the name and type combination is already being published in the service's domain. If renaming is allowed and a conflict occurs, the service name will have-#
appended to it where#
is an increasing integer starting at 2.callback
- an optional callback function which should expect 2 or 3 arguments and return none. The arguments to the callback function will be one of the following sets: on successful publishing:the serviceObject userdatathe string "published" if an error occurs during publishing:the serviceObject userdatathe string "error"a string specifying the specific error that occurred
- the serviceObject
- this method should only be called on serviceObjects which were created with
hs.bonjour.service.new .
#
resolve
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.bonjour.service:resolve([timeout], [callback]) -> serviceObject
|
| Type | Method |
| Description | Resolve the address and details for a discovered service. |
| Parameters |
timeout
- an optional number, default 0.0, specifying the maximum number of seconds to attempt to resolve the details for this service. Specifying 0.0 means that the resolution should not timeout and that resolution should continue indefinitely.callback
- an optional callback function which should expect 2 or 3 arguments and return none. on successful resolution:the serviceObject userdatathe string "resolved" if an error occurs during resolution:the serviceObject userdatathe string "error"a string specifying the specific error that occurred iftimeout
is specified and is any number other than 0.0, the following will be sent to the callback when the timeout has been reached:the serviceObject userdatathe string "stop"
- the serviceObject
- this method should only be called on serviceObjects which were returned by an
hs.bonjour
browserObject or created withhs.bonjour.service.remote . - For a remote service, this method must be called in order to retrieve the
addresses , theport , thehostname , and any the associatedtext records for the service. - To reduce the usage of system resources, you should generally specify a timeout value or make sure to invoke
hs.bonjour.service:stop after you have verified that you have received the details you require.