source: frontend/node_modules/bonjour-service/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 5.6 KB
Line 
1# bonjour-service
2
3![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/onlxltd/bonjour-service/publish-release.yml?style=flat-square) ![npm bundle size](https://img.shields.io/bundlephobia/min/bonjour-service?style=flat-square) ![GitHub Release Date](https://img.shields.io/github/release-date/onlxltd/bonjour-service?style=flat-square) ![npm](https://img.shields.io/npm/dw/bonjour-service?color=%23888&style=flat-square) ![GitHub](https://img.shields.io/github/license/onlxltd/bonjour-service?style=flat-square) [![DeepScan grade](https://deepscan.io/api/teams/13435/projects/16430/branches/352351/badge/grade.svg?style=flat-square)](https://deepscan.io/dashboard#view=project&tid=13435&pid=16430&bid=352351)
4
5A Bonjour/Zeroconf protocol implementation in TypeScript. Publish
6services on the local network or discover existing services using
7multicast DNS.
8
9This is a rewrite of the project Bonjour (https://github.com/watson/bonjour) into modern TypeScript.
10
11bonjour-service is supported by [ON LX Limited](https://onlx.ltd/?src=bonjour-service). Check out our projects such as [Ctrl Suite](https://onlx.ltd/ctrl-suite?src=bonjour-service) and [Ctrl for iPad](https://onlx.ltd/ctrl-for-ipad?src=bonjour-service).
12
13
14
15## Installation
16Add to your project dependencies using Yarn or NPM.
17
18#### Install with Yarn
19```
20yarn add bonjour-service
21```
22#### Install with NPM
23```
24npm install bonjour-service
25```
26
27## Usage
28
29```js
30import { Bonjour } from 'bonjour-service'
31
32const instance = new Bonjour()
33
34// advertise an HTTP server on port 3000
35instance.publish({ name: 'My Web Server', type: 'http', port: 3000 })
36
37// browse for all http services
38instance.find({ type: 'http' }, function (service) {
39 console.log('Found an HTTP server:', service)
40})
41```
42
43## API
44
45### Initializing
46
47```js
48var instance = new Bonjour({ options }, errorCallback)
49```
50
51The `options` are optional and will be used when initializing the
52underlying multicast-dns server. For details see [the multicast-dns
53documentation](https://github.com/mafintosh/multicast-dns#mdns--multicastdnsoptions).
54
55`errorCallback` is an optional callback used to gracefully handle errors that would otherwise
56crash the process. While not being strictly required, providing this is highly recommended
57
58### Publishing
59
60#### `var service = bonjour.publish(options)`
61
62Publishes a new service.
63
64Options are:
65
66- `name` (string)
67- `host` (string, optional) - defaults to local hostname
68- `port` (number)
69- `type` (string)
70- `subtypes` (array of strings, optional)
71- `protocol` (string, optional) - `udp` or `tcp` (default)
72- `txt` (object, optional) - a key/value object to broadcast as the TXT
73 record
74- `disableIPv6` (boolean, optional) disble IPv6 addresses
75
76IANA maintains a [list of official service types and port
77numbers](http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).
78
79#### `bonjour.unpublishAll([callback])`
80
81Unpublish all services. The optional `callback` will be called when the
82services have been unpublished.
83
84#### `bonjour.destroy()`
85
86Destroy the mdns instance. Closes the udp socket.
87
88### Browser
89
90#### `var browser = bonjour.find(options[, onup])`
91
92Listen for services advertised on the network. An optional callback can
93be provided as the 2nd argument and will be added as an event listener
94for the `up` event.
95
96Options (all optional):
97
98- `type` (string)
99- `subtypes` (array of strings)
100- `protocol` (string) - defaults to `tcp`
101- `txt` (object) - passed into [dns-txt
102 module](https://github.com/watson/dns-txt) contructor. Set to `{
103 binary: true }` if you want to keep the TXT records in binary
104
105#### `var browser = bonjour.findOne(options[, callback])`
106
107Listen for and call the `callback` with the first instance of a service
108matching the `options`. If no `callback` is given, it's expected that
109you listen for the `up` event. The returned `browser` will automatically
110stop it self after the first matching service.
111
112Options are the same as given in the `browser.find` function.
113
114#### `Event: up`
115
116Emitted every time a new service is found that matches the browser.
117
118#### `Event: down`
119
120Emitted every time an existing service emmits a goodbye message.
121
122#### `Event: txt-update`
123
124Emitted every time an existing service does a new announcement with an updated TXT record.
125
126#### `browser.services()`
127
128An array of services known by the browser to be online.
129
130#### `browser.start()`
131
132Start looking for matching services.
133
134#### `browser.stop()`
135
136Stop looking for matching services.
137
138#### `browser.update()`
139
140Broadcast the query again.
141
142### Service
143
144#### `Event: up`
145
146Emitted when the service is up.
147
148#### `Event: error`
149
150Emitted if an error occurrs while publishing the service.
151
152#### `service.stop([callback])`
153
154Unpublish the service. The optional `callback` will be called when the
155service have been unpublished.
156
157#### `service.start()`
158
159Publish the service.
160
161#### `service.name`
162
163The name of the service, e.g. `Apple TV`.
164
165#### `service.type`
166
167The type of the service, e.g. `http`.
168
169#### `service.subtypes`
170
171An array of subtypes. Note that this property might be `null`.
172
173#### `service.protocol`
174
175The protocol used by the service, e.g. `tcp`.
176
177#### `service.host`
178
179The hostname or ip address where the service resides.
180
181#### `service.port`
182
183The port on which the service listens, e.g. `5000`.
184
185#### `service.fqdn`
186
187The fully qualified domain name of the service. E.g. if given the name
188`Foo Bar`, the type `http` and the protocol `tcp`, the `service.fqdn`
189property will be `Foo Bar._http._tcp.local`.
190
191#### `service.txt`
192
193The TXT record advertised by the service (a key/value object). Note that
194this property might be `null`.
195
196#### `service.published`
197
198A boolean indicating if the service is currently published.
199
200## License
201
202MIT
Note: See TracBrowser for help on using the repository browser.