bonjour-hap 3.10.1 → 3.10.3-beta.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.
Files changed (2) hide show
  1. package/index.d.ts +120 -25
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,57 +1,144 @@
1
- import { SocketOptions } from "dgram";
1
+ import { RemoteInfo, Socket } from "dgram";
2
2
 
3
- export type BonjourFindOptions = {
4
- type: string;
5
- subtypes?: string[];
3
+ /**
4
+ * Options accepted by the underlying multicast-dns responder.
5
+ * Forwarded by `Bonjour(options)` straight into `multicast-dns`.
6
+ */
7
+ export interface MulticastOptions {
8
+ /** Multicast port. Defaults to 5353. */
9
+ port?: number;
10
+ /** Socket type. Defaults to 'udp4'. */
11
+ type?: "udp4" | "udp6";
12
+ /** Multicast IP address. Defaults to 224.0.0.251 for udp4. Required for udp6. */
13
+ ip?: string;
14
+ /** Alias for `ip`. */
15
+ host?: string;
16
+ /** Interface name. Required for IPv6 multicast. */
17
+ interface?: string;
18
+ /** Whether to allow address reuse. Defaults to true. */
19
+ reuseAddr?: boolean;
20
+ /** Pre-created dgram socket. */
21
+ socket?: Socket;
22
+ /** Whether to join the multicast group. Defaults to true. */
23
+ multicast?: boolean;
24
+ /** Multicast TTL. Defaults to 255. */
25
+ ttl?: number;
26
+ /** Multicast loopback. Defaults to true. */
27
+ loopback?: boolean;
28
+ /** Bind address, or `false` to skip binding. */
29
+ bind?: string | false;
30
+ }
31
+
32
+ export interface BonjourFindOptions {
33
+ /** If omitted, performs a wildcard search across all service types. */
34
+ type?: string;
35
+ /** Defaults to 'tcp'. */
6
36
  protocol?: "tcp" | "udp";
7
- txt?: Record<string, any>;
8
- };
37
+ /** Filter to a specific service instance name. */
38
+ name?: string;
39
+ /** Options forwarded to the TXT record decoder. */
40
+ txt?: { binary?: boolean };
41
+ }
9
42
 
43
+ /**
44
+ * A service discovered via {@link Bonjour.find} / {@link Bonjour.findOne}.
45
+ *
46
+ * Populated from incoming SRV/TXT/A/AAAA records. Services without a matching
47
+ * SRV record are filtered out before being emitted, so all SRV-derived fields
48
+ * are guaranteed to be present on emitted services.
49
+ */
10
50
  export interface BonjourService {
11
51
  name: string;
52
+ fqdn: string;
12
53
  type: string;
54
+ subtypes: string[];
13
55
  protocol: "tcp" | "udp";
14
56
  host: string;
15
57
  port: number;
58
+ referer: RemoteInfo;
16
59
  addresses: string[];
17
- txt: Record<string, string>;
18
- rawTxt?: Buffer;
60
+ /** Decoded TXT record, if a TXT record was received. */
61
+ txt?: Record<string, string>;
62
+ /** Raw TXT record blocks, if a TXT record was received. */
63
+ rawTxt?: Buffer[];
19
64
  }
20
65
 
21
- export interface MulticastOptions extends SocketOptions {
22
- multicastAddress?: string;
23
- multicastInterface?: string;
24
- multicastTTL?: number;
25
- reuseAddr?: boolean;
26
- }
66
+ export interface Browser {
67
+ /** Currently-known services. Updated as services come up, change, or go down. */
68
+ services: BonjourService[];
27
69
 
28
- export class Browser {
29
70
  start(): void;
30
71
  stop(): void;
72
+ /** Send a fresh PTR query to refresh the service list. */
31
73
  update(): void;
32
- on(event: "up" | "down", listener: (service: BonjourService) => void): this;
74
+
75
+ on(event: "up" | "down" | "update", listener: (service: BonjourService) => void): this;
33
76
  }
34
77
 
35
- export class Advertisement {
36
- stop(): void;
78
+ /**
79
+ * A service published via {@link Bonjour.publish}. Returned to the caller so
80
+ * they can update the TXT record, stop, or destroy the advertisement.
81
+ */
82
+ export interface Advertisement {
83
+ name: string;
84
+ type: string;
85
+ protocol: "tcp" | "udp";
86
+ host: string;
87
+ port: number;
88
+ fqdn: string;
89
+ subtypes: string[] | null;
90
+ txt: Record<string, string> | null;
91
+ /** True once the initial announcement has been confirmed. */
92
+ published: boolean;
93
+
37
94
  start(): void;
38
- update(txt: Record<string, string>): void;
95
+ /**
96
+ * Stop advertising. The callback is required if the service has not been
97
+ * activated yet (the runtime calls it synchronously in that case).
98
+ */
99
+ stop(callback?: () => void): void;
100
+ /** Tear down the service and remove all listeners. */
101
+ destroy(): void;
102
+ /** Replace the TXT record. If `silent` is true, the new record is registered but not re-announced. */
103
+ updateTxt(txt: Record<string, string>, silent?: boolean): void;
104
+
105
+ /** Emitted once after the first successful announcement. */
106
+ on(event: "up", listener: () => void): this;
107
+ /** Emitted if the service name is already in use on the network. */
39
108
  on(event: "error", listener: (err: Error) => void): this;
40
109
  }
41
110
 
42
111
  export interface PublishOptions {
43
112
  name: string;
44
113
  type: string;
45
- subtypes?: string[];
46
114
  port: number;
47
115
  host?: string;
48
- txt?: Record<string, string>;
49
116
  protocol?: "tcp" | "udp";
50
- }
117
+ subtypes?: string[];
118
+ txt?: Record<string, string>;
119
+ /** Probe for name conflicts before announcing. Defaults to true. */
120
+ probe?: boolean;
121
+
122
+ /**
123
+ * Adds a meta enumeration record (`_services._dns-sd._udp.local`) when announcing.
124
+ * Only safe to enable when a single service is advertised on the responder, otherwise
125
+ * removing one service will break enumeration for the others.
126
+ */
127
+ addUnsafeServiceEnumerationRecord?: boolean;
51
128
 
52
- export default class Bonjour {
53
- constructor(options?: MulticastOptions);
129
+ /**
130
+ * Restricts the service to be advertised on the specified IP addresses or interface names.
131
+ * Interface names and addresses can be mixed.
132
+ * If an interface name is given, ANY address on that interface is advertised.
133
+ * If an IP address is given, only that address is advertised.
134
+ */
135
+ restrictedAddresses?: string[];
136
+
137
+ /** If true, the service will not advertise IPv6 (AAAA) records. */
138
+ disabledIpv6?: boolean;
139
+ }
54
140
 
141
+ export interface Bonjour {
55
142
  publish(options: PublishOptions): Advertisement;
56
143
  unpublishAll(callback?: () => void): void;
57
144
  find(
@@ -60,7 +147,15 @@ export default class Bonjour {
60
147
  ): Browser;
61
148
  findOne(
62
149
  options: BonjourFindOptions,
63
- callback: (service: BonjourService) => void
150
+ callback?: (service: BonjourService) => void
64
151
  ): Browser;
65
152
  destroy(): void;
66
153
  }
154
+
155
+ export interface BonjourFactory {
156
+ new (options?: MulticastOptions): Bonjour;
157
+ (options?: MulticastOptions): Bonjour;
158
+ }
159
+
160
+ declare const Bonjour: BonjourFactory;
161
+ export default Bonjour;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bonjour-hap",
3
- "version": "3.10.1",
3
+ "version": "3.10.3-beta.0",
4
4
  "description": "A Bonjour/Zeroconf implementation in pure JavaScript (for HAP)",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",