react-native-zeroconf 0.17.3 → 1.0.0-rc.1
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/NOTICE +2 -6
- package/README.md +1 -1
- package/android/CMakeLists.txt +64 -0
- package/android/build.gradle +1 -17
- package/android/generated/java/com/balthazargronon/RCTZeroconf/NativeZeroconfSpec.java +96 -0
- package/android/generated/jni/CMakeLists.txt +28 -0
- package/android/generated/jni/RNZeroconfSpec-generated.cpp +77 -0
- package/android/generated/jni/RNZeroconfSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNZeroconfSpec/RNZeroconfSpecJSI.h +798 -0
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/{ZeroconfModule.java → NsdHost.java} +97 -140
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/NsdPayload.java +87 -0
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/NsdPromise.java +40 -0
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/Zeroconf.java +4 -6
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfNativeSupport.java +60 -0
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfOptions.java +15 -26
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfReactPackage.java +5 -15
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/nsd/NsdServiceImpl.java +90 -96
- package/android/src/main/jni/mdnsresponder/mDNSShared/dnssd_clientshim.c +31 -6
- package/cpp/Backend.cpp +16 -0
- package/cpp/Backend.h +116 -0
- package/cpp/ZeroconfModule.cpp +280 -0
- package/cpp/ZeroconfModule.h +144 -0
- package/cpp/android/NsdBackend.cpp +462 -0
- package/cpp/android/NsdBackend.h +61 -0
- package/cpp/android/ZeroconfAndroidModule.cpp +49 -0
- package/cpp/android/ZeroconfAndroidModule.h +15 -0
- package/cpp/apple/DispatchExecutor.cpp +66 -0
- package/cpp/apple/DispatchExecutor.h +37 -0
- package/cpp/apple/LocalNetworkAccess.h +19 -0
- package/cpp/apple/LocalNetworkAccess.mm +87 -0
- package/cpp/dnssd/DnssdBackend.cpp +976 -0
- package/cpp/dnssd/DnssdBackend.h +114 -0
- package/cpp/dnssd/Executor.h +28 -0
- package/cpp/embedded/EmbeddedExecutor.cpp +124 -0
- package/cpp/embedded/EmbeddedExecutor.h +57 -0
- package/ios/ZeroconfOnLoad.mm +34 -0
- package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec-generated.mm +140 -0
- package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec.h +189 -0
- package/ios/generated/ReactCodegen/RNZeroconfSpecJSI.h +798 -0
- package/lib/module/NativeZeroconf.js +15 -0
- package/lib/module/NativeZeroconf.js.map +1 -0
- package/lib/module/bridge.js +124 -0
- package/lib/module/bridge.js.map +1 -0
- package/{dist → lib/module}/index.js +149 -149
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +24 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeZeroconf.d.ts +75 -0
- package/lib/typescript/src/NativeZeroconf.d.ts.map +1 -0
- package/lib/typescript/src/bridge.d.ts +22 -0
- package/lib/typescript/src/bridge.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +111 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +175 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +64 -29
- package/react-native-zeroconf.podspec +2 -1
- package/react-native.config.js +17 -0
- package/src/NativeZeroconf.ts +120 -0
- package/src/bridge.ts +153 -0
- package/src/index.ts +607 -0
- package/{index.d.ts → src/types.ts} +5 -99
- package/windows/RNZeroconf/RNZeroconf.vcxproj +17 -2
- package/windows/RNZeroconf/RNZeroconf.vcxproj.filters +0 -6
- package/windows/RNZeroconf/ReactPackageProvider.cpp +23 -20
- package/windows/RNZeroconf/WindowsBackend.cpp +156 -0
- package/windows/RNZeroconf/WindowsBackend.h +13 -0
- package/windows/RNZeroconf/ZeroconfCore.cpp +2 -2
- package/windows/RNZeroconf/ZeroconfCore.h +2 -2
- package/windows/RNZeroconf/ZeroconfWindowsModule.cpp +22 -0
- package/windows/RNZeroconf/ZeroconfWindowsModule.h +14 -0
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroConfImplFactory.java +0 -56
- package/android/src/main/java/com/balthazargronon/RCTZeroconf/dnssd/DnssdImpl.java +0 -654
- package/android/src/main/java/com/github/druk/dnssd/BaseListener.java +0 -33
- package/android/src/main/java/com/github/druk/dnssd/BrowseListener.java +0 -67
- package/android/src/main/java/com/github/druk/dnssd/DNSRecord.java +0 -47
- package/android/src/main/java/com/github/druk/dnssd/DNSSD.java +0 -681
- package/android/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java +0 -198
- package/android/src/main/java/com/github/druk/dnssd/DNSSDException.java +0 -66
- package/android/src/main/java/com/github/druk/dnssd/DNSSDRecordRegistrar.java +0 -55
- package/android/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java +0 -54
- package/android/src/main/java/com/github/druk/dnssd/DNSSDService.java +0 -35
- package/android/src/main/java/com/github/druk/dnssd/DomainListener.java +0 -57
- package/android/src/main/java/com/github/druk/dnssd/InternalBrowseListener.java +0 -76
- package/android/src/main/java/com/github/druk/dnssd/InternalDNSSD.java +0 -870
- package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRecordRegistrar.java +0 -30
- package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRegistration.java +0 -34
- package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDService.java +0 -29
- package/android/src/main/java/com/github/druk/dnssd/InternalDomainListener.java +0 -62
- package/android/src/main/java/com/github/druk/dnssd/InternalQueryListener.java +0 -61
- package/android/src/main/java/com/github/druk/dnssd/InternalRegisterListener.java +0 -51
- package/android/src/main/java/com/github/druk/dnssd/InternalResolveListener.java +0 -58
- package/android/src/main/java/com/github/druk/dnssd/NSClass.java +0 -16
- package/android/src/main/java/com/github/druk/dnssd/NSType.java +0 -58
- package/android/src/main/java/com/github/druk/dnssd/QueryListener.java +0 -54
- package/android/src/main/java/com/github/druk/dnssd/RegisterListener.java +0 -46
- package/android/src/main/java/com/github/druk/dnssd/RegisterRecordListener.java +0 -35
- package/android/src/main/java/com/github/druk/dnssd/ResolveListener.java +0 -55
- package/android/src/main/java/com/github/druk/dnssd/TXTRecord.java +0 -293
- package/android/src/main/jni/Android.mk +0 -73
- package/android/src/main/jni/Application.mk +0 -3
- package/android/src/main/jni/DNSSD.java.h +0 -290
- package/android/src/main/jni/JNISupport.c +0 -1221
- package/ios/RNZeroconf/RNNetServiceSerializer.h +0 -31
- package/ios/RNZeroconf/RNNetServiceSerializer.m +0 -84
- package/ios/RNZeroconf/RNZeroconf.h +0 -17
- package/ios/RNZeroconf/RNZeroconf.m +0 -1025
- package/ios/RNZeroconf.xcodeproj/project.pbxproj +0 -261
- package/ios/RNZeroconf.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/src/index.js +0 -563
- package/windows/RNZeroconf/RNZeroconf.cpp +0 -228
- package/windows/RNZeroconf/RNZeroconf.h +0 -70
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const ImplType: {
|
|
2
|
-
readonly NSD: 'NSD'
|
|
3
|
-
readonly DNSSD: 'DNSSD'
|
|
4
|
-
}
|
|
5
|
-
|
|
6
1
|
/** Android only: which discovery implementation to use */
|
|
2
|
+
export const ImplType = {
|
|
3
|
+
NSD: 'NSD',
|
|
4
|
+
DNSSD: 'DNSSD',
|
|
5
|
+
} as const
|
|
6
|
+
|
|
7
7
|
export type ImplType = (typeof ImplType)[keyof typeof ImplType]
|
|
8
8
|
|
|
9
9
|
export interface Service {
|
|
@@ -158,91 +158,6 @@ export interface ServiceTypesScanOptions {
|
|
|
158
158
|
networkInterface?: string
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
/** Extends the `events` package EventEmitter */
|
|
162
|
-
export default class Zeroconf {
|
|
163
|
-
constructor()
|
|
164
|
-
|
|
165
|
-
on<E extends keyof ZeroconfEvents>(event: E, listener: ZeroconfEvents[E]): this
|
|
166
|
-
once<E extends keyof ZeroconfEvents>(event: E, listener: ZeroconfEvents[E]): this
|
|
167
|
-
addListener<E extends keyof ZeroconfEvents>(event: E, listener: ZeroconfEvents[E]): this
|
|
168
|
-
removeListener<E extends keyof ZeroconfEvents>(event: E, listener: ZeroconfEvents[E]): this
|
|
169
|
-
off<E extends keyof ZeroconfEvents>(event: E, listener: ZeroconfEvents[E]): this
|
|
170
|
-
removeAllListeners(event?: keyof ZeroconfEvents): this
|
|
171
|
-
/** Adds a listener and returns a function that removes it */
|
|
172
|
-
subscribe<E extends keyof ZeroconfEvents>(event: E, listener: ZeroconfEvents[E]): () => void
|
|
173
|
-
listenerCount(event: keyof ZeroconfEvents): number
|
|
174
|
-
|
|
175
|
-
/** Add the native event listeners (called automatically in the constructor) */
|
|
176
|
-
addDeviceListeners(): void
|
|
177
|
-
|
|
178
|
-
/** Remove the native event listeners, call it when you are done with the instance */
|
|
179
|
-
removeDeviceListeners(): void
|
|
180
|
-
|
|
181
|
-
/** All the services found so far, keyed by name */
|
|
182
|
-
getServices(): Record<string, Service>
|
|
183
|
-
|
|
184
|
-
/** Service types found by `scanServiceTypes` */
|
|
185
|
-
getServiceTypes(): ServiceType[]
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Scan for the service types advertised on the network, emits `typeFound` and `typeRemove`.
|
|
189
|
-
* On iOS it requires the `com.apple.developer.networking.multicast` entitlement.
|
|
190
|
-
*/
|
|
191
|
-
scanServiceTypes(options?: ServiceTypesScanOptions): void
|
|
192
|
-
|
|
193
|
-
/** Scan for services, defaults to `_http._tcp.` on the `local.` domain */
|
|
194
|
-
scan(options?: ScanOptions): void
|
|
195
|
-
/** @deprecated Use `scan({ type, protocol, domain, implType })` */
|
|
196
|
-
scan(type?: string, protocol?: string, domain?: string, implType?: ImplType): void
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Checks the Local Network permission. iOS can show the permission prompt when it hasn't been answered yet.
|
|
200
|
-
* Android 17 (API 37): apps targeting API 37 need `ACCESS_LOCAL_NETWORK`, requested when missing unless
|
|
201
|
-
* `request` is `false`. Resolves `'granted'` when there is nothing to grant.
|
|
202
|
-
*/
|
|
203
|
-
checkLocalNetworkAccess(
|
|
204
|
-
options?: LocalNetworkAccessOptions,
|
|
205
|
-
): Promise<'granted' | 'denied' | 'unknown'>
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Stop the current scan
|
|
209
|
-
* @param implType Android only, defaults to the implementation used by the last scan
|
|
210
|
-
*/
|
|
211
|
-
stop(implType?: ImplType): void
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Publish a service. Resolves with the published service once it is advertised, its name can differ
|
|
215
|
-
* from the requested one when that name is already taken. Rejects with a `ZeroconfError`.
|
|
216
|
-
*/
|
|
217
|
-
publishService(options: PublishOptions): Promise<PublishedService>
|
|
218
|
-
/** @deprecated Use `publishService({ type, protocol, domain, name, port, txt, implType })` */
|
|
219
|
-
publishService(
|
|
220
|
-
type: string,
|
|
221
|
-
protocol: string,
|
|
222
|
-
domain: string | undefined,
|
|
223
|
-
name: string,
|
|
224
|
-
port: number,
|
|
225
|
-
txt?: TxtRecord,
|
|
226
|
-
implType?: ImplType,
|
|
227
|
-
): Promise<PublishedService>
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Unpublish a service. Resolves once it is no longer advertised, rejects with a `ZeroconfError`
|
|
231
|
-
* (e.g. code `'NOT_PUBLISHED'`).
|
|
232
|
-
* @param implType Android only, defaults to the implementation the service was published with
|
|
233
|
-
*/
|
|
234
|
-
unpublishService(name: string, implType?: ImplType): Promise<PublishedService | null>
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Replace the TXT record of a published service, resolves with the updated service.
|
|
238
|
-
* Android `NSD` has no update: the service is published again under the same name.
|
|
239
|
-
*/
|
|
240
|
-
updateService(name: string, options: UpdateOptions): Promise<PublishedService>
|
|
241
|
-
|
|
242
|
-
/** Resolve one service by name without scanning. Rejects with code `'TIMEOUT'` when it doesn't answer in time */
|
|
243
|
-
resolveService(options: ResolveOptions): Promise<Service>
|
|
244
|
-
}
|
|
245
|
-
|
|
246
161
|
export interface UseZeroconfOptions extends ScanOptions {
|
|
247
162
|
/** Scan only while true, defaults to `true` */
|
|
248
163
|
enabled?: boolean
|
|
@@ -259,12 +174,6 @@ export interface UseZeroconfResult {
|
|
|
259
174
|
restart(): void
|
|
260
175
|
}
|
|
261
176
|
|
|
262
|
-
/**
|
|
263
|
-
* Scans while mounted and returns the resolved services. Scans again when the options change,
|
|
264
|
-
* stops and cleans up on unmount. Each hook runs its own scan, several can run at once.
|
|
265
|
-
*/
|
|
266
|
-
export function useZeroconf(options?: UseZeroconfOptions): UseZeroconfResult
|
|
267
|
-
|
|
268
177
|
export interface UseServiceTypesOptions extends ServiceTypesScanOptions {
|
|
269
178
|
/** Scan only while true, defaults to `true` */
|
|
270
179
|
enabled?: boolean
|
|
@@ -280,6 +189,3 @@ export interface UseServiceTypesResult {
|
|
|
280
189
|
/** Clears the service types and scans again */
|
|
281
190
|
restart(): void
|
|
282
191
|
}
|
|
283
|
-
|
|
284
|
-
/** Lists the service types advertised on the network while mounted */
|
|
285
|
-
export function useServiceTypes(options?: UseServiceTypesOptions): UseServiceTypesResult
|
|
@@ -83,6 +83,8 @@
|
|
|
83
83
|
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
|
84
84
|
<AdditionalIncludeDirectories>
|
|
85
85
|
$(MSBuildThisFileDirectory);
|
|
86
|
+
$(MSBuildThisFileDirectory)..\..\cpp;
|
|
87
|
+
$(MSBuildThisFileDirectory)..\..\android\generated\jni\react\renderer\components\RNZeroconfSpec;
|
|
86
88
|
%(AdditionalIncludeDirectories)
|
|
87
89
|
</AdditionalIncludeDirectories>
|
|
88
90
|
</ClCompile>
|
|
@@ -105,8 +107,9 @@
|
|
|
105
107
|
</ItemDefinitionGroup>
|
|
106
108
|
<PropertyGroup Label="UserMacros" />
|
|
107
109
|
<ItemGroup>
|
|
108
|
-
<ClInclude Include="RNZeroconf.h" />
|
|
109
110
|
<ClInclude Include="ZeroconfCore.h" />
|
|
111
|
+
<ClInclude Include="WindowsBackend.h" />
|
|
112
|
+
<ClInclude Include="ZeroconfWindowsModule.h" />
|
|
110
113
|
<ClInclude Include="ReactPackageProvider.h">
|
|
111
114
|
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
|
|
112
115
|
</ClInclude>
|
|
@@ -115,7 +118,19 @@
|
|
|
115
118
|
<ClInclude Include="targetver.h" />
|
|
116
119
|
</ItemGroup>
|
|
117
120
|
<ItemGroup>
|
|
118
|
-
|
|
121
|
+
<!-- The C++ module shared with iOS and Android, built from codegen's spec (android/generated) -->
|
|
122
|
+
<ClCompile Include="..\..\cpp\Backend.cpp">
|
|
123
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
124
|
+
</ClCompile>
|
|
125
|
+
<ClCompile Include="..\..\cpp\ZeroconfModule.cpp">
|
|
126
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
127
|
+
</ClCompile>
|
|
128
|
+
<ClCompile Include="ZeroconfWindowsModule.cpp">
|
|
129
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
130
|
+
</ClCompile>
|
|
131
|
+
<ClCompile Include="WindowsBackend.cpp">
|
|
132
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
133
|
+
</ClCompile>
|
|
119
134
|
<!-- The DNS-SD core has no React Native dependency, it is also built by test/windows/run.cmd -->
|
|
120
135
|
<ClCompile Include="ZeroconfCore.cpp">
|
|
121
136
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
<ClInclude Include="resource.h">
|
|
22
22
|
<Filter>Header Files</Filter>
|
|
23
23
|
</ClInclude>
|
|
24
|
-
<ClInclude Include="RNZeroconf.h">
|
|
25
|
-
<Filter>Header Files</Filter>
|
|
26
|
-
</ClInclude>
|
|
27
24
|
<ClInclude Include="ZeroconfCore.h">
|
|
28
25
|
<Filter>Header Files</Filter>
|
|
29
26
|
</ClInclude>
|
|
@@ -32,9 +29,6 @@
|
|
|
32
29
|
</ClInclude>
|
|
33
30
|
</ItemGroup>
|
|
34
31
|
<ItemGroup>
|
|
35
|
-
<ClCompile Include="RNZeroconf.cpp">
|
|
36
|
-
<Filter>Source Files</Filter>
|
|
37
|
-
</ClCompile>
|
|
38
32
|
<ClCompile Include="ZeroconfCore.cpp">
|
|
39
33
|
<Filter>Source Files</Filter>
|
|
40
34
|
</ClCompile>
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
#include "pch.h"
|
|
2
|
-
|
|
3
|
-
#include "ReactPackageProvider.h"
|
|
4
|
-
#if __has_include("ReactPackageProvider.g.cpp")
|
|
5
|
-
#include "ReactPackageProvider.g.cpp"
|
|
6
|
-
#endif
|
|
7
|
-
|
|
8
|
-
#include
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
namespace winrt::
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
#include "pch.h"
|
|
2
|
+
|
|
3
|
+
#include "ReactPackageProvider.h"
|
|
4
|
+
#if __has_include("ReactPackageProvider.g.cpp")
|
|
5
|
+
#include "ReactPackageProvider.g.cpp"
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <TurboModuleProvider.h>
|
|
9
|
+
|
|
10
|
+
#include "ZeroconfWindowsModule.h"
|
|
11
|
+
|
|
12
|
+
using namespace winrt::Microsoft::ReactNative;
|
|
13
|
+
|
|
14
|
+
namespace winrt::RNZeroconf::implementation
|
|
15
|
+
{
|
|
16
|
+
|
|
17
|
+
void ReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept
|
|
18
|
+
{
|
|
19
|
+
// The C++ module of every platform (cpp/ZeroconfModule), with the windns.h backend
|
|
20
|
+
AddTurboModuleProvider<facebook::react::ZeroconfWindowsModule>(packageBuilder, L"Zeroconf");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace winrt::RNZeroconf::implementation
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#include "WindowsBackend.h"
|
|
2
|
+
|
|
3
|
+
#include "ZeroconfCore.h"
|
|
4
|
+
|
|
5
|
+
#include <utility>
|
|
6
|
+
|
|
7
|
+
namespace rnzeroconf {
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
std::wstring Wide(const std::string &value) {
|
|
12
|
+
return win::Widen(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Service FromCore(const win::Service &service) {
|
|
16
|
+
Service converted;
|
|
17
|
+
converted.name = win::Narrow(service.name);
|
|
18
|
+
converted.fullName = win::Narrow(service.fullName);
|
|
19
|
+
converted.host = win::Narrow(service.host);
|
|
20
|
+
converted.port = service.port;
|
|
21
|
+
for (const auto &address : service.addresses) {
|
|
22
|
+
converted.addresses.push_back(win::Narrow(address));
|
|
23
|
+
}
|
|
24
|
+
for (const auto &[key, value] : service.txt) {
|
|
25
|
+
converted.txt.emplace_back(win::Narrow(key), win::Narrow(value));
|
|
26
|
+
}
|
|
27
|
+
return converted;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The core's codes are numbers for domain "Windows" (Win32 / DNS_STATUS), strings for "RNZeroconf"
|
|
31
|
+
Error FromCore(const win::Error &error) {
|
|
32
|
+
return Error{
|
|
33
|
+
win::Narrow(error.domain),
|
|
34
|
+
error.stringCode.empty() ? std::to_string(error.code) : win::Narrow(error.stringCode),
|
|
35
|
+
win::Narrow(error.message),
|
|
36
|
+
win::Narrow(error.serviceName)};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
win::TxtPairs ToCore(const TxtPairs &txt) {
|
|
40
|
+
win::TxtPairs converted;
|
|
41
|
+
for (const auto &[key, value] : txt) {
|
|
42
|
+
converted.emplace_back(Wide(key), Wide(value));
|
|
43
|
+
}
|
|
44
|
+
return converted;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
win::ServiceCallback ToCore(ServiceCallback resolve) {
|
|
48
|
+
return [resolve = std::move(resolve)](const win::Service &service) { resolve(FromCore(service)); };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
win::ErrorCallback ToCore(ErrorCallback reject) {
|
|
52
|
+
return [reject = std::move(reject)](const win::Error &error) { reject(FromCore(error)); };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class WindowsBackend : public Backend {
|
|
56
|
+
public:
|
|
57
|
+
explicit WindowsBackend(Events events) : core_(std::make_unique<win::Zeroconf>(CoreEvents(std::move(events)))) {}
|
|
58
|
+
|
|
59
|
+
void Scan(
|
|
60
|
+
const std::string &scanId,
|
|
61
|
+
const std::string &type,
|
|
62
|
+
const std::string &protocol,
|
|
63
|
+
const std::string &domain,
|
|
64
|
+
const ScanOptions &options) override {
|
|
65
|
+
core_->Scan(scanId, Wide(type), Wide(protocol), Wide(domain), Wide(options.subtype), Wide(options.networkInterface),
|
|
66
|
+
options.resolveTimeoutSeconds);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void Stop(const std::string &scanId) override {
|
|
70
|
+
if (scanId.empty()) {
|
|
71
|
+
core_->StopAll();
|
|
72
|
+
} else {
|
|
73
|
+
core_->Stop(scanId);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void Publish(
|
|
78
|
+
const std::string &type,
|
|
79
|
+
const std::string &protocol,
|
|
80
|
+
const std::string &domain,
|
|
81
|
+
const std::string &name,
|
|
82
|
+
uint16_t port,
|
|
83
|
+
const TxtPairs &txt,
|
|
84
|
+
const PublishOptions &options,
|
|
85
|
+
ServiceCallback resolve,
|
|
86
|
+
ErrorCallback reject) override {
|
|
87
|
+
// windns.h can't register subtypes
|
|
88
|
+
if (!options.subtypes.empty()) {
|
|
89
|
+
reject(LibraryError("UNSUPPORTED", "Publishing subtypes is not supported on Windows", name));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
core_->Publish(Wide(type), Wide(protocol), Wide(domain), Wide(name), port, ToCore(txt), Wide(options.networkInterface),
|
|
93
|
+
ToCore(std::move(resolve)), ToCore(std::move(reject)));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void Unpublish(const std::string &name, ServiceCallback resolve, ErrorCallback reject) override {
|
|
97
|
+
core_->Unpublish(Wide(name), ToCore(std::move(resolve)), ToCore(std::move(reject)));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void Update(const std::string &name, const TxtPairs &txt, ServiceCallback resolve, ErrorCallback reject) override {
|
|
101
|
+
core_->Update(Wide(name), ToCore(txt), ToCore(std::move(resolve)), ToCore(std::move(reject)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void ResolveService(
|
|
105
|
+
const std::string &name,
|
|
106
|
+
const std::string &type,
|
|
107
|
+
const std::string &protocol,
|
|
108
|
+
const std::string &domain,
|
|
109
|
+
const ResolveOptions &options,
|
|
110
|
+
ServiceCallback resolve,
|
|
111
|
+
ErrorCallback reject) override {
|
|
112
|
+
core_->ResolveService(Wide(name), Wide(type), Wide(protocol), Wide(domain), Wide(options.networkInterface), options.timeoutSeconds,
|
|
113
|
+
ToCore(std::move(resolve)), ToCore(std::move(reject)));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void Shutdown() override {
|
|
117
|
+
core_->StopAll();
|
|
118
|
+
core_->UnpublishAll();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private:
|
|
122
|
+
static win::Events CoreEvents(Events events) {
|
|
123
|
+
win::Events core;
|
|
124
|
+
core.start = events.start;
|
|
125
|
+
core.stop = events.stop;
|
|
126
|
+
core.found = [found = events.found](const std::string &scanId, const std::wstring &name) {
|
|
127
|
+
if (found) found(scanId, win::Narrow(name));
|
|
128
|
+
};
|
|
129
|
+
core.remove = [remove = events.remove](const std::string &scanId, const std::wstring &name) {
|
|
130
|
+
if (remove) remove(scanId, win::Narrow(name));
|
|
131
|
+
};
|
|
132
|
+
core.resolved = [resolved = events.resolved](const std::string &scanId, const win::Service &service) {
|
|
133
|
+
if (resolved) resolved(scanId, FromCore(service));
|
|
134
|
+
};
|
|
135
|
+
core.published = [published = events.published](const win::Service &service) {
|
|
136
|
+
if (published) published(FromCore(service));
|
|
137
|
+
};
|
|
138
|
+
core.unpublished = [unpublished = events.unpublished](const win::Service &service) {
|
|
139
|
+
if (unpublished) unpublished(FromCore(service));
|
|
140
|
+
};
|
|
141
|
+
core.error = [error = events.error](const std::string &scanId, const win::Error &value) {
|
|
142
|
+
if (error) error(scanId, FromCore(value));
|
|
143
|
+
};
|
|
144
|
+
return core;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
std::unique_ptr<win::Zeroconf> core_;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
} // namespace
|
|
151
|
+
|
|
152
|
+
std::shared_ptr<Backend> CreateWindowsBackend(Events events) {
|
|
153
|
+
return std::make_shared<WindowsBackend>(std::move(events));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
} // namespace rnzeroconf
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The Windows backend of the C++ module: ZeroconfCore (windns.h) behind cpp/Backend.h.
|
|
2
|
+
// Declared without windows.h, which stays in WindowsBackend.cpp and ZeroconfCore.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include "../../cpp/Backend.h"
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
|
|
9
|
+
namespace rnzeroconf {
|
|
10
|
+
|
|
11
|
+
std::shared_ptr<Backend> CreateWindowsBackend(Events events);
|
|
12
|
+
|
|
13
|
+
} // namespace rnzeroconf
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
#pragma comment(lib, "iphlpapi.lib")
|
|
14
14
|
#pragma comment(lib, "ws2_32.lib")
|
|
15
15
|
|
|
16
|
-
namespace rnzeroconf {
|
|
16
|
+
namespace rnzeroconf::win {
|
|
17
17
|
|
|
18
18
|
using After = std::vector<std::function<void()>>;
|
|
19
19
|
|
|
@@ -1092,4 +1092,4 @@ void Zeroconf::UnpublishAll() {
|
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
1094
|
|
|
1095
|
-
} // namespace rnzeroconf
|
|
1095
|
+
} // namespace rnzeroconf::win
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
#include <utility>
|
|
32
32
|
#include <vector>
|
|
33
33
|
|
|
34
|
-
namespace rnzeroconf {
|
|
34
|
+
namespace rnzeroconf::win {
|
|
35
35
|
|
|
36
36
|
using TxtPairs = std::vector<std::pair<std::wstring, std::wstring>>;
|
|
37
37
|
|
|
@@ -164,4 +164,4 @@ std::wstring Widen(const std::string &value);
|
|
|
164
164
|
std::string Narrow(const std::wstring &value);
|
|
165
165
|
std::wstring DescribeStatus(DWORD status);
|
|
166
166
|
|
|
167
|
-
} // namespace rnzeroconf
|
|
167
|
+
} // namespace rnzeroconf::win
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#include "ZeroconfWindowsModule.h"
|
|
2
|
+
|
|
3
|
+
#include "WindowsBackend.h"
|
|
4
|
+
|
|
5
|
+
namespace facebook::react {
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
ZeroconfPlatform WindowsPlatform() {
|
|
10
|
+
ZeroconfPlatform platform;
|
|
11
|
+
// One mDNS stack on Windows, implType is Android's
|
|
12
|
+
platform.backendKey = [](const std::string &) { return std::string("windns"); };
|
|
13
|
+
platform.createBackend = [](const std::string &, rnzeroconf::Events events) { return rnzeroconf::CreateWindowsBackend(std::move(events)); };
|
|
14
|
+
return platform;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
} // namespace
|
|
18
|
+
|
|
19
|
+
ZeroconfWindowsModule::ZeroconfWindowsModule(std::shared_ptr<CallInvoker> jsInvoker)
|
|
20
|
+
: ZeroconfModule(std::move(jsInvoker), WindowsPlatform()) {}
|
|
21
|
+
|
|
22
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The C++ module on Windows, registered with AddTurboModuleProvider in ReactPackageProvider.cpp:
|
|
2
|
+
// the windns.h backend (ZeroconfCore). Windows has no Local Network permission to grant.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include "../../cpp/ZeroconfModule.h"
|
|
6
|
+
|
|
7
|
+
namespace facebook::react {
|
|
8
|
+
|
|
9
|
+
class ZeroconfWindowsModule : public ZeroconfModule {
|
|
10
|
+
public:
|
|
11
|
+
explicit ZeroconfWindowsModule(std::shared_ptr<CallInvoker> jsInvoker);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
} // namespace facebook::react
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
package com.balthazargronon.RCTZeroconf;
|
|
2
|
-
|
|
3
|
-
import com.balthazargronon.RCTZeroconf.nsd.NsdServiceImpl;
|
|
4
|
-
import com.balthazargronon.RCTZeroconf.dnssd.DnssdImpl;
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
-
import com.facebook.react.bridge.ReactContext;
|
|
7
|
-
|
|
8
|
-
import java.util.ArrayList;
|
|
9
|
-
import java.util.HashMap;
|
|
10
|
-
import java.util.List;
|
|
11
|
-
import java.util.Map;
|
|
12
|
-
|
|
13
|
-
public class ZeroConfImplFactory {
|
|
14
|
-
public static final String NSD_IMPL = "NSD";
|
|
15
|
-
public static final String DNSSD_IMPL = "DNSSD";
|
|
16
|
-
|
|
17
|
-
private Map<String, Zeroconf> zeroconfMap = new HashMap<>();
|
|
18
|
-
|
|
19
|
-
private ZeroconfModule zeroconfModule;
|
|
20
|
-
private ReactApplicationContext context;
|
|
21
|
-
|
|
22
|
-
public ZeroConfImplFactory(ZeroconfModule zeroconfModule, ReactApplicationContext context) {
|
|
23
|
-
this.zeroconfModule = zeroconfModule;
|
|
24
|
-
this.context = context;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public Zeroconf getZeroconf(String implType) {
|
|
28
|
-
if (implType == null || implType.trim().isEmpty()) implType = ZeroConfImplFactory.NSD_IMPL;
|
|
29
|
-
return getOrCreateImpl(implType);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private Zeroconf getOrCreateImpl(String implType) {
|
|
33
|
-
if (!zeroconfMap.containsKey(implType)) {
|
|
34
|
-
switch (implType) {
|
|
35
|
-
case NSD_IMPL:
|
|
36
|
-
zeroconfMap.put(NSD_IMPL, new NsdServiceImpl(zeroconfModule, context));
|
|
37
|
-
break;
|
|
38
|
-
case DNSSD_IMPL:
|
|
39
|
-
zeroconfMap.put(DNSSD_IMPL, new DnssdImpl(zeroconfModule, context));
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
throw new IllegalArgumentException(String.format("%s implType is not supported. Only %s and %s are supported", implType, NSD_IMPL, DNSSD_IMPL));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return zeroconfMap.get(implType);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Implementations that have already been created, without instantiating new ones
|
|
51
|
-
*/
|
|
52
|
-
public List<Zeroconf> getCreatedImpls() {
|
|
53
|
-
return new ArrayList<>(zeroconfMap.values());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|