Discover and publish Bonjour (mDNS / Zeroconf) network services.
Use createSearch() to search the network for services advertised by other
devices, and advertise() to advertise your own. The networkServices()
convenience function returns a snapshot of all service types currently
active on the local network.
Common service type strings
The hs.bonjour.serviceTypes object maps short names to their mDNS strings,
e.g. hs.bonjour.serviceTypes.ssh → "_ssh._tcp.".
Searching for a service
// Find all SSH services on the local network and resolve each one constsearch = hs.bonjour.createSearch() search.findServices('_ssh._tcp.', 'local.', (event, svc, moreComing) => { if (event === 'serviceFound') { svc.resolve(5, ev=> { if (ev === 'resolved') console.log(svc.hostname + ':' + svc.port) }) } })
Advertising a service
hs.bonjour.advertise('My Web Server', '_http._tcp.', 8080, ev=> { if (ev === 'published') console.log('Now advertising!') elseif (ev === 'error') console.error('Advertising failed') }) // Later, to stop: hs.bonjour.stopAdvertising('My Web Server', '_http._tcp.')
Listing all active service types
hs.bonjour.networkServices(5).then(types=> { console.log('Active service types: ' + types.join(', ')) })
Discover and publish Bonjour (mDNS / Zeroconf) network services. Use
createSearch()to search the network for services advertised by other devices, andadvertise()to advertise your own. ThenetworkServices()convenience function returns a snapshot of all service types currently active on the local network.Common service type strings
The
hs.bonjour.serviceTypesobject maps short names to their mDNS strings, e.g.hs.bonjour.serviceTypes.ssh→"_ssh._tcp.".Searching for a service
Advertising a service
Listing all active service types