@cappitolian/network-discovery 0.0.10 → 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.
@@ -132,20 +132,12 @@ public class NetworkDiscovery {
132
132
 
133
133
  @Override
134
134
  public void onServiceResolved(NsdServiceInfo serviceInfo) {
135
- Log.d(TAG, "Android: Service RESOLVED");
136
- Log.d(TAG, " Name: " + serviceInfo.getServiceName());
137
- Log.d(TAG, " Host: " + (serviceInfo.getHost() != null ? serviceInfo.getHost().getHostAddress() : "null"));
138
- Log.d(TAG, " Port: " + serviceInfo.getPort());
139
-
135
+ Log.d(TAG, "Service resolved: " + serviceInfo);
136
+
140
137
  JSObject serviceData = buildServiceObject(serviceInfo);
141
-
142
- Log.d(TAG, "Android: Calling callback.onServiceFound with data: " + serviceData.toString());
143
-
144
138
  callback.onServiceFound(serviceData);
145
-
146
- Log.d(TAG, "Android: callback.onServiceFound COMPLETED");
147
- }
148
- });
139
+ }
140
+ });
149
141
  }
150
142
 
151
143
  @Override
@@ -1,129 +1,116 @@
1
- package com.cappitolian.plugins.networkdiscovery;
2
-
3
- import com.getcapacitor.JSObject;
4
- import com.getcapacitor.Plugin;
5
- import com.getcapacitor.PluginCall;
6
- import com.getcapacitor.PluginMethod;
7
- import com.getcapacitor.annotation.CapacitorPlugin;
8
-
9
- @CapacitorPlugin(name = "NetworkDiscovery")
10
- public class NetworkDiscoveryPlugin extends Plugin {
11
-
12
- private NetworkDiscovery implementation;
13
-
14
- @Override
15
- public void load() {
16
- implementation = new NetworkDiscovery(this, getContext());
17
- }
18
-
19
- @PluginMethod
20
- public void startAdvertising(PluginCall call) {
21
- String serviceName = call.getString("serviceName");
22
- String serviceType = call.getString("serviceType");
23
- Integer port = call.getInt("port");
24
- JSObject txtRecord = call.getObject("txtRecord");
25
-
26
- if (serviceName == null || serviceType == null || port == null) {
27
- call.reject("Missing required parameters");
28
- return;
29
- }
30
-
31
- implementation.startAdvertising(
32
- serviceName,
33
- serviceType,
34
- port,
35
- txtRecord,
36
- new NetworkDiscovery.AdvertisingCallback() {
37
- @Override
38
- public void onSuccess() {
39
- JSObject ret = new JSObject();
40
- ret.put("success", true);
41
- call.resolve(ret);
42
- }
43
-
44
- @Override
45
- public void onError(String error) {
46
- call.reject(error);
47
- }
48
- }
49
- );
50
- }
51
-
52
- @PluginMethod
53
- public void stopAdvertising(PluginCall call) {
54
- implementation.stopAdvertising(new NetworkDiscovery.StopCallback() {
55
- @Override
56
- public void onSuccess() {
57
- JSObject ret = new JSObject();
58
- ret.put("success", true);
59
- call.resolve(ret);
60
- }
61
-
62
- @Override
63
- public void onError(String error) {
64
- call.reject(error);
65
- }
66
- });
67
- }
68
-
69
- @PluginMethod
70
- public void startDiscovery(PluginCall call) {
71
- String serviceType = call.getString("serviceType");
72
-
73
- if (serviceType == null) {
74
- call.reject("Missing serviceType parameter");
75
- return;
76
- }
77
-
78
- implementation.startDiscovery(serviceType, new NetworkDiscovery.DiscoveryCallback() {
79
- @Override
80
- public void onDiscoveryStarted() {
81
- call.resolve();
82
- }
83
-
84
- @Override
85
- public void onServiceFound(JSObject service) {
86
- // ✅ IMPORTANTE: Usar getBridge().executeOnMainThread
87
- getBridge().executeOnMainThread(new Runnable() {
88
- @Override
89
- public void run() {
90
- notifyListeners("serviceFound", service);
91
- }
92
- });
93
- }
94
-
95
- @Override
96
- public void onServiceLost(JSObject service) {
97
- // ✅ IMPORTANTE: Usar getBridge().executeOnMainThread
98
- getBridge().executeOnMainThread(new Runnable() {
99
- @Override
100
- public void run() {
101
- notifyListeners("serviceLost", service);
102
- }
103
- });
104
- }
105
-
106
- @Override
107
- public void onError(String error) {
108
- call.reject(error);
109
- }
110
- });
111
- }
112
-
113
- @PluginMethod
114
- public void stopDiscovery(PluginCall call) {
115
- implementation.stopDiscovery(new NetworkDiscovery.StopCallback() {
116
- @Override
117
- public void onSuccess() {
118
- JSObject ret = new JSObject();
119
- ret.put("success", true);
120
- call.resolve(ret);
121
- }
122
-
123
- @Override
124
- public void onError(String error) {
125
- call.reject(error);
126
- }
127
- });
128
- }
1
+ package com.cappitolian.plugins.networkdiscovery;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.getcapacitor.Plugin;
5
+ import com.getcapacitor.PluginCall;
6
+ import com.getcapacitor.PluginMethod;
7
+ import com.getcapacitor.annotation.CapacitorPlugin;
8
+
9
+ @CapacitorPlugin(name = "NetworkDiscovery")
10
+ public class NetworkDiscoveryPlugin extends Plugin {
11
+ private NetworkDiscovery implementation;
12
+
13
+ @Override
14
+ public void load() {
15
+ implementation = new NetworkDiscovery(this, getContext());
16
+ }
17
+
18
+ @PluginMethod
19
+ public void startAdvertising(PluginCall call) {
20
+ String serviceName = call.getString("serviceName");
21
+ String serviceType = call.getString("serviceType");
22
+ Integer port = call.getInt("port");
23
+ JSObject txtRecord = call.getObject("txtRecord");
24
+
25
+ if (serviceName == null || serviceType == null || port == null) {
26
+ call.reject("Missing required parameters");
27
+ return;
28
+ }
29
+
30
+ implementation.startAdvertising(
31
+ serviceName,
32
+ serviceType,
33
+ port,
34
+ txtRecord,
35
+ new NetworkDiscovery.AdvertisingCallback() {
36
+ @Override
37
+ public void onSuccess() {
38
+ JSObject ret = new JSObject();
39
+ ret.put("success", true);
40
+ call.resolve(ret);
41
+ }
42
+
43
+ @Override
44
+ public void onError(String error) {
45
+ call.reject(error);
46
+ }
47
+ }
48
+ );
49
+ }
50
+
51
+ @PluginMethod
52
+ public void stopAdvertising(PluginCall call) {
53
+ implementation.stopAdvertising(new NetworkDiscovery.StopCallback() {
54
+ @Override
55
+ public void onSuccess() {
56
+ JSObject ret = new JSObject();
57
+ ret.put("success", true);
58
+ call.resolve(ret);
59
+ }
60
+
61
+ @Override
62
+ public void onError(String error) {
63
+ call.reject(error);
64
+ }
65
+ });
66
+ }
67
+
68
+ @PluginMethod
69
+ public void startDiscovery(PluginCall call) {
70
+ String serviceType = call.getString("serviceType");
71
+
72
+ if (serviceType == null) {
73
+ call.reject("Missing serviceType parameter");
74
+ return;
75
+ }
76
+
77
+ implementation.startDiscovery(serviceType, new NetworkDiscovery.DiscoveryCallback() {
78
+ @Override
79
+ public void onDiscoveryStarted() {
80
+ call.resolve();
81
+ }
82
+
83
+ @Override
84
+ public void onServiceFound(JSObject service) {
85
+ notifyListeners("serviceFound", service);
86
+ }
87
+
88
+ @Override
89
+ public void onServiceLost(JSObject service) {
90
+ notifyListeners("serviceLost", service);
91
+ }
92
+
93
+ @Override
94
+ public void onError(String error) {
95
+ call.reject(error);
96
+ }
97
+ });
98
+ }
99
+
100
+ @PluginMethod
101
+ public void stopDiscovery(PluginCall call) {
102
+ implementation.stopDiscovery(new NetworkDiscovery.StopCallback() {
103
+ @Override
104
+ public void onSuccess() {
105
+ JSObject ret = new JSObject();
106
+ ret.put("success", true);
107
+ call.resolve(ret);
108
+ }
109
+
110
+ @Override
111
+ public void onError(String error) {
112
+ call.reject(error);
113
+ }
114
+ });
115
+ }
129
116
  }
@@ -1,75 +1,104 @@
1
- import Foundation
2
- import Capacitor
3
-
4
- @objc(NetworkDiscoveryPlugin)
5
- public class NetworkDiscoveryPlugin: CAPPlugin, NetworkDiscoveryDelegate {
6
- private var implementation: NetworkDiscovery?
7
-
8
- override public func load() {
9
- implementation = NetworkDiscovery()
10
- implementation?.delegate = self
11
- }
12
-
13
- @objc func startAdvertising(_ call: CAPPluginCall) {
14
- guard let serviceName = call.getString("serviceName"),
15
- let serviceType = call.getString("serviceType"),
16
- let port = call.getInt("port") else {
17
- call.reject("Missing required parameters")
18
- return
19
- }
20
-
21
- let txtRecord = call.getObject("txtRecord") as? [String: String]
22
-
23
- implementation?.startAdvertising(
24
- serviceName: serviceName,
25
- serviceType: serviceType,
26
- port: port,
27
- txtRecord: txtRecord
28
- )
29
-
30
- call.resolve(["success": true])
31
- }
32
-
33
- @objc func stopAdvertising(_ call: CAPPluginCall) {
34
- implementation?.stopAdvertising()
35
- call.resolve(["success": true])
36
- }
37
-
38
- @objc func startDiscovery(_ call: CAPPluginCall) {
39
- guard let serviceType = call.getString("serviceType") else {
40
- call.reject("Missing serviceType parameter")
41
- return
42
- }
43
-
44
- let domain = call.getString("domain") ?? "local."
45
-
46
- implementation?.startDiscovery(serviceType: serviceType, domain: domain)
47
- call.resolve()
48
- }
49
-
50
- @objc func stopDiscovery(_ call: CAPPluginCall) {
51
- implementation?.stopDiscovery()
52
- call.resolve(["success": true])
53
- }
54
-
55
- // MARK: - NetworkDiscoveryDelegate
56
- public func advertisingDidStart() {
57
- print("Advertising started successfully")
58
- }
59
-
60
- public func advertisingDidFail(error: String) {
61
- print("Advertising failed: \(error)")
62
- }
63
-
64
- public func serviceFound(serviceData: [String : Any]) {
65
- notifyListeners("serviceFound", data: serviceData)
66
- }
67
-
68
- public func serviceLost(serviceData: [String : Any]) {
69
- notifyListeners("serviceLost", data: serviceData)
70
- }
71
-
72
- public func discoveryDidFail(error: String) {
73
- print("Discovery failed: \(error)")
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,86 +1,86 @@
1
- {
2
- "name": "@cappitolian/network-discovery",
3
- "version": "0.0.10",
4
- "description": "A Capacitor plugin for network service discovery using mDNS/Bonjour. Allows automatic server-client connection without manual IP configuration.",
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
- "ios/Sources",
14
- "ios/Tests",
15
- "Package.swift",
16
- "CappitolianNetworkDiscovery.podspec"
17
- ],
18
- "author": "Cappitolian",
19
- "license": "MIT",
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/alessandrycruz1987/network-discovery.git"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/alessandrycruz1987/network-discovery.git/issues"
26
- },
27
- "keywords": [
28
- "capacitor",
29
- "plugin",
30
- "native",
31
- "network",
32
- "discovery",
33
- "mdns",
34
- "bonjour",
35
- "nsd",
36
- "zeroconf"
37
- ],
38
- "scripts": {
39
- "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
40
- "verify:ios": "xcodebuild -scheme CappitolianNetworkDiscovery -destination generic/platform=iOS",
41
- "verify:android": "cd android && ./gradlew clean build test && cd ..",
42
- "verify:web": "npm run build",
43
- "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
44
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
45
- "eslint": "eslint . --ext ts",
46
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
47
- "swiftlint": "node-swiftlint",
48
- "docgen": "docgen --api NetworkDiscoveryPlugin --output-readme README.md --output-json dist/docs.json",
49
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
50
- "clean": "rimraf ./dist",
51
- "watch": "tsc --watch",
52
- "prepublishOnly": "npm run build"
53
- },
54
- "devDependencies": {
55
- "@capacitor/android": "^7.0.0",
56
- "@capacitor/core": "^7.0.0",
57
- "@capacitor/docgen": "^0.3.1",
58
- "@capacitor/ios": "^7.0.0",
59
- "@ionic/eslint-config": "^0.4.0",
60
- "@ionic/prettier-config": "^4.0.0",
61
- "@ionic/swiftlint-config": "^2.0.0",
62
- "eslint": "^8.57.1",
63
- "prettier": "^3.6.2",
64
- "prettier-plugin-java": "^2.7.7",
65
- "rimraf": "^6.1.0",
66
- "rollup": "^4.53.2",
67
- "swiftlint": "^2.0.0",
68
- "typescript": "^5.9.3"
69
- },
70
- "peerDependencies": {
71
- "@capacitor/core": "^7.0.0"
72
- },
73
- "prettier": "@ionic/prettier-config",
74
- "swiftlint": "@ionic/swiftlint-config",
75
- "eslintConfig": {
76
- "extends": "@ionic/eslint-config/recommended"
77
- },
78
- "capacitor": {
79
- "ios": {
80
- "src": "ios"
81
- },
82
- "android": {
83
- "src": "android"
84
- }
85
- }
1
+ {
2
+ "name": "@cappitolian/network-discovery",
3
+ "version": "0.0.12",
4
+ "description": "A Capacitor plugin for network service discovery using mDNS/Bonjour. Allows automatic server-client connection without manual IP configuration.",
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
+ "ios/Sources",
14
+ "ios/Tests",
15
+ "Package.swift",
16
+ "CappitolianNetworkDiscovery.podspec"
17
+ ],
18
+ "author": "Cappitolian",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/alessandrycruz1987/network-discovery.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/alessandrycruz1987/network-discovery.git/issues"
26
+ },
27
+ "keywords": [
28
+ "capacitor",
29
+ "plugin",
30
+ "native",
31
+ "network",
32
+ "discovery",
33
+ "mdns",
34
+ "bonjour",
35
+ "nsd",
36
+ "zeroconf"
37
+ ],
38
+ "scripts": {
39
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
40
+ "verify:ios": "xcodebuild -scheme CappitolianNetworkDiscovery -destination generic/platform=iOS",
41
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
42
+ "verify:web": "npm run build",
43
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
44
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
45
+ "eslint": "eslint . --ext ts",
46
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
47
+ "swiftlint": "node-swiftlint",
48
+ "docgen": "docgen --api NetworkDiscoveryPlugin --output-readme README.md --output-json dist/docs.json",
49
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
50
+ "clean": "rimraf ./dist",
51
+ "watch": "tsc --watch",
52
+ "prepublishOnly": "npm run build"
53
+ },
54
+ "devDependencies": {
55
+ "@capacitor/android": "^7.4.5",
56
+ "@capacitor/core": "^7.4.5",
57
+ "@capacitor/docgen": "^0.3.1",
58
+ "@capacitor/ios": "^7.4.5",
59
+ "@ionic/eslint-config": "^0.4.0",
60
+ "@ionic/prettier-config": "^4.0.0",
61
+ "@ionic/swiftlint-config": "^2.0.0",
62
+ "eslint": "^8.57.1",
63
+ "prettier": "^3.6.2",
64
+ "prettier-plugin-java": "^2.7.7",
65
+ "rimraf": "^6.1.0",
66
+ "rollup": "^4.53.2",
67
+ "swiftlint": "^2.0.0",
68
+ "typescript": "^5.9.3"
69
+ },
70
+ "peerDependencies": {
71
+ "@capacitor/core": ">=7.0.0"
72
+ },
73
+ "prettier": "@ionic/prettier-config",
74
+ "swiftlint": "@ionic/swiftlint-config",
75
+ "eslintConfig": {
76
+ "extends": "@ionic/eslint-config/recommended"
77
+ },
78
+ "capacitor": {
79
+ "ios": {
80
+ "src": "ios"
81
+ },
82
+ "android": {
83
+ "src": "android"
84
+ }
85
+ }
86
86
  }