@cappitolian/network-discovery 0.0.4 → 0.0.6

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
@@ -10,7 +10,7 @@ let package = Package(
10
10
  targets: ["NetworkDiscoveryPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
14
  ],
15
15
  targets: [
16
16
  .target(
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
@@ -2,15 +2,32 @@ import Foundation
2
2
  import Capacitor
3
3
 
4
4
  @objc(NetworkDiscoveryPlugin)
5
- public class NetworkDiscoveryPlugin: CAPPlugin, NetworkDiscoveryDelegate {
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
6
18
  private var implementation: NetworkDiscovery?
7
19
 
8
- override public func load() {
20
+ // MARK: - Lifecycle
21
+ public override func load() {
22
+ print("✅ NetworkDiscoveryPlugin: Plugin loaded")
9
23
  implementation = NetworkDiscovery()
10
24
  implementation?.delegate = self
11
25
  }
12
26
 
27
+ // MARK: - Plugin Methods
13
28
  @objc func startAdvertising(_ call: CAPPluginCall) {
29
+ print("📞 NetworkDiscoveryPlugin: startAdvertising() called")
30
+
14
31
  guard let serviceName = call.getString("serviceName"),
15
32
  let serviceType = call.getString("serviceType"),
16
33
  let port = call.getInt("port") else {
@@ -20,6 +37,8 @@ public class NetworkDiscoveryPlugin: CAPPlugin, NetworkDiscoveryDelegate {
20
37
 
21
38
  let txtRecord = call.getObject("txtRecord") as? [String: String]
22
39
 
40
+ print("📡 NetworkDiscoveryPlugin: Starting advertising - \(serviceName)")
41
+
23
42
  implementation?.startAdvertising(
24
43
  serviceName: serviceName,
25
44
  serviceType: serviceType,
@@ -31,11 +50,14 @@ public class NetworkDiscoveryPlugin: CAPPlugin, NetworkDiscoveryDelegate {
31
50
  }
32
51
 
33
52
  @objc func stopAdvertising(_ call: CAPPluginCall) {
53
+ print("📞 NetworkDiscoveryPlugin: stopAdvertising() called")
34
54
  implementation?.stopAdvertising()
35
55
  call.resolve(["success": true])
36
56
  }
37
57
 
38
58
  @objc func startDiscovery(_ call: CAPPluginCall) {
59
+ print("📞 NetworkDiscoveryPlugin: startDiscovery() called")
60
+
39
61
  guard let serviceType = call.getString("serviceType") else {
40
62
  call.reject("Missing serviceType parameter")
41
63
  return
@@ -43,33 +65,40 @@ public class NetworkDiscoveryPlugin: CAPPlugin, NetworkDiscoveryDelegate {
43
65
 
44
66
  let domain = call.getString("domain") ?? "local."
45
67
 
68
+ print("🔍 NetworkDiscoveryPlugin: Starting discovery for \(serviceType)")
69
+
46
70
  implementation?.startDiscovery(serviceType: serviceType, domain: domain)
47
71
  call.resolve()
48
72
  }
49
73
 
50
74
  @objc func stopDiscovery(_ call: CAPPluginCall) {
75
+ print("📞 NetworkDiscoveryPlugin: stopDiscovery() called")
51
76
  implementation?.stopDiscovery()
52
77
  call.resolve(["success": true])
53
78
  }
54
79
 
55
80
  // MARK: - NetworkDiscoveryDelegate
56
81
  public func advertisingDidStart() {
57
- print("Advertising started successfully")
82
+ print("✅ NetworkDiscoveryPlugin: Advertising started successfully")
58
83
  }
59
84
 
60
85
  public func advertisingDidFail(error: String) {
61
- print("Advertising failed: \(error)")
86
+ print("❌ NetworkDiscoveryPlugin: Advertising failed - \(error)")
62
87
  }
63
88
 
64
89
  public func serviceFound(serviceData: [String : Any]) {
90
+ print("📨 NetworkDiscoveryPlugin: Service found, notifying listeners")
91
+ print(" Service data: \(serviceData)")
65
92
  notifyListeners("serviceFound", data: serviceData)
66
93
  }
67
94
 
68
95
  public func serviceLost(serviceData: [String : Any]) {
96
+ print("📨 NetworkDiscoveryPlugin: Service lost, notifying listeners")
97
+ print(" Service data: \(serviceData)")
69
98
  notifyListeners("serviceLost", data: serviceData)
70
99
  }
71
100
 
72
101
  public func discoveryDidFail(error: String) {
73
- print("Discovery failed: \(error)")
102
+ print("❌ NetworkDiscoveryPlugin: Discovery failed - \(error)")
74
103
  }
75
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappitolian/network-discovery",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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.0.0",
56
- "@capacitor/core": "^7.0.0",
55
+ "@capacitor/android": "^7.4.5",
56
+ "@capacitor/core": "^7.4.5",
57
57
  "@capacitor/docgen": "^0.3.1",
58
- "@capacitor/ios": "^7.0.0",
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": "^7.0.0"
71
+ "@capacitor/core": ">=7.0.0"
72
72
  },
73
73
  "prettier": "@ionic/prettier-config",
74
74
  "swiftlint": "@ionic/swiftlint-config",