dnssd-advertise 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE.md +22 -0
- package/README.md +56 -0
- package/dist/dnssd-advertise.d.ts +28 -0
- package/dist/dnssd-advertise.js +2552 -0
- package/dist/dnssd-advertise.js.map +1 -0
- package/dist/dnssd-advertise.mjs +2550 -0
- package/dist/dnssd-advertise.mjs.map +1 -0
- package/package.json +85 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Phil Pluckthun,
|
|
4
|
+
Copyright (c) 650 Industries, Inc. (aka Expo),
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# dnssd-advertise
|
|
2
|
+
|
|
3
|
+
A well-behaved Bonjour/DNS-SD service advertiser for Node.js, designed for long-running processes.
|
|
4
|
+
|
|
5
|
+
- Aims to be compliant with [RFC 6762](https://datatracker.ietf.org/doc/html/rfc6762) and [RFC 6763](https://datatracker.ietf.org/doc/html/rfc6763#section-6)
|
|
6
|
+
- Handles network interface changes, socket recovery, and re-announcements for long-running processes
|
|
7
|
+
- Supports dual-stack IPv4 and IPv6 service announcement with NIC-scoped responses
|
|
8
|
+
- Single dependency ([dns-message](https://github.com/kitten/dns-message) is bundled)
|
|
9
|
+
|
|
10
|
+
## Quick Reference
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
import { advertise } from 'dnssd-advertise';
|
|
14
|
+
|
|
15
|
+
const stop = advertise({
|
|
16
|
+
name: 'My Service',
|
|
17
|
+
type: 'http',
|
|
18
|
+
protocol: 'tcp',
|
|
19
|
+
port: 3000,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
process.on('exit', () => {
|
|
23
|
+
stop();
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Conflict Resolution
|
|
28
|
+
|
|
29
|
+
When a conflict is detected during probing, as per the specification, the name or hostname of your service may be altered:
|
|
30
|
+
|
|
31
|
+
- When the `name` conflicts a 4-character hex ID is appended (e.g. `My Service (B0A1)`
|
|
32
|
+
- When the `hostname` conflicts a number is appended to it (e.g. `my-hostname-2`)
|
|
33
|
+
|
|
34
|
+
When a conflict is detected during announcing, the probing phase restarts with the same conflict resolution.
|
|
35
|
+
|
|
36
|
+
## API Reference
|
|
37
|
+
|
|
38
|
+
### `advertise(options): () => Promise<void>`
|
|
39
|
+
|
|
40
|
+
Starts advertising a DNS-SD service on all available network interfaces.
|
|
41
|
+
|
|
42
|
+
Returns a function that, when called, stops advertising and sends goodbye packets to remove the service from the network.
|
|
43
|
+
Stopping the advertiser is, while preferred, optional as per the mDNS specification.
|
|
44
|
+
|
|
45
|
+
#### Options
|
|
46
|
+
|
|
47
|
+
| Option | Type | Description |
|
|
48
|
+
| ---------- | -------------------------- | ------------------------------------------------------------------ |
|
|
49
|
+
| `name` | `string` | Instance/display name of the service (e.g., "Living Room Speaker") |
|
|
50
|
+
| `type` | `string` | Service type without protocol (e.g., "http", "ssh", "airplay") |
|
|
51
|
+
| `protocol` | `'tcp' \| 'udp'` | Protocol used by the service |
|
|
52
|
+
| `port` | `number` | Port the service is listening on |
|
|
53
|
+
| `hostname` | `string` | Hostname to advertise (defaults to system hostname) |
|
|
54
|
+
| `subtypes` | `string[]` | Optional list of subtypes |
|
|
55
|
+
| `txt` | `Record<string, TxtValue>` | Optional service metadata as key-value pairs |
|
|
56
|
+
| `ttl` | `number` | TTL for DNS records in seconds (defaults to 250s) |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type TxtValue = string | number | boolean | null | undefined;
|
|
2
|
+
|
|
3
|
+
interface AdvertiseOptions {
|
|
4
|
+
/** Instance/display name of the service */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Service type without protocol (e.g. "http") */
|
|
7
|
+
type: string;
|
|
8
|
+
/** Protocol used by the service (typically "tcp" or "udp") */
|
|
9
|
+
protocol: 'tcp' | 'udp' | (string & {});
|
|
10
|
+
/** Hostname of device offering the service */
|
|
11
|
+
hostname?: string;
|
|
12
|
+
/** Port the service is listening on */
|
|
13
|
+
port: number;
|
|
14
|
+
/** List of subtypes for selective discovery */
|
|
15
|
+
subtypes?: string[];
|
|
16
|
+
/** Service metadata */
|
|
17
|
+
txt?: Record<string, TxtValue>;
|
|
18
|
+
/** TTL to apply to service records */
|
|
19
|
+
ttl?: number;
|
|
20
|
+
}
|
|
21
|
+
interface AdvertiserHandle {
|
|
22
|
+
readonly promise: Promise<void>;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
declare function advertise(options: AdvertiseOptions): () => Promise<void>;
|
|
26
|
+
|
|
27
|
+
export { advertise };
|
|
28
|
+
export type { AdvertiseOptions, AdvertiserHandle };
|