react-native-zeroconf 0.16.1 → 0.17.0

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 (44) hide show
  1. package/NOTICE +0 -3
  2. package/README.md +1 -1
  3. package/android/build.gradle +0 -3
  4. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroConfImplFactory.java +1 -1
  5. package/android/src/main/java/com/balthazargronon/RCTZeroconf/Zeroconf.java +12 -2
  6. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfModule.java +129 -4
  7. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroconfOptions.java +72 -0
  8. package/android/src/main/java/com/balthazargronon/RCTZeroconf/dnssd/DnssdImpl.java +633 -0
  9. package/android/src/main/java/com/balthazargronon/RCTZeroconf/nsd/NsdServiceImpl.java +331 -34
  10. package/android/src/main/java/com/balthazargronon/RCTZeroconf/nsd/ServiceTypesQuery.java +296 -0
  11. package/android/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java +1 -1
  12. package/android/src/main/jni/mdnsresponder/mDNSShared/dnssd_clientshim.c +59 -22
  13. package/dist/index.js +234 -48
  14. package/index.d.ts +101 -6
  15. package/ios/RNZeroconf/RNZeroconf.m +285 -22
  16. package/package.json +28 -4
  17. package/src/index.js +214 -44
  18. package/windows/ExperimentalFeatures.props +33 -0
  19. package/windows/NuGet.config +11 -0
  20. package/windows/RNZeroconf/RNZeroconf.cpp +227 -0
  21. package/windows/RNZeroconf/RNZeroconf.def +3 -0
  22. package/windows/RNZeroconf/RNZeroconf.h +70 -0
  23. package/windows/RNZeroconf/RNZeroconf.rc +0 -0
  24. package/windows/RNZeroconf/RNZeroconf.vcxproj +150 -0
  25. package/windows/RNZeroconf/RNZeroconf.vcxproj.filters +50 -0
  26. package/windows/RNZeroconf/ReactPackageProvider.cpp +20 -0
  27. package/windows/RNZeroconf/ReactPackageProvider.h +24 -0
  28. package/windows/RNZeroconf/ReactPackageProvider.idl +9 -0
  29. package/windows/RNZeroconf/ZeroconfCore.cpp +1042 -0
  30. package/windows/RNZeroconf/ZeroconfCore.h +165 -0
  31. package/windows/RNZeroconf/pch.cpp +1 -0
  32. package/windows/RNZeroconf/pch.h +30 -0
  33. package/windows/RNZeroconf/resource.h +5 -0
  34. package/windows/RNZeroconf/targetver.h +8 -0
  35. package/windows/RNZeroconf.sln +43 -0
  36. package/android/src/main/java/com/balthazargronon/RCTZeroconf/rx2dnssd/DnssdImpl.java +0 -305
  37. package/android/src/main/java/com/github/druk/rx2dnssd/BonjourService.java +0 -400
  38. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2BrowseListener.java +0 -55
  39. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2Dnssd.java +0 -127
  40. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2DnssdCommon.java +0 -280
  41. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2DnssdEmbedded.java +0 -31
  42. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2QueryListener.java +0 -70
  43. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2RegisterListener.java +0 -47
  44. package/android/src/main/java/com/github/druk/rx2dnssd/Rx2ResolveListener.java +0 -51
@@ -1,280 +0,0 @@
1
- package com.github.druk.rx2dnssd;
2
-
3
- import com.github.druk.dnssd.DNSSD;
4
- import com.github.druk.dnssd.DNSSDException;
5
- import com.github.druk.dnssd.DNSSDService;
6
- import com.github.druk.dnssd.NSClass;
7
- import com.github.druk.dnssd.NSType;
8
- import com.github.druk.dnssd.TXTRecord;
9
-
10
- import androidx.annotation.NonNull;
11
-
12
- import java.util.Map;
13
-
14
- import io.reactivex.BackpressureStrategy;
15
- import io.reactivex.Flowable;
16
- import io.reactivex.FlowableEmitter;
17
- import io.reactivex.FlowableOnSubscribe;
18
- import io.reactivex.FlowableTransformer;
19
- import io.reactivex.functions.Action;
20
-
21
- abstract class Rx2DnssdCommon implements Rx2Dnssd {
22
-
23
- final private DNSSD mDNSSD;
24
-
25
- Rx2DnssdCommon(DNSSD dnssd) {
26
- mDNSSD = dnssd;
27
- }
28
-
29
- public DNSSD getDNSSD() {
30
- return mDNSSD;
31
- }
32
-
33
- /**
34
- * Browse for instances of a service.<P>
35
- *
36
- * @param regType The registration type being browsed for followed by the protocol, separated by a
37
- * dot (e.g. "_ftp._tcp"). The transport protocol must be "_tcp" or "_udp".
38
- * <p>
39
- * @param domain If non-null, specifies the domain on which to browse for services.
40
- * Most applications will not specify a domain, instead browsing on the
41
- * default domain(s).
42
- * <p>
43
- * @return A {@link Flowable} that represents the active browse operation.
44
- */
45
- @NonNull
46
- @Override
47
- //TODO: Finbugs: new DNSSDServiceCreator<BonjourService> should be a static class (Performance issue ???)
48
- public Flowable<BonjourService> browse(@NonNull final String regType, @NonNull final String domain) {
49
- return createFlowable(emitter ->
50
- mDNSSD.browse(0, DNSSD.ALL_INTERFACES, regType, domain,
51
- new Rx2BrowseListener(emitter)));
52
- }
53
-
54
- /**
55
- * Resolve a {@link Flowable} to a target host name, port number, and txt record.<P>
56
- * <p>
57
- * Note: Applications should NOT use resolve() solely for txt record monitoring - use
58
- * queryRecord() instead, as it is more efficient for this task.<P>
59
- * <p>
60
- * Note: resolve() behaves correctly for typical services that have a single SRV record and
61
- * a single TXT record (the TXT record may be empty.) To resolve non-standard services with
62
- * multiple SRV or TXT records, use queryRecord().<P>
63
- *
64
- * @return A {@link FlowableTransformer} that transform not resolved object to resolved.
65
- */
66
- @NonNull
67
- @Override
68
- public FlowableTransformer<BonjourService, BonjourService> resolve() {
69
- return flowable -> flowable.flatMap(bs -> {
70
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
71
- return Flowable.just(bs);
72
- }
73
- return createFlowable(emitter ->
74
- mDNSSD.resolve(bs.getFlags(), bs.getIfIndex(), bs.getServiceName(), bs.getRegType(), bs.getDomain(),
75
- new Rx2ResolveListener(emitter, bs)));
76
- });
77
- }
78
-
79
- /**
80
- * Query ipv4 and ipv6 addresses
81
- *
82
- * @return A {@link FlowableTransformer} that transform object without addresses to object with addresses.
83
- */
84
- @NonNull
85
- @Override
86
- @Deprecated
87
- public FlowableTransformer<BonjourService, BonjourService> queryRecords() {
88
- return flowable -> flowable.flatMap(bs -> {
89
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
90
- return Flowable.just(bs);
91
- }
92
- BonjourService.Builder builder = new BonjourService.Builder(bs);
93
-
94
- Flowable<BonjourService> flowableV4 = createFlowable(emitter ->
95
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.A, NSClass.IN, true,
96
- new Rx2QueryListener(emitter, builder, true)));
97
- Flowable<BonjourService> flowableV6 = createFlowable(emitter ->
98
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.AAAA, NSClass.IN, true,
99
- new Rx2QueryListener(emitter, builder, true)));
100
-
101
- return flowableV4.mergeWith(flowableV6);
102
- });
103
- }
104
-
105
- /**
106
- * Query ipv4 and ipv6 addresses with auto-stop (first response or timeout)
107
- *
108
- * @return A {@link FlowableTransformer} that transform object without addresses to object with addresses.
109
- */
110
- @NonNull
111
- @Override
112
- public FlowableTransformer<BonjourService, BonjourService> queryIPRecords() {
113
- return flowable -> flowable.flatMap(bs -> {
114
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
115
- return Flowable.just(bs);
116
- }
117
- BonjourService.Builder builder = new BonjourService.Builder(bs);
118
-
119
- Flowable<BonjourService> flowableV4 = createFlowable(emitter ->
120
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.A, NSClass.IN, true,
121
- new Rx2QueryListener(emitter, builder, true)));
122
- Flowable<BonjourService> flowableV6 = createFlowable(emitter ->
123
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.AAAA, NSClass.IN, true,
124
- new Rx2QueryListener(emitter, builder, true)));
125
-
126
- return flowableV4.mergeWith(flowableV6);
127
- });
128
- }
129
-
130
- /**
131
- * Query ipv4 address with auto-stop (first response or timeout)
132
- *
133
- * @return A {@link FlowableTransformer} that transform object without address to object with address.
134
- */
135
- @NonNull
136
- @Override
137
- public FlowableTransformer<BonjourService, BonjourService> queryIPV4Records() {
138
- return flowable -> flowable.flatMap(bs -> {
139
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
140
- return Flowable.just(bs);
141
- }
142
- return createFlowable(emitter ->
143
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.A, NSClass.IN, true,
144
- new Rx2QueryListener(emitter, new BonjourService.Builder(bs), true)));
145
- });
146
- }
147
-
148
- /**
149
- * Query ipv6 address with auto-stop (first response or timeout)
150
- *
151
- * @return A {@link FlowableTransformer} that transform object without address to object with address.
152
- */
153
- @NonNull
154
- @Override
155
- public FlowableTransformer<BonjourService, BonjourService> queryIPV6Records() {
156
- return flowable -> flowable.flatMap(bs -> {
157
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
158
- return Flowable.just(bs);
159
- }
160
- return createFlowable(emitter ->
161
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.AAAA, NSClass.IN, true,
162
- new Rx2QueryListener(emitter, new BonjourService.Builder(bs), true)));
163
- });
164
- }
165
-
166
- /**
167
- * Query ipv4 and ipv6 addresses
168
- *
169
- * @return A {@link Flowable} with ip addresses
170
- */
171
- @NonNull
172
- @Override
173
- public Flowable<BonjourService> queryIPRecords(BonjourService bs) {
174
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
175
- return Flowable.just(bs);
176
- }
177
- final BonjourService.Builder builder = new BonjourService.Builder(bs);
178
- return createFlowable((DNSSDServiceCreator<BonjourService>) subscriber ->
179
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.A, NSClass.IN, false, new Rx2QueryListener(subscriber, builder, false)))
180
- .mergeWith(createFlowable(subscriber ->
181
- mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), NSType.AAAA, NSClass.IN, false, new Rx2QueryListener(subscriber, builder, false))));
182
- }
183
-
184
- /**
185
- * Query ipv4 address
186
- *
187
- * @return A {@link Flowable}
188
- */
189
- @NonNull
190
- @Override
191
- public Flowable<BonjourService> queryIPV4Records(BonjourService bs) {
192
- return queryRecords(bs, NSType.A);
193
- }
194
-
195
- /**
196
- * Query ipv6 address
197
- *
198
- * @return A {@link Flowable}
199
- */
200
- @NonNull
201
- @Override
202
- public Flowable<BonjourService> queryIPV6Records(BonjourService bs) {
203
- return queryRecords(bs, NSType.AAAA);
204
- }
205
-
206
- /**
207
- * Query TXT records
208
- *
209
- * @return A {@link Flowable}
210
- */
211
- @NonNull
212
- @Override
213
- public Flowable<BonjourService> queryTXTRecords(BonjourService bs) {
214
- return queryRecords(bs, NSType.TXT);
215
- }
216
-
217
- private Flowable<BonjourService> queryRecords(BonjourService bs, int type) {
218
- if ((bs.getFlags() & BonjourService.LOST) == BonjourService.LOST) {
219
- return Flowable.just(bs);
220
- }
221
- return createFlowable(subscriber -> mDNSSD.queryRecord(0, bs.getIfIndex(), bs.getHostname(), type, NSClass.IN, false,
222
- new Rx2QueryListener(subscriber, new BonjourService.Builder(bs), false)));
223
- }
224
-
225
- @NonNull
226
- @Override
227
- public Flowable<BonjourService> register(@NonNull final BonjourService bs) {
228
- return createFlowable(emitter ->
229
- mDNSSD.register(bs.getFlags(), bs.getIfIndex(), bs.getServiceName(), bs.getRegType(), bs.getDomain(), null, bs.getPort(),
230
- createTxtRecord(bs.getTxtRecords()), new Rx2RegisterListener(emitter)));
231
- }
232
-
233
- @SuppressWarnings("PMD.SignatureDeclareThrowsException")
234
- private static class DNSSDServiceAction<T> implements FlowableOnSubscribe<T>, Action {
235
-
236
- private final DNSSDServiceCreator<T> creator;
237
- private DNSSDService service;
238
-
239
- DNSSDServiceAction(DNSSDServiceCreator<T> creator) {
240
- this.creator = creator;
241
- }
242
-
243
- @Override
244
- public void subscribe(FlowableEmitter<T> emitter) {
245
- if (!emitter.isCancelled() && creator != null) {
246
- try {
247
- service = creator.getService(emitter);
248
- } catch (DNSSDException e) {
249
- emitter.onError(e);
250
- }
251
- }
252
- }
253
-
254
- @Override
255
- public void run() {
256
- if (service != null) {
257
- service.stop();
258
- service = null;
259
- }
260
- }
261
- }
262
-
263
- private interface DNSSDServiceCreator<T> {
264
- DNSSDService getService(FlowableEmitter<? super T> emitter) throws DNSSDException;
265
- }
266
-
267
- private <T> Flowable<T> createFlowable(DNSSDServiceCreator<T> creator) {
268
- DNSSDServiceAction<T> action = new DNSSDServiceAction<>(creator);
269
- return Flowable.create(action, BackpressureStrategy.BUFFER)
270
- .doFinally(action);
271
- }
272
-
273
- private static TXTRecord createTxtRecord(Map<String, String> records) {
274
- TXTRecord txtRecord = new TXTRecord();
275
- for (Map.Entry<String, String> entry : records.entrySet()) {
276
- txtRecord.set(entry.getKey(), entry.getValue());
277
- }
278
- return txtRecord;
279
- }
280
- }
@@ -1,31 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Andriy Druk
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- package com.github.druk.rx2dnssd;
17
-
18
- import android.content.Context;
19
-
20
- import com.github.druk.dnssd.DNSSDEmbedded;
21
-
22
- /**
23
- * RxDnssdEmbedded is implementation of RxDnssd with embedded DNS-SD {@link Rx2Dnssd}
24
- */
25
- public class Rx2DnssdEmbedded extends Rx2DnssdCommon {
26
-
27
- public Rx2DnssdEmbedded(Context context) {
28
- super(new DNSSDEmbedded(context));
29
- }
30
-
31
- }
@@ -1,70 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Andriy Druk
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- package com.github.druk.rx2dnssd;
17
-
18
- import com.github.druk.dnssd.DNSSD;
19
- import com.github.druk.dnssd.DNSSDService;
20
- import com.github.druk.dnssd.NSType;
21
- import com.github.druk.dnssd.QueryListener;
22
-
23
- import java.net.InetAddress;
24
- import java.net.UnknownHostException;
25
-
26
- import io.reactivex.FlowableEmitter;
27
-
28
- class Rx2QueryListener implements QueryListener {
29
-
30
- private final FlowableEmitter<? super BonjourService> emitter;
31
- private final BonjourService.Builder builder;
32
- private final boolean completable;
33
-
34
- Rx2QueryListener(FlowableEmitter<? super BonjourService> emitter, BonjourService.Builder builder, boolean completable) {
35
- this.emitter = emitter;
36
- this.builder = builder;
37
- this.completable = completable;
38
- }
39
-
40
- @Override
41
- public void queryAnswered(DNSSDService query, int flags, int ifIndex, String fullName, int rrtype, int rrclass, byte[] rdata, int ttl) {
42
- if (emitter.isCancelled()) {
43
- return;
44
- }
45
- if (rrtype == NSType.A || rrtype == NSType.AAAA) {
46
- try {
47
- InetAddress inetAddress = InetAddress.getByAddress(rdata);
48
- builder.inetAddress(inetAddress);
49
- } catch (UnknownHostException e) {
50
- emitter.tryOnError(e);
51
- }
52
- } else if (rrtype == NSType.TXT) {
53
- builder.dnsRecords(DNSSD.parseTXTRecords(rdata));
54
- } else {
55
- emitter.tryOnError(new Exception("Unsupported type of record: " + rrtype));
56
- }
57
- emitter.onNext(builder.build());
58
- if (completable) {
59
- emitter.onComplete();
60
- }
61
- }
62
-
63
- @Override
64
- public void operationFailed(DNSSDService service, int errorCode) {
65
- if (emitter.isCancelled()) {
66
- return;
67
- }
68
- emitter.onError(new RuntimeException("DNSSD queryRecord error: " + errorCode));
69
- }
70
- }
@@ -1,47 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Andriy Druk
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- package com.github.druk.rx2dnssd;
17
-
18
- import com.github.druk.dnssd.DNSSDRegistration;
19
- import com.github.druk.dnssd.DNSSDService;
20
- import com.github.druk.dnssd.RegisterListener;
21
-
22
- import io.reactivex.FlowableEmitter;
23
-
24
- class Rx2RegisterListener implements RegisterListener {
25
- private final FlowableEmitter<? super BonjourService> emitter;
26
-
27
- Rx2RegisterListener(FlowableEmitter<? super BonjourService> emitter) {
28
- this.emitter = emitter;
29
- }
30
-
31
- @Override
32
- public void serviceRegistered(DNSSDRegistration registration, int flags, String serviceName, String regType, String domain) {
33
- if (emitter.isCancelled()) {
34
- return;
35
- }
36
- BonjourService service = new BonjourService.Builder(flags, 0, serviceName, regType, domain).build();
37
- emitter.onNext(service);
38
- }
39
-
40
- @Override
41
- public void operationFailed(DNSSDService service, int errorCode) {
42
- if (emitter.isCancelled()) {
43
- return;
44
- }
45
- emitter.onError(new RuntimeException("DNSSD browse error: " + errorCode));
46
- }
47
- }
@@ -1,51 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Andriy Druk
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- package com.github.druk.rx2dnssd;
17
-
18
- import com.github.druk.dnssd.DNSSDService;
19
- import com.github.druk.dnssd.ResolveListener;
20
-
21
- import java.util.Map;
22
-
23
- import io.reactivex.FlowableEmitter;
24
-
25
- class Rx2ResolveListener implements ResolveListener {
26
- private final FlowableEmitter<? super BonjourService> emitter;
27
- private final BonjourService.Builder builder;
28
-
29
- Rx2ResolveListener(FlowableEmitter<? super BonjourService> emitter, BonjourService service) {
30
- this.emitter = emitter;
31
- this.builder = new BonjourService.Builder(service);
32
- }
33
-
34
- @Override
35
- public void serviceResolved(DNSSDService resolver, int flags, int ifIndex, String fullName, String hostName, int port, Map<String, String> txtRecord) {
36
- if (emitter.isCancelled()) {
37
- return;
38
- }
39
- BonjourService bonjourService = builder.port(port).hostname(hostName).dnsRecords(txtRecord).build();
40
- emitter.onNext(bonjourService);
41
- emitter.onComplete();
42
- }
43
-
44
- @Override
45
- public void operationFailed(DNSSDService service, int errorCode) {
46
- if (emitter.isCancelled()) {
47
- return;
48
- }
49
- emitter.onError(new RuntimeException("DNSSD resolve error: " + errorCode));
50
- }
51
- }