@devioarts/capacitor-mdns 0.0.2 → 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/Package.swift +1 -1
- package/README.md +54 -67
- package/android/build.gradle +11 -11
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/mDNS.kt +217 -51
- package/android/src/main/java/com/devioarts/capacitor/mdns/mDNSPlugin.kt +20 -9
- package/dist/docs.json +65 -3
- package/dist/esm/definitions.d.ts +28 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +12 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +13 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +13 -3
- package/dist/plugin.js.map +1 -1
- package/docs/electron.md +65 -0
- package/docs/platform-setup.md +52 -0
- package/docs/playground.md +19 -0
- package/docs/runtime-behavior.md +14 -0
- package/electron/dist/plugin-settings.js +15 -0
- package/electron/dist/plugin-settings.js.map +1 -0
- package/electron/dist/plugin.cjs.js +344 -0
- package/electron/dist/plugin.cjs.js.map +1 -0
- package/electron/global.d.ts +2 -0
- package/electron/mdns-bridge.cjs +9 -4
- package/electron/mdns.ts +151 -63
- package/electron/rollup.config.mjs +22 -0
- package/electron/src/index.ts +1 -0
- package/electron/src/plugin-settings.ts +12 -0
- package/electron/tsconfig.json +21 -0
- package/electron/types-public/index.d.ts +25 -0
- package/ios/Sources/mDNSPlugin/mDNS.swift +95 -28
- package/ios/Sources/mDNSPlugin/mDNSPlugin.swift +12 -3
- package/ios/Tests/mDNSPluginTests/mDNSPluginTests.swift +3 -9
- package/package.json +47 -22
|
@@ -26,7 +26,7 @@ import org.json.JSONObject
|
|
|
26
26
|
* - discover -> {
|
|
27
27
|
* error: boolean, errorMessage: string|null,
|
|
28
28
|
* servicesFound: number,
|
|
29
|
-
* services: Array<{ name, type, domain: "local.", port, hosts
|
|
29
|
+
* services: Array<{ name, type, domain: "local.", port, hosts: string[] }>
|
|
30
30
|
* }
|
|
31
31
|
*/
|
|
32
32
|
@CapacitorPlugin(name = "mDNS")
|
|
@@ -52,6 +52,14 @@ class mDNSPlugin : Plugin() {
|
|
|
52
52
|
|
|
53
53
|
private fun jnull(msg: String?): Any = msg ?: JSONObject.NULL
|
|
54
54
|
|
|
55
|
+
private fun normalizeType(raw: String?): String {
|
|
56
|
+
val type = raw?.trim()?.takeIf { it.isNotEmpty() } ?: "_http._tcp."
|
|
57
|
+
return if (type.endsWith(".")) type else "$type."
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private fun normalizeName(raw: String?): String =
|
|
61
|
+
raw?.trim()?.takeIf { it.isNotEmpty() } ?: (context?.packageName ?: "DevIOArtsMDNS")
|
|
62
|
+
|
|
55
63
|
private fun jsResultBroadcast(publishing: Boolean, name: String, error: Boolean, msg: String?): JSObject =
|
|
56
64
|
JSObject().put("publishing", publishing)
|
|
57
65
|
.put("name", name)
|
|
@@ -72,6 +80,11 @@ class mDNSPlugin : Plugin() {
|
|
|
72
80
|
|
|
73
81
|
// ----------------------- API -----------------------
|
|
74
82
|
|
|
83
|
+
@PluginMethod
|
|
84
|
+
fun getPluginPlatform(call: PluginCall) {
|
|
85
|
+
call.resolve(JSObject().put("platform", "android"))
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
/**
|
|
76
89
|
* Start advertising a Bonjour/mDNS service.
|
|
77
90
|
* - type: default "_http._tcp."
|
|
@@ -80,11 +93,11 @@ class mDNSPlugin : Plugin() {
|
|
|
80
93
|
*/
|
|
81
94
|
@PluginMethod
|
|
82
95
|
fun startBroadcast(call: PluginCall) {
|
|
83
|
-
val type = call.getString("type")
|
|
84
|
-
val name = call.getString("name")
|
|
96
|
+
val type = normalizeType(call.getString("type"))
|
|
97
|
+
val name = normalizeName(call.getString("name"))
|
|
85
98
|
val port = call.getInt("port") ?: 0
|
|
86
99
|
|
|
87
|
-
if (port
|
|
100
|
+
if (port !in 1..65535) {
|
|
88
101
|
call.resolve(jsResultBroadcast(false, "", true, "Missing/invalid port"))
|
|
89
102
|
return
|
|
90
103
|
}
|
|
@@ -127,8 +140,8 @@ class mDNSPlugin : Plugin() {
|
|
|
127
140
|
*/
|
|
128
141
|
@PluginMethod
|
|
129
142
|
fun discover(call: PluginCall) {
|
|
130
|
-
val type = call.getString("type")
|
|
131
|
-
val targetName = call.getString("name")
|
|
143
|
+
val type = normalizeType(call.getString("type"))
|
|
144
|
+
val targetName = call.getString("name")?.trim()?.takeIf { it.isNotEmpty() }
|
|
132
145
|
val timeout = call.getInt("timeout") ?: 3000
|
|
133
146
|
|
|
134
147
|
scope.launch {
|
|
@@ -139,10 +152,8 @@ class mDNSPlugin : Plugin() {
|
|
|
139
152
|
put("name", s.name)
|
|
140
153
|
put("type", s.type) // Android returns full type with dot
|
|
141
154
|
put("domain", "local.") // NSD is mDNS only
|
|
142
|
-
// normalize hosts to [] or [addr]
|
|
143
155
|
val hosts = JSONArray()
|
|
144
|
-
|
|
145
|
-
if (!addr.isNullOrEmpty()) hosts.put(addr)
|
|
156
|
+
s.hosts.forEach { hosts.put(it) }
|
|
146
157
|
put("hosts", hosts)
|
|
147
158
|
put("port", s.port)
|
|
148
159
|
// TXT not available via NSD -> omitted on Android
|
package/dist/docs.json
CHANGED
|
@@ -13,6 +13,23 @@
|
|
|
13
13
|
}
|
|
14
14
|
],
|
|
15
15
|
"methods": [
|
|
16
|
+
{
|
|
17
|
+
"name": "getPluginPlatform",
|
|
18
|
+
"signature": "() => Promise<MdnsPluginPlatformResult>",
|
|
19
|
+
"parameters": [],
|
|
20
|
+
"returns": "Promise<MdnsPluginPlatformResult>",
|
|
21
|
+
"tags": [
|
|
22
|
+
{
|
|
23
|
+
"name": "returns",
|
|
24
|
+
"text": "Promise resolving to `MdnsPluginPlatformResult`."
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"docs": "Return the platform implementation currently serving plugin calls.",
|
|
28
|
+
"complexTypes": [
|
|
29
|
+
"MdnsPluginPlatformResult"
|
|
30
|
+
],
|
|
31
|
+
"slug": "getpluginplatform"
|
|
32
|
+
},
|
|
16
33
|
{
|
|
17
34
|
"name": "startBroadcast",
|
|
18
35
|
"signature": "(options: MdnsBroadcastOptions) => Promise<MdnsBroadcastResult>",
|
|
@@ -53,7 +70,7 @@
|
|
|
53
70
|
},
|
|
54
71
|
{
|
|
55
72
|
"name": "remarks",
|
|
56
|
-
"text": "The `publishing` flag may be `false` after a successful stop."
|
|
73
|
+
"text": "The `publishing` flag may be `false` after a successful stop.\nStopping is idempotent and is safe to call even if publishing never fully started."
|
|
57
74
|
}
|
|
58
75
|
],
|
|
59
76
|
"docs": "Stop advertising the currently registered service (no-op if none).",
|
|
@@ -98,6 +115,28 @@
|
|
|
98
115
|
"properties": []
|
|
99
116
|
},
|
|
100
117
|
"interfaces": [
|
|
118
|
+
{
|
|
119
|
+
"name": "MdnsPluginPlatformResult",
|
|
120
|
+
"slug": "mdnspluginplatformresult",
|
|
121
|
+
"docs": "Result of getPluginPlatform(). Useful for validating that calls are routed\nthrough the expected platform bridge.",
|
|
122
|
+
"tags": [
|
|
123
|
+
{
|
|
124
|
+
"name": "public"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"methods": [],
|
|
128
|
+
"properties": [
|
|
129
|
+
{
|
|
130
|
+
"name": "platform",
|
|
131
|
+
"tags": [],
|
|
132
|
+
"docs": "Platform implementation that produced this result.",
|
|
133
|
+
"complexTypes": [
|
|
134
|
+
"MdnsPluginPlatform"
|
|
135
|
+
],
|
|
136
|
+
"type": "MdnsPluginPlatform"
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
101
140
|
{
|
|
102
141
|
"name": "MdnsBroadcastResult",
|
|
103
142
|
"slug": "mdnsbroadcastresult",
|
|
@@ -145,7 +184,7 @@
|
|
|
145
184
|
"docs": "Options for starting a Bonjour/mDNS advertisement.",
|
|
146
185
|
"tags": [
|
|
147
186
|
{
|
|
148
|
-
"text": "- 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.",
|
|
187
|
+
"text": "- 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- 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.",
|
|
149
188
|
"name": "remarks"
|
|
150
189
|
},
|
|
151
190
|
{
|
|
@@ -359,7 +398,7 @@
|
|
|
359
398
|
"docs": "Options for Bonjour/mDNS discovery.",
|
|
360
399
|
"tags": [
|
|
361
400
|
{
|
|
362
|
-
"text": "- The `
|
|
401
|
+
"text": "- 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- Discovery is timeboxed. Concurrent discovery requests are serialized or safely replace\n the previous native session so old callbacks cannot complete a newer request.",
|
|
363
402
|
"name": "remarks"
|
|
364
403
|
},
|
|
365
404
|
{
|
|
@@ -425,6 +464,29 @@
|
|
|
425
464
|
],
|
|
426
465
|
"enums": [],
|
|
427
466
|
"typeAliases": [
|
|
467
|
+
{
|
|
468
|
+
"name": "MdnsPluginPlatform",
|
|
469
|
+
"slug": "mdnspluginplatform",
|
|
470
|
+
"docs": "Runtime implementation that handled a plugin call.",
|
|
471
|
+
"types": [
|
|
472
|
+
{
|
|
473
|
+
"text": "'ios'",
|
|
474
|
+
"complexTypes": []
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
"text": "'android'",
|
|
478
|
+
"complexTypes": []
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"text": "'electron'",
|
|
482
|
+
"complexTypes": []
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
"text": "'web'",
|
|
486
|
+
"complexTypes": []
|
|
487
|
+
}
|
|
488
|
+
]
|
|
489
|
+
},
|
|
428
490
|
{
|
|
429
491
|
"name": "MdnsTxt",
|
|
430
492
|
"slug": "mdnstxt",
|
|
@@ -3,7 +3,21 @@
|
|
|
3
3
|
* Values are UTF-8 strings; binary payloads are not supported by this API.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type MdnsTxt = Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Runtime implementation that handled a plugin call.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type MdnsPluginPlatform = 'ios' | 'android' | 'electron' | 'web';
|
|
12
|
+
/**
|
|
13
|
+
* Result of getPluginPlatform(). Useful for validating that calls are routed
|
|
14
|
+
* through the expected platform bridge.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface MdnsPluginPlatformResult {
|
|
18
|
+
/** Platform implementation that produced this result. */
|
|
19
|
+
platform: MdnsPluginPlatform;
|
|
20
|
+
}
|
|
7
21
|
/**
|
|
8
22
|
* Normalized description of a discovered Bonjour/mDNS service.
|
|
9
23
|
* Returned from {@link mDNSPlugin.discover}.
|
|
@@ -44,6 +58,9 @@ export interface MdnsService {
|
|
|
44
58
|
* - The `type` **must** end with a dot (`.`). If omitted, the implementation appends it.
|
|
45
59
|
* - Instance `name` should be short and human-readable; the OS may append `" (n)"` to ensure uniqueness.
|
|
46
60
|
* - Android NSD does not expose TXT records to other apps; advertising TXT is supported on iOS.
|
|
61
|
+
* - Native implementations guard publish with a timeout and return `error: true` instead of
|
|
62
|
+
* leaving the Promise pending when the OS does not deliver a publish callback.
|
|
63
|
+
* - Only one advertisement is active at a time. Starting a new one stops the previous one first.
|
|
47
64
|
*
|
|
48
65
|
* @public
|
|
49
66
|
*/
|
|
@@ -73,9 +90,11 @@ export interface MdnsBroadcastOptions {
|
|
|
73
90
|
* Options for Bonjour/mDNS discovery.
|
|
74
91
|
*
|
|
75
92
|
* @remarks
|
|
76
|
-
* - The `
|
|
93
|
+
* - The `name` filter matches the normalized name and also accepts prefix matches
|
|
77
94
|
* (to handle OS-added `" (n)"` suffixes).
|
|
78
95
|
* - When `useNW` is `true` on iOS, discovery uses `NWBrowser` for better P2P behavior.
|
|
96
|
+
* - Discovery is timeboxed. Concurrent discovery requests are serialized or safely replace
|
|
97
|
+
* the previous native session so old callbacks cannot complete a newer request.
|
|
79
98
|
*
|
|
80
99
|
* @public
|
|
81
100
|
*/
|
|
@@ -165,6 +184,12 @@ export interface MdnsStopResult {
|
|
|
165
184
|
* @public
|
|
166
185
|
*/
|
|
167
186
|
export interface mDNSPlugin {
|
|
187
|
+
/**
|
|
188
|
+
* Return the platform implementation currently serving plugin calls.
|
|
189
|
+
*
|
|
190
|
+
* @returns Promise resolving to `MdnsPluginPlatformResult`.
|
|
191
|
+
*/
|
|
192
|
+
getPluginPlatform(): Promise<MdnsPluginPlatformResult>;
|
|
168
193
|
/**
|
|
169
194
|
* Start advertising a Bonjour/mDNS service.
|
|
170
195
|
*
|
|
@@ -177,6 +202,7 @@ export interface mDNSPlugin {
|
|
|
177
202
|
*
|
|
178
203
|
* @returns Promise resolving to `MdnsStopResult`.
|
|
179
204
|
* @remarks The `publishing` flag may be `false` after a successful stop.
|
|
205
|
+
* Stopping is idempotent and is safe to call even if publishing never fully started.
|
|
180
206
|
*/
|
|
181
207
|
stopBroadcast(): Promise<MdnsStopResult>;
|
|
182
208
|
/**
|
|
@@ -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 `
|
|
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 * 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 * - 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 * - 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.\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 `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 * - Discovery is timeboxed. Concurrent discovery requests are serialized or safely replace\n * the previous native session so old callbacks cannot complete a newer request.\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 * 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. On Android, `txt` is typically absent.\n */\n discover(options?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;\n}\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
2
|
const mDNS = registerPlugin('mDNS', {
|
|
3
3
|
web: () => import('./web').then((m) => new m.mDNSWeb()),
|
|
4
|
+
electron: () => Promise.resolve(window.CapacitorCustomPlatform.plugins.mDNS),
|
|
4
5
|
});
|
|
5
6
|
export * from './definitions';
|
|
6
7
|
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,IAAI,GAAG,cAAc,CAAa,MAAM,EAAE;IAC9C,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,IAAI,GAAG,cAAc,CAAa,MAAM,EAAE;IAC9C,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,CAAC,OAAO,CAAC,OAAO,CAAE,MAAc,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAkB,CAAC;CACpG,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { mDNSPlugin } from './definitions';\n\nconst mDNS = registerPlugin<mDNSPlugin>('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\n electron: () => Promise.resolve((window as any).CapacitorCustomPlatform.plugins.mDNS as mDNSPlugin),\n});\n\nexport * from './definitions';\nexport { mDNS };\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { mDNSPlugin, MdnsBroadcastOptions, MdnsDiscoverOptions, MdnsBroadcastResult, MdnsStopResult, MdnsDiscoverResult } from './definitions';
|
|
2
|
+
import type { mDNSPlugin, MdnsBroadcastOptions, MdnsDiscoverOptions, MdnsBroadcastResult, MdnsStopResult, MdnsDiscoverResult, MdnsPluginPlatformResult } from './definitions';
|
|
3
3
|
/**
|
|
4
4
|
* Web implementation of the mDNS plugin.
|
|
5
5
|
*
|
|
@@ -9,8 +9,10 @@ import type { mDNSPlugin, MdnsBroadcastOptions, MdnsDiscoverOptions, MdnsBroadca
|
|
|
9
9
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
10
10
|
*/
|
|
11
11
|
export declare class mDNSWeb extends WebPlugin implements mDNSPlugin {
|
|
12
|
+
private readonly unsupportedMessage;
|
|
12
13
|
/** Electron preload bridge (if present). */
|
|
13
14
|
private get electronApi();
|
|
15
|
+
getPluginPlatform(): Promise<MdnsPluginPlatformResult>;
|
|
14
16
|
startBroadcast(options: MdnsBroadcastOptions): Promise<MdnsBroadcastResult>;
|
|
15
17
|
stopBroadcast(): Promise<MdnsStopResult>;
|
|
16
18
|
discover(options?: MdnsDiscoverOptions): Promise<MdnsDiscoverResult>;
|
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,7 @@ 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 };
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
//# 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","sour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,mCAAmC,CAAC,CAAC;QACjD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,UAA+B,EAAE;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC;QAC7B,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ;YAAE,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,kBAAkB,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC;IAChG,CAAC;CACF","sourcesContent":["// src/web.ts\nimport { WebPlugin } from '@capacitor/core';\n\nimport type {\n mDNSPlugin,\n MdnsBroadcastOptions,\n MdnsDiscoverOptions,\n MdnsBroadcastResult,\n MdnsStopResult,\n MdnsDiscoverResult,\n MdnsPluginPlatformResult,\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 } {\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"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ var core = require('@capacitor/core');
|
|
|
4
4
|
|
|
5
5
|
const mDNS = core.registerPlugin('mDNS', {
|
|
6
6
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.mDNSWeb()),
|
|
7
|
+
electron: () => Promise.resolve(window.CapacitorCustomPlatform.plugins.mDNS),
|
|
7
8
|
});
|
|
8
9
|
|
|
9
10
|
// src/web.ts
|
|
@@ -16,19 +17,28 @@ const mDNS = core.registerPlugin('mDNS', {
|
|
|
16
17
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
17
18
|
*/
|
|
18
19
|
class mDNSWeb extends core.WebPlugin {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.unsupportedMessage = 'mDNS is not supported in this browser runtime';
|
|
23
|
+
}
|
|
19
24
|
/** Electron preload bridge (if present). */
|
|
20
25
|
get electronApi() {
|
|
21
26
|
if (typeof window === 'undefined')
|
|
22
27
|
return undefined;
|
|
23
28
|
return window.mDNS || window.mdns;
|
|
24
29
|
}
|
|
30
|
+
async getPluginPlatform() {
|
|
31
|
+
const api = this.electronApi;
|
|
32
|
+
if (api === null || api === void 0 ? void 0 : api.getPluginPlatform)
|
|
33
|
+
return api.getPluginPlatform();
|
|
34
|
+
return { platform: 'web' };
|
|
35
|
+
}
|
|
25
36
|
async startBroadcast(options) {
|
|
26
37
|
const api = this.electronApi;
|
|
27
38
|
if (api === null || api === void 0 ? void 0 : api.startBroadcast)
|
|
28
39
|
return api.startBroadcast(options);
|
|
29
40
|
console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);
|
|
30
|
-
|
|
31
|
-
return { publishing: true, name: '', error: false, errorMessage: null };
|
|
41
|
+
return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };
|
|
32
42
|
}
|
|
33
43
|
async stopBroadcast() {
|
|
34
44
|
const api = this.electronApi;
|
|
@@ -42,7 +52,7 @@ class mDNSWeb extends core.WebPlugin {
|
|
|
42
52
|
if (api === null || api === void 0 ? void 0 : api.discover)
|
|
43
53
|
return api.discover(options);
|
|
44
54
|
console.log('[WEB_NOT_SUPPORTED] discover', options);
|
|
45
|
-
return { services: [], error:
|
|
55
|
+
return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
|
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 mDNS = registerPlugin('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\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 /** 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 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
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst mDNS = registerPlugin('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\n electron: () => Promise.resolve(window.CapacitorCustomPlatform.plugins.mDNS),\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}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;AACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3D,IAAI,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,CAAC;AAChF,CAAC;;ACJD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,OAAO,SAASC,cAAS,CAAC;AACvC,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,kBAAkB,GAAG,+CAA+C;AACjF,IAAI;AACJ;AACA,IAAI,IAAI,WAAW,GAAG;AACtB,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW;AACzC,YAAY,OAAO,SAAS;AAC5B,QAAQ,OAAO,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI;AACzC,IAAI;AACJ,IAAI,MAAM,iBAAiB,GAAG;AAC9B,QAAQ,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW;AACpC,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM,GAAG,MAAM,GAAG,GAAG,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,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC;AAC5D,QAAQ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,kBAAkB,EAAE,aAAa,EAAE,CAAC,EAAE;AACrG,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ var capacitormDNS = (function (exports, core) {
|
|
|
3
3
|
|
|
4
4
|
const mDNS = core.registerPlugin('mDNS', {
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.mDNSWeb()),
|
|
6
|
+
electron: () => Promise.resolve(window.CapacitorCustomPlatform.plugins.mDNS),
|
|
6
7
|
});
|
|
7
8
|
|
|
8
9
|
// src/web.ts
|
|
@@ -15,19 +16,28 @@ var capacitormDNS = (function (exports, core) {
|
|
|
15
16
|
* and log a console message with the [WEB_NOT_SUPPORTED] tag.
|
|
16
17
|
*/
|
|
17
18
|
class mDNSWeb extends core.WebPlugin {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.unsupportedMessage = 'mDNS is not supported in this browser runtime';
|
|
22
|
+
}
|
|
18
23
|
/** Electron preload bridge (if present). */
|
|
19
24
|
get electronApi() {
|
|
20
25
|
if (typeof window === 'undefined')
|
|
21
26
|
return undefined;
|
|
22
27
|
return window.mDNS || window.mdns;
|
|
23
28
|
}
|
|
29
|
+
async getPluginPlatform() {
|
|
30
|
+
const api = this.electronApi;
|
|
31
|
+
if (api === null || api === void 0 ? void 0 : api.getPluginPlatform)
|
|
32
|
+
return api.getPluginPlatform();
|
|
33
|
+
return { platform: 'web' };
|
|
34
|
+
}
|
|
24
35
|
async startBroadcast(options) {
|
|
25
36
|
const api = this.electronApi;
|
|
26
37
|
if (api === null || api === void 0 ? void 0 : api.startBroadcast)
|
|
27
38
|
return api.startBroadcast(options);
|
|
28
39
|
console.log('[WEB_NOT_SUPPORTED] startBroadcast', options);
|
|
29
|
-
|
|
30
|
-
return { publishing: true, name: '', error: false, errorMessage: null };
|
|
40
|
+
return { publishing: false, name: '', error: true, errorMessage: this.unsupportedMessage };
|
|
31
41
|
}
|
|
32
42
|
async stopBroadcast() {
|
|
33
43
|
const api = this.electronApi;
|
|
@@ -41,7 +51,7 @@ var capacitormDNS = (function (exports, core) {
|
|
|
41
51
|
if (api === null || api === void 0 ? void 0 : api.discover)
|
|
42
52
|
return api.discover(options);
|
|
43
53
|
console.log('[WEB_NOT_SUPPORTED] discover', options);
|
|
44
|
-
return { services: [], error:
|
|
54
|
+
return { services: [], error: true, errorMessage: this.unsupportedMessage, servicesFound: 0 };
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst mDNS = registerPlugin('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\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 /** 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 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
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst mDNS = registerPlugin('mDNS', {\n web: () => import('./web').then((m) => new m.mDNSWeb()),\n electron: () => Promise.resolve(window.CapacitorCustomPlatform.plugins.mDNS),\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}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,E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,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,kBAAkB,EAAE;IAClG,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW;IACpC,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,aAAa;IACvE,YAAY,OAAO,GAAG,CAAC,aAAa,EAAE;IACtC,QAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC;IACxD,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE;IACtE,IAAI;IACJ,IAAI,MAAM,QAAQ,CAAC,OAAO,GAAG,EAAE,EAAE;IACjC,QAAQ,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW;IACpC,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,QAAQ;IAClE,YAAY,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC;IACxC,QAAQ,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC;IAC5D,QAAQ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,CAAC,kBAAkB,EAAE,aAAa,EAAE,CAAC,EAAE;IACrG,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
package/docs/electron.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Electron setup
|
|
2
|
+
|
|
3
|
+
Electron support is maintained for
|
|
4
|
+
[`devioarts/capacitor-electron`](https://github.com/devioarts/capacitor-electron).
|
|
5
|
+
|
|
6
|
+
## Capacitor Electron
|
|
7
|
+
|
|
8
|
+
Use the root package API in application code, the same as iOS and Android:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { mDNS } from '@devioarts/capacitor-mdns';
|
|
12
|
+
|
|
13
|
+
await mDNS.startBroadcast({ type: '_http._tcp.', name: 'MyService', port: 9100 });
|
|
14
|
+
const platform = await mDNS.getPluginPlatform();
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The Electron runtime generator reads plugin metadata from:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { pluginSettings } from '@devioarts/capacitor-mdns/electron/settings';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The Electron main-process plugin class is exported from:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { mDNS } from '@devioarts/capacitor-mdns/electron';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Manual bridge
|
|
30
|
+
|
|
31
|
+
The older manual bridge remains available for apps that do not use
|
|
32
|
+
`devioarts/capacitor-electron`.
|
|
33
|
+
|
|
34
|
+
Install the runtime Bonjour dependency in the Electron app:
|
|
35
|
+
|
|
36
|
+
```shell
|
|
37
|
+
npm i bonjour-service@1.4.0
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Main process
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { app } from 'electron';
|
|
44
|
+
import { mDNS } from '@devioarts/capacitor-mdns/electron';
|
|
45
|
+
|
|
46
|
+
const mdns = new mDNS();
|
|
47
|
+
|
|
48
|
+
app.whenReady().then(() => {
|
|
49
|
+
mdns.init();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
app.on('before-quit', async () => {
|
|
53
|
+
await mdns.destroy();
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Preload
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const { contextBridge, ipcRenderer } = require('electron');
|
|
61
|
+
const { createMDNSAPI } = require('@devioarts/capacitor-mdns/electron/mdns-bridge.cjs');
|
|
62
|
+
|
|
63
|
+
contextBridge.exposeInMainWorld('mDNS', createMDNSAPI({ ipcRenderer }));
|
|
64
|
+
contextBridge.exposeInMainWorld('mdns', createMDNSAPI({ ipcRenderer }));
|
|
65
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Platform setup
|
|
2
|
+
|
|
3
|
+
## Android
|
|
4
|
+
|
|
5
|
+
Add the mDNS/network permissions to your Android manifest.
|
|
6
|
+
|
|
7
|
+
`android/app/src/main/AndroidManifest.xml`
|
|
8
|
+
|
|
9
|
+
```xml
|
|
10
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
11
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
12
|
+
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
|
13
|
+
|
|
14
|
+
<application>
|
|
15
|
+
<!-- Your app configuration -->
|
|
16
|
+
</application>
|
|
17
|
+
</manifest>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The plugin also declares these permissions in its own Android manifest, so they
|
|
21
|
+
are merged into your app during `npx cap sync`. Keeping them in your app
|
|
22
|
+
manifest is still useful when you want the native project to show the network
|
|
23
|
+
requirements explicitly.
|
|
24
|
+
|
|
25
|
+
On some devices, mDNS discovery can still return no results if multicast traffic is blocked by the
|
|
26
|
+
network, router, VPN, or device policy.
|
|
27
|
+
|
|
28
|
+
The plugin does not request location or `NEARBY_WIFI_DEVICES` by default. Add
|
|
29
|
+
those only if your app has separate Wi-Fi scanning or nearby-device features
|
|
30
|
+
that require them.
|
|
31
|
+
|
|
32
|
+
## iOS
|
|
33
|
+
|
|
34
|
+
Add the local network permissions and every Bonjour service type your app uses to
|
|
35
|
+
`ios/App/App/Info.plist`.
|
|
36
|
+
|
|
37
|
+
```xml
|
|
38
|
+
<key>NSLocalNetworkUsageDescription</key>
|
|
39
|
+
<string>It is needed for the correct functioning of the application</string>
|
|
40
|
+
<key>NSAppTransportSecurity</key>
|
|
41
|
+
<dict>
|
|
42
|
+
<key>NSAllowsLocalNetworking</key>
|
|
43
|
+
<true/>
|
|
44
|
+
</dict>
|
|
45
|
+
<key>NSBonjourServices</key>
|
|
46
|
+
<array>
|
|
47
|
+
<string>_http._tcp</string>
|
|
48
|
+
</array>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For a custom service such as `_capmdnse2e._tcp.`, add `_capmdnse2e._tcp` to
|
|
52
|
+
`NSBonjourServices`.
|