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,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.ArrayList;
8
+ import java.util.Collections;
10
9
  import java.util.List;
11
10
 
12
11
  /**
13
- * Created by Jeremy White on 8/1/2016.
14
- * Copyright © 2016 Balthazar Gronon MIT
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 new ArrayList<>();
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
- List<NativeModule> modules = new ArrayList<>();
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.ZeroconfModule;
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 ZeroconfModule zeroconfModule;
52
- private ReactApplicationContext reactApplicationContext;
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 Promise promise;
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 Promise promise, double timeoutSeconds) {
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(ZeroconfModule zeroconfModule, ReactApplicationContext reactApplicationContext) {
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 = ZeroconfModule.isServiceTypesScan(type, protocol);
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 ? ZeroconfModule.findNetwork(reactApplicationContext, options.networkInterface) : 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(ZeroconfModule.EVENT_FOUND, nameToMap(serviceType), scanId);
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(ZeroconfModule.EVENT_REMOVE, nameToMap(serviceType), scanId);
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(ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_EXCEPTION, "Listing service types failed: " + message, null, scanId);
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(ZeroconfModule.EVENT_START, new WritableNativeMap(), scanId);
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(ZeroconfModule.EVENT_RESOLVE, serviceInfoToMap(serviceInfo), scanId);
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(ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, "Resolving service " + serviceInfo.getServiceName() + " failed: " + ZeroconfModule.describeNsdError(errorCode), serviceInfo.getServiceName(), scanId);
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(ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, "Starting service discovery failed: " + ZeroconfModule.describeNsdError(errorCode), null, scanId);
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(ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, "Stopping service discovery failed: " + ZeroconfModule.describeNsdError(errorCode), null, scanId);
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(ZeroconfModule.EVENT_START, new WritableNativeMap(), scanId);
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(ZeroconfModule.EVENT_STOP, new WritableNativeMap(), scanId);
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(ZeroconfModule.EVENT_FOUND, serviceNameToMap(serviceInfo), scanId);
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(ZeroconfModule.EVENT_REMOVE, serviceNameToMap(serviceInfo), scanId);
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 : ZeroconfModule.ERROR_CODE_UNSUPPORTED;
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 Promise promise, @Nullable String scanId) {
251
- boolean unsupported = ZeroconfModule.ERROR_CODE_UNSUPPORTED.equals(code);
252
- String errorCode = unsupported ? ZeroconfModule.ERROR_CODE_UNSUPPORTED : ZeroconfModule.ERROR_CODE_UNKNOWN_INTERFACE;
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
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_LIBRARY, errorCode, message, null);
252
+ NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_LIBRARY, errorCode, message, null);
258
253
  } else {
259
- zeroconfModule.sendError(ZeroconfModule.ERROR_DOMAIN_LIBRARY, errorCode, message, null, scanId);
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(ZeroconfModule.EVENT_STOP, new WritableNativeMap(), scanId);
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, WritableMap body, String scanId) {
325
- body.putString(ZeroconfModule.KEY_SCAN_ID, scanId);
326
- zeroconfModule.sendEvent(getReactApplicationContext(), eventName, body);
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 WritableMap nameToMap(String name) {
330
- WritableMap service = new WritableNativeMap();
331
- service.putString(ZeroconfModule.KEY_SERVICE_NAME, name);
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 WritableMap serviceNameToMap(NsdServiceInfo serviceInfo) {
336
- WritableMap service = new WritableNativeMap();
337
- service.putString(ZeroconfModule.KEY_SERVICE_NAME, serviceInfo.getServiceName());
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, ReadableArray txt, ZeroconfOptions options, Promise promise) {
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 ? ZeroconfModule.findNetwork(reactApplicationContext, options.networkInterface) : 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 ReadableArray txt, final Promise promise) {
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
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_NOT_PUBLISHED, "Service " + serviceName + " is not published", serviceName);
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 Promise promise) {
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 ? ZeroconfModule.findNetwork(reactApplicationContext, options.networkInterface) : 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
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, "Resolving service " + name + " failed: " + ZeroconfModule.describeNsdError(errorCode), name);
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
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_TIMEOUT, "Resolving service " + name + " failed: timed out", name);
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 Promise promise) {
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
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_NOT_PUBLISHED, "Service " + serviceName + " is not published", serviceName);
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(ZeroconfModule.EVENT_FOUND, nameToMap(type), scan.scanId);
508
+ sendScanEvent(NsdHost.EVENT_FOUND, nameToMap(type), scan.scanId);
514
509
  }
515
510
  for (String type : removed) {
516
- sendScanEvent(ZeroconfModule.EVENT_REMOVE, nameToMap(type), scan.scanId);
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 ReactApplicationContext getReactApplicationContext() {
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(ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_TIMEOUT, "Resolving service " + serviceName + " failed: timed out", serviceName, scanId);
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(ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_EXCEPTION, "Resolving service " + serviceName + " failed: " + e.getMessage(), serviceName, next.scanId);
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 Promise promise;
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
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_LIBRARY, ZeroconfModule.ERROR_CODE_TIMEOUT, "Resolving service " + serviceName + " failed: timed out", serviceName);
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: " + ZeroconfModule.describeNsdError(errorCode);
644
+ String message = "Resolving service " + serviceInfo.getServiceName() + " failed: " + NsdHost.describeNsdError(errorCode);
650
645
  if (promise != null) {
651
- ZeroconfModule.reject(promise, ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
646
+ NsdHost.reject(promise, NsdHost.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
652
647
  } else if (mScans.containsKey(scanId)) {
653
- zeroconfModule.sendError(ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName(), scanId);
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(ZeroconfModule.EVENT_RESOLVE, serviceInfoToMap(serviceInfo), scanId);
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 Promise registerPromise;
676
- @Nullable private Promise unregisterPromise;
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 Promise registerPromise, String serviceType, int port, @Nullable Network network) {
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, ReadableArray txt) {
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 (int i = 0; i < txt.size(); i++) {
705
- ReadableArray pair = txt.getArray(i);
706
- serviceInfo.setAttribute(pair.getString(0), pair.getString(1));
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
- WritableMap registeredToMap(NsdServiceInfo serviceInfo) {
713
- WritableMap service = serviceInfoToMap(serviceInfo);
714
- WritableMap txtMap = new WritableNativeMap();
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(ZeroconfModule.KEY_SERVICE_TXT, txtMap);
719
- service.putInt(ZeroconfModule.KEY_SERVICE_PORT, port);
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(getReactApplicationContext(), ZeroconfModule.EVENT_PUBLISHED, registeredToMap(NsdServiceInfo));
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: " + ZeroconfModule.describeNsdError(errorCode);
745
- zeroconfModule.sendError(ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
746
- ZeroconfModule.reject(registerPromise, ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
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(getReactApplicationContext(), ZeroconfModule.EVENT_UNREGISTERED, registeredToMap(nsdServiceInfo));
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: " + ZeroconfModule.describeNsdError(errorCode);
770
- zeroconfModule.sendError(ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
771
- ZeroconfModule.reject(unregisterPromise, ZeroconfModule.ERROR_DOMAIN_NSD, errorCode, message, serviceInfo.getServiceName());
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 WritableMap serviceInfoToMap(NsdServiceInfo serviceInfo) {
806
- WritableMap service = new WritableNativeMap();
807
- service.putString(ZeroconfModule.KEY_SERVICE_NAME, serviceInfo.getServiceName());
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(ZeroconfModule.KEY_SERVICE_HOST, hostname);
813
+ service.putString(NsdHost.KEY_SERVICE_HOST, hostname);
820
814
 
821
- WritableArray addresses = new WritableNativeArray();
815
+ List<String> addresses = new ArrayList<>();
822
816
  for (InetAddress address : hostAddresses) {
823
- addresses.pushString(address.getHostAddress());
817
+ addresses.add(address.getHostAddress());
824
818
  }
825
819
 
826
- service.putArray(ZeroconfModule.KEY_SERVICE_ADDRESSES, addresses);
820
+ service.putArray(NsdHost.KEY_SERVICE_ADDRESSES, addresses);
827
821
  }
828
- service.putString(ZeroconfModule.KEY_SERVICE_FULL_NAME, fullServiceName);
829
- service.putInt(ZeroconfModule.KEY_SERVICE_PORT, serviceInfo.getPort());
822
+ service.putString(NsdHost.KEY_SERVICE_FULL_NAME, fullServiceName);
823
+ service.putInt(NsdHost.KEY_SERVICE_PORT, serviceInfo.getPort());
830
824
 
831
- WritableMap txtRecords = new WritableNativeMap();
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(ZeroconfModule.KEY_SERVICE_TXT, txtRecords);
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, 0, result, namestr, typestr, domstr, x->context);
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
- if (inErrorCode == kDNSServiceErr_NoError && inRRType == kDNSServiceType_A)
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
- (const struct sockaddr *) &sa4, inTTL, x->context);
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
- err = DNSServiceQueryRecord(&x->aQuery, inFlags, inInterfaceIndex, inHostName, kDNSServiceType_A,
800
- kDNSServiceClass_IN, DNSServiceGetAddrInfoResponse, x);
801
- if (err) { DNSServiceGetAddrInfoDispose((mDNS_DirectOP*)x); errormsg = "DNSServiceQueryRecord"; goto fail; }
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);