A Bonjour/Zeroconf protocol implementation in JavaScript.
This project is still work-in-progress
npm install bonjour
Advertise a new service:
var bonjour = require('bonjour')()
// advertise an HTTP server on port 3000
bonjour.publish({ name: 'My Web Server', type: 'http', port: 3000 })
Discover services:
bonjour.find({ type: 'http' }, function (service) {
console.log('Found an HTTP server:', service)
})
var bonjour = require('bonjour')([options])
Options are:
multicast
- use udp multicastinginterface
- explicitly specify a network interface. defaults to allport
- set the udp portip
- set the udp ipttl
- set the multicast ttlloopback
- receive your own packetsreuseAddr
- set the reuseAddr option when creating the socket (requires node >=0.11.13)
Allow the user to publish a new service on the network.
A service have the following properties:
- name:
'Apple TV'
- type:
'airplay'
- protocol:
'tcp'
- host:
'hostname.local'
- port:
5000
- txt:
{...}
(optional) - subtypes:
['api-v1']
(optional)
Publishes a new service.
Options are:
name
(string)host
(string, optional) - defaults to local hostnameport
(number)type
(string)subtypes
(array of strings, optional)protocol
(string, optional) - defaults totcp
txt
(object, optional) - a key/value object to broadcast as the TXT record
Unpublish all services. The optional callback
will be called when the
services have been unpublished.
Destroy the mdns instance. Closes the udp socket.
Listen for services advertised on the network. An optional callback can
be provided as the 2nd argument and will be added as an event listener
for the up
event.
Options are:
type
(string)subtypes
(array of strings, optional)protocol
(string, optional) - defaults totcp
Listen for and call the callback
with the first instance of a service
matching the options
. If no callback
is given, it's expected that
you listen for the up
event. The returned browser
will automatically
stop it self after the first matching service.
Options are the same as given in the browser.find
function.
Emitted every time a new service is found that matches the browser.
Emitted every time an existing service emmits a goodbye message.
An array of services known by the browser to be online.
Stop looking for matching services.
Start looking for matching services.
Emitted when the service is up.
Emitted if an error occurrs while publishing the service.
Unpublish the service. The optional callback
will be called when the
service have been unpublished.
Publish the service.
The name of the service, e.g. Apple TV
.
The type of the service, e.g. http
.
An array of subtypes. Note that this property might be null
.
The protocol used by the service, e.g. tcp
.
The hostname or ip address where the service resides.
The port on which the service listens, e.g. 5000
.
The fully qualified domain name of the service. E.g. if given the name
Foo Bar
, the type http
and the protocol tcp
, the service.fqdn
property will be Foo Bar._http._tcp.local
.
The TXT record advertised by the service (a key/value object). Note that
this property might be null
.
A boolean indicating if the service is currently published.
- Support receiving "goodbye" packets in the browser
- Support notifying the browser when a service changes
- Support TTL in the cache (in case of TTL=0, it should be handled as a goodbye packet nad the TTL should be set to 1 second)
MIT