@devioarts/capacitor-mdns 0.0.3 → 0.2.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 +110 -0
- package/DevioartsCapacitorMdns.podspec +3 -3
- package/Package.swift +1 -1
- package/README.md +272 -101
- package/android/build.gradle +3 -9
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/AndroidNsdBackend.kt +145 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/MdnsOptions.kt +32 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/MdnsValidation.kt +26 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/NsdBackend.kt +59 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/mDNS.kt +496 -175
- package/android/src/main/java/com/devioarts/capacitor/mdns/mDNSPlugin.kt +85 -49
- package/dist/docs.json +313 -15
- package/dist/esm/definitions.d.ts +89 -16
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +22 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +8 -1
- package/dist/esm/web.js +35 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +57 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +57 -4
- package/dist/plugin.js.map +1 -1
- package/docs/electron.md +91 -0
- package/docs/platform-setup.md +58 -0
- package/docs/playground.md +50 -0
- package/docs/runtime-behavior.md +80 -0
- package/electron/dist/plugin-settings.js +22 -0
- package/electron/dist/plugin-settings.js.map +1 -0
- package/electron/dist/plugin.cjs.js +774 -0
- package/electron/dist/plugin.cjs.js.map +1 -0
- package/electron/global.d.ts +2 -0
- package/electron/mdns-bridge.cjs +33 -4
- package/electron/mdns.ts +628 -107
- package/electron/rollup.config.mjs +22 -0
- package/electron/src/index.ts +2 -0
- package/electron/src/plugin-settings.ts +19 -0
- package/electron/tsconfig.json +21 -0
- package/electron/types-public/index.d.ts +47 -0
- package/ios/Sources/mDNSPlugin/mDNS.swift +481 -124
- package/ios/Sources/mDNSPlugin/mDNSPlugin.swift +85 -23
- package/ios/Tests/mDNSPluginTests/BridgeTests.swift +46 -0
- package/ios/Tests/mDNSPluginTests/MDNSTests.swift +490 -0
- package/package.json +55 -20
- package/ios/Tests/mDNSPluginTests/mDNSPluginTests.swift +0 -15
|
@@ -1,17 +1,34 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
1
2
|
/**
|
|
2
3
|
* Key–value map for TXT records of a Bonjour/mDNS service.
|
|
3
4
|
* Values are UTF-8 strings; binary payloads are not supported by this API.
|
|
4
5
|
* @public
|
|
5
6
|
*/
|
|
6
7
|
export type MdnsTxt = Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Runtime implementation that handled a plugin call.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type MdnsPluginPlatform = 'ios' | 'android' | 'electron' | 'web';
|
|
13
|
+
/**
|
|
14
|
+
* Result of getPluginPlatform(). Useful for validating that calls are routed
|
|
15
|
+
* through the expected platform bridge.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface MdnsPluginPlatformResult {
|
|
19
|
+
/** Platform implementation that produced this result. */
|
|
20
|
+
platform: MdnsPluginPlatform;
|
|
21
|
+
}
|
|
7
22
|
/**
|
|
8
23
|
* Normalized description of a discovered Bonjour/mDNS service.
|
|
9
24
|
* Returned from {@link mDNSPlugin.discover}.
|
|
10
25
|
*
|
|
11
26
|
* @remarks
|
|
12
27
|
* - `hosts` contains resolved IPv4/IPv6 numeric addresses (no DNS names).
|
|
13
|
-
* -
|
|
14
|
-
*
|
|
28
|
+
* - IPv4 addresses precede IPv6; order within each family follows discovery order.
|
|
29
|
+
* - Native IPv6 scope suffixes are preserved (`%<scope-id>` on iOS; the OS-provided scope on Android).
|
|
30
|
+
* Electron may return link-local IPv6 without a scope; callers must not assume every address is reachable.
|
|
31
|
+
* - Resolved TXT records are returned when present.
|
|
15
32
|
* - `domain` is typically `"local."`.
|
|
16
33
|
*
|
|
17
34
|
* @public
|
|
@@ -23,16 +40,18 @@ export interface MdnsService {
|
|
|
23
40
|
type: string;
|
|
24
41
|
/** Service domain; typically `"local."`. */
|
|
25
42
|
domain: string;
|
|
26
|
-
/**
|
|
43
|
+
/** Port the service advertises. */
|
|
27
44
|
port: number;
|
|
28
45
|
/**
|
|
29
|
-
* Resolved numeric IP addresses
|
|
46
|
+
* Resolved numeric IP addresses, IPv4 first, then IPv6 with any available scope suffix.
|
|
30
47
|
* @example
|
|
31
48
|
* `["192.168.1.42", "fe80::1234:abcd:..."]`
|
|
32
49
|
*/
|
|
33
50
|
hosts: string[];
|
|
51
|
+
/** Host name when supplied by the platform, e.g. `"my-device.local."`. */
|
|
52
|
+
hostname?: string;
|
|
34
53
|
/**
|
|
35
|
-
* TXT dictionary (key → value).
|
|
54
|
+
* TXT dictionary (key → value).
|
|
36
55
|
* @remarks Not all services publish TXT data.
|
|
37
56
|
*/
|
|
38
57
|
txt?: MdnsTxt;
|
|
@@ -41,9 +60,13 @@ export interface MdnsService {
|
|
|
41
60
|
* Options for starting a Bonjour/mDNS advertisement.
|
|
42
61
|
*
|
|
43
62
|
* @remarks
|
|
44
|
-
* -
|
|
63
|
+
* - Service types accept an optional trailing dot; results always include it.
|
|
45
64
|
* - Instance `name` should be short and human-readable; the OS may append `" (n)"` to ensure uniqueness.
|
|
46
|
-
*
|
|
65
|
+
* Electron rejects a name conflict instead of renaming the service.
|
|
66
|
+
* - Advertising TXT is supported on iOS, Android and Electron. Invalid input preserves the active advertisement.
|
|
67
|
+
* - Native implementations guard publish with a timeout and return `error: true` instead of
|
|
68
|
+
* leaving the Promise pending when the OS does not deliver a publish callback.
|
|
69
|
+
* - Only one advertisement is active at a time. Starting a new one stops the previous one first.
|
|
47
70
|
*
|
|
48
71
|
* @public
|
|
49
72
|
*/
|
|
@@ -55,9 +78,9 @@ export interface MdnsBroadcastOptions {
|
|
|
55
78
|
*/
|
|
56
79
|
type?: string;
|
|
57
80
|
/**
|
|
58
|
-
* Service instance name.
|
|
81
|
+
* Service instance name (maximum 63 UTF-8 bytes). Defaults to `DevIOArtsMDNS`.
|
|
59
82
|
*/
|
|
60
|
-
name
|
|
83
|
+
name?: string;
|
|
61
84
|
/**
|
|
62
85
|
* TCP port to advertise.
|
|
63
86
|
* @remarks Must be a positive integer (1–65535).
|
|
@@ -65,7 +88,7 @@ export interface MdnsBroadcastOptions {
|
|
|
65
88
|
port: number;
|
|
66
89
|
/**
|
|
67
90
|
* Optional TXT key–value pairs (UTF-8 strings).
|
|
68
|
-
* @remarks
|
|
91
|
+
* @remarks Keys must be unique ignoring case, nonempty printable ASCII without `=`. Each `key=value` entry must fit in 255 UTF-8 bytes. The complete record is limited to 1300 bytes including length prefixes. Non-string values are rejected.
|
|
69
92
|
*/
|
|
70
93
|
txt?: MdnsTxt;
|
|
71
94
|
}
|
|
@@ -73,9 +96,12 @@ export interface MdnsBroadcastOptions {
|
|
|
73
96
|
* Options for Bonjour/mDNS discovery.
|
|
74
97
|
*
|
|
75
98
|
* @remarks
|
|
76
|
-
* - The `
|
|
99
|
+
* - The `name` filter matches the normalized name and also accepts prefix matches
|
|
77
100
|
* (to handle OS-added `" (n)"` suffixes).
|
|
78
101
|
* - When `useNW` is `true` on iOS, discovery uses `NWBrowser` for better P2P behavior.
|
|
102
|
+
* - A valid new discovery replaces the previous request with an error on every platform.
|
|
103
|
+
* - Dots and hyphens are equivalent when matching names; returned names retain their advertised spelling.
|
|
104
|
+
* - Without a name filter, browsing continues for the entire timeout. With a filter it may finish once a matching IP address resolves.
|
|
79
105
|
*
|
|
80
106
|
* @public
|
|
81
107
|
*/
|
|
@@ -92,7 +118,7 @@ export interface MdnsDiscoverOptions {
|
|
|
92
118
|
*/
|
|
93
119
|
name?: string;
|
|
94
120
|
/**
|
|
95
|
-
* Discovery timeout in milliseconds.
|
|
121
|
+
* Discovery timeout in milliseconds. Finite numbers only; fractions are truncated and the delay is clamped to 0–2147483647.
|
|
96
122
|
* @defaultValue `3000`
|
|
97
123
|
*/
|
|
98
124
|
timeout?: number;
|
|
@@ -115,7 +141,7 @@ export interface MdnsBroadcastResult {
|
|
|
115
141
|
errorMessage: string | null;
|
|
116
142
|
/** Final (possibly uniquified) service instance name. Empty on failure. */
|
|
117
143
|
name: string;
|
|
118
|
-
/** Whether
|
|
144
|
+
/** Whether an advertiser is active, or may still be active after failed cleanup. */
|
|
119
145
|
publishing: boolean;
|
|
120
146
|
}
|
|
121
147
|
/**
|
|
@@ -129,7 +155,7 @@ export interface MdnsDiscoverResult {
|
|
|
129
155
|
errorMessage: string | null;
|
|
130
156
|
/** Convenience count equal to services.length. */
|
|
131
157
|
servicesFound: number;
|
|
132
|
-
/**
|
|
158
|
+
/** Resolved services with numeric addresses. Empty on error; partial results are discarded. */
|
|
133
159
|
services: MdnsService[];
|
|
134
160
|
}
|
|
135
161
|
/**
|
|
@@ -142,9 +168,36 @@ export interface MdnsStopResult {
|
|
|
142
168
|
error: boolean;
|
|
143
169
|
/** Error description or null on success. */
|
|
144
170
|
errorMessage: string | null;
|
|
145
|
-
/**
|
|
171
|
+
/** False after confirmed stop; true when stopping failed and the advertiser may still be active. */
|
|
146
172
|
publishing: boolean;
|
|
147
173
|
}
|
|
174
|
+
/** Options for continuous discovery on iOS, Android and Electron. */
|
|
175
|
+
export interface MdnsWatchOptions {
|
|
176
|
+
/** Nonempty list of service types. Trailing dots are optional; duplicates are merged. */
|
|
177
|
+
types: string[];
|
|
178
|
+
}
|
|
179
|
+
/** Native browsers have been requested; later failures are reported through `watchError`. */
|
|
180
|
+
export interface MdnsWatchResult {
|
|
181
|
+
error: boolean;
|
|
182
|
+
errorMessage: string | null;
|
|
183
|
+
watchersStarted: number;
|
|
184
|
+
}
|
|
185
|
+
/** Stops watching independently of any active broadcast. */
|
|
186
|
+
export interface MdnsWatchStopResult {
|
|
187
|
+
error: boolean;
|
|
188
|
+
errorMessage: string | null;
|
|
189
|
+
watching: boolean;
|
|
190
|
+
}
|
|
191
|
+
/** Both found and lost events contain a complete service snapshot, including `hosts`. */
|
|
192
|
+
export interface MdnsServiceEvent {
|
|
193
|
+
service: MdnsService;
|
|
194
|
+
}
|
|
195
|
+
/** Browser failures stop the watch; exhausted service resolution retries leave it running. */
|
|
196
|
+
export interface MdnsWatchErrorEvent {
|
|
197
|
+
type: string;
|
|
198
|
+
errorMessage: string;
|
|
199
|
+
watching: boolean;
|
|
200
|
+
}
|
|
148
201
|
/**
|
|
149
202
|
* Public API surface of the Capacitor mDNS plugin.
|
|
150
203
|
*
|
|
@@ -165,6 +218,12 @@ export interface MdnsStopResult {
|
|
|
165
218
|
* @public
|
|
166
219
|
*/
|
|
167
220
|
export interface mDNSPlugin {
|
|
221
|
+
/**
|
|
222
|
+
* Return the platform implementation currently serving plugin calls.
|
|
223
|
+
*
|
|
224
|
+
* @returns Promise resolving to `MdnsPluginPlatformResult`.
|
|
225
|
+
*/
|
|
226
|
+
getPluginPlatform(): Promise<MdnsPluginPlatformResult>;
|
|
168
227
|
/**
|
|
169
228
|
* Start advertising a Bonjour/mDNS service.
|
|
170
229
|
*
|
|
@@ -177,6 +236,7 @@ export interface mDNSPlugin {
|
|
|
177
236
|
*
|
|
178
237
|
* @returns Promise resolving to `MdnsStopResult`.
|
|
179
238
|
* @remarks The `publishing` flag may be `false` after a successful stop.
|
|
239
|
+
* Stopping is idempotent and is safe to call even if publishing never fully started.
|
|
180
240
|
*/
|
|
181
241
|
stopBroadcast(): Promise<MdnsStopResult>;
|
|
182
242
|
/**
|
|
@@ -184,7 +244,20 @@ export interface mDNSPlugin {
|
|
|
184
244
|
*
|
|
185
245
|
* @param options - {@link MdnsDiscoverOptions}
|
|
186
246
|
* @returns Promise resolving to `MdnsDiscoverResult`.
|
|
187
|
-
* @remarks The result list is normalized across platforms.
|
|
247
|
+
* @remarks The result list is normalized across platforms.
|
|
188
248
|
*/
|
|
189
249
|
discover(options?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;
|
|
250
|
+
/**
|
|
251
|
+
* Continuously watch several service types. A valid call replaces the previous watch.
|
|
252
|
+
* Register listeners before starting. Each resolved service emits `serviceFound` once;
|
|
253
|
+
* disappearance emits `serviceLost` with its last snapshot. No loss is emitted for an
|
|
254
|
+
* unresolved service. Watching and one-shot discovery can run together.
|
|
255
|
+
* Thanks to Idrimi for contributing the original continuous discovery feature (PR #7).
|
|
256
|
+
*/
|
|
257
|
+
watchServices(options: MdnsWatchOptions): Promise<MdnsWatchResult>;
|
|
258
|
+
/** Stop all watchers. No events from that watch are emitted after this resolves. */
|
|
259
|
+
stopWatching(): Promise<MdnsWatchStopResult>;
|
|
260
|
+
addListener(eventName: 'serviceFound' | 'serviceLost', handler: (event: MdnsServiceEvent) => void): Promise<PluginListenerHandle>;
|
|
261
|
+
addListener(eventName: 'watchError', handler: (event: MdnsWatchErrorEvent) => void): Promise<PluginListenerHandle>;
|
|
262
|
+
removeAllListeners(): Promise<void>;
|
|
190
263
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,qBAAqB","sourcesContent":["// src/definitions.ts\n\n/**\n * Key–value map for TXT records of a Bonjour/mDNS service.\n * Values are UTF-8 strings; binary payloads are not supported by this API.\n * @public\n */\nexport type MdnsTxt = Record<string, string>;\n\n/**\n * Normalized description of a discovered Bonjour/mDNS service.\n * Returned from {@link mDNSPlugin.discover}.\n *\n * @remarks\n * - `hosts` contains resolved IPv4/IPv6 numeric addresses (no DNS names).\n * - iOS returns `txt` when present. Android (NSD) does not expose TXT records via public APIs,\n * so `txt` is usually omitted on Android.\n * - `domain` is typically `\"local.\"`.\n *\n * @public\n */\nexport interface MdnsService {\n /** Instance name of the service (may be uniqued by the OS, e.g. \"My App (2)\"). */\n name: string;\n\n /** Full service type including the trailing dot, e.g. `\"_http._tcp.\"`. */\n type: string;\n\n /** Service domain; typically `\"local.\"`. */\n domain: string;\n\n /** TCP port the service advertises. */\n port: number;\n\n /**\n * Resolved numeric IP addresses (IPv4/IPv6).\n * @example\n * `[\"192.168.1.42\", \"fe80::1234:abcd:...\"]`\n */\n hosts: string[];\n\n /**\n * TXT dictionary (key → value). Usually present on iOS; Android NSD does not populate this.\n * @remarks Not all services publish TXT data.\n */\n txt?: MdnsTxt;\n}\n\n/**\n * Options for starting a Bonjour/mDNS advertisement.\n *\n * @remarks\n * - The `type` **must** end with a dot (`.`). If omitted, the implementation appends it.\n * - Instance `name` should be short and human-readable; the OS may append `\" (n)\"` to ensure uniqueness.\n * - Android NSD does not expose TXT records to other apps; advertising TXT is supported on iOS.\n *\n * @public\n */\nexport interface MdnsBroadcastOptions {\n /**\n * Service type (including the trailing dot).\n * @defaultValue `\"_http._tcp.\"`\n * @example `\"_myapp._tcp.\"`\n */\n type?: string;\n\n /**\n * Service instance name.\n */\n name: string;\n\n /**\n * TCP port to advertise.\n * @remarks Must be a positive integer (1–65535).\n */\n port: number;\n\n /**\n * Optional TXT key–value pairs (UTF-8 strings).\n * @remarks May be ignored on Android due to platform limitations.\n */\n txt?: MdnsTxt;\n}\n\n/**\n * Options for Bonjour/mDNS discovery.\n *\n * @remarks\n * - The `id` filter matches the normalized name and also accepts prefix matches\n * (to handle OS-added `\" (n)\"` suffixes).\n * - When `useNW` is `true` on iOS, discovery uses `NWBrowser` for better P2P behavior.\n *\n * @public\n */\nexport interface MdnsDiscoverOptions {\n /**\n * Service type (including the trailing dot).\n * @defaultValue `\"_http._tcp.\"`\n * @example `\"_comm._tcp.\"`\n */\n type?: string;\n\n /**\n * Optional instance name filter (prefix-safe).\n * @example `\"MyAppName\"`\n */\n name?: string;\n\n /**\n * Discovery timeout in milliseconds.\n * @defaultValue `3000`\n */\n timeout?: number;\n\n /**\n * iOS-only hint to use `NWBrowser` instead of `NetServiceBrowser`.\n * @defaultValue `true`\n */\n useNW?: boolean;\n}\n\n/**\n * Result of startBroadcast(). Indicates whether advertising is active\n * and the final service name. On failure, `error` is true and `errorMessage`\n * describes the issue.\n * @public\n */\nexport interface MdnsBroadcastResult {\n /** True if the operation failed. */\n error: boolean;\n /** Error description or null on success. */\n errorMessage: string | null;\n /** Final (possibly uniquified) service instance name. Empty on failure. */\n name: string;\n /** Whether the advertiser is currently active. */\n publishing: boolean;\n}\n\n/**\n * Result of discover(). Contains normalized services and error information.\n * @public\n */\nexport interface MdnsDiscoverResult {\n /** True if discovery encountered an error (partial results may still be present). */\n error: boolean;\n /** Error description or null when no error occurred. */\n errorMessage: string | null;\n /** Convenience count equal to services.length. */\n servicesFound: number;\n /** Normalized list of discovered services. */\n services: MdnsService[];\n}\n\n/**\n * Result of stopBroadcast(). Indicates whether the advertiser is active\n * after the call (normally false) and includes error information.\n * @public\n */\nexport interface MdnsStopResult {\n /** True if an error occurred while stopping. */\n error: boolean;\n /** Error description or null on success. */\n errorMessage: string | null;\n /** Whether the advertiser remains active (should be false on success). */\n publishing: boolean;\n}\n\n/**\n * Public API surface of the Capacitor mDNS plugin.\n *\n * @example\n * ```ts\n * import { mDNS } from 'capacitor-mdns';\n *\n * // Start advertising\n * await mDNS.startBroadcast({ type: '_http._tcp.', name: 'my.app.id', port: 9235 });\n *\n * // Discover services\n * const { services } = await mDNS.discover({ type: '_http._tcp.', timeout: 3000 });\n *\n * // Stop advertising\n * await mDNS.stopBroadcast();\n * ```\n *\n * @public\n */\nexport interface mDNSPlugin {\n /**\n * Start advertising a Bonjour/mDNS service.\n *\n * @param options - {@link MdnsBroadcastOptions}\n * @returns Promise resolving to `MdnsBroadcastResult` (`true` on success).\n */\n startBroadcast(options: MdnsBroadcastOptions): Promise<MdnsBroadcastResult>;\n\n /**\n * Stop advertising the currently registered service (no-op if none).\n *\n * @returns Promise resolving to `MdnsStopResult`.\n * @remarks The `publishing` flag may be `false` after a successful stop.\n */\n stopBroadcast(): Promise<MdnsStopResult>;\n\n /**\n * Discover services of a given type and optionally filter by instance name.\n *\n * @param options - {@link MdnsDiscoverOptions}\n * @returns Promise resolving to `MdnsDiscoverResult`.\n * @remarks The result list is normalized across platforms. On Android, `txt` is typically absent.\n */\n discover(options?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,qBAAqB","sourcesContent":["// src/definitions.ts\n\nimport type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Key–value map for TXT records of a Bonjour/mDNS service.\n * Values are UTF-8 strings; binary payloads are not supported by this API.\n * @public\n */\nexport type MdnsTxt = Record<string, string>;\n\n/**\n * Runtime implementation that handled a plugin call.\n * @public\n */\nexport type MdnsPluginPlatform = 'ios' | 'android' | 'electron' | 'web';\n\n/**\n * Result of getPluginPlatform(). Useful for validating that calls are routed\n * through the expected platform bridge.\n * @public\n */\nexport interface MdnsPluginPlatformResult {\n /** Platform implementation that produced this result. */\n platform: MdnsPluginPlatform;\n}\n\n/**\n * Normalized description of a discovered Bonjour/mDNS service.\n * Returned from {@link mDNSPlugin.discover}.\n *\n * @remarks\n * - `hosts` contains resolved IPv4/IPv6 numeric addresses (no DNS names).\n * - IPv4 addresses precede IPv6; order within each family follows discovery order.\n * - Native IPv6 scope suffixes are preserved (`%<scope-id>` on iOS; the OS-provided scope on Android).\n * Electron may return link-local IPv6 without a scope; callers must not assume every address is reachable.\n * - Resolved TXT records are returned when present.\n * - `domain` is typically `\"local.\"`.\n *\n * @public\n */\nexport interface MdnsService {\n /** Instance name of the service (may be uniqued by the OS, e.g. \"My App (2)\"). */\n name: string;\n\n /** Full service type including the trailing dot, e.g. `\"_http._tcp.\"`. */\n type: string;\n\n /** Service domain; typically `\"local.\"`. */\n domain: string;\n\n /** Port the service advertises. */\n port: number;\n\n /**\n * Resolved numeric IP addresses, IPv4 first, then IPv6 with any available scope suffix.\n * @example\n * `[\"192.168.1.42\", \"fe80::1234:abcd:...\"]`\n */\n hosts: string[];\n\n /** Host name when supplied by the platform, e.g. `\"my-device.local.\"`. */\n hostname?: string;\n\n /**\n * TXT dictionary (key → value).\n * @remarks Not all services publish TXT data.\n */\n txt?: MdnsTxt;\n}\n\n/**\n * Options for starting a Bonjour/mDNS advertisement.\n *\n * @remarks\n * - Service types accept an optional trailing dot; results always include it.\n * - Instance `name` should be short and human-readable; the OS may append `\" (n)\"` to ensure uniqueness.\n * Electron rejects a name conflict instead of renaming the service.\n * - Advertising TXT is supported on iOS, Android and Electron. Invalid input preserves the active advertisement.\n * - Native implementations guard publish with a timeout and return `error: true` instead of\n * leaving the Promise pending when the OS does not deliver a publish callback.\n * - Only one advertisement is active at a time. Starting a new one stops the previous one first.\n *\n * @public\n */\nexport interface MdnsBroadcastOptions {\n /**\n * Service type (including the trailing dot).\n * @defaultValue `\"_http._tcp.\"`\n * @example `\"_myapp._tcp.\"`\n */\n type?: string;\n\n /**\n * Service instance name (maximum 63 UTF-8 bytes). Defaults to `DevIOArtsMDNS`.\n */\n name?: string;\n\n /**\n * TCP port to advertise.\n * @remarks Must be a positive integer (1–65535).\n */\n port: number;\n\n /**\n * Optional TXT key–value pairs (UTF-8 strings).\n * @remarks Keys must be unique ignoring case, nonempty printable ASCII without `=`. Each `key=value` entry must fit in 255 UTF-8 bytes. The complete record is limited to 1300 bytes including length prefixes. Non-string values are rejected.\n */\n txt?: MdnsTxt;\n}\n\n/**\n * Options for Bonjour/mDNS discovery.\n *\n * @remarks\n * - The `name` filter matches the normalized name and also accepts prefix matches\n * (to handle OS-added `\" (n)\"` suffixes).\n * - When `useNW` is `true` on iOS, discovery uses `NWBrowser` for better P2P behavior.\n * - A valid new discovery replaces the previous request with an error on every platform.\n * - Dots and hyphens are equivalent when matching names; returned names retain their advertised spelling.\n * - Without a name filter, browsing continues for the entire timeout. With a filter it may finish once a matching IP address resolves.\n *\n * @public\n */\nexport interface MdnsDiscoverOptions {\n /**\n * Service type (including the trailing dot).\n * @defaultValue `\"_http._tcp.\"`\n * @example `\"_comm._tcp.\"`\n */\n type?: string;\n\n /**\n * Optional instance name filter (prefix-safe).\n * @example `\"MyAppName\"`\n */\n name?: string;\n\n /**\n * Discovery timeout in milliseconds. Finite numbers only; fractions are truncated and the delay is clamped to 0–2147483647.\n * @defaultValue `3000`\n */\n timeout?: number;\n\n /**\n * iOS-only hint to use `NWBrowser` instead of `NetServiceBrowser`.\n * @defaultValue `true`\n */\n useNW?: boolean;\n}\n\n/**\n * Result of startBroadcast(). Indicates whether advertising is active\n * and the final service name. On failure, `error` is true and `errorMessage`\n * describes the issue.\n * @public\n */\nexport interface MdnsBroadcastResult {\n /** True if the operation failed. */\n error: boolean;\n /** Error description or null on success. */\n errorMessage: string | null;\n /** Final (possibly uniquified) service instance name. Empty on failure. */\n name: string;\n /** Whether an advertiser is active, or may still be active after failed cleanup. */\n publishing: boolean;\n}\n\n/**\n * Result of discover(). Contains normalized services and error information.\n * @public\n */\nexport interface MdnsDiscoverResult {\n /** True if discovery encountered an error (partial results may still be present). */\n error: boolean;\n /** Error description or null when no error occurred. */\n errorMessage: string | null;\n /** Convenience count equal to services.length. */\n servicesFound: number;\n /** Resolved services with numeric addresses. Empty on error; partial results are discarded. */\n services: MdnsService[];\n}\n\n/**\n * Result of stopBroadcast(). Indicates whether the advertiser is active\n * after the call (normally false) and includes error information.\n * @public\n */\nexport interface MdnsStopResult {\n /** True if an error occurred while stopping. */\n error: boolean;\n /** Error description or null on success. */\n errorMessage: string | null;\n /** False after confirmed stop; true when stopping failed and the advertiser may still be active. */\n publishing: boolean;\n}\n\n/** Options for continuous discovery on iOS, Android and Electron. */\nexport interface MdnsWatchOptions {\n /** Nonempty list of service types. Trailing dots are optional; duplicates are merged. */\n types: string[];\n}\n\n/** Native browsers have been requested; later failures are reported through `watchError`. */\nexport interface MdnsWatchResult {\n error: boolean;\n errorMessage: string | null;\n watchersStarted: number;\n}\n\n/** Stops watching independently of any active broadcast. */\nexport interface MdnsWatchStopResult {\n error: boolean;\n errorMessage: string | null;\n watching: boolean;\n}\n\n/** Both found and lost events contain a complete service snapshot, including `hosts`. */\nexport interface MdnsServiceEvent {\n service: MdnsService;\n}\n\n/** Browser failures stop the watch; exhausted service resolution retries leave it running. */\nexport interface MdnsWatchErrorEvent {\n type: string;\n errorMessage: string;\n watching: boolean;\n}\n\n/**\n * Public API surface of the Capacitor mDNS plugin.\n *\n * @example\n * ```ts\n * import { mDNS } from 'capacitor-mdns';\n *\n * // Start advertising\n * await mDNS.startBroadcast({ type: '_http._tcp.', name: 'my.app.id', port: 9235 });\n *\n * // Discover services\n * const { services } = await mDNS.discover({ type: '_http._tcp.', timeout: 3000 });\n *\n * // Stop advertising\n * await mDNS.stopBroadcast();\n * ```\n *\n * @public\n */\nexport interface mDNSPlugin {\n /**\n * Return the platform implementation currently serving plugin calls.\n *\n * @returns Promise resolving to `MdnsPluginPlatformResult`.\n */\n getPluginPlatform(): Promise<MdnsPluginPlatformResult>;\n\n /**\n * Start advertising a Bonjour/mDNS service.\n *\n * @param options - {@link MdnsBroadcastOptions}\n * @returns Promise resolving to `MdnsBroadcastResult` (`true` on success).\n */\n startBroadcast(options: MdnsBroadcastOptions): Promise<MdnsBroadcastResult>;\n\n /**\n * Stop advertising the currently registered service (no-op if none).\n *\n * @returns Promise resolving to `MdnsStopResult`.\n * @remarks The `publishing` flag may be `false` after a successful stop.\n * Stopping is idempotent and is safe to call even if publishing never fully started.\n */\n stopBroadcast(): Promise<MdnsStopResult>;\n\n /**\n * Discover services of a given type and optionally filter by instance name.\n *\n * @param options - {@link MdnsDiscoverOptions}\n * @returns Promise resolving to `MdnsDiscoverResult`.\n * @remarks The result list is normalized across platforms.\n */\n discover(options?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;\n\n /**\n * Continuously watch several service types. A valid call replaces the previous watch.\n * Register listeners before starting. Each resolved service emits `serviceFound` once;\n * disappearance emits `serviceLost` with its last snapshot. No loss is emitted for an\n * unresolved service. Watching and one-shot discovery can run together.\n * Thanks to Idrimi for contributing the original continuous discovery feature (PR #7).\n */\n watchServices(options: MdnsWatchOptions): Promise<MdnsWatchResult>;\n\n /** Stop all watchers. No events from that watch are emitted after this resolves. */\n stopWatching(): Promise<MdnsWatchStopResult>;\n\n addListener(\n eventName: 'serviceFound' | 'serviceLost',\n handler: (event: MdnsServiceEvent) => void,\n ): Promise<PluginListenerHandle>;\n addListener(eventName: 'watchError', handler: (event: MdnsWatchErrorEvent) => void): Promise<PluginListenerHandle>;\n removeAllListeners(): Promise<void>;\n}\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
|
-
const
|
|
2
|
+
const platformPlugin = registerPlugin('mDNS', {
|
|
3
3
|
web: () => import('./web').then((m) => new m.mDNSWeb()),
|
|
4
|
+
electron: () => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const plugin = (_b = (_a = window.CapacitorCustomPlatform) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.mDNS;
|
|
7
|
+
if (!plugin)
|
|
8
|
+
throw new Error('mDNS Electron plugin is not registered; run npx cap-electron sync in the app');
|
|
9
|
+
return Promise.resolve(plugin);
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const mDNS = new Proxy(platformPlugin, {
|
|
13
|
+
get(target, property, receiver) {
|
|
14
|
+
if (property !== 'discover')
|
|
15
|
+
return Reflect.get(target, property, receiver);
|
|
16
|
+
return (options) => {
|
|
17
|
+
const timeout = options === null || options === void 0 ? void 0 : options.timeout;
|
|
18
|
+
// Native JSON bridges turn NaN/Infinity into null, losing the invalid input.
|
|
19
|
+
if (timeout != null && (typeof timeout !== 'number' || !Number.isFinite(timeout))) {
|
|
20
|
+
return Promise.resolve({ error: true, errorMessage: 'Invalid timeout', servicesFound: 0, services: [] });
|
|
21
|
+
}
|
|
22
|
+
return target.discover(options);
|
|
23
|
+
};
|
|
24
|
+
},
|
|
4
25
|
});
|
|
5
26
|
export * from './definitions';
|
|
6
27
|
export { mDNS };
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAa,MAAM,EAAE;IACxD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IACvD,QAAQ,EAAE,GAAG,EAAE;;QACb,MAAM,MAAM,GAAG,MAAA,MAAC,MAAc,CAAC,uBAAuB,0CAAE,OAAO,0CAAE,IAA8B,CAAC;QAChG,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;QAC7G,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE;IACrC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ;QAC5B,IAAI,QAAQ,KAAK,UAAU;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5E,OAAO,CAAC,OAA6B,EAAE,EAAE;YACvC,MAAM,OAAO,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC;YACjC,6EAA6E;YAC7E,IAAI,OAAO,IAAI,IAAI,IAAI,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;gBAClF,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;YAC3G,CAAC;YACD,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { MdnsDiscoverOptions, mDNSPlugin } from './definitions';\n\nconst platformPlugin = registerPlugin<mDNSPlugin>('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\n electron: () => {\n const plugin = (window as any).CapacitorCustomPlatform?.plugins?.mDNS as mDNSPlugin | undefined;\n if (!plugin) throw new Error('mDNS Electron plugin is not registered; run npx cap-electron sync in the app');\n return Promise.resolve(plugin);\n },\n});\n\nconst mDNS = new Proxy(platformPlugin, {\n get(target, property, receiver) {\n if (property !== 'discover') return Reflect.get(target, property, receiver);\n return (options?: MdnsDiscoverOptions) => {\n const timeout = options?.timeout;\n // Native JSON bridges turn NaN/Infinity into null, losing the invalid input.\n if (timeout != null && (typeof timeout !== 'number' || !Number.isFinite(timeout))) {\n return Promise.resolve({ error: true, errorMessage: 'Invalid timeout', servicesFound: 0, services: [] });\n }\n return target.discover(options);\n };\n },\n});\n\nexport * from './definitions';\nexport { mDNS };\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
3
|
+
import type { mDNSPlugin, MdnsBroadcastOptions, MdnsDiscoverOptions, MdnsBroadcastResult, MdnsStopResult, MdnsDiscoverResult, MdnsPluginPlatformResult, MdnsWatchOptions, MdnsWatchResult, MdnsWatchStopResult } from './definitions';
|
|
3
4
|
/**
|
|
4
5
|
* Web implementation of the mDNS plugin.
|
|
5
6
|
*
|
|
@@ -9,9 +10,15 @@ import type { mDNSPlugin, MdnsBroadcastOptions, MdnsDiscoverOptions, MdnsBroadca
|
|
|
9
10
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
10
11
|
*/
|
|
11
12
|
export declare class mDNSWeb extends WebPlugin implements mDNSPlugin {
|
|
13
|
+
private readonly unsupportedMessage;
|
|
12
14
|
/** Electron preload bridge (if present). */
|
|
13
15
|
private get electronApi();
|
|
16
|
+
getPluginPlatform(): Promise<MdnsPluginPlatformResult>;
|
|
14
17
|
startBroadcast(options: MdnsBroadcastOptions): Promise<MdnsBroadcastResult>;
|
|
15
18
|
stopBroadcast(): Promise<MdnsStopResult>;
|
|
16
19
|
discover(options?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;
|
|
20
|
+
watchServices(options: MdnsWatchOptions): Promise<MdnsWatchResult>;
|
|
21
|
+
stopWatching(): Promise<MdnsWatchStopResult>;
|
|
22
|
+
addListener(eventName: string, handler: (data: any) => void): Promise<PluginListenerHandle>;
|
|
23
|
+
removeAllListeners(): Promise<void>;
|
|
17
24
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -9,19 +9,28 @@ import { WebPlugin } from '@capacitor/core';
|
|
|
9
9
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
10
10
|
*/
|
|
11
11
|
export class mDNSWeb extends WebPlugin {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.unsupportedMessage = 'mDNS is not supported in this browser runtime';
|
|
15
|
+
}
|
|
12
16
|
/** Electron preload bridge (if present). */
|
|
13
17
|
get electronApi() {
|
|
14
18
|
if (typeof window === 'undefined')
|
|
15
19
|
return undefined;
|
|
16
20
|
return window.mDNS || window.mdns;
|
|
17
21
|
}
|
|
22
|
+
async getPluginPlatform() {
|
|
23
|
+
const api = this.electronApi;
|
|
24
|
+
if (api === null || api === void 0 ? void 0 : api.getPluginPlatform)
|
|
25
|
+
return api.getPluginPlatform();
|
|
26
|
+
return { platform: 'web' };
|
|
27
|
+
}
|
|
18
28
|
async startBroadcast(options) {
|
|
19
29
|
const api = this.electronApi;
|
|
20
30
|
if (api === null || api === void 0 ? void 0 : api.startBroadcast)
|
|
21
31
|
return api.startBroadcast(options);
|
|
22
32
|
console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);
|
|
23
|
-
|
|
24
|
-
return { publishing: true, name: '', error: false, errorMessage: null };
|
|
33
|
+
return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };
|
|
25
34
|
}
|
|
26
35
|
async stopBroadcast() {
|
|
27
36
|
const api = this.electronApi;
|
|
@@ -35,7 +44,30 @@ export class mDNSWeb extends WebPlugin {
|
|
|
35
44
|
if (api === null || api === void 0 ? void 0 : api.discover)
|
|
36
45
|
return api.discover(options);
|
|
37
46
|
console.log('[WEB_NOT_SUPPORTED] discover', options);
|
|
38
|
-
return { services: [], error:
|
|
47
|
+
return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };
|
|
48
|
+
}
|
|
49
|
+
async watchServices(options) {
|
|
50
|
+
var _a;
|
|
51
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.watchServices)
|
|
52
|
+
return this.electronApi.watchServices(options);
|
|
53
|
+
return { error: true, errorMessage: this.unsupportedMessage, watchersStarted: 0 };
|
|
54
|
+
}
|
|
55
|
+
async stopWatching() {
|
|
56
|
+
var _a;
|
|
57
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.stopWatching)
|
|
58
|
+
return this.electronApi.stopWatching();
|
|
59
|
+
return { watching: false, error: false, errorMessage: null };
|
|
60
|
+
}
|
|
61
|
+
async addListener(eventName, handler) {
|
|
62
|
+
var _a;
|
|
63
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.addListener)
|
|
64
|
+
return this.electronApi.addListener(eventName, handler);
|
|
65
|
+
return super.addListener(eventName, handler);
|
|
66
|
+
}
|
|
67
|
+
async removeAllListeners() {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
await ((_b = (_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.removeAllListeners) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
70
|
+
await super.removeAllListeners();
|
|
39
71
|
}
|
|
40
72
|
}
|
|
41
73
|
//# sourceMappingURL=web.js.map
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgB5C;;;;;;;GAOG;AACH,MAAM,OAAO,OAAQ,SAAQ,SAAS;IAAtC;;QACmB,uBAAkB,GAAG,+CAA+C,CAAC;IAiExF,CAAC;IA/DC,4CAA4C;IAC5C,IAAY,WAAW;QAYrB,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,SAAS,CAAC;QACpD,OAAQ,MAAc,CAAC,IAAI,IAAK,MAAc,CAAC,IAAI,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,iBAAiB;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC;QAC7B,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,iBAAiB;YAAE,OAAO,GAAG,CAAC,iBAAiB,EAAE,CAAC;QAC3D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA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WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACpF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,kBAAkB,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,YAAY;;QAChB,IAAI,MAAA,IAAI,CAAC,WAAW,0CAAE,YAAY;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;QAC3E,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,SAAiB,EAAE,OAA4B;;QAC/D,IAAI,MAAA,IAAI,CAAC,WAAW,0CAAE,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC3F,OAAO,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,kBAAkB;;QACtB,MAAM,CAAA,MAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,kBAAkB,kDAAI,CAAA,CAAC;QAC/C,MAAM,KAAK,CAAC,kBAAkB,EAAE,CAAC;IACnC,CAAC;CACF","sourcesContent":["// src/web.ts\nimport { WebPlugin } from '@capacitor/core';\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nimport type {\n mDNSPlugin,\n MdnsBroadcastOptions,\n MdnsDiscoverOptions,\n MdnsBroadcastResult,\n MdnsStopResult,\n MdnsDiscoverResult,\n MdnsPluginPlatformResult,\n MdnsWatchOptions,\n MdnsWatchResult,\n MdnsWatchStopResult,\n} from './definitions';\n\n/**\n * Web implementation of the mDNS plugin.\n *\n * This class behaves as a thin proxy:\n * - In Electron (when a preload exposes window.mDNS/window.mdns), calls are forwarded over IPC.\n * - In a regular browser, mDNS is not available; methods resolve with well-shaped stub values\n * and log a console message with the [WEB_NOT_SUPPORTED] tag.\n */\nexport class mDNSWeb extends WebPlugin implements mDNSPlugin {\n private readonly unsupportedMessage = 'mDNS is not supported in this browser runtime';\n\n /** Electron preload bridge (if present). */\n private get electronApi():\n | undefined\n | {\n startBroadcast(o: MdnsBroadcastOptions): Promise<MdnsBroadcastResult>;\n stopBroadcast(): Promise<MdnsStopResult>;\n discover(o?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;\n getPluginPlatform?(): Promise<MdnsPluginPlatformResult>;\n watchServices?(options: MdnsWatchOptions): Promise<MdnsWatchResult>;\n stopWatching?(): Promise<MdnsWatchStopResult>;\n addListener?(eventName: string, handler: (data: any) => void): Promise<PluginListenerHandle>;\n removeAllListeners?(): Promise<void>;\n } {\n if (typeof window === 'undefined') return undefined;\n return (window as any).mDNS || (window as any).mdns;\n }\n\n async getPluginPlatform(): Promise<MdnsPluginPlatformResult> {\n const api = this.electronApi;\n if (api?.getPluginPlatform) return api.getPluginPlatform();\n return { platform: 'web' };\n }\n\n async startBroadcast(options: MdnsBroadcastOptions): Promise<MdnsBroadcastResult> {\n const api = this.electronApi;\n if (api?.startBroadcast) return api.startBroadcast(options);\n console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);\n return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };\n }\n\n async stopBroadcast(): Promise<MdnsStopResult> {\n const api = this.electronApi;\n if (api?.stopBroadcast) return api.stopBroadcast();\n console.log('[WEB_NOT_SUPPORTED] stopBroadcast');\n return { publishing: false, error: false, errorMessage: null };\n }\n\n async discover(options: MdnsDiscoverOptions = {}): Promise<MdnsDiscoverResult> {\n const api = this.electronApi;\n if (api?.discover) return api.discover(options);\n console.log('[WEB_NOT_SUPPORTED] discover', options);\n return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };\n }\n\n async watchServices(options: MdnsWatchOptions): Promise<MdnsWatchResult> {\n if (this.electronApi?.watchServices) return this.electronApi.watchServices(options);\n return { error: true, errorMessage: this.unsupportedMessage, watchersStarted: 0 };\n }\n\n async stopWatching(): Promise<MdnsWatchStopResult> {\n if (this.electronApi?.stopWatching) return this.electronApi.stopWatching();\n return { watching: false, error: false, errorMessage: null };\n }\n\n async addListener(eventName: string, handler: (data: any) => void): Promise<PluginListenerHandle> {\n if (this.electronApi?.addListener) return this.electronApi.addListener(eventName, handler);\n return super.addListener(eventName, handler);\n }\n\n async removeAllListeners(): Promise<void> {\n await this.electronApi?.removeAllListeners?.();\n await super.removeAllListeners();\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -2,8 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const platformPlugin = core.registerPlugin('mDNS', {
|
|
6
6
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.mDNSWeb()),
|
|
7
|
+
electron: () => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const plugin = (_b = (_a = window.CapacitorCustomPlatform) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.mDNS;
|
|
10
|
+
if (!plugin)
|
|
11
|
+
throw new Error('mDNS Electron plugin is not registered; run npx cap-electron sync in the app');
|
|
12
|
+
return Promise.resolve(plugin);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const mDNS = new Proxy(platformPlugin, {
|
|
16
|
+
get(target, property, receiver) {
|
|
17
|
+
if (property !== 'discover')
|
|
18
|
+
return Reflect.get(target, property, receiver);
|
|
19
|
+
return (options) => {
|
|
20
|
+
const timeout = options === null || options === void 0 ? void 0 : options.timeout;
|
|
21
|
+
// Native JSON bridges turn NaN/Infinity into null, losing the invalid input.
|
|
22
|
+
if (timeout != null && (typeof timeout !== 'number' || !Number.isFinite(timeout))) {
|
|
23
|
+
return Promise.resolve({ error: true, errorMessage: 'Invalid timeout', servicesFound: 0, services: [] });
|
|
24
|
+
}
|
|
25
|
+
return target.discover(options);
|
|
26
|
+
};
|
|
27
|
+
},
|
|
7
28
|
});
|
|
8
29
|
|
|
9
30
|
// src/web.ts
|
|
@@ -16,19 +37,28 @@ const mDNS = core.registerPlugin('mDNS', {
|
|
|
16
37
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
17
38
|
*/
|
|
18
39
|
class mDNSWeb extends core.WebPlugin {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.unsupportedMessage = 'mDNS is not supported in this browser runtime';
|
|
43
|
+
}
|
|
19
44
|
/** Electron preload bridge (if present). */
|
|
20
45
|
get electronApi() {
|
|
21
46
|
if (typeof window === 'undefined')
|
|
22
47
|
return undefined;
|
|
23
48
|
return window.mDNS || window.mdns;
|
|
24
49
|
}
|
|
50
|
+
async getPluginPlatform() {
|
|
51
|
+
const api = this.electronApi;
|
|
52
|
+
if (api === null || api === void 0 ? void 0 : api.getPluginPlatform)
|
|
53
|
+
return api.getPluginPlatform();
|
|
54
|
+
return { platform: 'web' };
|
|
55
|
+
}
|
|
25
56
|
async startBroadcast(options) {
|
|
26
57
|
const api = this.electronApi;
|
|
27
58
|
if (api === null || api === void 0 ? void 0 : api.startBroadcast)
|
|
28
59
|
return api.startBroadcast(options);
|
|
29
60
|
console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);
|
|
30
|
-
|
|
31
|
-
return { publishing: true, name: '', error: false, errorMessage: null };
|
|
61
|
+
return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };
|
|
32
62
|
}
|
|
33
63
|
async stopBroadcast() {
|
|
34
64
|
const api = this.electronApi;
|
|
@@ -42,7 +72,30 @@ class mDNSWeb extends core.WebPlugin {
|
|
|
42
72
|
if (api === null || api === void 0 ? void 0 : api.discover)
|
|
43
73
|
return api.discover(options);
|
|
44
74
|
console.log('[WEB_NOT_SUPPORTED] discover', options);
|
|
45
|
-
return { services: [], error:
|
|
75
|
+
return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };
|
|
76
|
+
}
|
|
77
|
+
async watchServices(options) {
|
|
78
|
+
var _a;
|
|
79
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.watchServices)
|
|
80
|
+
return this.electronApi.watchServices(options);
|
|
81
|
+
return { error: true, errorMessage: this.unsupportedMessage, watchersStarted: 0 };
|
|
82
|
+
}
|
|
83
|
+
async stopWatching() {
|
|
84
|
+
var _a;
|
|
85
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.stopWatching)
|
|
86
|
+
return this.electronApi.stopWatching();
|
|
87
|
+
return { watching: false, error: false, errorMessage: null };
|
|
88
|
+
}
|
|
89
|
+
async addListener(eventName, handler) {
|
|
90
|
+
var _a;
|
|
91
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.addListener)
|
|
92
|
+
return this.electronApi.addListener(eventName, handler);
|
|
93
|
+
return super.addListener(eventName, handler);
|
|
94
|
+
}
|
|
95
|
+
async removeAllListeners() {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
await ((_b = (_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.removeAllListeners) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
98
|
+
await super.removeAllListeners();
|
|
46
99
|
}
|
|
47
100
|
}
|
|
48
101
|
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst platformPlugin = registerPlugin('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\n electron: () => {\n var _a, _b;\n const plugin = (_b = (_a = window.CapacitorCustomPlatform) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.mDNS;\n if (!plugin)\n throw new Error('mDNS Electron plugin is not registered; run npx cap-electron sync in the app');\n return Promise.resolve(plugin);\n },\n});\nconst mDNS = new Proxy(platformPlugin, {\n get(target, property, receiver) {\n if (property !== 'discover')\n return Reflect.get(target, property, receiver);\n return (options) => {\n const timeout = options === null || options === void 0 ? void 0 : options.timeout;\n // Native JSON bridges turn NaN/Infinity into null, losing the invalid input.\n if (timeout != null && (typeof timeout !== 'number' || !Number.isFinite(timeout))) {\n return Promise.resolve({ error: true, errorMessage: 'Invalid timeout', servicesFound: 0, services: [] });\n }\n return target.discover(options);\n };\n },\n});\nexport * from './definitions';\nexport { mDNS };\n//# sourceMappingURL=index.js.map","// src/web.ts\nimport { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation of the mDNS plugin.\n *\n * This class behaves as a thin proxy:\n * - In Electron (when a preload exposes window.mDNS/window.mdns), calls are forwarded over IPC.\n * - In a regular browser, mDNS is not available; methods resolve with well-shaped stub values\n * and log a console message with the [WEB_NOT_SUPPORTED] tag.\n */\nexport class mDNSWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.unsupportedMessage = 'mDNS is not supported in this browser runtime';\n }\n /** Electron preload bridge (if present). */\n get electronApi() {\n if (typeof window === 'undefined')\n return undefined;\n return window.mDNS || window.mdns;\n }\n async getPluginPlatform() {\n const api = this.electronApi;\n if (api === null || api === void 0 ? void 0 : api.getPluginPlatform)\n return api.getPluginPlatform();\n return { platform: 'web' };\n }\n async startBroadcast(options) {\n const api = this.electronApi;\n if (api === null || api === void 0 ? void 0 : api.startBroadcast)\n return api.startBroadcast(options);\n console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);\n return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };\n }\n async stopBroadcast() {\n const api = this.electronApi;\n if (api === null || api === void 0 ? void 0 : api.stopBroadcast)\n return api.stopBroadcast();\n console.log('[WEB_NOT_SUPPORTED] stopBroadcast');\n return { publishing: false, error: false, errorMessage: null };\n }\n async discover(options = {}) {\n const api = this.electronApi;\n if (api === null || api === void 0 ? void 0 : api.discover)\n return api.discover(options);\n console.log('[WEB_NOT_SUPPORTED] discover', options);\n return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };\n }\n async watchServices(options) {\n var _a;\n if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.watchServices)\n return this.electronApi.watchServices(options);\n return { error: true, errorMessage: this.unsupportedMessage, watchersStarted: 0 };\n }\n async stopWatching() {\n var _a;\n if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.stopWatching)\n return this.electronApi.stopWatching();\n return { watching: false, error: false, errorMessage: null };\n }\n async addListener(eventName, handler) {\n var _a;\n if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.addListener)\n return this.electronApi.addListener(eventName, handler);\n return super.addListener(eventName, handler);\n }\n async removeAllListeners() {\n var _a, _b;\n await ((_b = (_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.removeAllListeners) === null || _b === void 0 ? void 0 : _b.call(_a));\n await super.removeAllListeners();\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACA,MAAM,cAAc,GAAGA,mBAAc,CAAC,MAAM,EAAE;AAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3D,IAAI,QAAQ,EAAE,MAAM;AACpB,QAAQ,IAAI,EAAE,EAAE,EAAE;AAClB,QAAQ,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,uBAAuB,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,IAAI;AAChK,QAAQ,IAAI,CAAC,MAAM;AACnB,YAAY,MAAM,IAAI,KAAK,CAAC,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AE;AACd,QAAQ,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,WAAW;AACvF,YAAY,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC;AACnE,QAAQ,OAAO,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC;AACpD,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,IAAI,EAAE,EAAE,EAAE;AAClB,QAAQ,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,kBAAkB,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1J,QAAQ,MAAM,KAAK,CAAC,kBAAkB,EAAE;AACxC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
var capacitormDNS = (function (exports, core) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const platformPlugin = core.registerPlugin('mDNS', {
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.mDNSWeb()),
|
|
6
|
+
electron: () => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const plugin = (_b = (_a = window.CapacitorCustomPlatform) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.mDNS;
|
|
9
|
+
if (!plugin)
|
|
10
|
+
throw new Error('mDNS Electron plugin is not registered; run npx cap-electron sync in the app');
|
|
11
|
+
return Promise.resolve(plugin);
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const mDNS = new Proxy(platformPlugin, {
|
|
15
|
+
get(target, property, receiver) {
|
|
16
|
+
if (property !== 'discover')
|
|
17
|
+
return Reflect.get(target, property, receiver);
|
|
18
|
+
return (options) => {
|
|
19
|
+
const timeout = options === null || options === void 0 ? void 0 : options.timeout;
|
|
20
|
+
// Native JSON bridges turn NaN/Infinity into null, losing the invalid input.
|
|
21
|
+
if (timeout != null && (typeof timeout !== 'number' || !Number.isFinite(timeout))) {
|
|
22
|
+
return Promise.resolve({ error: true, errorMessage: 'Invalid timeout', servicesFound: 0, services: [] });
|
|
23
|
+
}
|
|
24
|
+
return target.discover(options);
|
|
25
|
+
};
|
|
26
|
+
},
|
|
6
27
|
});
|
|
7
28
|
|
|
8
29
|
// src/web.ts
|
|
@@ -15,19 +36,28 @@ var capacitormDNS = (function (exports, core) {
|
|
|
15
36
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
16
37
|
*/
|
|
17
38
|
class mDNSWeb extends core.WebPlugin {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
41
|
+
this.unsupportedMessage = 'mDNS is not supported in this browser runtime';
|
|
42
|
+
}
|
|
18
43
|
/** Electron preload bridge (if present). */
|
|
19
44
|
get electronApi() {
|
|
20
45
|
if (typeof window === 'undefined')
|
|
21
46
|
return undefined;
|
|
22
47
|
return window.mDNS || window.mdns;
|
|
23
48
|
}
|
|
49
|
+
async getPluginPlatform() {
|
|
50
|
+
const api = this.electronApi;
|
|
51
|
+
if (api === null || api === void 0 ? void 0 : api.getPluginPlatform)
|
|
52
|
+
return api.getPluginPlatform();
|
|
53
|
+
return { platform: 'web' };
|
|
54
|
+
}
|
|
24
55
|
async startBroadcast(options) {
|
|
25
56
|
const api = this.electronApi;
|
|
26
57
|
if (api === null || api === void 0 ? void 0 : api.startBroadcast)
|
|
27
58
|
return api.startBroadcast(options);
|
|
28
59
|
console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);
|
|
29
|
-
|
|
30
|
-
return { publishing: true, name: '', error: false, errorMessage: null };
|
|
60
|
+
return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };
|
|
31
61
|
}
|
|
32
62
|
async stopBroadcast() {
|
|
33
63
|
const api = this.electronApi;
|
|
@@ -41,7 +71,30 @@ var capacitormDNS = (function (exports, core) {
|
|
|
41
71
|
if (api === null || api === void 0 ? void 0 : api.discover)
|
|
42
72
|
return api.discover(options);
|
|
43
73
|
console.log('[WEB_NOT_SUPPORTED] discover', options);
|
|
44
|
-
return { services: [], error:
|
|
74
|
+
return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };
|
|
75
|
+
}
|
|
76
|
+
async watchServices(options) {
|
|
77
|
+
var _a;
|
|
78
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.watchServices)
|
|
79
|
+
return this.electronApi.watchServices(options);
|
|
80
|
+
return { error: true, errorMessage: this.unsupportedMessage, watchersStarted: 0 };
|
|
81
|
+
}
|
|
82
|
+
async stopWatching() {
|
|
83
|
+
var _a;
|
|
84
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.stopWatching)
|
|
85
|
+
return this.electronApi.stopWatching();
|
|
86
|
+
return { watching: false, error: false, errorMessage: null };
|
|
87
|
+
}
|
|
88
|
+
async addListener(eventName, handler) {
|
|
89
|
+
var _a;
|
|
90
|
+
if ((_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.addListener)
|
|
91
|
+
return this.electronApi.addListener(eventName, handler);
|
|
92
|
+
return super.addListener(eventName, handler);
|
|
93
|
+
}
|
|
94
|
+
async removeAllListeners() {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
await ((_b = (_a = this.electronApi) === null || _a === void 0 ? void 0 : _a.removeAllListeners) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
97
|
+
await super.removeAllListeners();
|
|
45
98
|
}
|
|
46
99
|
}
|
|
47
100
|
|