bare-mdns-discovery
Reference for bare-mdns-discovery: multicast DNS (mDNS) queries and service discovery for Bare.
bare-mdns-discovery provides multicast DNS (mDNS) for Bare: low-level record queries and higher-level local service discovery. It's pure JavaScript, built on bare-dgram.
npm i bare-mdns-discoveryUsage
const { MDNS } = require('bare-mdns-discovery')
const mdns = new MDNS()
await mdns.ready()
mdns.on('records', (records, rinfo) => {
for (const r of records) console.log(r.type, r.name, r.data)
})
mdns.query('_http._tcp.local')API
MDNS
new MDNS(opts?)
Create a low-level mDNS instance.
Options:
debug(boolean): Enable debug logging. Default:false.iface(string): IPv4 address of the network interface to join the multicast group on. Required on Android — without this,addMembershipfalls back to the OS default interface which may not be the WiFi interface, causing responses to be silently dropped. Pass the WiFi IP (e.g. frombare-wifi-android'sgetWifiIP()).
await mdns.ready()
Wait until the responder is bound and ready.
mdns.query(name[, type])
Send an mDNS query. Matching answers arrive on the records event ((records, rinfo)).
mdns.close()
Close the responder.
Discovery
new Discovery(opts?)
High-level service discovery. Extends MDNS.
Options:
service(string): Service type without prefix/suffix, e.g.'http','googlecast'.debug(boolean): Enable debug logging. Default:false.
discovery.discover([timeout]) · discovery.services
Browse for advertised services; services holds the discovered set and a service event fires as each is found.
discovery.close()
Close the socket. Returns a Promise.
See also
bare-dgram—the UDP sockets this builds on.- Bare modules—the full
bare-*catalog. - Bare runtime API—the runtime this runs on.