@dawidzawada/bonjour-zeroconf 1.0.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.
Files changed (125) hide show
  1. package/BonjourZeroconf.podspec +30 -0
  2. package/LICENSE +20 -0
  3. package/README.md +35 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +128 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/dawidzawada/bonjourzeroconf/BonjourZeroconf+AddressResolver.kt +182 -0
  10. package/android/src/main/java/com/margelo/nitro/dawidzawada/bonjourzeroconf/BonjourZeroconf+Listeners.kt +45 -0
  11. package/android/src/main/java/com/margelo/nitro/dawidzawada/bonjourzeroconf/BonjourZeroconf.kt +183 -0
  12. package/android/src/main/java/com/margelo/nitro/dawidzawada/bonjourzeroconf/BonjourZeroconfPackage.kt +22 -0
  13. package/ios/AddressResolverError.swift +20 -0
  14. package/ios/BonjourZeroconf+AddressResolver.swift +133 -0
  15. package/ios/BonjourZeroconf+Listeners.swift +26 -0
  16. package/ios/BonjourZeroconf.swift +201 -0
  17. package/ios/LocalNetworkAuthorization.swift +66 -0
  18. package/ios/LocalNetworkPermission+Listeners.swift +14 -0
  19. package/ios/LocalNetworkPermission.swift +41 -0
  20. package/ios/ServiceCache.swift +30 -0
  21. package/ios/Utils/Loggy.swift +37 -0
  22. package/lib/module/index.js +9 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/permissions.ios.js +23 -0
  26. package/lib/module/permissions.ios.js.map +1 -0
  27. package/lib/module/permissions.js +9 -0
  28. package/lib/module/permissions.js.map +1 -0
  29. package/lib/module/specs/BonjourFail.js +9 -0
  30. package/lib/module/specs/BonjourFail.js.map +1 -0
  31. package/lib/module/specs/BonjourListener.js +2 -0
  32. package/lib/module/specs/BonjourListener.js.map +1 -0
  33. package/lib/module/specs/BonjourZeroconf.nitro.js +4 -0
  34. package/lib/module/specs/BonjourZeroconf.nitro.js.map +1 -0
  35. package/lib/module/specs/LocalNetworkPermission.nitro.js +4 -0
  36. package/lib/module/specs/LocalNetworkPermission.nitro.js.map +1 -0
  37. package/lib/module/specs/ScanResult.js +2 -0
  38. package/lib/module/specs/ScanResult.js.map +1 -0
  39. package/lib/module/useIsScanning.js +19 -0
  40. package/lib/module/useIsScanning.js.map +1 -0
  41. package/lib/typescript/package.json +1 -0
  42. package/lib/typescript/src/index.d.ts +9 -0
  43. package/lib/typescript/src/index.d.ts.map +1 -0
  44. package/lib/typescript/src/permissions.d.ts +3 -0
  45. package/lib/typescript/src/permissions.d.ts.map +1 -0
  46. package/lib/typescript/src/permissions.ios.d.ts +3 -0
  47. package/lib/typescript/src/permissions.ios.d.ts.map +1 -0
  48. package/lib/typescript/src/specs/BonjourFail.d.ts +6 -0
  49. package/lib/typescript/src/specs/BonjourFail.d.ts.map +1 -0
  50. package/lib/typescript/src/specs/BonjourListener.d.ts +4 -0
  51. package/lib/typescript/src/specs/BonjourListener.d.ts.map +1 -0
  52. package/lib/typescript/src/specs/BonjourZeroconf.nitro.d.ts +19 -0
  53. package/lib/typescript/src/specs/BonjourZeroconf.nitro.d.ts.map +1 -0
  54. package/lib/typescript/src/specs/LocalNetworkPermission.nitro.d.ts +9 -0
  55. package/lib/typescript/src/specs/LocalNetworkPermission.nitro.d.ts.map +1 -0
  56. package/lib/typescript/src/specs/ScanResult.d.ts +8 -0
  57. package/lib/typescript/src/specs/ScanResult.d.ts.map +1 -0
  58. package/lib/typescript/src/useIsScanning.d.ts +2 -0
  59. package/lib/typescript/src/useIsScanning.d.ts.map +1 -0
  60. package/nitro.json +20 -0
  61. package/nitrogen/generated/android/c++/JBonjourFail.hpp +62 -0
  62. package/nitrogen/generated/android/c++/JBonjourListener.hpp +68 -0
  63. package/nitrogen/generated/android/c++/JFunc_void.hpp +74 -0
  64. package/nitrogen/generated/android/c++/JFunc_void_BonjourFail.hpp +76 -0
  65. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +74 -0
  66. package/nitrogen/generated/android/c++/JFunc_void_std__vector_ScanResult_.hpp +97 -0
  67. package/nitrogen/generated/android/c++/JHybridBonjourZeroconfSpec.cpp +96 -0
  68. package/nitrogen/generated/android/c++/JHybridBonjourZeroconfSpec.hpp +69 -0
  69. package/nitrogen/generated/android/c++/JScanOptions.hpp +57 -0
  70. package/nitrogen/generated/android/c++/JScanResult.hpp +74 -0
  71. package/nitrogen/generated/android/dawidzawada_bonjourzeroconf+autolinking.cmake +82 -0
  72. package/nitrogen/generated/android/dawidzawada_bonjourzeroconf+autolinking.gradle +27 -0
  73. package/nitrogen/generated/android/dawidzawada_bonjourzeroconfOnLoad.cpp +52 -0
  74. package/nitrogen/generated/android/dawidzawada_bonjourzeroconfOnLoad.hpp +25 -0
  75. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/BonjourFail.kt +22 -0
  76. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/BonjourListener.kt +42 -0
  77. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/Func_void.kt +80 -0
  78. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/Func_void_BonjourFail.kt +80 -0
  79. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/Func_void_bool.kt +80 -0
  80. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/Func_void_std__vector_ScanResult_.kt +80 -0
  81. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/HybridBonjourZeroconfSpec.kt +90 -0
  82. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/ScanOptions.kt +38 -0
  83. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/ScanResult.kt +50 -0
  84. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dawidzawada/bonjourzeroconf/dawidzawada_bonjourzeroconfOnLoad.kt +35 -0
  85. package/nitrogen/generated/ios/BonjourZeroconf+autolinking.rb +60 -0
  86. package/nitrogen/generated/ios/BonjourZeroconf-Swift-Cxx-Bridge.cpp +90 -0
  87. package/nitrogen/generated/ios/BonjourZeroconf-Swift-Cxx-Bridge.hpp +282 -0
  88. package/nitrogen/generated/ios/BonjourZeroconf-Swift-Cxx-Umbrella.hpp +65 -0
  89. package/nitrogen/generated/ios/BonjourZeroconfAutolinking.mm +41 -0
  90. package/nitrogen/generated/ios/BonjourZeroconfAutolinking.swift +40 -0
  91. package/nitrogen/generated/ios/c++/HybridBonjourZeroconfSpecSwift.cpp +11 -0
  92. package/nitrogen/generated/ios/c++/HybridBonjourZeroconfSpecSwift.hpp +120 -0
  93. package/nitrogen/generated/ios/c++/HybridLocalNetworkPermissionSpecSwift.cpp +11 -0
  94. package/nitrogen/generated/ios/c++/HybridLocalNetworkPermissionSpecSwift.hpp +87 -0
  95. package/nitrogen/generated/ios/swift/BonjourFail.swift +44 -0
  96. package/nitrogen/generated/ios/swift/BonjourListener.swift +47 -0
  97. package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
  98. package/nitrogen/generated/ios/swift/Func_void_BonjourFail.swift +47 -0
  99. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  100. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  101. package/nitrogen/generated/ios/swift/Func_void_std__vector_ScanResult_.swift +47 -0
  102. package/nitrogen/generated/ios/swift/HybridBonjourZeroconfSpec.swift +60 -0
  103. package/nitrogen/generated/ios/swift/HybridBonjourZeroconfSpec_cxx.swift +203 -0
  104. package/nitrogen/generated/ios/swift/HybridLocalNetworkPermissionSpec.swift +57 -0
  105. package/nitrogen/generated/ios/swift/HybridLocalNetworkPermissionSpec_cxx.swift +155 -0
  106. package/nitrogen/generated/ios/swift/ScanOptions.swift +48 -0
  107. package/nitrogen/generated/ios/swift/ScanResult.swift +149 -0
  108. package/nitrogen/generated/shared/c++/BonjourFail.hpp +63 -0
  109. package/nitrogen/generated/shared/c++/BonjourListener.hpp +75 -0
  110. package/nitrogen/generated/shared/c++/HybridBonjourZeroconfSpec.cpp +26 -0
  111. package/nitrogen/generated/shared/c++/HybridBonjourZeroconfSpec.hpp +80 -0
  112. package/nitrogen/generated/shared/c++/HybridLocalNetworkPermissionSpec.cpp +22 -0
  113. package/nitrogen/generated/shared/c++/HybridLocalNetworkPermissionSpec.hpp +66 -0
  114. package/nitrogen/generated/shared/c++/ScanOptions.hpp +75 -0
  115. package/nitrogen/generated/shared/c++/ScanResult.hpp +92 -0
  116. package/package.json +169 -0
  117. package/src/index.ts +22 -0
  118. package/src/permissions.ios.ts +27 -0
  119. package/src/permissions.ts +7 -0
  120. package/src/specs/BonjourFail.ts +5 -0
  121. package/src/specs/BonjourListener.ts +3 -0
  122. package/src/specs/BonjourZeroconf.nitro.ts +20 -0
  123. package/src/specs/LocalNetworkPermission.nitro.ts +7 -0
  124. package/src/specs/ScanResult.ts +7 -0
  125. package/src/useIsScanning.ts +17 -0
@@ -0,0 +1,75 @@
1
+ ///
2
+ /// ScanOptions.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+
27
+
28
+ #include <optional>
29
+
30
+ namespace margelo::nitro::dawidzawada_bonjourzeroconf {
31
+
32
+ /**
33
+ * A struct which can be represented as a JavaScript object (ScanOptions).
34
+ */
35
+ struct ScanOptions {
36
+ public:
37
+ std::optional<double> addressResolveTimeout SWIFT_PRIVATE;
38
+
39
+ public:
40
+ ScanOptions() = default;
41
+ explicit ScanOptions(std::optional<double> addressResolveTimeout): addressResolveTimeout(addressResolveTimeout) {}
42
+ };
43
+
44
+ } // namespace margelo::nitro::dawidzawada_bonjourzeroconf
45
+
46
+ namespace margelo::nitro {
47
+
48
+ // C++ ScanOptions <> JS ScanOptions (object)
49
+ template <>
50
+ struct JSIConverter<margelo::nitro::dawidzawada_bonjourzeroconf::ScanOptions> final {
51
+ static inline margelo::nitro::dawidzawada_bonjourzeroconf::ScanOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
52
+ jsi::Object obj = arg.asObject(runtime);
53
+ return margelo::nitro::dawidzawada_bonjourzeroconf::ScanOptions(
54
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "addressResolveTimeout"))
55
+ );
56
+ }
57
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::dawidzawada_bonjourzeroconf::ScanOptions& arg) {
58
+ jsi::Object obj(runtime);
59
+ obj.setProperty(runtime, "addressResolveTimeout", JSIConverter<std::optional<double>>::toJSI(runtime, arg.addressResolveTimeout));
60
+ return obj;
61
+ }
62
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
63
+ if (!value.isObject()) {
64
+ return false;
65
+ }
66
+ jsi::Object obj = value.getObject(runtime);
67
+ if (!nitro::isPlainObject(runtime, obj)) {
68
+ return false;
69
+ }
70
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "addressResolveTimeout"))) return false;
71
+ return true;
72
+ }
73
+ };
74
+
75
+ } // namespace margelo::nitro
@@ -0,0 +1,92 @@
1
+ ///
2
+ /// ScanResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+
27
+
28
+ #include <string>
29
+ #include <optional>
30
+
31
+ namespace margelo::nitro::dawidzawada_bonjourzeroconf {
32
+
33
+ /**
34
+ * A struct which can be represented as a JavaScript object (ScanResult).
35
+ */
36
+ struct ScanResult {
37
+ public:
38
+ std::string name SWIFT_PRIVATE;
39
+ std::optional<std::string> ipv4 SWIFT_PRIVATE;
40
+ std::optional<std::string> ipv6 SWIFT_PRIVATE;
41
+ std::optional<std::string> hostname SWIFT_PRIVATE;
42
+ std::optional<double> port SWIFT_PRIVATE;
43
+
44
+ public:
45
+ ScanResult() = default;
46
+ explicit ScanResult(std::string name, std::optional<std::string> ipv4, std::optional<std::string> ipv6, std::optional<std::string> hostname, std::optional<double> port): name(name), ipv4(ipv4), ipv6(ipv6), hostname(hostname), port(port) {}
47
+ };
48
+
49
+ } // namespace margelo::nitro::dawidzawada_bonjourzeroconf
50
+
51
+ namespace margelo::nitro {
52
+
53
+ // C++ ScanResult <> JS ScanResult (object)
54
+ template <>
55
+ struct JSIConverter<margelo::nitro::dawidzawada_bonjourzeroconf::ScanResult> final {
56
+ static inline margelo::nitro::dawidzawada_bonjourzeroconf::ScanResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
57
+ jsi::Object obj = arg.asObject(runtime);
58
+ return margelo::nitro::dawidzawada_bonjourzeroconf::ScanResult(
59
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "name")),
60
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "ipv4")),
61
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "ipv6")),
62
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "hostname")),
63
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "port"))
64
+ );
65
+ }
66
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::dawidzawada_bonjourzeroconf::ScanResult& arg) {
67
+ jsi::Object obj(runtime);
68
+ obj.setProperty(runtime, "name", JSIConverter<std::string>::toJSI(runtime, arg.name));
69
+ obj.setProperty(runtime, "ipv4", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.ipv4));
70
+ obj.setProperty(runtime, "ipv6", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.ipv6));
71
+ obj.setProperty(runtime, "hostname", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.hostname));
72
+ obj.setProperty(runtime, "port", JSIConverter<std::optional<double>>::toJSI(runtime, arg.port));
73
+ return obj;
74
+ }
75
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
76
+ if (!value.isObject()) {
77
+ return false;
78
+ }
79
+ jsi::Object obj = value.getObject(runtime);
80
+ if (!nitro::isPlainObject(runtime, obj)) {
81
+ return false;
82
+ }
83
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "name"))) return false;
84
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "ipv4"))) return false;
85
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "ipv6"))) return false;
86
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "hostname"))) return false;
87
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "port"))) return false;
88
+ return true;
89
+ }
90
+ };
91
+
92
+ } // namespace margelo::nitro
package/package.json ADDED
@@ -0,0 +1,169 @@
1
+ {
2
+ "name": "@dawidzawada/bonjour-zeroconf",
3
+ "version": "1.0.0",
4
+ "description": "React Native Zeroconf scanner using Bonjour (iOS) and NSD (Android). Powered by Nitro Modules.",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.ts",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "nitrogen",
22
+ "nitro.json",
23
+ "*.podspec",
24
+ "react-native.config.js",
25
+ "!ios/build",
26
+ "!android/build",
27
+ "!android/gradle",
28
+ "!android/gradlew",
29
+ "!android/gradlew.bat",
30
+ "!android/local.properties",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__",
34
+ "!**/.*"
35
+ ],
36
+ "scripts": {
37
+ "example": "yarn workspace @dawidzawada/bonjour-zeroconf-example",
38
+ "test": "jest",
39
+ "typecheck": "tsc",
40
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
41
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
42
+ "prepare": "bob build",
43
+ "nitrogen": "nitrogen",
44
+ "release": "release-it --only-version"
45
+ },
46
+ "keywords": [
47
+ "react-native",
48
+ "ios",
49
+ "android"
50
+ ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/dawidzawada/bonjour-zeroconf.git"
54
+ },
55
+ "author": "Dawid Zawada <dawidzaw7@gmail.com> (https://github.com/dawidzawada)",
56
+ "license": "MIT",
57
+ "bugs": {
58
+ "url": "https://github.com/dawidzawada/bonjour-zeroconf/issues"
59
+ },
60
+ "homepage": "https://github.com/dawidzawada/bonjour-zeroconf#readme",
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/",
63
+ "access": "public"
64
+ },
65
+ "devDependencies": {
66
+ "@commitlint/config-conventional": "^19.8.1",
67
+ "@eslint/compat": "^1.3.2",
68
+ "@eslint/eslintrc": "^3.3.1",
69
+ "@eslint/js": "^9.35.0",
70
+ "@evilmartians/lefthook": "^1.12.3",
71
+ "@react-native/babel-preset": "0.81.1",
72
+ "@react-native/eslint-config": "^0.81.1",
73
+ "@release-it/conventional-changelog": "^10.0.1",
74
+ "@types/jest": "^29.5.14",
75
+ "@types/react": "^19.1.0",
76
+ "commitlint": "^19.8.1",
77
+ "del-cli": "^6.0.0",
78
+ "eslint": "^9.35.0",
79
+ "eslint-config-prettier": "^10.1.8",
80
+ "eslint-plugin-prettier": "^5.5.4",
81
+ "jest": "^29.7.0",
82
+ "nitrogen": "0.31.8",
83
+ "prettier": "^3.6.2",
84
+ "react": "19.1.0",
85
+ "react-native": "0.81.1",
86
+ "react-native-builder-bob": "^0.40.13",
87
+ "react-native-nitro-modules": "0.31.8",
88
+ "release-it": "^19.0.4",
89
+ "turbo": "^2.5.6",
90
+ "typescript": "^5.9.2"
91
+ },
92
+ "peerDependencies": {
93
+ "react": "*",
94
+ "react-native": "*",
95
+ "react-native-nitro-modules": "0.31.8"
96
+ },
97
+ "workspaces": [
98
+ "example"
99
+ ],
100
+ "packageManager": "yarn@3.6.1",
101
+ "jest": {
102
+ "preset": "react-native",
103
+ "modulePathIgnorePatterns": [
104
+ "<rootDir>/example/node_modules",
105
+ "<rootDir>/lib/"
106
+ ]
107
+ },
108
+ "commitlint": {
109
+ "extends": [
110
+ "@commitlint/config-conventional"
111
+ ]
112
+ },
113
+ "release-it": {
114
+ "git": {
115
+ "commitMessage": "chore: release ${version}",
116
+ "tagName": "v${version}"
117
+ },
118
+ "npm": {
119
+ "publish": true
120
+ },
121
+ "github": {
122
+ "release": true
123
+ },
124
+ "plugins": {
125
+ "@release-it/conventional-changelog": {
126
+ "preset": {
127
+ "name": "angular"
128
+ }
129
+ }
130
+ }
131
+ },
132
+ "prettier": {
133
+ "quoteProps": "consistent",
134
+ "singleQuote": true,
135
+ "tabWidth": 2,
136
+ "trailingComma": "es5",
137
+ "useTabs": false
138
+ },
139
+ "react-native-builder-bob": {
140
+ "source": "src",
141
+ "output": "lib",
142
+ "targets": [
143
+ [
144
+ "custom",
145
+ {
146
+ "script": "nitrogen",
147
+ "clean": "nitrogen/"
148
+ }
149
+ ],
150
+ [
151
+ "module",
152
+ {
153
+ "esm": true
154
+ }
155
+ ],
156
+ [
157
+ "typescript",
158
+ {
159
+ "project": "tsconfig.build.json"
160
+ }
161
+ ]
162
+ ]
163
+ },
164
+ "create-react-native-library": {
165
+ "languages": "kotlin-swift",
166
+ "type": "nitro-module",
167
+ "version": "0.54.6"
168
+ }
169
+ }
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type { BonjourZeroconf } from './specs/BonjourZeroconf.nitro';
3
+ import { useIsScanning } from './useIsScanning';
4
+ import { type ScanResult } from './specs/ScanResult';
5
+ import { type ScanOptions } from './specs/BonjourZeroconf.nitro';
6
+ import { BonjourFail } from './specs/BonjourFail';
7
+ import {
8
+ requestLocalNetworkPermission,
9
+ useLocalNetworkPermission,
10
+ } from './permissions';
11
+
12
+ export const Scanner =
13
+ NitroModules.createHybridObject<BonjourZeroconf>('BonjourZeroconf');
14
+
15
+ export {
16
+ useIsScanning,
17
+ requestLocalNetworkPermission,
18
+ useLocalNetworkPermission,
19
+ BonjourFail,
20
+ type ScanResult,
21
+ type ScanOptions,
22
+ };
@@ -0,0 +1,27 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type { LocalNetworkPermission } from './specs/LocalNetworkPermission.nitro';
3
+ import { useEffect, useState } from 'react';
4
+
5
+ const LocalNetworkPermission =
6
+ NitroModules.createHybridObject<LocalNetworkPermission>(
7
+ 'LocalNetworkPermission'
8
+ );
9
+
10
+ export const requestLocalNetworkPermission = async () => {
11
+ return await LocalNetworkPermission.requestPermission();
12
+ };
13
+
14
+ export const useLocalNetworkPermission = () => {
15
+ const [permissionGranted, setPermissionGranted] = useState(false);
16
+
17
+ useEffect(() => {
18
+ const { remove } = LocalNetworkPermission.listenForPermission((granted) => {
19
+ setPermissionGranted(granted);
20
+ });
21
+ return () => {
22
+ remove();
23
+ };
24
+ }, []);
25
+
26
+ return [permissionGranted, requestLocalNetworkPermission];
27
+ };
@@ -0,0 +1,7 @@
1
+ export const requestLocalNetworkPermission = async () => {
2
+ return true;
3
+ };
4
+
5
+ export const useLocalNetworkPermission = () => {
6
+ return [true, requestLocalNetworkPermission];
7
+ };
@@ -0,0 +1,5 @@
1
+ export enum BonjourFail {
2
+ RESOLVE_FAILED,
3
+ EXTRACTION_FAILED,
4
+ DISCOVERY_FAILED,
5
+ }
@@ -0,0 +1,3 @@
1
+ export interface BonjourListener {
2
+ remove: () => void;
3
+ }
@@ -0,0 +1,20 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { BonjourFail } from './BonjourFail';
3
+ import type { BonjourListener } from './BonjourListener';
4
+ import type { ScanResult } from './ScanResult';
5
+
6
+ export interface ScanOptions {
7
+ addressResolveTimeout?: number;
8
+ }
9
+
10
+ export interface BonjourZeroconf
11
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
12
+ readonly isScanning: boolean;
13
+ scan(type: string, domain: string, options?: ScanOptions): void;
14
+ stop(): void;
15
+ listenForScanResults(
16
+ onResult: (results: ScanResult[]) => void
17
+ ): BonjourListener;
18
+ listenForScanState(onChange: (isScanning: boolean) => void): BonjourListener;
19
+ listenForScanFail(onFail: (fail: BonjourFail) => void): BonjourListener;
20
+ }
@@ -0,0 +1,7 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { BonjourListener } from './BonjourListener';
3
+
4
+ export interface LocalNetworkPermission extends HybridObject<{ ios: 'swift' }> {
5
+ requestPermission(): Promise<boolean>;
6
+ listenForPermission(onChange: (granted: boolean) => void): BonjourListener;
7
+ }
@@ -0,0 +1,7 @@
1
+ export interface ScanResult {
2
+ name: string;
3
+ ipv4?: string;
4
+ ipv6?: string;
5
+ hostname?: string;
6
+ port?: number;
7
+ }
@@ -0,0 +1,17 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { Scanner } from './index';
3
+
4
+ export const useIsScanning = () => {
5
+ const [scanRunning, setScanRunning] = useState(false);
6
+
7
+ useEffect(() => {
8
+ const { remove } = Scanner.listenForScanState((scanning) => {
9
+ setScanRunning(scanning);
10
+ });
11
+ return () => {
12
+ remove();
13
+ };
14
+ }, []);
15
+
16
+ return scanRunning;
17
+ };