react-native-zeroconf 0.17.4 → 1.0.0-rc.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.
Files changed (115) hide show
  1. package/NOTICE +2 -6
  2. package/Package.swift +19 -3
  3. package/README.md +1 -3
  4. package/android/CMakeLists.txt +64 -0
  5. package/android/build.gradle +1 -17
  6. package/android/generated/java/com/balthazargronon/RCTZeroconf/NativeZeroconfSpec.java +96 -0
  7. package/android/generated/jni/CMakeLists.txt +28 -0
  8. package/android/generated/jni/RNZeroconfSpec-generated.cpp +77 -0
  9. package/android/generated/jni/RNZeroconfSpec.h +31 -0
  10. package/android/generated/jni/react/renderer/components/RNZeroconfSpec/RNZeroconfSpecJSI.h +798 -0
  11. package/android/src/main/java/com/balthazargronon/RCTZeroconf/{ZeroconfModule.java → NsdHost.java} +97 -140
  12. package/android/src/main/java/com/balthazargronon/RCTZeroconf/NsdPayload.java +87 -0
  13. package/android/src/main/java/com/balthazargronon/RCTZeroconf/NsdPromise.java +40 -0
  14. package/android/src/main/java/com/balthazargronon/RCTZeroconf/Zeroconf.java +4 -6
  15. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfNativeSupport.java +60 -0
  16. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfOptions.java +15 -26
  17. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfReactPackage.java +5 -15
  18. package/android/src/main/java/com/balthazargronon/RCTZeroconf/nsd/NsdServiceImpl.java +90 -96
  19. package/android/src/main/jni/mdnsresponder/mDNSShared/dnssd_clientshim.c +31 -6
  20. package/cpp/Backend.cpp +16 -0
  21. package/cpp/Backend.h +116 -0
  22. package/cpp/ZeroconfModule.cpp +280 -0
  23. package/cpp/ZeroconfModule.h +144 -0
  24. package/cpp/android/NsdBackend.cpp +462 -0
  25. package/cpp/android/NsdBackend.h +61 -0
  26. package/cpp/android/ZeroconfAndroidModule.cpp +49 -0
  27. package/cpp/android/ZeroconfAndroidModule.h +15 -0
  28. package/cpp/apple/DispatchExecutor.cpp +66 -0
  29. package/cpp/apple/DispatchExecutor.h +37 -0
  30. package/cpp/apple/LocalNetworkAccess.h +19 -0
  31. package/cpp/apple/LocalNetworkAccess.mm +87 -0
  32. package/cpp/dnssd/DnssdBackend.cpp +976 -0
  33. package/cpp/dnssd/DnssdBackend.h +114 -0
  34. package/cpp/dnssd/Executor.h +28 -0
  35. package/cpp/embedded/EmbeddedExecutor.cpp +124 -0
  36. package/cpp/embedded/EmbeddedExecutor.h +57 -0
  37. package/ios/ZeroconfOnLoad.mm +34 -0
  38. package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec-generated.mm +140 -0
  39. package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec.h +189 -0
  40. package/ios/generated/ReactCodegen/RNZeroconfSpecJSI.h +798 -0
  41. package/lib/module/NativeZeroconf.js +15 -0
  42. package/lib/module/NativeZeroconf.js.map +1 -0
  43. package/lib/module/bridge.js +124 -0
  44. package/lib/module/bridge.js.map +1 -0
  45. package/{dist → lib/module}/index.js +149 -149
  46. package/lib/module/index.js.map +1 -0
  47. package/lib/module/package.json +1 -0
  48. package/lib/module/types.js +24 -0
  49. package/lib/module/types.js.map +1 -0
  50. package/lib/typescript/package.json +1 -0
  51. package/lib/typescript/src/NativeZeroconf.d.ts +75 -0
  52. package/lib/typescript/src/NativeZeroconf.d.ts.map +1 -0
  53. package/lib/typescript/src/bridge.d.ts +22 -0
  54. package/lib/typescript/src/bridge.d.ts.map +1 -0
  55. package/lib/typescript/src/index.d.ts +111 -0
  56. package/lib/typescript/src/index.d.ts.map +1 -0
  57. package/lib/typescript/src/types.d.ts +175 -0
  58. package/lib/typescript/src/types.d.ts.map +1 -0
  59. package/package.json +64 -29
  60. package/react-native-zeroconf.podspec +2 -1
  61. package/react-native.config.js +17 -0
  62. package/src/NativeZeroconf.ts +120 -0
  63. package/src/bridge.ts +153 -0
  64. package/src/index.ts +607 -0
  65. package/{index.d.ts → src/types.ts} +5 -99
  66. package/windows/RNZeroconf/RNZeroconf.vcxproj +17 -2
  67. package/windows/RNZeroconf/RNZeroconf.vcxproj.filters +0 -6
  68. package/windows/RNZeroconf/ReactPackageProvider.cpp +23 -20
  69. package/windows/RNZeroconf/WindowsBackend.cpp +156 -0
  70. package/windows/RNZeroconf/WindowsBackend.h +13 -0
  71. package/windows/RNZeroconf/ZeroconfCore.cpp +2 -2
  72. package/windows/RNZeroconf/ZeroconfCore.h +2 -2
  73. package/windows/RNZeroconf/ZeroconfWindowsModule.cpp +22 -0
  74. package/windows/RNZeroconf/ZeroconfWindowsModule.h +14 -0
  75. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroConfImplFactory.java +0 -56
  76. package/android/src/main/java/com/balthazargronon/RCTZeroconf/dnssd/DnssdImpl.java +0 -654
  77. package/android/src/main/java/com/github/druk/dnssd/BaseListener.java +0 -33
  78. package/android/src/main/java/com/github/druk/dnssd/BrowseListener.java +0 -67
  79. package/android/src/main/java/com/github/druk/dnssd/DNSRecord.java +0 -47
  80. package/android/src/main/java/com/github/druk/dnssd/DNSSD.java +0 -681
  81. package/android/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java +0 -198
  82. package/android/src/main/java/com/github/druk/dnssd/DNSSDException.java +0 -66
  83. package/android/src/main/java/com/github/druk/dnssd/DNSSDRecordRegistrar.java +0 -55
  84. package/android/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java +0 -54
  85. package/android/src/main/java/com/github/druk/dnssd/DNSSDService.java +0 -35
  86. package/android/src/main/java/com/github/druk/dnssd/DomainListener.java +0 -57
  87. package/android/src/main/java/com/github/druk/dnssd/InternalBrowseListener.java +0 -76
  88. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSD.java +0 -870
  89. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRecordRegistrar.java +0 -30
  90. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRegistration.java +0 -34
  91. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDService.java +0 -29
  92. package/android/src/main/java/com/github/druk/dnssd/InternalDomainListener.java +0 -62
  93. package/android/src/main/java/com/github/druk/dnssd/InternalQueryListener.java +0 -61
  94. package/android/src/main/java/com/github/druk/dnssd/InternalRegisterListener.java +0 -51
  95. package/android/src/main/java/com/github/druk/dnssd/InternalResolveListener.java +0 -58
  96. package/android/src/main/java/com/github/druk/dnssd/NSClass.java +0 -16
  97. package/android/src/main/java/com/github/druk/dnssd/NSType.java +0 -58
  98. package/android/src/main/java/com/github/druk/dnssd/QueryListener.java +0 -54
  99. package/android/src/main/java/com/github/druk/dnssd/RegisterListener.java +0 -46
  100. package/android/src/main/java/com/github/druk/dnssd/RegisterRecordListener.java +0 -35
  101. package/android/src/main/java/com/github/druk/dnssd/ResolveListener.java +0 -55
  102. package/android/src/main/java/com/github/druk/dnssd/TXTRecord.java +0 -293
  103. package/android/src/main/jni/Android.mk +0 -73
  104. package/android/src/main/jni/Application.mk +0 -3
  105. package/android/src/main/jni/DNSSD.java.h +0 -290
  106. package/android/src/main/jni/JNISupport.c +0 -1221
  107. package/ios/RNZeroconf/RNNetServiceSerializer.h +0 -31
  108. package/ios/RNZeroconf/RNNetServiceSerializer.m +0 -84
  109. package/ios/RNZeroconf/RNZeroconf.h +0 -17
  110. package/ios/RNZeroconf/RNZeroconf.m +0 -1025
  111. package/ios/RNZeroconf.xcodeproj/project.pbxproj +0 -261
  112. package/ios/RNZeroconf.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  113. package/src/index.js +0 -563
  114. package/windows/RNZeroconf/RNZeroconf.cpp +0 -228
  115. package/windows/RNZeroconf/RNZeroconf.h +0 -70
@@ -1,228 +0,0 @@
1
- #include "pch.h"
2
-
3
- #include "RNZeroconf.h"
4
-
5
- using namespace rnzeroconf;
6
-
7
- namespace winrt::RNZeroconf
8
- {
9
-
10
- namespace {
11
-
12
- std::wstring Wide(std::string const &value) {
13
- return Widen(value);
14
- }
15
-
16
- std::wstring StringOption(React::JSValue const &options, char const *key) {
17
- if (options.Type() != React::JSValueType::Object) {
18
- return L"";
19
- }
20
- auto const &value = options.AsObject();
21
- auto it = value.find(key);
22
- return it != value.end() && it->second.Type() == React::JSValueType::String ? Wide(it->second.AsString()) : L"";
23
- }
24
-
25
- double NumberOption(React::JSValue const &options, char const *key) {
26
- if (options.Type() != React::JSValueType::Object) {
27
- return 0;
28
- }
29
- auto const &value = options.AsObject();
30
- auto it = value.find(key);
31
- return it != value.end() && (it->second.Type() == React::JSValueType::Double || it->second.Type() == React::JSValueType::Int64)
32
- ? it->second.AsDouble()
33
- : 0;
34
- }
35
-
36
- // [[key, value], ...] from JavaScript
37
- TxtPairs ReadTxt(React::JSValue const &txt) {
38
- TxtPairs pairs;
39
- if (txt.Type() != React::JSValueType::Array) {
40
- return pairs;
41
- }
42
- for (auto const &pair : txt.AsArray()) {
43
- if (pair.Type() == React::JSValueType::Array && pair.AsArray().size() == 2) {
44
- pairs.emplace_back(Wide(pair.AsArray()[0].AsString()), Wide(pair.AsArray()[1].AsString()));
45
- }
46
- }
47
- return pairs;
48
- }
49
-
50
- React::JSValueObject ServiceObject(Service const &service) {
51
- React::JSValueArray addresses;
52
- for (auto const &address : service.addresses) {
53
- addresses.push_back(Narrow(address));
54
- }
55
- React::JSValueObject txt;
56
- for (auto const &pair : service.txt) {
57
- txt[Narrow(pair.first)] = Narrow(pair.second);
58
- }
59
- React::JSValueObject object;
60
- object["name"] = Narrow(service.name);
61
- object["fullName"] = Narrow(service.fullName);
62
- object["host"] = Narrow(service.host);
63
- object["port"] = static_cast<int64_t>(service.port);
64
- object["addresses"] = std::move(addresses);
65
- object["txt"] = std::move(txt);
66
- return object;
67
- }
68
-
69
- React::JSValueObject ErrorObject(Error const &error) {
70
- React::JSValueObject object;
71
- object["message"] = Narrow(error.message);
72
- if (error.stringCode.empty()) {
73
- object["code"] = error.code;
74
- } else {
75
- object["code"] = Narrow(error.stringCode);
76
- }
77
- object["domain"] = Narrow(error.domain);
78
- if (!error.serviceName.empty()) {
79
- object["serviceName"] = Narrow(error.serviceName);
80
- }
81
- return object;
82
- }
83
-
84
- // Rejects with the same { message, code, domain, serviceName } in userInfo as iOS and Android
85
- void Reject(React::ReactPromise<React::JSValue> const &promise, Error const &error) {
86
- React::ReactError reactError;
87
- reactError.Code = error.stringCode.empty() ? std::to_string(error.code) : Narrow(error.stringCode);
88
- reactError.Message = Narrow(error.message);
89
- reactError.UserInfo = ErrorObject(error);
90
- promise.Reject(std::move(reactError));
91
- }
92
-
93
- } // namespace
94
-
95
- void RNZeroconf::Initialize(React::ReactContext const &reactContext) noexcept {
96
- m_context = reactContext;
97
-
98
- Events events;
99
- events.start = [this](std::string const &scanId) {
100
- React::JSValueObject body;
101
- body["scanId"] = scanId;
102
- Emit(L"RNZeroconfStart", std::move(body));
103
- };
104
- events.stop = [this](std::string const &scanId) {
105
- React::JSValueObject body;
106
- body["scanId"] = scanId;
107
- Emit(L"RNZeroconfStop", std::move(body));
108
- };
109
- events.found = [this](std::string const &scanId, std::wstring const &name) {
110
- React::JSValueObject body;
111
- body["name"] = Narrow(name);
112
- body["scanId"] = scanId;
113
- Emit(L"RNZeroconfFound", std::move(body));
114
- };
115
- events.remove = [this](std::string const &scanId, std::wstring const &name) {
116
- React::JSValueObject body;
117
- body["name"] = Narrow(name);
118
- body["scanId"] = scanId;
119
- Emit(L"RNZeroconfRemove", std::move(body));
120
- };
121
- events.resolved = [this](std::string const &scanId, Service const &service) {
122
- React::JSValueObject body = ServiceObject(service);
123
- body["scanId"] = scanId;
124
- Emit(L"RNZeroconfResolved", std::move(body));
125
- };
126
- events.published = [this](Service const &service) { Emit(L"RNZeroconfServiceRegistered", ServiceObject(service)); };
127
- events.unpublished = [this](Service const &service) { Emit(L"RNZeroconfServiceUnregistered", ServiceObject(service)); };
128
- events.error = [this](std::string const &scanId, Error const &error) {
129
- React::JSValueObject body = ErrorObject(error);
130
- if (!scanId.empty()) {
131
- body["scanId"] = scanId;
132
- }
133
- Emit(L"RNZeroconfError", std::move(body));
134
- };
135
- m_zeroconf = std::make_unique<Zeroconf>(std::move(events));
136
- }
137
-
138
- void RNZeroconf::Emit(std::wstring_view eventName, React::JSValueObject body) noexcept {
139
- m_context.EmitJSEvent(L"RCTDeviceEventEmitter", eventName, std::move(body));
140
- }
141
-
142
- void RNZeroconf::scan(std::string scanId, std::string type, std::string protocol, std::string domain, React::JSValue options) noexcept {
143
- m_zeroconf->Scan(scanId, Wide(type), Wide(protocol), Wide(domain), StringOption(options, "subtype"), StringOption(options, "networkInterface"),
144
- NumberOption(options, "resolveTimeout"));
145
- }
146
-
147
- void RNZeroconf::stop(React::JSValue scanId) noexcept {
148
- if (scanId.Type() == React::JSValueType::String && !scanId.AsString().empty()) {
149
- m_zeroconf->Stop(scanId.AsString());
150
- } else {
151
- m_zeroconf->StopAll();
152
- }
153
- }
154
-
155
- void RNZeroconf::registerService(
156
- std::string type,
157
- std::string protocol,
158
- std::string domain,
159
- std::string name,
160
- int port,
161
- React::JSValue txt,
162
- React::JSValue options,
163
- React::ReactPromise<React::JSValue> promise) noexcept {
164
- // windns.h can't register subtypes
165
- if (options.Type() == React::JSValueType::Object) {
166
- auto const &object = options.AsObject();
167
- auto subtypes = object.find("subtypes");
168
- if (subtypes != object.end() && subtypes->second.Type() == React::JSValueType::Array && !subtypes->second.AsArray().empty()) {
169
- Error error;
170
- error.domain = L"RNZeroconf";
171
- error.stringCode = L"UNSUPPORTED";
172
- error.message = L"Publishing subtypes is not supported on Windows";
173
- error.serviceName = Wide(name);
174
- Reject(promise, error);
175
- return;
176
- }
177
- }
178
- m_zeroconf->Publish(
179
- Wide(type),
180
- Wide(protocol),
181
- Wide(domain),
182
- Wide(name),
183
- static_cast<uint16_t>(port),
184
- ReadTxt(txt),
185
- StringOption(options, "networkInterface"),
186
- [promise](Service const &service) mutable { promise.Resolve(React::JSValue(ServiceObject(service))); },
187
- [promise](Error const &error) mutable { Reject(promise, error); });
188
- }
189
-
190
- void RNZeroconf::unregisterService(std::string name, React::ReactPromise<React::JSValue> promise) noexcept {
191
- m_zeroconf->Unpublish(
192
- Wide(name),
193
- [promise](Service const &service) mutable { promise.Resolve(React::JSValue(ServiceObject(service))); },
194
- [promise](Error const &error) mutable { Reject(promise, error); });
195
- }
196
-
197
- void RNZeroconf::updateService(std::string name, React::JSValue txt, React::ReactPromise<React::JSValue> promise) noexcept {
198
- m_zeroconf->Update(
199
- Wide(name),
200
- ReadTxt(txt),
201
- [promise](Service const &service) mutable { promise.Resolve(React::JSValue(ServiceObject(service))); },
202
- [promise](Error const &error) mutable { Reject(promise, error); });
203
- }
204
-
205
- void RNZeroconf::resolveService(
206
- std::string name,
207
- std::string type,
208
- std::string protocol,
209
- std::string domain,
210
- React::JSValue options,
211
- React::ReactPromise<React::JSValue> promise) noexcept {
212
- m_zeroconf->ResolveService(
213
- Wide(name),
214
- Wide(type),
215
- Wide(protocol),
216
- Wide(domain),
217
- StringOption(options, "networkInterface"),
218
- NumberOption(options, "timeout"),
219
- [promise](Service const &service) mutable { promise.Resolve(React::JSValue(ServiceObject(service))); },
220
- [promise](Error const &error) mutable { Reject(promise, error); });
221
- }
222
-
223
- void RNZeroconf::checkLocalNetworkAccess(React::JSValue, React::JSValue, React::ReactPromise<React::JSValue> promise) noexcept {
224
- // Nothing to grant on Windows, as on Android before Android 17
225
- promise.Resolve(React::JSValue("granted"));
226
- }
227
-
228
- } // namespace winrt::RNZeroconf
@@ -1,70 +0,0 @@
1
- #pragma once
2
-
3
- #include "pch.h"
4
- #include "resource.h"
5
-
6
- #include "NativeModules.h"
7
- #include "ZeroconfCore.h"
8
-
9
- #include <memory>
10
- #include <string>
11
-
12
- namespace winrt::RNZeroconf
13
- {
14
-
15
- // The RNZeroconf native module on Windows, with the same methods and events as on iOS.
16
- // The DNS-SD work is done by ZeroconfCore (windns.h).
17
- REACT_MODULE(RNZeroconf)
18
- struct RNZeroconf
19
- {
20
- REACT_INIT(Initialize)
21
- void Initialize(React::ReactContext const &reactContext) noexcept;
22
-
23
- // options: resolveTimeout, subtype, networkInterface
24
- REACT_METHOD(scan)
25
- void scan(std::string scanId, std::string type, std::string protocol, std::string domain, React::JSValue options) noexcept;
26
-
27
- // An empty scanId stops every scan
28
- REACT_METHOD(stop)
29
- void stop(React::JSValue scanId) noexcept;
30
-
31
- // txt: [key, value] pairs. options: subtypes, networkInterface
32
- REACT_METHOD(registerService)
33
- void registerService(
34
- std::string type,
35
- std::string protocol,
36
- std::string domain,
37
- std::string name,
38
- int port,
39
- React::JSValue txt,
40
- React::JSValue options,
41
- React::ReactPromise<React::JSValue> promise) noexcept;
42
-
43
- REACT_METHOD(unregisterService)
44
- void unregisterService(std::string name, React::ReactPromise<React::JSValue> promise) noexcept;
45
-
46
- REACT_METHOD(updateService)
47
- void updateService(std::string name, React::JSValue txt, React::ReactPromise<React::JSValue> promise) noexcept;
48
-
49
- // options: timeout, networkInterface
50
- REACT_METHOD(resolveService)
51
- void resolveService(
52
- std::string name,
53
- std::string type,
54
- std::string protocol,
55
- std::string domain,
56
- React::JSValue options,
57
- React::ReactPromise<React::JSValue> promise) noexcept;
58
-
59
- // Windows has no Local Network permission: resolves "granted"
60
- REACT_METHOD(checkLocalNetworkAccess)
61
- void checkLocalNetworkAccess(React::JSValue type, React::JSValue timeout, React::ReactPromise<React::JSValue> promise) noexcept;
62
-
63
- private:
64
- void Emit(std::wstring_view eventName, React::JSValueObject body) noexcept;
65
-
66
- React::ReactContext m_context;
67
- std::unique_ptr<rnzeroconf::Zeroconf> m_zeroconf;
68
- };
69
-
70
- } // namespace winrt::RNZeroconf