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.
- package/NOTICE +2 -6
- package/Package.swift +19 -3
- package/README.md +1 -3
- 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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// The native module's interface: codegen generates its C++ spec (cpp/ZeroconfModule implements it).
|
|
2
|
+
// JavaScript only reaches it through src/index.ts.
|
|
3
|
+
import { TurboModuleRegistry, type CodegenTypes, type TurboModule } from 'react-native'
|
|
4
|
+
|
|
5
|
+
export type TxtEntry = {
|
|
6
|
+
key: string
|
|
7
|
+
value: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type NativeService = {
|
|
11
|
+
name: string
|
|
12
|
+
fullName: string
|
|
13
|
+
host: string
|
|
14
|
+
port: number
|
|
15
|
+
addresses: string[]
|
|
16
|
+
txt: TxtEntry[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// code is a string for domain 'RNZeroconf' ('TIMEOUT'), the platform's number as a string otherwise ('-65555')
|
|
20
|
+
export type NativeError = {
|
|
21
|
+
message: string
|
|
22
|
+
code: string
|
|
23
|
+
domain: string
|
|
24
|
+
serviceName: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A promise settles with one or the other: rejections would lose code and domain on some platforms
|
|
28
|
+
export type NativeResult = {
|
|
29
|
+
service?: NativeService
|
|
30
|
+
error?: NativeError
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type NativeAccessResult = {
|
|
34
|
+
status?: string
|
|
35
|
+
error?: NativeError
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ScanEvent = {
|
|
39
|
+
scanId: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type NameEvent = {
|
|
43
|
+
scanId: string
|
|
44
|
+
name: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ResolvedEvent = {
|
|
48
|
+
scanId: string
|
|
49
|
+
service: NativeService
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// scanId is empty for errors that are not about a scan
|
|
53
|
+
export type ErrorEvent = {
|
|
54
|
+
scanId: string
|
|
55
|
+
error: NativeError
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type NativeScanOptions = {
|
|
59
|
+
resolveTimeout?: number
|
|
60
|
+
subtype?: string
|
|
61
|
+
networkInterface?: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type NativePublishOptions = {
|
|
65
|
+
subtypes?: string[]
|
|
66
|
+
networkInterface?: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type NativeResolveOptions = {
|
|
70
|
+
timeout?: number
|
|
71
|
+
networkInterface?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface Spec extends TurboModule {
|
|
75
|
+
// implType picks the Android implementation ('NSD' or 'DNSSD'), the other platforms ignore it
|
|
76
|
+
scan(
|
|
77
|
+
scanId: string,
|
|
78
|
+
type: string,
|
|
79
|
+
protocol: string,
|
|
80
|
+
domain: string,
|
|
81
|
+
implType: string,
|
|
82
|
+
options: NativeScanOptions,
|
|
83
|
+
): void
|
|
84
|
+
// An empty scanId stops every scan
|
|
85
|
+
stop(scanId: string, implType: string): void
|
|
86
|
+
registerService(
|
|
87
|
+
type: string,
|
|
88
|
+
protocol: string,
|
|
89
|
+
domain: string,
|
|
90
|
+
name: string,
|
|
91
|
+
port: number,
|
|
92
|
+
txt: TxtEntry[],
|
|
93
|
+
implType: string,
|
|
94
|
+
options: NativePublishOptions,
|
|
95
|
+
): Promise<NativeResult>
|
|
96
|
+
updateService(name: string, txt: TxtEntry[], implType: string): Promise<NativeResult>
|
|
97
|
+
unregisterService(name: string, implType: string): Promise<NativeResult>
|
|
98
|
+
resolveService(
|
|
99
|
+
name: string,
|
|
100
|
+
type: string,
|
|
101
|
+
protocol: string,
|
|
102
|
+
domain: string,
|
|
103
|
+
implType: string,
|
|
104
|
+
options: NativeResolveOptions,
|
|
105
|
+
): Promise<NativeResult>
|
|
106
|
+
// An empty type uses the first one in NSBonjourServices (iOS)
|
|
107
|
+
checkLocalNetworkAccess(type: string, timeout: number): Promise<NativeAccessResult>
|
|
108
|
+
|
|
109
|
+
readonly onStart: CodegenTypes.EventEmitter<ScanEvent>
|
|
110
|
+
readonly onStop: CodegenTypes.EventEmitter<ScanEvent>
|
|
111
|
+
readonly onFound: CodegenTypes.EventEmitter<NameEvent>
|
|
112
|
+
readonly onRemove: CodegenTypes.EventEmitter<NameEvent>
|
|
113
|
+
readonly onResolved: CodegenTypes.EventEmitter<ResolvedEvent>
|
|
114
|
+
readonly onError: CodegenTypes.EventEmitter<ErrorEvent>
|
|
115
|
+
readonly onPublished: CodegenTypes.EventEmitter<NativeService>
|
|
116
|
+
readonly onUnpublished: CodegenTypes.EventEmitter<NativeService>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Null when the module isn't in the app: Expo Go, or an app not rebuilt after installing the library
|
|
120
|
+
export default TurboModuleRegistry.get<Spec>('Zeroconf')
|
package/src/bridge.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// The C++ module (src/NativeZeroconf.ts) in the shapes the class works with: TXT records as pairs,
|
|
2
|
+
// error codes as numbers for the platform domains, and promises rejecting with { userInfo }
|
|
3
|
+
import NativeZeroconf, {
|
|
4
|
+
type NativeError,
|
|
5
|
+
type NativeResult,
|
|
6
|
+
type NativeService,
|
|
7
|
+
type TxtEntry,
|
|
8
|
+
} from './NativeZeroconf'
|
|
9
|
+
import type { ImplType, PublishedService, Service, ZeroconfError } from './types'
|
|
10
|
+
|
|
11
|
+
export type LocalNetworkAccess = 'granted' | 'denied' | 'unknown'
|
|
12
|
+
|
|
13
|
+
export type BridgeEvent =
|
|
14
|
+
'start' | 'stop' | 'found' | 'remove' | 'resolved' | 'error' | 'published' | 'unpublished'
|
|
15
|
+
|
|
16
|
+
// Event payloads as the class handles them: scan events carry their scan id, errors are
|
|
17
|
+
// { message, code, domain, serviceName }
|
|
18
|
+
export interface BridgePayload {
|
|
19
|
+
scanId?: string
|
|
20
|
+
name?: string
|
|
21
|
+
[key: string]: unknown
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Bridge {
|
|
25
|
+
scan(
|
|
26
|
+
scanId: string,
|
|
27
|
+
type: string,
|
|
28
|
+
protocol: string,
|
|
29
|
+
domain: string,
|
|
30
|
+
implType: ImplType,
|
|
31
|
+
options: Record<string, unknown>,
|
|
32
|
+
): void
|
|
33
|
+
stop(scanId: string, implType: ImplType): void
|
|
34
|
+
registerService(
|
|
35
|
+
type: string,
|
|
36
|
+
protocol: string,
|
|
37
|
+
domain: string,
|
|
38
|
+
name: string,
|
|
39
|
+
port: number,
|
|
40
|
+
txt: Array<[string, string]>,
|
|
41
|
+
implType: ImplType,
|
|
42
|
+
options: Record<string, unknown>,
|
|
43
|
+
): Promise<PublishedService>
|
|
44
|
+
updateService(
|
|
45
|
+
name: string,
|
|
46
|
+
txt: Array<[string, string]>,
|
|
47
|
+
implType: ImplType,
|
|
48
|
+
): Promise<PublishedService>
|
|
49
|
+
unregisterService(name: string, implType: ImplType): Promise<PublishedService | null>
|
|
50
|
+
resolveService(
|
|
51
|
+
name: string,
|
|
52
|
+
type: string,
|
|
53
|
+
protocol: string,
|
|
54
|
+
domain: string,
|
|
55
|
+
implType: ImplType,
|
|
56
|
+
options: Record<string, unknown>,
|
|
57
|
+
): Promise<Omit<Service, 'ipv4' | 'ipv6'> | null>
|
|
58
|
+
// iOS: a service type from NSBonjourServices to check with. Android: the permission check
|
|
59
|
+
checkLocalNetworkAccess(type: string | null, timeout: number): Promise<LocalNetworkAccess>
|
|
60
|
+
listen(event: BridgeEvent, handler: (payload: BridgePayload) => void): { remove(): void }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The C++ module
|
|
64
|
+
|
|
65
|
+
// Codes are strings natively: numbers for the platform domains ('-65555'), names for the library's ('TIMEOUT')
|
|
66
|
+
const fromNativeError = (error: NativeError) => ({
|
|
67
|
+
message: error.message,
|
|
68
|
+
code: error.domain === 'RNZeroconf' ? error.code : Number(error.code),
|
|
69
|
+
domain: error.domain as ZeroconfError['domain'],
|
|
70
|
+
...(error.serviceName ? { serviceName: error.serviceName } : {}),
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const fromNativeService = (service: NativeService): Omit<Service, 'ipv4' | 'ipv6'> => ({
|
|
74
|
+
name: service.name,
|
|
75
|
+
fullName: service.fullName,
|
|
76
|
+
host: service.host,
|
|
77
|
+
port: service.port,
|
|
78
|
+
addresses: service.addresses,
|
|
79
|
+
txt: Object.fromEntries(service.txt.map(({ key, value }) => [key, value])),
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const toTxtEntries = (txt: Array<[string, string]>): TxtEntry[] =>
|
|
83
|
+
txt.map(([key, value]) => ({ key, value }))
|
|
84
|
+
|
|
85
|
+
// A rejection carries the same payload as error events, in userInfo
|
|
86
|
+
const settled = async (result: Promise<NativeResult>) => {
|
|
87
|
+
const { service, error } = await result
|
|
88
|
+
if (error) {
|
|
89
|
+
throw { userInfo: fromNativeError(error) }
|
|
90
|
+
}
|
|
91
|
+
return service ? fromNativeService(service) : null
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const turboBridge = (module: NonNullable<typeof NativeZeroconf>): Bridge => ({
|
|
95
|
+
scan: (scanId, type, protocol, domain, implType, options) =>
|
|
96
|
+
module.scan(scanId, type, protocol, domain, implType, options),
|
|
97
|
+
stop: (scanId, implType) => module.stop(scanId, implType),
|
|
98
|
+
registerService: async (type, protocol, domain, name, port, txt, implType, options) =>
|
|
99
|
+
(await settled(
|
|
100
|
+
module.registerService(
|
|
101
|
+
type,
|
|
102
|
+
protocol,
|
|
103
|
+
domain,
|
|
104
|
+
name,
|
|
105
|
+
port,
|
|
106
|
+
toTxtEntries(txt),
|
|
107
|
+
implType,
|
|
108
|
+
options,
|
|
109
|
+
),
|
|
110
|
+
)) as PublishedService,
|
|
111
|
+
updateService: async (name, txt, implType) =>
|
|
112
|
+
(await settled(module.updateService(name, toTxtEntries(txt), implType))) as PublishedService,
|
|
113
|
+
unregisterService: async (name, implType) =>
|
|
114
|
+
(await settled(module.unregisterService(name, implType))) as PublishedService | null,
|
|
115
|
+
resolveService: (name, type, protocol, domain, implType, options) =>
|
|
116
|
+
settled(module.resolveService(name, type, protocol, domain, implType, options)),
|
|
117
|
+
checkLocalNetworkAccess: async (type, timeout) => {
|
|
118
|
+
const { status, error } = await module.checkLocalNetworkAccess(type ?? '', timeout)
|
|
119
|
+
if (error) {
|
|
120
|
+
throw { userInfo: fromNativeError(error) }
|
|
121
|
+
}
|
|
122
|
+
return (status ?? 'unknown') as LocalNetworkAccess
|
|
123
|
+
},
|
|
124
|
+
listen: (event, handler) => {
|
|
125
|
+
// An empty scan id means the event is not about a scan: it reaches every instance
|
|
126
|
+
const withScan = (scanId: string, payload: BridgePayload) =>
|
|
127
|
+
handler(scanId ? { ...payload, scanId } : payload)
|
|
128
|
+
switch (event) {
|
|
129
|
+
case 'start':
|
|
130
|
+
return module.onStart(({ scanId }) => withScan(scanId, {}))
|
|
131
|
+
case 'stop':
|
|
132
|
+
return module.onStop(({ scanId }) => withScan(scanId, {}))
|
|
133
|
+
case 'found':
|
|
134
|
+
return module.onFound(({ scanId, name }) => withScan(scanId, { name }))
|
|
135
|
+
case 'remove':
|
|
136
|
+
return module.onRemove(({ scanId, name }) => withScan(scanId, { name }))
|
|
137
|
+
case 'resolved':
|
|
138
|
+
return module.onResolved(({ scanId, service }) =>
|
|
139
|
+
withScan(scanId, { ...fromNativeService(service) }),
|
|
140
|
+
)
|
|
141
|
+
case 'error':
|
|
142
|
+
return module.onError(({ scanId, error }) =>
|
|
143
|
+
withScan(scanId, { ...fromNativeError(error) }),
|
|
144
|
+
)
|
|
145
|
+
case 'published':
|
|
146
|
+
return module.onPublished(service => handler({ ...fromNativeService(service) }))
|
|
147
|
+
case 'unpublished':
|
|
148
|
+
return module.onUnpublished(service => handler({ ...fromNativeService(service) }))
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
export const getBridge = (): Bridge | null => (NativeZeroconf ? turboBridge(NativeZeroconf) : null)
|