#
hs.bonjour
Find and publish network services advertised by multicast DNS (Bonjour) with Hammerspoon.
This module will allow you to discover services advertised on your network through multicast DNS and publish services offered by your computer.
#
Submodules
#
API Overview
Functions - API calls offered directly by the extension
machineServices networkServices
Constructors - API calls which return an object, typically one that offers API methods
new
Methods - API calls which can only be made on an object returned by a constructor
findBrowsableDomains findRegistrationDomains findServices includesPeerToPeer stop
#
API Documentation
#
Functions
#
machineServices
#
networkServices
#
Constructors
#
new
#
Methods
#
findBrowsableDomains
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.bonjour:findBrowsableDomains(callback) -> browserObject
|
| Type | Method |
| Description | Return a list of zero-conf and bonjour domains visible to the users computer. |
| Parameters |
callback
- a function which will be invoked as visible domains are discovered. The function should accept the following parameters and return none:browserObject
- the userdata object for the browserObject which initiated the searchtype
- a string which will be 'domain' or 'error'iftype
== 'domain', the remaining arguments will be:added
- a boolean value indicating whether this callback invocation represents a newly discovered or added domain (true) or that the domain has been removed from the network (false)domain
- a string specifying the name of the domain discovered or removedmoreExpected
- a boolean value indicating whether or not the browser expects to discover additional domains or not.iftype
== 'error', the remaining arguments will be:errorString
- a string specifying the error which has occurred
- the browserObject
- This method returns domains which are visible to your machine; however, your machine may or may not be able to access or publish records within the returned domains. See
hs.bonjour:findRegistrationDomains - For most non-corporate network users, it is likely that the callback will only be invoked once for the
local
domain. This is normal. Corporate networks or networks including Linux machines using additional domains defined with Avahi may see additional domains as well, though most Avahi installations now use only 'local' by default unless specifically configured to do otherwise. - When
moreExpected
becomes false, it is the macOS's best guess as to whether additional records are available. - Generally macOS is fairly accurate in this regard concerning domain searches, so to reduce the impact on system resources, it is recommended that you use
hs.bonjour:stop when this parameter is false
#
findRegistrationDomains
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.bonjour:findRegistrationDomains(callback) -> browserObject
|
| Type | Method |
| Description | Return a list of zero-conf and bonjour domains this computer can register services in. |
| Parameters |
callback
- a function which will be invoked as domains are discovered. The function should accept the following parameters and return none:browserObject
- the userdata object for the browserObject which initiated the searchtype
- a string which will be 'domain' or 'error'iftype
== 'domain', the remaining arguments will be:added
- a boolean value indicating whether this callback invocation represents a newly discovered or added domain (true) or that the domain has been removed from the network (false)domain
- a string specifying the name of the domain discovered or removedmoreExpected
- a boolean value indicating whether or not the browser expects to discover additional domains or not.iftype
== 'error', the remaining arguments will be:errorString
- a string specifying the error which has occurred
- the browserObject
- This is the preferred method for accessing domains as it guarantees that the host machine can connect to services in the returned domains. Access to domains outside this list may be more limited. See also
hs.bonjour:findBrowsableDomains - For most non-corporate network users, it is likely that the callback will only be invoked once for the
local
domain. This is normal. Corporate networks or networks including Linux machines using additional domains defined with Avahi may see additional domains as well, though most Avahi installations now use only 'local' by default unless specifically configured to do otherwise. - When
moreExpected
becomes false, it is the macOS's best guess as to whether additional records are available. - Generally macOS is fairly accurate in this regard concerning domain searches, so to reduce the impact on system resources, it is recommended that you use
hs.bonjour:stop when this parameter is false
#
findServices
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.bonjour:findServices(type, [domain], [callback]) -> browserObject
|
| Type | Method |
| Description | Find advertised services of the type specified. |
| Parameters |
type
- a string specifying the type of service to discover on your network. This string should be specified in the format of '_service._protocol.' where _protocol is one of '_tcp' or '_udp'. Examples of common service types can be found inhs.bonjour.serviceTypes .domain
- an optional string specifying the domain to look for advertised services in. The domain should end with a period. If you omit this parameter, the default registration domain will be used, usually "local."callback
- a callback function which will be invoked as service advertisements meeting the specified criteria are discovered. The callback function should expect 2-5 arguments as follows: if a service is discovered or advertising for the service is terminated, the arguments will be:the browserObjectthe string "domain"a boolean indicating whether the service is being advertised (true) or should be removed because advertisements for the service are being terminated (false)the serviceObject for the specific advertisement (seehs.bonjour.service
)a boolean indicating if more advertisements are expected (true) or if the macOS believes that there are no more advertisements to be discovered (false). if an error occurs, the callback arguments will be:the browserObjectthe string "error"a string specifying the specific error that occurred
- the browserObject
- macOS will indicate when it believes there are no more advertisements of the type specified by
type
indomain
by marking the last argument to your callback function as false. This is a best guess and may not always be accurate if your network is slow or some servers on your network are particularly slow to respond. - In addition, if you leave the browser running this method, you will get future updates when services are removed because of server shutdowns or added because of new servers being booted up.
- Leaving the browser running does consume some system resources though, so you will have to determine, based upon your specific requirements, if this is a concern for your specific task or not. To terminate the browser when you have retrieved all of the information you require, you can use the
hs.bonjour:stop method. - The special type "_services._dns-sd._udp." can be used to discover the types of services being advertised on your network. The
hs.bonjour.service
objects returned to the callback function cannot actually be resolved, but you can use thehs.bonjour.service:name
method to create a list of services that are currently present and being advertised. - this special type is used by the shortcut function
hs.bonjour.networkServices for this specific purpose. - The special domain "dns-sd.org." can be specified to find services advertised through Wide-Area Service Discovery as described at http://www.dns-sd.org. This can be used to discover a limited number of globally available sites on the internet, especially with a service type of
_http._tcp.
. - In theory, with additional software, you may be able to publish services on your machine for Wide-Area Service discovery using this domain with
hs.bonjour.service.new
but the local dns server requirements and security implications of doing so are beyond the scope of this documentation. You should refer to http://www.dns-sd.org and your local DNS Server administrator or provider for more details.