react-native-zeroconf 0.17.3 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/NOTICE +2 -6
  2. package/README.md +1 -1
  3. package/android/CMakeLists.txt +64 -0
  4. package/android/build.gradle +1 -17
  5. package/android/generated/java/com/balthazargronon/RCTZeroconf/NativeZeroconfSpec.java +96 -0
  6. package/android/generated/jni/CMakeLists.txt +28 -0
  7. package/android/generated/jni/RNZeroconfSpec-generated.cpp +77 -0
  8. package/android/generated/jni/RNZeroconfSpec.h +31 -0
  9. package/android/generated/jni/react/renderer/components/RNZeroconfSpec/RNZeroconfSpecJSI.h +798 -0
  10. package/android/src/main/java/com/balthazargronon/RCTZeroconf/{ZeroconfModule.java → NsdHost.java} +97 -140
  11. package/android/src/main/java/com/balthazargronon/RCTZeroconf/NsdPayload.java +87 -0
  12. package/android/src/main/java/com/balthazargronon/RCTZeroconf/NsdPromise.java +40 -0
  13. package/android/src/main/java/com/balthazargronon/RCTZeroconf/Zeroconf.java +4 -6
  14. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfNativeSupport.java +60 -0
  15. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfOptions.java +15 -26
  16. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfReactPackage.java +5 -15
  17. package/android/src/main/java/com/balthazargronon/RCTZeroconf/nsd/NsdServiceImpl.java +90 -96
  18. package/android/src/main/jni/mdnsresponder/mDNSShared/dnssd_clientshim.c +31 -6
  19. package/cpp/Backend.cpp +16 -0
  20. package/cpp/Backend.h +116 -0
  21. package/cpp/ZeroconfModule.cpp +280 -0
  22. package/cpp/ZeroconfModule.h +144 -0
  23. package/cpp/android/NsdBackend.cpp +462 -0
  24. package/cpp/android/NsdBackend.h +61 -0
  25. package/cpp/android/ZeroconfAndroidModule.cpp +49 -0
  26. package/cpp/android/ZeroconfAndroidModule.h +15 -0
  27. package/cpp/apple/DispatchExecutor.cpp +66 -0
  28. package/cpp/apple/DispatchExecutor.h +37 -0
  29. package/cpp/apple/LocalNetworkAccess.h +19 -0
  30. package/cpp/apple/LocalNetworkAccess.mm +87 -0
  31. package/cpp/dnssd/DnssdBackend.cpp +976 -0
  32. package/cpp/dnssd/DnssdBackend.h +114 -0
  33. package/cpp/dnssd/Executor.h +28 -0
  34. package/cpp/embedded/EmbeddedExecutor.cpp +124 -0
  35. package/cpp/embedded/EmbeddedExecutor.h +57 -0
  36. package/ios/ZeroconfOnLoad.mm +34 -0
  37. package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec-generated.mm +140 -0
  38. package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec.h +189 -0
  39. package/ios/generated/ReactCodegen/RNZeroconfSpecJSI.h +798 -0
  40. package/lib/module/NativeZeroconf.js +15 -0
  41. package/lib/module/NativeZeroconf.js.map +1 -0
  42. package/lib/module/bridge.js +124 -0
  43. package/lib/module/bridge.js.map +1 -0
  44. package/{dist → lib/module}/index.js +149 -149
  45. package/lib/module/index.js.map +1 -0
  46. package/lib/module/package.json +1 -0
  47. package/lib/module/types.js +24 -0
  48. package/lib/module/types.js.map +1 -0
  49. package/lib/typescript/package.json +1 -0
  50. package/lib/typescript/src/NativeZeroconf.d.ts +75 -0
  51. package/lib/typescript/src/NativeZeroconf.d.ts.map +1 -0
  52. package/lib/typescript/src/bridge.d.ts +22 -0
  53. package/lib/typescript/src/bridge.d.ts.map +1 -0
  54. package/lib/typescript/src/index.d.ts +111 -0
  55. package/lib/typescript/src/index.d.ts.map +1 -0
  56. package/lib/typescript/src/types.d.ts +175 -0
  57. package/lib/typescript/src/types.d.ts.map +1 -0
  58. package/package.json +64 -29
  59. package/react-native-zeroconf.podspec +2 -1
  60. package/react-native.config.js +17 -0
  61. package/src/NativeZeroconf.ts +120 -0
  62. package/src/bridge.ts +153 -0
  63. package/src/index.ts +607 -0
  64. package/{index.d.ts → src/types.ts} +5 -99
  65. package/windows/RNZeroconf/RNZeroconf.vcxproj +17 -2
  66. package/windows/RNZeroconf/RNZeroconf.vcxproj.filters +0 -6
  67. package/windows/RNZeroconf/ReactPackageProvider.cpp +23 -20
  68. package/windows/RNZeroconf/WindowsBackend.cpp +156 -0
  69. package/windows/RNZeroconf/WindowsBackend.h +13 -0
  70. package/windows/RNZeroconf/ZeroconfCore.cpp +2 -2
  71. package/windows/RNZeroconf/ZeroconfCore.h +2 -2
  72. package/windows/RNZeroconf/ZeroconfWindowsModule.cpp +22 -0
  73. package/windows/RNZeroconf/ZeroconfWindowsModule.h +14 -0
  74. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroConfImplFactory.java +0 -56
  75. package/android/src/main/java/com/balthazargronon/RCTZeroconf/dnssd/DnssdImpl.java +0 -654
  76. package/android/src/main/java/com/github/druk/dnssd/BaseListener.java +0 -33
  77. package/android/src/main/java/com/github/druk/dnssd/BrowseListener.java +0 -67
  78. package/android/src/main/java/com/github/druk/dnssd/DNSRecord.java +0 -47
  79. package/android/src/main/java/com/github/druk/dnssd/DNSSD.java +0 -681
  80. package/android/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java +0 -198
  81. package/android/src/main/java/com/github/druk/dnssd/DNSSDException.java +0 -66
  82. package/android/src/main/java/com/github/druk/dnssd/DNSSDRecordRegistrar.java +0 -55
  83. package/android/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java +0 -54
  84. package/android/src/main/java/com/github/druk/dnssd/DNSSDService.java +0 -35
  85. package/android/src/main/java/com/github/druk/dnssd/DomainListener.java +0 -57
  86. package/android/src/main/java/com/github/druk/dnssd/InternalBrowseListener.java +0 -76
  87. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSD.java +0 -870
  88. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRecordRegistrar.java +0 -30
  89. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRegistration.java +0 -34
  90. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDService.java +0 -29
  91. package/android/src/main/java/com/github/druk/dnssd/InternalDomainListener.java +0 -62
  92. package/android/src/main/java/com/github/druk/dnssd/InternalQueryListener.java +0 -61
  93. package/android/src/main/java/com/github/druk/dnssd/InternalRegisterListener.java +0 -51
  94. package/android/src/main/java/com/github/druk/dnssd/InternalResolveListener.java +0 -58
  95. package/android/src/main/java/com/github/druk/dnssd/NSClass.java +0 -16
  96. package/android/src/main/java/com/github/druk/dnssd/NSType.java +0 -58
  97. package/android/src/main/java/com/github/druk/dnssd/QueryListener.java +0 -54
  98. package/android/src/main/java/com/github/druk/dnssd/RegisterListener.java +0 -46
  99. package/android/src/main/java/com/github/druk/dnssd/RegisterRecordListener.java +0 -35
  100. package/android/src/main/java/com/github/druk/dnssd/ResolveListener.java +0 -55
  101. package/android/src/main/java/com/github/druk/dnssd/TXTRecord.java +0 -293
  102. package/android/src/main/jni/Android.mk +0 -73
  103. package/android/src/main/jni/Application.mk +0 -3
  104. package/android/src/main/jni/DNSSD.java.h +0 -290
  105. package/android/src/main/jni/JNISupport.c +0 -1221
  106. package/ios/RNZeroconf/RNNetServiceSerializer.h +0 -31
  107. package/ios/RNZeroconf/RNNetServiceSerializer.m +0 -84
  108. package/ios/RNZeroconf/RNZeroconf.h +0 -17
  109. package/ios/RNZeroconf/RNZeroconf.m +0 -1025
  110. package/ios/RNZeroconf.xcodeproj/project.pbxproj +0 -261
  111. package/ios/RNZeroconf.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  112. package/src/index.js +0 -563
  113. package/windows/RNZeroconf/RNZeroconf.cpp +0 -228
  114. package/windows/RNZeroconf/RNZeroconf.h +0 -70
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.ImplType = void 0;
7
- exports.useServiceTypes = useServiceTypes;
8
- exports.useZeroconf = useZeroconf;
9
- var _react = require("react");
10
- var _reactNative = require("react-native");
11
- var _events = require("events");
12
- const RNZeroconf = _reactNative.NativeModules.RNZeroconf;
13
- const ImplType = exports.ImplType = {
14
- NSD: 'NSD',
15
- DNSSD: 'DNSSD'
16
- };
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { Platform, PermissionsAndroid } from 'react-native';
5
+ import { EventEmitter } from 'events';
6
+ import { getBridge } from "./bridge.js";
7
+ import { ImplType } from "./types.js";
8
+ export * from "./types.js";
9
+
10
+ // Payloads of the native events, scan events carry the id of the scan they belong to
11
+
17
12
  const SCAN_DEFAULTS = {
18
13
  type: 'http',
19
14
  protocol: 'tcp',
@@ -41,7 +36,14 @@ const withDefaults = (defaults, options) => {
41
36
  });
42
37
  return merged;
43
38
  };
44
- const isOptionsObject = value => value !== null && typeof value === 'object';
39
+
40
+ // The positional forms of scan() and publishService() were removed in 1.0: a clear error for JavaScript
41
+ // callers, TypeScript already rejects them
42
+ const removedPositionalForm = (options, method, replacement) => {
43
+ if (typeof options === 'string') {
44
+ throw new TypeError(`react-native-zeroconf: ${method}() takes an options object since 1.0, use ${replacement}`);
45
+ }
46
+ };
45
47
 
46
48
  // Options passed to native code, without the undefined ones
47
49
  const nativeOptions = options => Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
@@ -57,13 +59,19 @@ let instanceCount = 0;
57
59
  */
58
60
  const toError = payload => {
59
61
  if (!payload || typeof payload !== 'object') {
60
- return new Error(payload);
62
+ return new Error(String(payload));
61
63
  }
62
- const error = new Error(payload.message);
63
- error.code = payload.code;
64
- error.domain = payload.domain;
65
- if (payload.serviceName) {
66
- error.serviceName = payload.serviceName;
64
+ const {
65
+ message,
66
+ code,
67
+ domain,
68
+ serviceName
69
+ } = payload;
70
+ const error = new Error(message);
71
+ error.code = code;
72
+ error.domain = domain;
73
+ if (serviceName) {
74
+ error.serviceName = serviceName;
67
75
  }
68
76
  return error;
69
77
  };
@@ -71,7 +79,10 @@ const toError = payload => {
71
79
  /**
72
80
  * Promise rejections carry the same payload as error events in userInfo
73
81
  */
74
- const toRejection = error => error && error.userInfo && error.userInfo.domain ? toError(error.userInfo) : error;
82
+ const toRejection = error => {
83
+ const userInfo = error?.userInfo;
84
+ return userInfo && userInfo.domain ? toError(userInfo) : error;
85
+ };
75
86
 
76
87
  /**
77
88
  * Normalizes rejections, and marks the promise handled so callers that don't await it
@@ -101,9 +112,6 @@ const withAddressFamilies = service => {
101
112
  };
102
113
  };
103
114
 
104
- /**
105
- * TXT records as ordered [key, value] pairs, from an object or an array of pairs
106
- */
107
115
  // Browsing this type lists the service types on the network instead of services
108
116
  const SERVICE_TYPES = {
109
117
  type: 'services._dns-sd',
@@ -118,51 +126,71 @@ const parseServiceType = name => {
118
126
  protocol: match[2]
119
127
  } : null;
120
128
  };
129
+
130
+ /**
131
+ * TXT records as ordered [key, value] pairs, from an object or an array of pairs
132
+ */
121
133
  const toTxtPairs = txt => {
122
134
  const entries = Array.isArray(txt) ? txt : Object.entries(txt || {});
123
135
  return entries.map(([key, value]) => [String(key), String(value)]);
124
136
  };
125
- class Zeroconf extends _events.EventEmitter {
126
- constructor(props) {
127
- super(props);
128
- if (!RNZeroconf) {
129
- throw new Error('react-native-zeroconf: native module not found. Make sure the library is linked and the app rebuilt. Expo Go is not supported, use a development build instead.');
130
- }
131
- this._services = {};
132
- this._serviceTypes = {};
133
- this._scanningTypes = false;
134
- this._publishedServices = {};
135
- this._publishedImplTypes = {};
136
- this._scanImplType = null;
137
- this._scanId = `zeroconf-${++instanceCount}`;
138
- this._hasScanned = false;
139
- this._dListeners = {};
137
+ let bridge = null;
138
+ const nativeModule = () => {
139
+ bridge = bridge || getBridge();
140
+ if (!bridge) {
141
+ throw new Error('react-native-zeroconf: native module not found. Make sure the library is linked and the app rebuilt. Expo Go is not supported, use a development build instead.');
142
+ }
143
+ return bridge;
144
+ };
145
+
146
+ // Typed events on top of the `events` EventEmitter
147
+
148
+ // Typed events, merged into the class below
149
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
150
+
151
+ /** Extends the `events` package EventEmitter */
152
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
153
+ class Zeroconf extends EventEmitter {
154
+ _services = {};
155
+ _serviceTypes = {};
156
+ _scanningTypes = false;
157
+ _publishedServices = {};
158
+ _publishedImplTypes = {};
159
+ _scanImplType = null;
160
+ _scanId = `zeroconf-${++instanceCount}`;
161
+ _hasScanned = false;
162
+ _dListeners = {};
163
+ constructor() {
164
+ super();
165
+ nativeModule();
140
166
  this.addDeviceListeners();
141
167
  }
142
168
 
143
169
  /**
144
- * Add all event listeners
170
+ * Add the native event listeners (called automatically in the constructor)
145
171
  */
146
172
  addDeviceListeners() {
147
173
  if (Object.keys(this._dListeners).length) {
148
- return this.emit('error', new Error('RNZeroconf listeners already in place.'));
174
+ this.emit('error', new Error('RNZeroconf listeners already in place.'));
175
+ return;
149
176
  }
150
- this._dListeners.start = _reactNative.DeviceEventEmitter.addListener('RNZeroconfStart', payload => {
177
+ const native = nativeModule();
178
+ this._dListeners.start = native.listen('start', payload => {
151
179
  if (this._isOwnEvent(payload)) {
152
180
  this.emit('start');
153
181
  }
154
182
  });
155
- this._dListeners.stop = _reactNative.DeviceEventEmitter.addListener('RNZeroconfStop', payload => {
183
+ this._dListeners.stop = native.listen('stop', payload => {
156
184
  if (this._isOwnEvent(payload)) {
157
185
  this.emit('stop');
158
186
  }
159
187
  });
160
- this._dListeners.error = _reactNative.DeviceEventEmitter.addListener('RNZeroconfError', err => {
188
+ this._dListeners.error = native.listen('error', err => {
161
189
  if (this._isOwnEvent(err) && this.listenerCount('error') > 0) {
162
190
  this.emit('error', toError(err));
163
191
  }
164
192
  });
165
- this._dListeners.found = _reactNative.DeviceEventEmitter.addListener('RNZeroconfFound', service => {
193
+ this._dListeners.found = native.listen('found', service => {
166
194
  if (!service || !service.name || !this._isOwnEvent(service)) {
167
195
  return;
168
196
  }
@@ -178,13 +206,15 @@ class Zeroconf extends _events.EventEmitter {
178
206
  }
179
207
  return;
180
208
  }
209
+
210
+ // Found services only have a name until they are resolved
181
211
  this._services[name] = {
182
212
  name
183
213
  };
184
214
  this.emit('found', name);
185
215
  this.emit('update');
186
216
  });
187
- this._dListeners.remove = _reactNative.DeviceEventEmitter.addListener('RNZeroconfRemove', service => {
217
+ this._dListeners.remove = native.listen('remove', service => {
188
218
  if (!service || !service.name || !this._isOwnEvent(service)) {
189
219
  return;
190
220
  }
@@ -204,7 +234,8 @@ class Zeroconf extends _events.EventEmitter {
204
234
  this.emit('remove', name);
205
235
  this.emit('update');
206
236
  });
207
- this._dListeners.resolved = _reactNative.DeviceEventEmitter.addListener('RNZeroconfResolved', data => {
237
+ this._dListeners.resolved = native.listen('resolved', payload => {
238
+ const data = payload;
208
239
  if (!data || !data.name || !this._isOwnEvent(data)) {
209
240
  return;
210
241
  }
@@ -217,14 +248,16 @@ class Zeroconf extends _events.EventEmitter {
217
248
  this.emit('resolved', service);
218
249
  this.emit('update');
219
250
  });
220
- this._dListeners.published = _reactNative.DeviceEventEmitter.addListener('RNZeroconfServiceRegistered', service => {
251
+ this._dListeners.published = native.listen('published', payload => {
252
+ const service = payload;
221
253
  if (!service || !service.name) {
222
254
  return;
223
255
  }
224
256
  this._publishedServices[service.name] = service;
225
257
  this.emit('published', service);
226
258
  });
227
- this._dListeners.unpublished = _reactNative.DeviceEventEmitter.addListener('RNZeroconfServiceUnregistered', service => {
259
+ this._dListeners.unpublished = native.listen('unpublished', payload => {
260
+ const service = payload;
228
261
  if (!service || !service.name) {
229
262
  return;
230
263
  }
@@ -246,29 +279,32 @@ class Zeroconf extends _events.EventEmitter {
246
279
  * every scan's events, as before multiple scans, and events without a scan id (publishing) go to everyone.
247
280
  */
248
281
  _isOwnEvent(payload) {
249
- if (!payload || typeof payload !== 'object' || payload.scanId == null || !this._hasScanned) {
282
+ if (!payload || typeof payload !== 'object' || !this._hasScanned) {
250
283
  return true;
251
284
  }
252
- return payload.scanId === this._scanId;
285
+ const {
286
+ scanId
287
+ } = payload;
288
+ return scanId == null || scanId === this._scanId;
253
289
  }
254
290
 
255
291
  /**
256
- * Remove all event listeners and clean map
292
+ * Remove the native event listeners, call it when you are done with the instance
257
293
  */
258
294
  removeDeviceListeners() {
259
- Object.keys(this._dListeners).forEach(name => this._dListeners[name].remove());
295
+ Object.values(this._dListeners).forEach(listener => listener.remove());
260
296
  this._dListeners = {};
261
297
  }
262
298
 
263
299
  /**
264
- * Get all the services already resolved
300
+ * All the services found so far, keyed by name
265
301
  */
266
302
  getServices() {
267
303
  return this._services;
268
304
  }
269
305
 
270
306
  /**
271
- * Get the service types found by scanServiceTypes, as [{ type, protocol }]
307
+ * Service types found by `scanServiceTypes`
272
308
  */
273
309
  getServiceTypes() {
274
310
  return Object.values(this._serviceTypes);
@@ -278,8 +314,6 @@ class Zeroconf extends _events.EventEmitter {
278
314
  * Scan for the service types advertised on the network (_http._tcp, _ipp._tcp...), emits typeFound and typeRemove.
279
315
  * On iOS, only types declared in NSBonjourServices can then be scanned.
280
316
  * On iOS it requires the multicast entitlement. On Android with NSD and on Windows, services other apps publish on the same device are left out.
281
- *
282
- * scanServiceTypes({ domain, implType })
283
317
  */
284
318
  scanServiceTypes({
285
319
  domain,
@@ -295,18 +329,11 @@ class Zeroconf extends _events.EventEmitter {
295
329
  }
296
330
 
297
331
  /**
298
- * Scan for Zeroconf services, defaults to _http._tcp. on the local. domain
299
- *
300
- * scan({ type, protocol, domain, implType, resolveTimeout })
301
- * scan(type, protocol, domain, implType) is deprecated
332
+ * Scan for services, defaults to `_http._tcp.` on the `local.` domain
302
333
  */
303
- scan(options, protocolArg, domainArg, implTypeArg) {
304
- this._startScan(isOptionsObject(options) ? options : {
305
- type: options,
306
- protocol: protocolArg,
307
- domain: domainArg,
308
- implType: implTypeArg
309
- }, false);
334
+ scan(options = {}) {
335
+ removedPositionalForm(options, 'scan', 'scan({ type, protocol, domain, implType })');
336
+ this._startScan(options, false);
310
337
  }
311
338
  _startScan(options, scanningTypes) {
312
339
  const {
@@ -318,41 +345,32 @@ class Zeroconf extends _events.EventEmitter {
318
345
  subtype,
319
346
  networkInterface
320
347
  } = withDefaults(SCAN_DEFAULTS, options);
348
+ const native = nativeModule();
321
349
  this._services = {};
322
350
  this._serviceTypes = {};
323
351
  this._scanningTypes = scanningTypes;
324
352
  this._hasScanned = true;
325
353
  this.emit('update');
326
- if (_reactNative.Platform.OS === 'android') {
354
+ if (Platform.OS === 'android') {
327
355
  if (this._scanImplType && implType !== this._scanImplType) {
328
356
  // This instance's scan moves to the other implementation
329
- RNZeroconf.stop(this._scanId, this._scanImplType);
357
+ native.stop(this._scanId, this._scanImplType);
330
358
  }
331
359
  this._scanImplType = implType;
332
- RNZeroconf.scan(this._scanId, type, protocol, domain, implType, nativeOptions({
333
- resolveTimeout,
334
- subtype,
335
- networkInterface
336
- }));
337
- } else {
338
- RNZeroconf.scan(this._scanId, type, protocol, domain, nativeOptions({
339
- resolveTimeout,
340
- subtype,
341
- networkInterface
342
- }));
343
360
  }
361
+ native.scan(this._scanId, type, protocol, domain, implType, nativeOptions({
362
+ resolveTimeout,
363
+ subtype,
364
+ networkInterface
365
+ }));
344
366
  }
345
367
 
346
368
  /**
347
- * Stop current scan if any,
348
- * Defaults to the implementation used by the last scan
369
+ * Stop the current scan
370
+ * @param implType Android only, defaults to the implementation used by the last scan
349
371
  */
350
372
  stop(implType = this._scanImplType || ImplType.NSD) {
351
- if (_reactNative.Platform.OS === 'android') {
352
- RNZeroconf.stop(this._scanId, implType);
353
- } else {
354
- RNZeroconf.stop(this._scanId);
355
- }
373
+ nativeModule().stop(this._scanId, implType);
356
374
  }
357
375
 
358
376
  /**
@@ -367,29 +385,25 @@ class Zeroconf extends _events.EventEmitter {
367
385
  timeout = 5,
368
386
  request = true
369
387
  } = {}) {
370
- if (_reactNative.Platform.OS === 'android') {
371
- if (!RNZeroconf.checkLocalNetworkAccess) {
372
- return 'unknown';
373
- }
374
- const status = await asPromise(RNZeroconf.checkLocalNetworkAccess());
388
+ const native = nativeModule();
389
+ if (Platform.OS === 'android') {
390
+ const status = await asPromise(native.checkLocalNetworkAccess(null, timeout));
375
391
  if (status !== 'denied' || !request) {
376
392
  return status;
377
393
  }
378
- const result = await _reactNative.PermissionsAndroid.request(ACCESS_LOCAL_NETWORK);
379
- return result === _reactNative.PermissionsAndroid.RESULTS.GRANTED ? 'granted' : 'denied';
394
+ const result = await PermissionsAndroid.request(ACCESS_LOCAL_NETWORK);
395
+ return result === PermissionsAndroid.RESULTS.GRANTED ? 'granted' : 'denied';
380
396
  }
381
397
  const serviceType = type ? `_${type}._${protocol}` : null;
382
- return asPromise(RNZeroconf.checkLocalNetworkAccess(serviceType, timeout));
398
+ return asPromise(native.checkLocalNetworkAccess(serviceType, timeout));
383
399
  }
384
400
 
385
401
  /**
386
- * Publish a service, resolves with the published service once it is advertised.
387
- * Its name can differ from the requested one when that name is already taken.
388
- *
389
- * publishService({ type, protocol, domain, name, port, txt, implType })
390
- * publishService(type, protocol, domain, name, port, txt, implType) is deprecated
402
+ * Publish a service. Resolves with the published service once it is advertised, its name can differ
403
+ * from the requested one when that name is already taken. Rejects with a `ZeroconfError`.
391
404
  */
392
- publishService(options, protocolArg, domainArg, nameArg, portArg, txtArg, implTypeArg) {
405
+ publishService(options) {
406
+ removedPositionalForm(options, 'publishService', 'publishService({ type, protocol, domain, name, port, txt, implType })');
393
407
  const {
394
408
  type,
395
409
  protocol,
@@ -400,49 +414,34 @@ class Zeroconf extends _events.EventEmitter {
400
414
  implType,
401
415
  subtypes,
402
416
  networkInterface
403
- } = withDefaults(PUBLISH_DEFAULTS, isOptionsObject(options) ? options : {
404
- type: options,
405
- protocol: protocolArg,
406
- domain: domainArg,
407
- name: nameArg,
408
- port: portArg,
409
- txt: txtArg,
410
- implType: implTypeArg
411
- });
417
+ } = withDefaults(PUBLISH_DEFAULTS, options);
418
+ const native = nativeModule();
412
419
  const txtRecord = toTxtPairs(txt);
413
- const native = nativeOptions({
420
+ const options_ = nativeOptions({
414
421
  subtypes,
415
422
  networkInterface
416
423
  });
417
- if (_reactNative.Platform.OS === 'android') {
424
+ if (Platform.OS === 'android') {
418
425
  this._publishedImplTypes[name] = implType;
419
- return asPromise(RNZeroconf.registerService(type, protocol, domain, name, port, txtRecord, implType, native));
420
426
  }
421
- return asPromise(RNZeroconf.registerService(type, protocol, domain, name, port, txtRecord, native));
427
+ return asPromise(native.registerService(type, protocol, domain, name, port, txtRecord, implType, options_));
422
428
  }
423
429
 
424
430
  /**
425
431
  * Replace the TXT record of a published service, resolves with the updated service.
426
- * Android NSD has no update, the service is published again under the same name.
427
- *
428
- * updateService(name, { txt })
432
+ * Android `NSD` has no update: the service is published again under the same name.
429
433
  */
430
434
  updateService(name, {
431
435
  txt = {},
432
436
  implType = this._publishedImplTypes[name] || ImplType.NSD
433
437
  } = {}) {
434
438
  const txtRecord = toTxtPairs(txt);
435
- if (_reactNative.Platform.OS === 'android') {
436
- return asPromise(RNZeroconf.updateService(name, txtRecord, implType));
437
- }
438
- return asPromise(RNZeroconf.updateService(name, txtRecord));
439
+ return asPromise(nativeModule().updateService(name, txtRecord, implType));
439
440
  }
440
441
 
441
442
  /**
442
443
  * Resolve one service by name without scanning, for a device found before.
443
444
  * Resolves with the service, rejects with code 'TIMEOUT' when it doesn't answer in time.
444
- *
445
- * resolveService({ name, type, protocol, domain, implType, timeout, networkInterface })
446
445
  */
447
446
  resolveService(options) {
448
447
  const {
@@ -457,38 +456,38 @@ class Zeroconf extends _events.EventEmitter {
457
456
  ...SCAN_DEFAULTS,
458
457
  timeout: 5
459
458
  }, options);
460
- const native = nativeOptions({
459
+ const native = nativeModule();
460
+ const nativeOptions_ = nativeOptions({
461
461
  timeout,
462
462
  networkInterface
463
463
  });
464
- const promise = _reactNative.Platform.OS === 'android' ? RNZeroconf.resolveService(name, type, protocol, domain, implType, native) : RNZeroconf.resolveService(name, type, protocol, domain, native);
464
+ const promise = native.resolveService(name, type, protocol, domain, implType, nativeOptions_);
465
465
  return asPromise(asPromise(promise).then(service => service && withAddressFamilies(service)));
466
466
  }
467
467
 
468
468
  /**
469
- * Unpublish a service, resolves once it is no longer advertised.
470
- * Defaults to the implementation the service was published with
469
+ * Unpublish a service. Resolves once it is no longer advertised, rejects with a `ZeroconfError`
470
+ * (e.g. code `'NOT_PUBLISHED'`).
471
+ * @param implType Android only, defaults to the implementation the service was published with
471
472
  */
472
473
  unpublishService(name, implType = this._publishedImplTypes[name] || ImplType.NSD) {
473
- if (_reactNative.Platform.OS === 'android') {
474
+ if (Platform.OS === 'android') {
474
475
  delete this._publishedImplTypes[name];
475
- return asPromise(RNZeroconf.unregisterService(name, implType));
476
476
  }
477
- return asPromise(RNZeroconf.unregisterService(name));
477
+ return asPromise(nativeModule().unregisterService(name, implType));
478
478
  }
479
479
  }
480
-
480
+ export default Zeroconf;
481
481
  // Runs a scan while mounted and enabled, and again when deps change or on restart
482
- exports.default = Zeroconf;
483
482
  function useScan(enabled, startScan, read, deps) {
484
- const zeroconfRef = (0, _react.useRef)(null);
485
- const [items, setItems] = (0, _react.useState)([]);
486
- const [isScanning, setIsScanning] = (0, _react.useState)(false);
487
- const [error, setError] = (0, _react.useState)(null);
488
- const [scanCount, setScanCount] = (0, _react.useState)(0);
489
- const readRef = (0, _react.useRef)(read);
483
+ const zeroconfRef = useRef(null);
484
+ const [items, setItems] = useState([]);
485
+ const [isScanning, setIsScanning] = useState(false);
486
+ const [error, setError] = useState(null);
487
+ const [scanCount, setScanCount] = useState(0);
488
+ const readRef = useRef(read);
490
489
  readRef.current = read;
491
- (0, _react.useEffect)(() => {
490
+ useEffect(() => {
492
491
  const zeroconf = new Zeroconf();
493
492
  zeroconfRef.current = zeroconf;
494
493
  const unsubscribes = [zeroconf.subscribe('start', () => setIsScanning(true)), zeroconf.subscribe('stop', () => setIsScanning(false)), zeroconf.subscribe('update', () => setItems(readRef.current(zeroconf))), zeroconf.subscribe('error', setError)];
@@ -499,7 +498,7 @@ function useScan(enabled, startScan, read, deps) {
499
498
  zeroconfRef.current = null;
500
499
  };
501
500
  }, []);
502
- (0, _react.useEffect)(() => {
501
+ useEffect(() => {
503
502
  const zeroconf = zeroconfRef.current;
504
503
  if (!zeroconf || !enabled) {
505
504
  return undefined;
@@ -508,13 +507,14 @@ function useScan(enabled, startScan, read, deps) {
508
507
  setError(null);
509
508
  startScan(zeroconf);
510
509
  return () => zeroconf.stop();
510
+ // The options are the dependencies, not the callbacks built from them
511
511
  }, [enabled, scanCount, ...deps]);
512
- const stop = (0, _react.useCallback)(() => {
512
+ const stop = useCallback(() => {
513
513
  if (zeroconfRef.current) {
514
514
  zeroconfRef.current.stop();
515
515
  }
516
516
  }, []);
517
- const restart = (0, _react.useCallback)(() => setScanCount(count => count + 1), []);
517
+ const restart = useCallback(() => setScanCount(count => count + 1), []);
518
518
  return {
519
519
  items,
520
520
  isScanning,
@@ -525,13 +525,12 @@ function useScan(enabled, startScan, read, deps) {
525
525
  }
526
526
 
527
527
  /**
528
- * Scans while mounted and returns the resolved services.
529
- * Scans again when the options change, stops and cleans up on unmount.
530
- * Each hook runs its own scan, several can run at once.
528
+ * Scans while mounted and returns the resolved services. Scans again when the options change,
529
+ * stops and cleans up on unmount. Each hook runs its own scan, several can run at once.
531
530
  *
532
531
  * const { services, isScanning, error, stop, restart } = useZeroconf({ type: 'http' })
533
532
  */
534
- function useZeroconf(options = {}) {
533
+ export function useZeroconf(options = {}) {
535
534
  const {
536
535
  type,
537
536
  protocol,
@@ -567,7 +566,7 @@ function useZeroconf(options = {}) {
567
566
  *
568
567
  * const { serviceTypes, isScanning, error, stop, restart } = useServiceTypes()
569
568
  */
570
- function useServiceTypes(options = {}) {
569
+ export function useServiceTypes(options = {}) {
571
570
  const {
572
571
  domain,
573
572
  implType,
@@ -587,3 +586,4 @@ function useServiceTypes(options = {}) {
587
586
  ...scan
588
587
  };
589
588
  }
589
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useEffect","useRef","useState","Platform","PermissionsAndroid","EventEmitter","getBridge","ImplType","SCAN_DEFAULTS","type","protocol","domain","implType","NSD","resolveTimeout","PUBLISH_DEFAULTS","txt","withDefaults","defaults","options","merged","Object","entries","forEach","key","value","undefined","removedPositionalForm","method","replacement","TypeError","nativeOptions","fromEntries","filter","ACCESS_LOCAL_NETWORK","instanceCount","toError","payload","Error","String","message","code","serviceName","error","toRejection","userInfo","asPromise","nativePromise","promise","Promise","resolve","catch","isIPv6","address","includes","withAddressFamilies","service","addresses","Array","isArray","ipv4","ipv6","SERVICE_TYPES","parseServiceType","name","match","exec","toTxtPairs","map","bridge","nativeModule","Zeroconf","_services","_serviceTypes","_scanningTypes","_publishedServices","_publishedImplTypes","_scanImplType","_scanId","_hasScanned","_dListeners","constructor","addDeviceListeners","keys","length","emit","native","start","listen","_isOwnEvent","stop","err","listenerCount","found","serviceType","remove","resolved","data","scanId","published","unpublished","subscribe","event","listener","on","removeListener","removeDeviceListeners","values","getServices","getServiceTypes","scanServiceTypes","networkInterface","_startScan","scan","scanningTypes","subtype","OS","checkLocalNetworkAccess","timeout","request","status","result","RESULTS","GRANTED","publishService","port","subtypes","txtRecord","options_","registerService","updateService","resolveService","nativeOptions_","then","unpublishService","unregisterService","useScan","enabled","startScan","read","deps","zeroconfRef","items","setItems","isScanning","setIsScanning","setError","scanCount","setScanCount","readRef","current","zeroconf","unsubscribes","unsubscribe","restart","count","useZeroconf","services","useServiceTypes","serviceTypes"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAChE,SAASC,QAAQ,EAAEC,kBAAkB,QAAQ,cAAc;AAC3D,SAASC,YAAY,QAAQ,QAAQ;AAErC,SAASC,SAAS,QAAkE,aAAU;AAC9F,SACEC,QAAQ,QAiBH,YAAS;AAEhB,cAAc,YAAS;;AAEvB;;AAUA,MAAMC,aAAa,GAAG;EACpBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,KAAK;EACfC,MAAM,E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ACRC,MAAM;IACNC,QAAQ;IACRE,cAAc;IACdqG,OAAO;IACPJ;EACF,CAAC,CAAC;EACJ;EACAwC,QAAQ,IAAIlI,MAAM,CAACsF,MAAM,CAAC4C,QAAQ,CAAC3C,WAAW,CAAC,CAAC,CAAC,CAAC3E,MAAM,CAACuB,OAAO,IAAIA,OAAO,CAACC,SAAS,CAAC,EACtF,CAAChD,IAAI,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,QAAQ,EAAEE,cAAc,EAAEqG,OAAO,EAAEJ,gBAAgB,CAC9E,CAAC;EACD,OAAO;IAAE8C,QAAQ,EAAEf,KAAK;IAAE,GAAG7B;EAAK,CAAC;AACrC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS6C,eAAeA,CAAC3I,OAA+B,GAAG,CAAC,CAAC,EAAyB;EAC3F,MAAM;IAAER,MAAM;IAAEC,QAAQ;IAAEmG,gBAAgB;IAAE0B,OAAO,GAAG;EAAK,CAAC,GAAGtH,OAAO;EACtE,MAAM;IAAE2H,KAAK;IAAE,GAAG7B;EAAK,CAAC,GAAGuB,OAAO,CAChCC,OAAO,EACPc,QAAQ,IAAIA,QAAQ,CAACzC,gBAAgB,CAAC;IAAEnG,MAAM;IAAEC,QAAQ;IAAEmG;EAAiB,CAAC,CAAC,EAC7EwC,QAAQ,IAAIA,QAAQ,CAAC1C,eAAe,CAAC,CAAC,EACtC,CAAClG,MAAM,EAAEC,QAAQ,EAAEmG,gBAAgB,CACrC,CAAC;EACD,OAAO;IAAEgD,YAAY,EAAEjB,KAAK;IAAE,GAAG7B;EAAK,CAAC;AACzC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ /** Android only: which discovery implementation to use */
4
+ export const ImplType = {
5
+ NSD: 'NSD',
6
+ DNSSD: 'DNSSD'
7
+ };
8
+
9
+ /** TXT records as an object, or as [key, value] pairs to control the order */
10
+
11
+ /**
12
+ * Errors emitted by the `error` event
13
+ *
14
+ * - `DNSSD`: DNSServiceErrorType, on iOS and from Android's embedded mDNSResponder,
15
+ * e.g. `-65555` type missing from NSBonjourServices, `-65570` Local Network access denied
16
+ * - `NsdManager`: Android NsdManager failure code
17
+ * - `Windows`: Win32 / DNS_STATUS code from the Windows DNS-SD functions
18
+ * - `RNZeroconf`: the library's own errors, e.g. `'EXCEPTION'`, `'TIMEOUT'`, `'UNKNOWN_INTERFACE'`
19
+ */
20
+
21
+ /** Published services don't carry the address family fields */
22
+
23
+ /** A service type advertised on the network, e.g. `{ type: 'http', protocol: 'tcp' }` for `_http._tcp` */
24
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ImplType","NSD","DNSSD"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,QAAQ,GAAG;EACtBC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE;AACT,CAAU;;AAsBV;;AAqEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;;AAuBA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}