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
|
@@ -1,36 +1,26 @@
|
|
|
1
1
|
package com.balthazargronon.RCTZeroconf;
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.ReactPackage;
|
|
4
|
-
import com.facebook.react.bridge.JavaScriptModule;
|
|
5
4
|
import com.facebook.react.bridge.NativeModule;
|
|
6
5
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
6
|
import com.facebook.react.uimanager.ViewManager;
|
|
8
7
|
|
|
9
|
-
import java.util.
|
|
8
|
+
import java.util.Collections;
|
|
10
9
|
import java.util.List;
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* The native module is the C++ one (cpp/android), registered by autolinking. This package only makes
|
|
13
|
+
* autolinking include the library's Android project, whose Java code the C++ module calls.
|
|
15
14
|
*/
|
|
16
15
|
public class ZeroconfReactPackage implements ReactPackage {
|
|
17
16
|
|
|
18
17
|
@Override
|
|
19
18
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Deprecated RN 0.47
|
|
24
|
-
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
|
25
|
-
return new ArrayList<>();
|
|
19
|
+
return Collections.emptyList();
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
@Override
|
|
29
23
|
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
modules.add(new ZeroconfModule(reactContext));
|
|
33
|
-
|
|
34
|
-
return modules;
|
|
24
|
+
return Collections.emptyList();
|
|
35
25
|
}
|
|
36
26
|
}
|
|
@@ -12,16 +12,11 @@ import android.os.Looper;
|
|
|
12
12
|
import android.util.Log;
|
|
13
13
|
|
|
14
14
|
import com.balthazargronon.RCTZeroconf.Zeroconf;
|
|
15
|
-
import com.balthazargronon.RCTZeroconf.
|
|
15
|
+
import com.balthazargronon.RCTZeroconf.NsdHost;
|
|
16
|
+
import com.balthazargronon.RCTZeroconf.NsdPayload;
|
|
17
|
+
import com.balthazargronon.RCTZeroconf.NsdPromise;
|
|
16
18
|
import com.balthazargronon.RCTZeroconf.ZeroconfOptions;
|
|
17
|
-
import com.facebook.react.bridge.Promise;
|
|
18
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
19
19
|
|
|
20
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
21
|
-
import com.facebook.react.bridge.WritableArray;
|
|
22
|
-
import com.facebook.react.bridge.WritableMap;
|
|
23
|
-
import com.facebook.react.bridge.WritableNativeArray;
|
|
24
|
-
import com.facebook.react.bridge.WritableNativeMap;
|
|
25
20
|
|
|
26
21
|
import java.net.InetAddress;
|
|
27
22
|
import java.nio.charset.StandardCharsets;
|
|
@@ -48,8 +43,8 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
48
43
|
// Reference counted: acquired once per running scan
|
|
49
44
|
private WifiManager.MulticastLock multicastLock;
|
|
50
45
|
private Map<String, ServiceRegistrationListener> mPublishedServices;
|
|
51
|
-
private
|
|
52
|
-
private
|
|
46
|
+
private NsdHost zeroconfModule;
|
|
47
|
+
private Context reactApplicationContext;
|
|
53
48
|
|
|
54
49
|
// Running scans, keyed by the id of the JS instance that started them
|
|
55
50
|
private final Map<String, NsdScan> mScans = new ConcurrentHashMap<>();
|
|
@@ -83,11 +78,11 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
83
78
|
@Nullable final String scanId;
|
|
84
79
|
final NsdServiceInfo serviceInfo;
|
|
85
80
|
// resolveService(): settled instead of emitting events
|
|
86
|
-
@Nullable final
|
|
81
|
+
@Nullable final NsdPromise promise;
|
|
87
82
|
// Seconds before the TIMEOUT error, counted from the start of the resolve
|
|
88
83
|
final double timeoutSeconds;
|
|
89
84
|
|
|
90
|
-
PendingResolve(@Nullable String scanId, NsdServiceInfo serviceInfo, @Nullable
|
|
85
|
+
PendingResolve(@Nullable String scanId, NsdServiceInfo serviceInfo, @Nullable NsdPromise promise, double timeoutSeconds) {
|
|
91
86
|
this.scanId = scanId;
|
|
92
87
|
this.serviceInfo = serviceInfo;
|
|
93
88
|
this.promise = promise;
|
|
@@ -95,7 +90,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
92
|
|
|
98
|
-
public NsdServiceImpl(
|
|
93
|
+
public NsdServiceImpl(NsdHost zeroconfModule, Context reactApplicationContext) {
|
|
99
94
|
this.zeroconfModule = zeroconfModule;
|
|
100
95
|
this.reactApplicationContext = reactApplicationContext;
|
|
101
96
|
mPublishedServices = new ConcurrentHashMap<String, ServiceRegistrationListener>();
|
|
@@ -109,12 +104,12 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
109
104
|
|
|
110
105
|
final NsdScan scan = new NsdScan(scanId);
|
|
111
106
|
scan.resolveTimeoutSeconds = options.resolveTimeoutSeconds;
|
|
112
|
-
final boolean typesOnly =
|
|
107
|
+
final boolean typesOnly = NsdHost.isServiceTypesScan(type, protocol);
|
|
113
108
|
|
|
114
109
|
Network network = null;
|
|
115
110
|
if (options.networkInterface != null && !typesOnly) {
|
|
116
111
|
String networkError = checkNetworkSupport(options.networkInterface);
|
|
117
|
-
network = networkError == null ?
|
|
112
|
+
network = networkError == null ? NsdHost.findNetwork(reactApplicationContext, options.networkInterface) : null;
|
|
118
113
|
if (network == null) {
|
|
119
114
|
sendNetworkError(networkError, options.networkInterface, null, scanId);
|
|
120
115
|
return;
|
|
@@ -132,7 +127,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
132
127
|
return;
|
|
133
128
|
}
|
|
134
129
|
}
|
|
135
|
-
sendScanEvent(
|
|
130
|
+
sendScanEvent(NsdHost.EVENT_FOUND, nameToMap(serviceType), scanId);
|
|
136
131
|
}
|
|
137
132
|
|
|
138
133
|
@Override
|
|
@@ -143,17 +138,17 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
143
138
|
return;
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
|
-
sendScanEvent(
|
|
141
|
+
sendScanEvent(NsdHost.EVENT_REMOVE, nameToMap(serviceType), scanId);
|
|
147
142
|
}
|
|
148
143
|
|
|
149
144
|
@Override
|
|
150
145
|
public void onError(String message) {
|
|
151
|
-
zeroconfModule.sendError(
|
|
146
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_EXCEPTION, "Listing service types failed: " + message, null, scanId);
|
|
152
147
|
}
|
|
153
148
|
});
|
|
154
149
|
mScans.put(scanId, scan);
|
|
155
150
|
scan.typesQuery.start();
|
|
156
|
-
sendScanEvent(
|
|
151
|
+
sendScanEvent(NsdHost.EVENT_START, new NsdPayload(), scanId);
|
|
157
152
|
syncLocalServiceTypes();
|
|
158
153
|
return;
|
|
159
154
|
}
|
|
@@ -166,12 +161,12 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
166
161
|
if (getHostAddresses(serviceInfo).isEmpty()) {
|
|
167
162
|
return;
|
|
168
163
|
}
|
|
169
|
-
sendScanEvent(
|
|
164
|
+
sendScanEvent(NsdHost.EVENT_RESOLVE, serviceInfoToMap(serviceInfo), scanId);
|
|
170
165
|
}
|
|
171
166
|
|
|
172
167
|
@Override
|
|
173
168
|
public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
|
|
174
|
-
zeroconfModule.sendError(
|
|
169
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_NSD, errorCode, "Resolving service " + serviceInfo.getServiceName() + " failed: " + NsdHost.describeNsdError(errorCode), serviceInfo.getServiceName(), scanId);
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
@Override
|
|
@@ -184,7 +179,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
184
179
|
scan.discoveryListener = new NsdManager.DiscoveryListener() {
|
|
185
180
|
@Override
|
|
186
181
|
public void onStartDiscoveryFailed(String serviceType, int errorCode) {
|
|
187
|
-
zeroconfModule.sendError(
|
|
182
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_NSD, errorCode, "Starting service discovery failed: " + NsdHost.describeNsdError(errorCode), null, scanId);
|
|
188
183
|
// The discovery never started, nothing to stop
|
|
189
184
|
if (mScans.remove(scanId, scan)) {
|
|
190
185
|
releaseMulticastLock();
|
|
@@ -193,25 +188,25 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
193
188
|
|
|
194
189
|
@Override
|
|
195
190
|
public void onStopDiscoveryFailed(String serviceType, int errorCode) {
|
|
196
|
-
zeroconfModule.sendError(
|
|
191
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_NSD, errorCode, "Stopping service discovery failed: " + NsdHost.describeNsdError(errorCode), null, scanId);
|
|
197
192
|
}
|
|
198
193
|
|
|
199
194
|
@Override
|
|
200
195
|
public void onDiscoveryStarted(String serviceType) {
|
|
201
196
|
Log.d(TAG, "Discovery started for " + scanId);
|
|
202
|
-
sendScanEvent(
|
|
197
|
+
sendScanEvent(NsdHost.EVENT_START, new NsdPayload(), scanId);
|
|
203
198
|
}
|
|
204
199
|
|
|
205
200
|
@Override
|
|
206
201
|
public void onDiscoveryStopped(String serviceType) {
|
|
207
202
|
Log.d(TAG, "Discovery stopped for " + scanId);
|
|
208
|
-
sendScanEvent(
|
|
203
|
+
sendScanEvent(NsdHost.EVENT_STOP, new NsdPayload(), scanId);
|
|
209
204
|
}
|
|
210
205
|
|
|
211
206
|
@Override
|
|
212
207
|
public void onServiceFound(NsdServiceInfo serviceInfo) {
|
|
213
208
|
Log.d(TAG, "Service found");
|
|
214
|
-
sendScanEvent(
|
|
209
|
+
sendScanEvent(NsdHost.EVENT_FOUND, serviceNameToMap(serviceInfo), scanId);
|
|
215
210
|
if (scan.infoCallbacks != null) {
|
|
216
211
|
scan.infoCallbacks.register(serviceInfo);
|
|
217
212
|
} else {
|
|
@@ -222,7 +217,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
222
217
|
@Override
|
|
223
218
|
public void onServiceLost(NsdServiceInfo serviceInfo) {
|
|
224
219
|
Log.d(TAG, "Service lost");
|
|
225
|
-
sendScanEvent(
|
|
220
|
+
sendScanEvent(NsdHost.EVENT_REMOVE, serviceNameToMap(serviceInfo), scanId);
|
|
226
221
|
if (scan.infoCallbacks != null) {
|
|
227
222
|
scan.infoCallbacks.unregister(serviceInfo.getServiceName());
|
|
228
223
|
}
|
|
@@ -244,19 +239,19 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
244
239
|
// Choosing the network of NSD requests needs Android 13, null when supported
|
|
245
240
|
@Nullable
|
|
246
241
|
private static String checkNetworkSupport(String networkInterface) {
|
|
247
|
-
return Build.VERSION.SDK_INT >= 33 ? null :
|
|
242
|
+
return Build.VERSION.SDK_INT >= 33 ? null : NsdHost.ERROR_CODE_UNSUPPORTED;
|
|
248
243
|
}
|
|
249
244
|
|
|
250
|
-
private void sendNetworkError(@Nullable String code, String networkInterface, @Nullable
|
|
251
|
-
boolean unsupported =
|
|
252
|
-
String errorCode = unsupported ?
|
|
245
|
+
private void sendNetworkError(@Nullable String code, String networkInterface, @Nullable NsdPromise promise, @Nullable String scanId) {
|
|
246
|
+
boolean unsupported = NsdHost.ERROR_CODE_UNSUPPORTED.equals(code);
|
|
247
|
+
String errorCode = unsupported ? NsdHost.ERROR_CODE_UNSUPPORTED : NsdHost.ERROR_CODE_UNKNOWN_INTERFACE;
|
|
253
248
|
String message = unsupported
|
|
254
249
|
? "Choosing the network interface needs Android 13 or later with NSD, use DNSSD"
|
|
255
250
|
: "Unknown network interface " + networkInterface;
|
|
256
251
|
if (promise != null) {
|
|
257
|
-
|
|
252
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_LIBRARY, errorCode, message, null);
|
|
258
253
|
} else {
|
|
259
|
-
zeroconfModule.sendError(
|
|
254
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_LIBRARY, errorCode, message, null, scanId);
|
|
260
255
|
}
|
|
261
256
|
}
|
|
262
257
|
|
|
@@ -283,7 +278,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
283
278
|
if (scan.typesQuery != null) {
|
|
284
279
|
scan.typesQuery.stop();
|
|
285
280
|
// No discovery listener reports it
|
|
286
|
-
sendScanEvent(
|
|
281
|
+
sendScanEvent(NsdHost.EVENT_STOP, new NsdPayload(), scanId);
|
|
287
282
|
}
|
|
288
283
|
|
|
289
284
|
synchronized (mResolveQueue) {
|
|
@@ -321,29 +316,29 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
321
316
|
}
|
|
322
317
|
}
|
|
323
318
|
|
|
324
|
-
private void sendScanEvent(String eventName,
|
|
325
|
-
body.putString(
|
|
326
|
-
zeroconfModule.sendEvent(
|
|
319
|
+
private void sendScanEvent(String eventName, NsdPayload body, String scanId) {
|
|
320
|
+
body.putString(NsdHost.KEY_SCAN_ID, scanId);
|
|
321
|
+
zeroconfModule.sendEvent(eventName, body);
|
|
327
322
|
}
|
|
328
323
|
|
|
329
|
-
private static
|
|
330
|
-
|
|
331
|
-
service.putString(
|
|
324
|
+
private static NsdPayload nameToMap(String name) {
|
|
325
|
+
NsdPayload service = new NsdPayload();
|
|
326
|
+
service.putString(NsdHost.KEY_SERVICE_NAME, name);
|
|
332
327
|
return service;
|
|
333
328
|
}
|
|
334
329
|
|
|
335
|
-
private static
|
|
336
|
-
|
|
337
|
-
service.putString(
|
|
330
|
+
private static NsdPayload serviceNameToMap(NsdServiceInfo serviceInfo) {
|
|
331
|
+
NsdPayload service = new NsdPayload();
|
|
332
|
+
service.putString(NsdHost.KEY_SERVICE_NAME, serviceInfo.getServiceName());
|
|
338
333
|
return service;
|
|
339
334
|
}
|
|
340
335
|
|
|
341
336
|
@Override
|
|
342
|
-
public void registerService(String type, String protocol, String domain, String name, int port,
|
|
337
|
+
public void registerService(String type, String protocol, String domain, String name, int port, Map<String, String> txt, ZeroconfOptions options, NsdPromise promise) {
|
|
343
338
|
Network network = null;
|
|
344
339
|
if (options.networkInterface != null) {
|
|
345
340
|
String networkError = checkNetworkSupport(options.networkInterface);
|
|
346
|
-
network = networkError == null ?
|
|
341
|
+
network = networkError == null ? NsdHost.findNetwork(reactApplicationContext, options.networkInterface) : null;
|
|
347
342
|
if (network == null) {
|
|
348
343
|
sendNetworkError(networkError, options.networkInterface, promise, null);
|
|
349
344
|
return;
|
|
@@ -362,10 +357,10 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
362
357
|
* without emitting unpublished and published
|
|
363
358
|
*/
|
|
364
359
|
@Override
|
|
365
|
-
public void updateService(String serviceName, final
|
|
360
|
+
public void updateService(String serviceName, final Map<String, String> txt, final NsdPromise promise) {
|
|
366
361
|
final ServiceRegistrationListener previous = mPublishedServices.remove(serviceName);
|
|
367
362
|
if (previous == null) {
|
|
368
|
-
|
|
363
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_NOT_PUBLISHED, "Service " + serviceName + " is not published", serviceName);
|
|
369
364
|
return;
|
|
370
365
|
}
|
|
371
366
|
final ServiceRegistrationListener next = new ServiceRegistrationListener(promise, previous.serviceType, previous.port, previous.network);
|
|
@@ -377,13 +372,13 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
377
372
|
}
|
|
378
373
|
|
|
379
374
|
@Override
|
|
380
|
-
public void resolveService(String name, String type, String protocol, String domain, ZeroconfOptions options, final
|
|
375
|
+
public void resolveService(String name, String type, String protocol, String domain, ZeroconfOptions options, final NsdPromise promise) {
|
|
381
376
|
final NsdServiceInfo serviceInfo = new NsdServiceInfo();
|
|
382
377
|
serviceInfo.setServiceName(name);
|
|
383
378
|
serviceInfo.setServiceType(String.format("_%s._%s", type, protocol));
|
|
384
379
|
if (options.networkInterface != null) {
|
|
385
380
|
String networkError = checkNetworkSupport(options.networkInterface);
|
|
386
|
-
Network network = networkError == null ?
|
|
381
|
+
Network network = networkError == null ? NsdHost.findNetwork(reactApplicationContext, options.networkInterface) : null;
|
|
387
382
|
if (network == null) {
|
|
388
383
|
sendNetworkError(networkError, options.networkInterface, promise, null);
|
|
389
384
|
return;
|
|
@@ -419,7 +414,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
419
414
|
if (settled[0]) return;
|
|
420
415
|
settled[0] = true;
|
|
421
416
|
}
|
|
422
|
-
|
|
417
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_NSD, errorCode, "Resolving service " + name + " failed: " + NsdHost.describeNsdError(errorCode), name);
|
|
423
418
|
}
|
|
424
419
|
|
|
425
420
|
@Override
|
|
@@ -450,19 +445,19 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
450
445
|
settled[0] = true;
|
|
451
446
|
}
|
|
452
447
|
finish.run();
|
|
453
|
-
|
|
448
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_TIMEOUT, "Resolving service " + name + " failed: timed out", name);
|
|
454
449
|
}, (long) (options.timeoutSeconds * 1000));
|
|
455
450
|
}
|
|
456
451
|
|
|
457
452
|
@Override
|
|
458
|
-
public void unregisterService(String serviceName, @Nullable
|
|
453
|
+
public void unregisterService(String serviceName, @Nullable NsdPromise promise) {
|
|
459
454
|
|
|
460
455
|
final NsdManager nsdManager = this.getNsdManager();
|
|
461
456
|
|
|
462
457
|
ServiceRegistrationListener serviceListener = mPublishedServices.get(serviceName);
|
|
463
458
|
|
|
464
459
|
if (serviceListener == null) {
|
|
465
|
-
|
|
460
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_NOT_PUBLISHED, "Service " + serviceName + " is not published", serviceName);
|
|
466
461
|
return;
|
|
467
462
|
}
|
|
468
463
|
|
|
@@ -510,10 +505,10 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
510
505
|
}
|
|
511
506
|
}
|
|
512
507
|
for (String type : found) {
|
|
513
|
-
sendScanEvent(
|
|
508
|
+
sendScanEvent(NsdHost.EVENT_FOUND, nameToMap(type), scan.scanId);
|
|
514
509
|
}
|
|
515
510
|
for (String type : removed) {
|
|
516
|
-
sendScanEvent(
|
|
511
|
+
sendScanEvent(NsdHost.EVENT_REMOVE, nameToMap(type), scan.scanId);
|
|
517
512
|
}
|
|
518
513
|
}
|
|
519
514
|
}
|
|
@@ -547,7 +542,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
547
542
|
mResolveManager = (NsdManager) fresh.getSystemService(Context.NSD_SERVICE);
|
|
548
543
|
}
|
|
549
544
|
|
|
550
|
-
private
|
|
545
|
+
private Context getReactApplicationContext() {
|
|
551
546
|
return reactApplicationContext;
|
|
552
547
|
}
|
|
553
548
|
|
|
@@ -561,7 +556,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
561
556
|
}
|
|
562
557
|
|
|
563
558
|
private void sendResolveTimeout(String serviceName, String scanId) {
|
|
564
|
-
zeroconfModule.sendError(
|
|
559
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_TIMEOUT, "Resolving service " + serviceName + " failed: timed out", serviceName, scanId);
|
|
565
560
|
}
|
|
566
561
|
|
|
567
562
|
private void resolveNext() {
|
|
@@ -581,7 +576,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
581
576
|
} catch (Throwable e) {
|
|
582
577
|
Log.e(TAG, "resolveService failed", e);
|
|
583
578
|
String serviceName = next.serviceInfo.getServiceName();
|
|
584
|
-
zeroconfModule.sendError(
|
|
579
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_EXCEPTION, "Resolving service " + serviceName + " failed: " + e.getMessage(), serviceName, next.scanId);
|
|
585
580
|
onResolveDone();
|
|
586
581
|
}
|
|
587
582
|
}
|
|
@@ -596,7 +591,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
596
591
|
private class ZeroResolveListener implements NsdManager.ResolveListener {
|
|
597
592
|
private final PendingResolve pending;
|
|
598
593
|
@Nullable private final String scanId;
|
|
599
|
-
@Nullable private final
|
|
594
|
+
@Nullable private final NsdPromise promise;
|
|
600
595
|
// Settled: answered, failed or timed out. A late answer after the timeout is ignored
|
|
601
596
|
private boolean settled = false;
|
|
602
597
|
|
|
@@ -620,7 +615,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
620
615
|
}
|
|
621
616
|
String serviceName = pending.serviceInfo.getServiceName();
|
|
622
617
|
if (promise != null) {
|
|
623
|
-
|
|
618
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_LIBRARY, NsdHost.ERROR_CODE_TIMEOUT, "Resolving service " + serviceName + " failed: timed out", serviceName);
|
|
624
619
|
} else if (mScans.containsKey(scanId)) {
|
|
625
620
|
sendResolveTimeout(serviceName, scanId);
|
|
626
621
|
}
|
|
@@ -646,11 +641,11 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
646
641
|
// Timed out: the queue already moved on to another client
|
|
647
642
|
return;
|
|
648
643
|
}
|
|
649
|
-
String message = "Resolving service " + serviceInfo.getServiceName() + " failed: " +
|
|
644
|
+
String message = "Resolving service " + serviceInfo.getServiceName() + " failed: " + NsdHost.describeNsdError(errorCode);
|
|
650
645
|
if (promise != null) {
|
|
651
|
-
|
|
646
|
+
NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
|
|
652
647
|
} else if (mScans.containsKey(scanId)) {
|
|
653
|
-
zeroconfModule.sendError(
|
|
648
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName(), scanId);
|
|
654
649
|
}
|
|
655
650
|
onResolveDone();
|
|
656
651
|
}
|
|
@@ -665,15 +660,15 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
665
660
|
promise.resolve(serviceInfoToMap(serviceInfo));
|
|
666
661
|
} else if (mScans.containsKey(scanId)) {
|
|
667
662
|
// The scan may have been stopped while resolving
|
|
668
|
-
sendScanEvent(
|
|
663
|
+
sendScanEvent(NsdHost.EVENT_RESOLVE, serviceInfoToMap(serviceInfo), scanId);
|
|
669
664
|
}
|
|
670
665
|
onResolveDone();
|
|
671
666
|
}
|
|
672
667
|
}
|
|
673
668
|
|
|
674
669
|
private class ServiceRegistrationListener implements NsdManager.RegistrationListener {
|
|
675
|
-
@Nullable private
|
|
676
|
-
@Nullable private
|
|
670
|
+
@Nullable private NsdPromise registerPromise;
|
|
671
|
+
@Nullable private NsdPromise unregisterPromise;
|
|
677
672
|
// What it was registered with, to register it again on updates
|
|
678
673
|
final String serviceType;
|
|
679
674
|
final int port;
|
|
@@ -685,14 +680,14 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
685
680
|
// The registration callback doesn't carry the TXT record, report the one registered
|
|
686
681
|
private final Map<String, String> txt = new java.util.LinkedHashMap<>();
|
|
687
682
|
|
|
688
|
-
ServiceRegistrationListener(@Nullable
|
|
683
|
+
ServiceRegistrationListener(@Nullable NsdPromise registerPromise, String serviceType, int port, @Nullable Network network) {
|
|
689
684
|
this.registerPromise = registerPromise;
|
|
690
685
|
this.serviceType = serviceType;
|
|
691
686
|
this.port = port;
|
|
692
687
|
this.network = network;
|
|
693
688
|
}
|
|
694
689
|
|
|
695
|
-
NsdServiceInfo buildServiceInfo(String name,
|
|
690
|
+
NsdServiceInfo buildServiceInfo(String name, Map<String, String> txt) {
|
|
696
691
|
NsdServiceInfo serviceInfo = new NsdServiceInfo();
|
|
697
692
|
serviceInfo.setServiceName(name);
|
|
698
693
|
serviceInfo.setServiceType(serviceType);
|
|
@@ -701,22 +696,21 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
701
696
|
serviceInfo.setNetwork(network);
|
|
702
697
|
}
|
|
703
698
|
this.txt.clear();
|
|
704
|
-
for (
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
this.txt.put(pair.getString(0), pair.getString(1));
|
|
699
|
+
for (Map.Entry<String, String> pair : txt.entrySet()) {
|
|
700
|
+
serviceInfo.setAttribute(pair.getKey(), pair.getValue());
|
|
701
|
+
this.txt.put(pair.getKey(), pair.getValue());
|
|
708
702
|
}
|
|
709
703
|
return serviceInfo;
|
|
710
704
|
}
|
|
711
705
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
706
|
+
NsdPayload registeredToMap(NsdServiceInfo serviceInfo) {
|
|
707
|
+
NsdPayload service = serviceInfoToMap(serviceInfo);
|
|
708
|
+
NsdPayload txtMap = new NsdPayload();
|
|
715
709
|
for (Map.Entry<String, String> entry : txt.entrySet()) {
|
|
716
710
|
txtMap.putString(entry.getKey(), entry.getValue());
|
|
717
711
|
}
|
|
718
|
-
service.putMap(
|
|
719
|
-
service.putInt(
|
|
712
|
+
service.putMap(NsdHost.KEY_SERVICE_TXT, txtMap);
|
|
713
|
+
service.putInt(NsdHost.KEY_SERVICE_PORT, port);
|
|
720
714
|
return service;
|
|
721
715
|
}
|
|
722
716
|
|
|
@@ -731,7 +725,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
731
725
|
syncLocalServiceTypes();
|
|
732
726
|
|
|
733
727
|
if (announceRegistered) {
|
|
734
|
-
zeroconfModule.sendEvent(
|
|
728
|
+
zeroconfModule.sendEvent(NsdHost.EVENT_PUBLISHED, registeredToMap(NsdServiceInfo));
|
|
735
729
|
}
|
|
736
730
|
if (registerPromise != null) {
|
|
737
731
|
registerPromise.resolve(registeredToMap(NsdServiceInfo));
|
|
@@ -741,9 +735,9 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
741
735
|
|
|
742
736
|
@Override
|
|
743
737
|
public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
|
|
744
|
-
String message = "Registering service " + serviceInfo.getServiceName() + " failed: " +
|
|
745
|
-
zeroconfModule.sendError(
|
|
746
|
-
|
|
738
|
+
String message = "Registering service " + serviceInfo.getServiceName() + " failed: " + NsdHost.describeNsdError(errorCode);
|
|
739
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
|
|
740
|
+
NsdHost.reject(registerPromise, NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
|
|
747
741
|
registerPromise = null;
|
|
748
742
|
}
|
|
749
743
|
|
|
@@ -752,7 +746,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
752
746
|
// Service has been unregistered. This only happens when you call
|
|
753
747
|
// NsdManager.unregisterService() and pass in this listener.
|
|
754
748
|
if (announceUnregistered) {
|
|
755
|
-
zeroconfModule.sendEvent(
|
|
749
|
+
zeroconfModule.sendEvent(NsdHost.EVENT_UNREGISTERED, registeredToMap(nsdServiceInfo));
|
|
756
750
|
}
|
|
757
751
|
if (afterUnregistered != null) {
|
|
758
752
|
afterUnregistered.run();
|
|
@@ -766,9 +760,9 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
766
760
|
|
|
767
761
|
@Override
|
|
768
762
|
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
|
|
769
|
-
String message = "Unregistering service " + serviceInfo.getServiceName() + " failed: " +
|
|
770
|
-
zeroconfModule.sendError(
|
|
771
|
-
|
|
763
|
+
String message = "Unregistering service " + serviceInfo.getServiceName() + " failed: " + NsdHost.describeNsdError(errorCode);
|
|
764
|
+
zeroconfModule.sendError(NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
|
|
765
|
+
NsdHost.reject(unregisterPromise, NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
|
|
772
766
|
unregisterPromise = null;
|
|
773
767
|
}
|
|
774
768
|
}
|
|
@@ -802,9 +796,9 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
802
796
|
return null;
|
|
803
797
|
}
|
|
804
798
|
|
|
805
|
-
private
|
|
806
|
-
|
|
807
|
-
service.putString(
|
|
799
|
+
private NsdPayload serviceInfoToMap(NsdServiceInfo serviceInfo) {
|
|
800
|
+
NsdPayload service = new NsdPayload();
|
|
801
|
+
service.putString(NsdHost.KEY_SERVICE_NAME, serviceInfo.getServiceName());
|
|
808
802
|
final List<InetAddress> hostAddresses = getHostAddresses(serviceInfo);
|
|
809
803
|
final String fullServiceName;
|
|
810
804
|
if (hostAddresses.isEmpty()) {
|
|
@@ -816,19 +810,19 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
816
810
|
hostname = hostAddresses.get(0).getHostName();
|
|
817
811
|
}
|
|
818
812
|
fullServiceName = hostname + serviceInfo.getServiceType();
|
|
819
|
-
service.putString(
|
|
813
|
+
service.putString(NsdHost.KEY_SERVICE_HOST, hostname);
|
|
820
814
|
|
|
821
|
-
|
|
815
|
+
List<String> addresses = new ArrayList<>();
|
|
822
816
|
for (InetAddress address : hostAddresses) {
|
|
823
|
-
addresses.
|
|
817
|
+
addresses.add(address.getHostAddress());
|
|
824
818
|
}
|
|
825
819
|
|
|
826
|
-
service.putArray(
|
|
820
|
+
service.putArray(NsdHost.KEY_SERVICE_ADDRESSES, addresses);
|
|
827
821
|
}
|
|
828
|
-
service.putString(
|
|
829
|
-
service.putInt(
|
|
822
|
+
service.putString(NsdHost.KEY_SERVICE_FULL_NAME, fullServiceName);
|
|
823
|
+
service.putInt(NsdHost.KEY_SERVICE_PORT, serviceInfo.getPort());
|
|
830
824
|
|
|
831
|
-
|
|
825
|
+
NsdPayload txtRecords = new NsdPayload();
|
|
832
826
|
|
|
833
827
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
834
828
|
Map<String, byte[]> attributes = serviceInfo.getAttributes();
|
|
@@ -840,7 +834,7 @@ public class NsdServiceImpl implements Zeroconf {
|
|
|
840
834
|
}
|
|
841
835
|
}
|
|
842
836
|
|
|
843
|
-
service.putMap(
|
|
837
|
+
service.putMap(NsdHost.KEY_SERVICE_TXT, txtRecords);
|
|
844
838
|
|
|
845
839
|
return service;
|
|
846
840
|
}
|
|
@@ -80,6 +80,7 @@ typedef struct
|
|
|
80
80
|
{
|
|
81
81
|
mDNS_DirectOP_Dispose *disposefn;
|
|
82
82
|
DNSServiceRef aQuery;
|
|
83
|
+
DNSServiceRef aaaaQuery; // react-native-zeroconf: IPv6 addresses too
|
|
83
84
|
DNSServiceGetAddrInfoReply callback;
|
|
84
85
|
void *context;
|
|
85
86
|
} mDNS_DirectOP_GetAddrInfo;
|
|
@@ -198,8 +199,9 @@ mDNSlocal void RegCallback(mDNS *const m, ServiceRecordSet *const sr, mStatus re
|
|
|
198
199
|
|
|
199
200
|
if (result == mStatus_NoError)
|
|
200
201
|
{
|
|
202
|
+
// react-native-zeroconf: kDNSServiceFlagsAdd marks a registration, as with Apple's implementation
|
|
201
203
|
if (x->callback)
|
|
202
|
-
x->callback((DNSServiceRef)x,
|
|
204
|
+
x->callback((DNSServiceRef)x, kDNSServiceFlagsAdd, result, namestr, typestr, domstr, x->context);
|
|
203
205
|
}
|
|
204
206
|
else if (result == mStatus_NameConflict)
|
|
205
207
|
{
|
|
@@ -739,6 +741,7 @@ static void DNSServiceGetAddrInfoDispose(mDNS_DirectOP *op)
|
|
|
739
741
|
{
|
|
740
742
|
mDNS_DirectOP_GetAddrInfo *x = (mDNS_DirectOP_GetAddrInfo*)op;
|
|
741
743
|
if (x->aQuery) DNSServiceRefDeallocate(x->aQuery);
|
|
744
|
+
if (x->aaaaQuery) DNSServiceRefDeallocate(x->aaaaQuery);
|
|
742
745
|
mDNSPlatformMemFree(x);
|
|
743
746
|
}
|
|
744
747
|
|
|
@@ -757,16 +760,27 @@ static void DNSSD_API DNSServiceGetAddrInfoResponse(
|
|
|
757
760
|
{
|
|
758
761
|
mDNS_DirectOP_GetAddrInfo * x = (mDNS_DirectOP_GetAddrInfo*)inContext;
|
|
759
762
|
struct sockaddr_in sa4;
|
|
763
|
+
struct sockaddr_in6 sa6;
|
|
764
|
+
const struct sockaddr * sa = (const struct sockaddr *) &sa4;
|
|
760
765
|
|
|
761
766
|
mDNSPlatformMemZero(&sa4, sizeof(sa4));
|
|
762
|
-
|
|
767
|
+
mDNSPlatformMemZero(&sa6, sizeof(sa6));
|
|
768
|
+
if (inErrorCode == kDNSServiceErr_NoError && inRRType == kDNSServiceType_A && inRDLen == 4)
|
|
763
769
|
{
|
|
764
770
|
sa4.sin_family = AF_INET;
|
|
765
771
|
mDNSPlatformMemCopy(&sa4.sin_addr.s_addr, inRData, 4);
|
|
766
772
|
}
|
|
773
|
+
else if (inErrorCode == kDNSServiceErr_NoError && inRRType == kDNSServiceType_AAAA && inRDLen == 16)
|
|
774
|
+
{
|
|
775
|
+
// react-native-zeroconf: AAAA answers become IPv6 addresses, as with Apple's implementation
|
|
776
|
+
sa6.sin6_family = AF_INET6;
|
|
777
|
+
mDNSPlatformMemCopy(&sa6.sin6_addr, inRData, 16);
|
|
778
|
+
sa6.sin6_scope_id = inInterfaceIndex;
|
|
779
|
+
sa = (const struct sockaddr *) &sa6;
|
|
780
|
+
}
|
|
767
781
|
|
|
768
782
|
x->callback((DNSServiceRef)x, inFlags, inInterfaceIndex, inErrorCode, inFullName,
|
|
769
|
-
|
|
783
|
+
sa, inTTL, x->context);
|
|
770
784
|
}
|
|
771
785
|
|
|
772
786
|
DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo(
|
|
@@ -791,14 +805,25 @@ DNSServiceErrorType DNSSD_API DNSServiceGetAddrInfo(
|
|
|
791
805
|
x->callback = inCallback;
|
|
792
806
|
x->context = inContext;
|
|
793
807
|
x->aQuery = mDNSNULL;
|
|
808
|
+
x->aaaaQuery = mDNSNULL;
|
|
794
809
|
|
|
795
810
|
// Start the query.
|
|
796
811
|
// (It would probably be more efficient to code this using mDNS_StartQuery directly,
|
|
797
812
|
// instead of wrapping DNSServiceQueryRecord, which then unnecessarily allocates
|
|
798
813
|
// more memory and then just calls through to mDNS_StartQuery. -- SC June 2010)
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
814
|
+
// react-native-zeroconf: an A query for IPv4 and an AAAA query for IPv6, both without a protocol
|
|
815
|
+
if (!inProtocol || (inProtocol & kDNSServiceProtocol_IPv4))
|
|
816
|
+
{
|
|
817
|
+
err = DNSServiceQueryRecord(&x->aQuery, inFlags, inInterfaceIndex, inHostName, kDNSServiceType_A,
|
|
818
|
+
kDNSServiceClass_IN, DNSServiceGetAddrInfoResponse, x);
|
|
819
|
+
if (err) { DNSServiceGetAddrInfoDispose((mDNS_DirectOP*)x); errormsg = "DNSServiceQueryRecord"; goto fail; }
|
|
820
|
+
}
|
|
821
|
+
if (!inProtocol || (inProtocol & kDNSServiceProtocol_IPv6))
|
|
822
|
+
{
|
|
823
|
+
err = DNSServiceQueryRecord(&x->aaaaQuery, inFlags, inInterfaceIndex, inHostName, kDNSServiceType_AAAA,
|
|
824
|
+
kDNSServiceClass_IN, DNSServiceGetAddrInfoResponse, x);
|
|
825
|
+
if (err) { DNSServiceGetAddrInfoDispose((mDNS_DirectOP*)x); errormsg = "DNSServiceQueryRecord"; goto fail; }
|
|
826
|
+
}
|
|
802
827
|
|
|
803
828
|
*outRef = (DNSServiceRef)x;
|
|
804
829
|
return(mStatus_NoError);
|