@devioarts/capacitor-mdns 0.0.2
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/DevioartsCapacitorMdns.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +248 -0
- package/android/build.gradle +64 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/mDNS.kt +221 -0
- package/android/src/main/java/com/devioarts/capacitor/mdns/mDNSPlugin.kt +157 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +457 -0
- package/dist/esm/definitions.d.ts +190 -0
- package/dist/esm/definitions.js +3 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +17 -0
- package/dist/esm/web.js +41 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +55 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +58 -0
- package/dist/plugin.js.map +1 -0
- package/electron/global.d.ts +28 -0
- package/electron/mdns-bridge.cjs +29 -0
- package/electron/mdns.ts +267 -0
- package/ios/Sources/mDNSPlugin/mDNS.swift +436 -0
- package/ios/Sources/mDNSPlugin/mDNSPlugin.swift +125 -0
- package/ios/Tests/mDNSPluginTests/mDNSPluginTests.swift +15 -0
- package/package.json +96 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Capacitor bridge for the iOS mDNS plugin.
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Exposes the native MDNS manager to JavaScript.
|
|
9
|
+
* - Validates and normalizes params (ensures trailing dot in type, sensible defaults).
|
|
10
|
+
* - Never rejects on runtime errors; always resolves with { error, errorMessage }.
|
|
11
|
+
*
|
|
12
|
+
* Methods:
|
|
13
|
+
* - startBroadcast({ type?, name?, port, txt? })
|
|
14
|
+
* - stopBroadcast()
|
|
15
|
+
* - discover({ type?, name?, timeout? })
|
|
16
|
+
*/
|
|
17
|
+
@objc(mDNSPlugin)
|
|
18
|
+
public class mDNSPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
19
|
+
|
|
20
|
+
public let identifier = "mDNSPlugin"
|
|
21
|
+
public let jsName = "mDNS"
|
|
22
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
23
|
+
CAPPluginMethod(name: "startBroadcast", returnType: CAPPluginReturnPromise),
|
|
24
|
+
CAPPluginMethod(name: "stopBroadcast", returnType: CAPPluginReturnPromise),
|
|
25
|
+
CAPPluginMethod(name: "discover", returnType: CAPPluginReturnPromise)
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
private let mdns = MDNS()
|
|
29
|
+
|
|
30
|
+
// MARK: - Helpers
|
|
31
|
+
|
|
32
|
+
private func jnull(_ v: String?) -> Any {
|
|
33
|
+
return v ?? NSNull()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private func normalizeType(_ raw: String?) -> String {
|
|
37
|
+
var t = raw ?? "_http._tcp."
|
|
38
|
+
if t.last != "." { t += "." }
|
|
39
|
+
return t
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// MARK: - API
|
|
43
|
+
|
|
44
|
+
/// startBroadcast({ type?, name?, port, txt? })
|
|
45
|
+
@objc public func startBroadcast(_ call: CAPPluginCall) {
|
|
46
|
+
let type = normalizeType(call.getString("type"))
|
|
47
|
+
let name = (call.getString("name")?.trimmingCharacters(in: .whitespacesAndNewlines)).flatMap { $0.isEmpty ? nil : $0 } ?? "DevIOArtsMDNS"
|
|
48
|
+
let port = call.getInt("port") ?? 0
|
|
49
|
+
let txt = call.getObject("txt") as? [String: String]
|
|
50
|
+
|
|
51
|
+
guard port > 0 else {
|
|
52
|
+
call.resolve([
|
|
53
|
+
"publishing": false,
|
|
54
|
+
"name": "",
|
|
55
|
+
"error": true,
|
|
56
|
+
"errorMessage": "Missing/invalid port"
|
|
57
|
+
])
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
mdns.broadcast(type: type, name: name, port: port, txt: txt) { result in
|
|
62
|
+
switch result {
|
|
63
|
+
case .success(let finalName):
|
|
64
|
+
call.resolve([
|
|
65
|
+
"publishing": true,
|
|
66
|
+
"name": finalName,
|
|
67
|
+
"error": false,
|
|
68
|
+
"errorMessage": NSNull()
|
|
69
|
+
])
|
|
70
|
+
case .failure(let err):
|
|
71
|
+
call.resolve([
|
|
72
|
+
"publishing": false,
|
|
73
|
+
"name": "",
|
|
74
|
+
"error": true,
|
|
75
|
+
"errorMessage": self.jnull(err.localizedDescription)
|
|
76
|
+
])
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// stopBroadcast()
|
|
82
|
+
@objc public func stopBroadcast(_ call: CAPPluginCall) {
|
|
83
|
+
do {
|
|
84
|
+
try mdns.stopBroadcast()
|
|
85
|
+
call.resolve([
|
|
86
|
+
"publishing": false,
|
|
87
|
+
"error": false,
|
|
88
|
+
"errorMessage": NSNull()
|
|
89
|
+
])
|
|
90
|
+
} catch {
|
|
91
|
+
call.resolve([
|
|
92
|
+
"publishing": false,
|
|
93
|
+
"error": true,
|
|
94
|
+
"errorMessage": jnull(error.localizedDescription)
|
|
95
|
+
])
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// discover({ type?, name?, timeout? })
|
|
100
|
+
@objc public func discover(_ call: CAPPluginCall) {
|
|
101
|
+
let type = normalizeType(call.getString("type"))
|
|
102
|
+
let targetName = call.getString("name")
|
|
103
|
+
let timeout = call.getInt("timeout") ?? 3000
|
|
104
|
+
let useNW = call.getBool("useNW") ?? true
|
|
105
|
+
|
|
106
|
+
mdns.discover(type: type, name: targetName, timeoutMs: timeout, useNW: useNW) { result in
|
|
107
|
+
switch result {
|
|
108
|
+
case .success(let services):
|
|
109
|
+
call.resolve([
|
|
110
|
+
"error": false,
|
|
111
|
+
"errorMessage": NSNull(),
|
|
112
|
+
"servicesFound": services.count,
|
|
113
|
+
"services": services
|
|
114
|
+
])
|
|
115
|
+
case .failure(let err):
|
|
116
|
+
call.resolve([
|
|
117
|
+
"error": true,
|
|
118
|
+
"errorMessage": self.jnull(err.localizedDescription),
|
|
119
|
+
"servicesFound": 0,
|
|
120
|
+
"services": []
|
|
121
|
+
])
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import mDNSPlugin
|
|
3
|
+
|
|
4
|
+
class mDNSTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = mDNS()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devioarts/capacitor-mdns",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "mDNS plugin for CapacitorJS",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"electron/",
|
|
14
|
+
"ios/Sources",
|
|
15
|
+
"ios/Tests",
|
|
16
|
+
"Package.swift",
|
|
17
|
+
"DevioartsCapacitorMdns.podspec"
|
|
18
|
+
],
|
|
19
|
+
"author": "Andy",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/devioarts/capacitor-mdns.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/devioarts/capacitor-mdns/issues"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"capacitor",
|
|
30
|
+
"plugin",
|
|
31
|
+
"native",
|
|
32
|
+
"multicast-dns",
|
|
33
|
+
"mdns",
|
|
34
|
+
"bonjour",
|
|
35
|
+
"zeroconf",
|
|
36
|
+
"zero-configuration",
|
|
37
|
+
"ios",
|
|
38
|
+
"android",
|
|
39
|
+
"electron"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
43
|
+
"verify:ios": "xcodebuild -scheme DevioartsCapacitorMdns -destination generic/platform=iOS",
|
|
44
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
45
|
+
"verify:web": "npm run build",
|
|
46
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
47
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
48
|
+
"eslint": "eslint . --ext ts",
|
|
49
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
50
|
+
"swiftlint": "node-swiftlint",
|
|
51
|
+
"docgen": "docgen --api mDNSPlugin --output-readme README.md --output-json dist/docs.json",
|
|
52
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
53
|
+
"clean": "rimraf ./dist",
|
|
54
|
+
"watch": "tsc --watch",
|
|
55
|
+
"test": "echo \"No test specified\"",
|
|
56
|
+
"prepublishOnly": "npm run build",
|
|
57
|
+
"release": "npm publish --access public"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@capacitor/android": "^7.0.0",
|
|
61
|
+
"@capacitor/core": "^7.0.0",
|
|
62
|
+
"@capacitor/docgen": "^0.3.0",
|
|
63
|
+
"@capacitor/ios": "^7.0.0",
|
|
64
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
65
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
66
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
67
|
+
"eslint": "^8.57.0",
|
|
68
|
+
"prettier": "^3.4.2",
|
|
69
|
+
"prettier-plugin-java": "^2.6.6",
|
|
70
|
+
"rimraf": "^6.0.1",
|
|
71
|
+
"rollup": "^4.30.1",
|
|
72
|
+
"swiftlint": "^2.0.0",
|
|
73
|
+
"typescript": "~4.1.5",
|
|
74
|
+
"electron": "^37.3.1",
|
|
75
|
+
"bonjour-service": "^1.3.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@capacitor/core": ">=7.0.0"
|
|
79
|
+
},
|
|
80
|
+
"prettier": "@ionic/prettier-config",
|
|
81
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
82
|
+
"eslintConfig": {
|
|
83
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
84
|
+
},
|
|
85
|
+
"capacitor": {
|
|
86
|
+
"ios": {
|
|
87
|
+
"src": "ios"
|
|
88
|
+
},
|
|
89
|
+
"android": {
|
|
90
|
+
"src": "android"
|
|
91
|
+
},
|
|
92
|
+
"electron": {
|
|
93
|
+
"src": "electron"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|