@cappitolian/network-discovery 0.0.11 → 0.0.12
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
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
// swift-tools-version: 5.9
|
|
2
|
-
import PackageDescription
|
|
3
|
-
|
|
4
|
-
let package = Package(
|
|
5
|
-
name: "CappitolianNetworkDiscovery",
|
|
6
|
-
platforms: [.iOS(.v15)],
|
|
7
|
-
products: [
|
|
8
|
-
.library(
|
|
9
|
-
name: "CappitolianNetworkDiscovery",
|
|
10
|
-
targets: ["NetworkDiscoveryPlugin"])
|
|
11
|
-
],
|
|
12
|
-
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "
|
|
14
|
-
],
|
|
15
|
-
targets: [
|
|
16
|
-
.target(
|
|
17
|
-
name: "NetworkDiscoveryPlugin",
|
|
18
|
-
dependencies: [
|
|
19
|
-
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
-
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
-
],
|
|
22
|
-
path: "ios/Sources/NetworkDiscoveryPlugin"),
|
|
23
|
-
.testTarget(
|
|
24
|
-
name: "NetworkDiscoveryPluginTests",
|
|
25
|
-
dependencies: ["NetworkDiscoveryPlugin"],
|
|
26
|
-
path: "ios/Tests/NetworkDiscoveryPluginTests")
|
|
27
|
-
]
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CappitolianNetworkDiscovery",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CappitolianNetworkDiscovery",
|
|
10
|
+
targets: ["NetworkDiscoveryPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "NetworkDiscoveryPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/NetworkDiscoveryPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "NetworkDiscoveryPluginTests",
|
|
25
|
+
dependencies: ["NetworkDiscoveryPlugin"],
|
|
26
|
+
path: "ios/Tests/NetworkDiscoveryPluginTests")
|
|
27
|
+
]
|
|
28
28
|
)
|
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ import { NetworkDiscovery } from '@cappitolian/network-discovery';
|
|
|
35
35
|
// Start advertising your server
|
|
36
36
|
await NetworkDiscovery.startAdvertising({
|
|
37
37
|
serviceName: 'MyAppServer',
|
|
38
|
-
serviceType: '_http._tcp', // or '_myapp._tcp' for custom service
|
|
38
|
+
serviceType: '_http._tcp', // or '_myapp._tcp' for custom service to avoid conflicts with other services
|
|
39
39
|
port: 8080,
|
|
40
40
|
txtRecord: {
|
|
41
41
|
ip: '192.168.1.100', // Your server IP
|
|
@@ -69,7 +69,7 @@ NetworkDiscovery.addListener('serviceLost', (service) => {
|
|
|
69
69
|
|
|
70
70
|
// Start discovery
|
|
71
71
|
await NetworkDiscovery.startDiscovery({
|
|
72
|
-
serviceType: '_http._tcp', // Must match the server's serviceType
|
|
72
|
+
serviceType: '_http._tcp', // Must match the server's serviceType or '_myapp._tcp' for custom service to avoid conflicts with other services
|
|
73
73
|
domain: 'local.' // Optional, defaults to 'local.'
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -94,7 +94,7 @@ async startServer() {
|
|
|
94
94
|
// Advertise server
|
|
95
95
|
await NetworkDiscovery.startAdvertising({
|
|
96
96
|
serviceName: 'MyAppServer',
|
|
97
|
-
serviceType: '_myapp._tcp'
|
|
97
|
+
serviceType: '_http._tcp', // Must match the server's serviceType or '_myapp._tcp' for custom service to avoid conflicts with other services
|
|
98
98
|
port: 8080,
|
|
99
99
|
txtRecord: {
|
|
100
100
|
ip: ip,
|
|
@@ -138,7 +138,7 @@ async findAndConnectToServer() {
|
|
|
138
138
|
|
|
139
139
|
// Start discovery
|
|
140
140
|
NetworkDiscovery.startDiscovery({
|
|
141
|
-
serviceType: '_myapp._tcp'
|
|
141
|
+
serviceType: '_http._tcp' // Must match the server's serviceType or '_myapp._tcp' for custom service to avoid conflicts with other services
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
// Timeout after 10 seconds
|
|
@@ -1,75 +1,104 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
|
|
4
|
-
@objc(NetworkDiscoveryPlugin)
|
|
5
|
-
public class NetworkDiscoveryPlugin: CAPPlugin, NetworkDiscoveryDelegate {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
implementation
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(NetworkDiscoveryPlugin)
|
|
5
|
+
public class NetworkDiscoveryPlugin: CAPPlugin, CAPBridgedPlugin, NetworkDiscoveryDelegate {
|
|
6
|
+
|
|
7
|
+
// MARK: - CAPBridgedPlugin Properties
|
|
8
|
+
public let identifier = "NetworkDiscoveryPlugin"
|
|
9
|
+
public let jsName = "NetworkDiscovery"
|
|
10
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
11
|
+
CAPPluginMethod(name: "startAdvertising", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "stopAdvertising", returnType: CAPPluginReturnPromise),
|
|
13
|
+
CAPPluginMethod(name: "startDiscovery", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "stopDiscovery", returnType: CAPPluginReturnPromise)
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
// MARK: - Properties
|
|
18
|
+
private var implementation: NetworkDiscovery?
|
|
19
|
+
|
|
20
|
+
// MARK: - Lifecycle
|
|
21
|
+
public override func load() {
|
|
22
|
+
print("✅ NetworkDiscoveryPlugin: Plugin loaded")
|
|
23
|
+
implementation = NetworkDiscovery()
|
|
24
|
+
implementation?.delegate = self
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// MARK: - Plugin Methods
|
|
28
|
+
@objc func startAdvertising(_ call: CAPPluginCall) {
|
|
29
|
+
print("📞 NetworkDiscoveryPlugin: startAdvertising() called")
|
|
30
|
+
|
|
31
|
+
guard let serviceName = call.getString("serviceName"),
|
|
32
|
+
let serviceType = call.getString("serviceType"),
|
|
33
|
+
let port = call.getInt("port") else {
|
|
34
|
+
call.reject("Missing required parameters")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let txtRecord = call.getObject("txtRecord") as? [String: String]
|
|
39
|
+
|
|
40
|
+
print("📡 NetworkDiscoveryPlugin: Starting advertising - \(serviceName)")
|
|
41
|
+
|
|
42
|
+
implementation?.startAdvertising(
|
|
43
|
+
serviceName: serviceName,
|
|
44
|
+
serviceType: serviceType,
|
|
45
|
+
port: port,
|
|
46
|
+
txtRecord: txtRecord
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
call.resolve(["success": true])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@objc func stopAdvertising(_ call: CAPPluginCall) {
|
|
53
|
+
print("📞 NetworkDiscoveryPlugin: stopAdvertising() called")
|
|
54
|
+
implementation?.stopAdvertising()
|
|
55
|
+
call.resolve(["success": true])
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@objc func startDiscovery(_ call: CAPPluginCall) {
|
|
59
|
+
print("📞 NetworkDiscoveryPlugin: startDiscovery() called")
|
|
60
|
+
|
|
61
|
+
guard let serviceType = call.getString("serviceType") else {
|
|
62
|
+
call.reject("Missing serviceType parameter")
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let domain = call.getString("domain") ?? "local."
|
|
67
|
+
|
|
68
|
+
print("🔍 NetworkDiscoveryPlugin: Starting discovery for \(serviceType)")
|
|
69
|
+
|
|
70
|
+
implementation?.startDiscovery(serviceType: serviceType, domain: domain)
|
|
71
|
+
call.resolve()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@objc func stopDiscovery(_ call: CAPPluginCall) {
|
|
75
|
+
print("📞 NetworkDiscoveryPlugin: stopDiscovery() called")
|
|
76
|
+
implementation?.stopDiscovery()
|
|
77
|
+
call.resolve(["success": true])
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// MARK: - NetworkDiscoveryDelegate
|
|
81
|
+
public func advertisingDidStart() {
|
|
82
|
+
print("✅ NetworkDiscoveryPlugin: Advertising started successfully")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public func advertisingDidFail(error: String) {
|
|
86
|
+
print("❌ NetworkDiscoveryPlugin: Advertising failed - \(error)")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public func serviceFound(serviceData: [String : Any]) {
|
|
90
|
+
print("📨 NetworkDiscoveryPlugin: Service found, notifying listeners")
|
|
91
|
+
print(" Service data: \(serviceData)")
|
|
92
|
+
notifyListeners("serviceFound", data: serviceData)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public func serviceLost(serviceData: [String : Any]) {
|
|
96
|
+
print("📨 NetworkDiscoveryPlugin: Service lost, notifying listeners")
|
|
97
|
+
print(" Service data: \(serviceData)")
|
|
98
|
+
notifyListeners("serviceLost", data: serviceData)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public func discoveryDidFail(error: String) {
|
|
102
|
+
print("❌ NetworkDiscoveryPlugin: Discovery failed - \(error)")
|
|
103
|
+
}
|
|
75
104
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappitolian/network-discovery",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "A Capacitor plugin for network service discovery using mDNS/Bonjour. Allows automatic server-client connection without manual IP configuration.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"prepublishOnly": "npm run build"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@capacitor/android": "^7.
|
|
56
|
-
"@capacitor/core": "^7.
|
|
55
|
+
"@capacitor/android": "^7.4.5",
|
|
56
|
+
"@capacitor/core": "^7.4.5",
|
|
57
57
|
"@capacitor/docgen": "^0.3.1",
|
|
58
|
-
"@capacitor/ios": "^7.
|
|
58
|
+
"@capacitor/ios": "^7.4.5",
|
|
59
59
|
"@ionic/eslint-config": "^0.4.0",
|
|
60
60
|
"@ionic/prettier-config": "^4.0.0",
|
|
61
61
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.9.3"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@capacitor/core": "
|
|
71
|
+
"@capacitor/core": ">=7.0.0"
|
|
72
72
|
},
|
|
73
73
|
"prettier": "@ionic/prettier-config",
|
|
74
74
|
"swiftlint": "@ionic/swiftlint-config",
|