react-native-zeroconf 0.17.2 → 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 (117) 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 -13
  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/mDNSPosix/PosixDaemon.c +19 -1
  19. package/android/src/main/jni/mdnsresponder/mDNSPosix/mDNSPosix.c +104 -1
  20. package/android/src/main/jni/mdnsresponder/mDNSPosix/mDNSPosix.h +7 -0
  21. package/android/src/main/jni/mdnsresponder/mDNSShared/dnssd_clientshim.c +34 -9
  22. package/cpp/Backend.cpp +16 -0
  23. package/cpp/Backend.h +116 -0
  24. package/cpp/ZeroconfModule.cpp +280 -0
  25. package/cpp/ZeroconfModule.h +144 -0
  26. package/cpp/android/NsdBackend.cpp +462 -0
  27. package/cpp/android/NsdBackend.h +61 -0
  28. package/cpp/android/ZeroconfAndroidModule.cpp +49 -0
  29. package/cpp/android/ZeroconfAndroidModule.h +15 -0
  30. package/cpp/apple/DispatchExecutor.cpp +66 -0
  31. package/cpp/apple/DispatchExecutor.h +37 -0
  32. package/cpp/apple/LocalNetworkAccess.h +19 -0
  33. package/cpp/apple/LocalNetworkAccess.mm +87 -0
  34. package/cpp/dnssd/DnssdBackend.cpp +976 -0
  35. package/cpp/dnssd/DnssdBackend.h +114 -0
  36. package/cpp/dnssd/Executor.h +28 -0
  37. package/cpp/embedded/EmbeddedExecutor.cpp +124 -0
  38. package/cpp/embedded/EmbeddedExecutor.h +57 -0
  39. package/ios/ZeroconfOnLoad.mm +34 -0
  40. package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec-generated.mm +140 -0
  41. package/ios/generated/ReactCodegen/RNZeroconfSpec/RNZeroconfSpec.h +189 -0
  42. package/ios/generated/ReactCodegen/RNZeroconfSpecJSI.h +798 -0
  43. package/lib/module/NativeZeroconf.js +15 -0
  44. package/lib/module/NativeZeroconf.js.map +1 -0
  45. package/lib/module/bridge.js +124 -0
  46. package/lib/module/bridge.js.map +1 -0
  47. package/{dist → lib/module}/index.js +149 -149
  48. package/lib/module/index.js.map +1 -0
  49. package/lib/module/package.json +1 -0
  50. package/lib/module/types.js +24 -0
  51. package/lib/module/types.js.map +1 -0
  52. package/lib/typescript/package.json +1 -0
  53. package/lib/typescript/src/NativeZeroconf.d.ts +75 -0
  54. package/lib/typescript/src/NativeZeroconf.d.ts.map +1 -0
  55. package/lib/typescript/src/bridge.d.ts +22 -0
  56. package/lib/typescript/src/bridge.d.ts.map +1 -0
  57. package/lib/typescript/src/index.d.ts +111 -0
  58. package/lib/typescript/src/index.d.ts.map +1 -0
  59. package/lib/typescript/src/types.d.ts +175 -0
  60. package/lib/typescript/src/types.d.ts.map +1 -0
  61. package/package.json +65 -29
  62. package/react-native-zeroconf.podspec +2 -1
  63. package/react-native.config.js +17 -0
  64. package/src/NativeZeroconf.ts +120 -0
  65. package/src/bridge.ts +153 -0
  66. package/src/index.ts +607 -0
  67. package/{index.d.ts → src/types.ts} +5 -99
  68. package/windows/RNZeroconf/RNZeroconf.vcxproj +17 -2
  69. package/windows/RNZeroconf/RNZeroconf.vcxproj.filters +0 -6
  70. package/windows/RNZeroconf/ReactPackageProvider.cpp +23 -20
  71. package/windows/RNZeroconf/WindowsBackend.cpp +156 -0
  72. package/windows/RNZeroconf/WindowsBackend.h +13 -0
  73. package/windows/RNZeroconf/ZeroconfCore.cpp +2 -2
  74. package/windows/RNZeroconf/ZeroconfCore.h +2 -2
  75. package/windows/RNZeroconf/ZeroconfWindowsModule.cpp +22 -0
  76. package/windows/RNZeroconf/ZeroconfWindowsModule.h +14 -0
  77. package/android/src/main/java/com/balthazargronon/RCTZeroconf/ZeroConfImplFactory.java +0 -56
  78. package/android/src/main/java/com/balthazargronon/RCTZeroconf/dnssd/DnssdImpl.java +0 -654
  79. package/android/src/main/java/com/github/druk/dnssd/BaseListener.java +0 -33
  80. package/android/src/main/java/com/github/druk/dnssd/BrowseListener.java +0 -67
  81. package/android/src/main/java/com/github/druk/dnssd/DNSRecord.java +0 -47
  82. package/android/src/main/java/com/github/druk/dnssd/DNSSD.java +0 -650
  83. package/android/src/main/java/com/github/druk/dnssd/DNSSDEmbedded.java +0 -135
  84. package/android/src/main/java/com/github/druk/dnssd/DNSSDException.java +0 -66
  85. package/android/src/main/java/com/github/druk/dnssd/DNSSDRecordRegistrar.java +0 -55
  86. package/android/src/main/java/com/github/druk/dnssd/DNSSDRegistration.java +0 -54
  87. package/android/src/main/java/com/github/druk/dnssd/DNSSDService.java +0 -35
  88. package/android/src/main/java/com/github/druk/dnssd/DomainListener.java +0 -57
  89. package/android/src/main/java/com/github/druk/dnssd/InternalBrowseListener.java +0 -76
  90. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSD.java +0 -870
  91. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRecordRegistrar.java +0 -30
  92. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDRegistration.java +0 -34
  93. package/android/src/main/java/com/github/druk/dnssd/InternalDNSSDService.java +0 -29
  94. package/android/src/main/java/com/github/druk/dnssd/InternalDomainListener.java +0 -62
  95. package/android/src/main/java/com/github/druk/dnssd/InternalQueryListener.java +0 -61
  96. package/android/src/main/java/com/github/druk/dnssd/InternalRegisterListener.java +0 -51
  97. package/android/src/main/java/com/github/druk/dnssd/InternalResolveListener.java +0 -58
  98. package/android/src/main/java/com/github/druk/dnssd/NSClass.java +0 -16
  99. package/android/src/main/java/com/github/druk/dnssd/NSType.java +0 -58
  100. package/android/src/main/java/com/github/druk/dnssd/QueryListener.java +0 -54
  101. package/android/src/main/java/com/github/druk/dnssd/RegisterListener.java +0 -46
  102. package/android/src/main/java/com/github/druk/dnssd/RegisterRecordListener.java +0 -35
  103. package/android/src/main/java/com/github/druk/dnssd/ResolveListener.java +0 -55
  104. package/android/src/main/java/com/github/druk/dnssd/TXTRecord.java +0 -293
  105. package/android/src/main/jni/Android.mk +0 -73
  106. package/android/src/main/jni/Application.mk +0 -3
  107. package/android/src/main/jni/DNSSD.java.h +0 -290
  108. package/android/src/main/jni/JNISupport.c +0 -1140
  109. package/ios/RNZeroconf/RNNetServiceSerializer.h +0 -31
  110. package/ios/RNZeroconf/RNNetServiceSerializer.m +0 -84
  111. package/ios/RNZeroconf/RNZeroconf.h +0 -17
  112. package/ios/RNZeroconf/RNZeroconf.m +0 -1025
  113. package/ios/RNZeroconf.xcodeproj/project.pbxproj +0 -261
  114. package/ios/RNZeroconf.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  115. package/src/index.js +0 -563
  116. package/windows/RNZeroconf/RNZeroconf.cpp +0 -228
  117. package/windows/RNZeroconf/RNZeroconf.h +0 -70
@@ -0,0 +1,114 @@
1
+ // The backend for the dns_sd API: Apple's system mDNSResponder (iOS, macOS, tvOS) and the mDNSResponder
2
+ // embedded in the library on Android (DNSSD).
3
+ #pragma once
4
+
5
+ #include "../Backend.h"
6
+ #include "Executor.h"
7
+
8
+ #include <map>
9
+ #include <memory>
10
+ #include <optional>
11
+ #include <set>
12
+ #include <string>
13
+
14
+ namespace rnzeroconf {
15
+
16
+ struct DnssdScan;
17
+ struct DnssdResolve;
18
+ struct DnssdPublication;
19
+
20
+ class DnssdBackend : public Backend, public std::enable_shared_from_this<DnssdBackend> {
21
+ public:
22
+ // Callbacks of events run on the executor's thread
23
+ static std::shared_ptr<DnssdBackend> Create(std::shared_ptr<Executor> executor, Events events);
24
+
25
+ void Scan(
26
+ const std::string &scanId,
27
+ const std::string &type,
28
+ const std::string &protocol,
29
+ const std::string &domain,
30
+ const ScanOptions &options) override;
31
+ void Stop(const std::string &scanId) override;
32
+
33
+ void Publish(
34
+ const std::string &type,
35
+ const std::string &protocol,
36
+ const std::string &domain,
37
+ const std::string &name,
38
+ uint16_t port,
39
+ const TxtPairs &txt,
40
+ const PublishOptions &options,
41
+ ServiceCallback resolve,
42
+ ErrorCallback reject) override;
43
+ void Unpublish(const std::string &name, ServiceCallback resolve, ErrorCallback reject) override;
44
+ void Update(const std::string &name, const TxtPairs &txt, ServiceCallback resolve, ErrorCallback reject) override;
45
+
46
+ void ResolveService(
47
+ const std::string &name,
48
+ const std::string &type,
49
+ const std::string &protocol,
50
+ const std::string &domain,
51
+ const ResolveOptions &options,
52
+ ServiceCallback resolve,
53
+ ErrorCallback reject) override;
54
+
55
+ void Shutdown() override;
56
+
57
+ // Runs a task on the executor's thread
58
+ void Post(Executor::Task task);
59
+
60
+ // dns_sd callbacks with their data copied, on the executor's thread
61
+ void OnBrowse(const std::shared_ptr<DnssdScan> &scan, DNSServiceFlags flags, DNSServiceErrorType error, const std::optional<std::string> &name, const std::string &regtype, const std::string &domain);
62
+ void OnResolve(const std::shared_ptr<DnssdResolve> &resolve, DNSServiceErrorType error, const std::string &host, uint16_t port, const std::string &txt);
63
+ void OnAddress(const std::shared_ptr<DnssdResolve> &resolve, DNSServiceFlags flags, DNSServiceErrorType error, const std::string &address);
64
+ void OnTxt(const std::shared_ptr<DnssdResolve> &resolve, DNSServiceFlags flags, DNSServiceErrorType error, const std::string &data);
65
+ void OnRegister(const std::shared_ptr<DnssdPublication> &publication, DNSServiceFlags flags, DNSServiceErrorType error, const std::optional<std::string> &name);
66
+
67
+ private:
68
+ DnssdBackend(std::shared_ptr<Executor> executor, Events events);
69
+
70
+ // Runs on the executor's thread, while the backend exists
71
+ void Run(std::function<void(DnssdBackend &)> task);
72
+
73
+ void StopScan(const std::string &scanId);
74
+ void StartResolve(const std::shared_ptr<DnssdScan> &scan, const std::string &name, const std::string &regtype, const std::string &domain);
75
+ void BeginResolve(const std::shared_ptr<DnssdResolve> &resolve);
76
+ void ResolveTimedOut(const std::shared_ptr<DnssdResolve> &resolve);
77
+ void ScheduleEmit(const std::shared_ptr<DnssdResolve> &resolve);
78
+ void EmitResolve(const std::shared_ptr<DnssdResolve> &resolve);
79
+ void WatchTxt(const std::shared_ptr<DnssdResolve> &resolve);
80
+ void FailResolve(const std::shared_ptr<DnssdResolve> &resolve, const Error &error);
81
+ void CancelResolve(const std::shared_ptr<DnssdResolve> &resolve);
82
+ void EndSingleResolve(const std::shared_ptr<DnssdResolve> &resolve);
83
+ bool IsActive(const std::shared_ptr<DnssdResolve> &resolve) const;
84
+ // Deallocates a ref on the next turn, its callback may be running. keepAlive outlives the ref
85
+ void DeallocateLater(DNSServiceRef &ref, std::shared_ptr<void> keepAlive);
86
+ bool IsNameInUse(const std::string &name) const;
87
+ Service PublishedService(const DnssdPublication &publication) const;
88
+ void SendError(const std::string &scanId, const Error &error);
89
+
90
+ std::shared_ptr<Executor> executor_;
91
+ Events events_;
92
+ std::map<std::string, std::shared_ptr<DnssdScan>> scans_;
93
+ // Registered, keyed by the name actually used, which can differ from the requested one
94
+ std::map<std::string, std::shared_ptr<DnssdPublication>> published_;
95
+ // Waiting for the register callback
96
+ std::set<std::shared_ptr<DnssdPublication>> pending_;
97
+ // resolveService() calls in flight
98
+ std::set<std::shared_ptr<DnssdResolve>> singleResolves_;
99
+ };
100
+
101
+ // Shared with the harness and the module
102
+
103
+ // Readable description of a DNSServiceErrorType
104
+ std::string DescribeDnssdError(DNSServiceErrorType code);
105
+ // { domain: 'DNSSD', code, message: "<action> <serviceName> failed: <description>" }
106
+ Error DnssdError(DNSServiceErrorType code, const std::string &action, const std::string &serviceName = "");
107
+ // TXT record bytes <-> ordered pairs. Entries longer than 255 bytes are left out and their keys listed in tooLong
108
+ std::string EncodeTxt(const TxtPairs &txt, std::vector<std::string> *tooLong);
109
+ TxtPairs DecodeTxt(const void *record, uint16_t length);
110
+ // The index of a network interface by name ("en0"), kDNSServiceInterfaceIndexAny for an empty name.
111
+ // False when the interface doesn't exist
112
+ bool InterfaceIndex(const std::string &name, uint32_t &index);
113
+
114
+ } // namespace rnzeroconf
@@ -0,0 +1,28 @@
1
+ // The serial thread a dns_sd backend runs on: every call into the backend and every dns_sd callback is
2
+ // delivered on it, so the backend needs no locks. Apple: a dispatch queue. Android: the embedded
3
+ // mDNSResponder's thread.
4
+ #pragma once
5
+
6
+ #include <dns_sd.h>
7
+
8
+ #include <cstdint>
9
+ #include <functional>
10
+
11
+ namespace rnzeroconf {
12
+
13
+ class Executor {
14
+ public:
15
+ using Task = std::function<void()>;
16
+ using TimerId = uint64_t;
17
+
18
+ virtual ~Executor() = default;
19
+ // Runs the task on the executor's thread, after the current one
20
+ virtual void Post(Task task) = 0;
21
+ // Runs the task after a delay, unless cancelled first. Ids are never 0
22
+ virtual TimerId PostDelayed(double seconds, Task task) = 0;
23
+ virtual void Cancel(TimerId timer) = 0;
24
+ // Delivers the callbacks of a new DNSServiceRef on the executor's thread
25
+ virtual void Attach(DNSServiceRef ref) = 0;
26
+ };
27
+
28
+ } // namespace rnzeroconf
@@ -0,0 +1,124 @@
1
+ #include "EmbeddedExecutor.h"
2
+
3
+ #include <utility>
4
+
5
+ // The embedded responder's entry points (mDNSPosix/PosixDaemon.c)
6
+ extern "C" {
7
+ int init();
8
+ int loop();
9
+ void stopLoop();
10
+ void lockCore();
11
+ void unlockCore();
12
+ }
13
+
14
+ namespace rnzeroconf {
15
+
16
+ // Started by the first use and kept for the life of the process: the responder can only be initialized
17
+ // once at a time, and backends release their last reference from the executor's own tasks
18
+ std::shared_ptr<EmbeddedExecutor> EmbeddedExecutor::Shared() {
19
+ static std::shared_ptr<EmbeddedExecutor> executor(new EmbeddedExecutor());
20
+ return executor;
21
+ }
22
+
23
+ EmbeddedExecutor::EmbeddedExecutor() {
24
+ responder_ = std::thread([this] { RunResponder(); });
25
+ worker_ = std::thread([this] { RunTasks(); });
26
+ }
27
+
28
+ EmbeddedExecutor::~EmbeddedExecutor() {
29
+ {
30
+ std::lock_guard<std::mutex> lock(mutex_);
31
+ stopping_ = true;
32
+ }
33
+ changed_.notify_all();
34
+ // The last reference can go away in one of the executor's own tasks
35
+ if (worker_.get_id() == std::this_thread::get_id()) {
36
+ worker_.detach();
37
+ } else {
38
+ worker_.join();
39
+ }
40
+ stopLoop();
41
+ responder_.join();
42
+ }
43
+
44
+ void EmbeddedExecutor::RunResponder() {
45
+ int error = init();
46
+ {
47
+ std::lock_guard<std::mutex> lock(mutex_);
48
+ started_ = true;
49
+ startError_ = error;
50
+ }
51
+ changed_.notify_all();
52
+ if (error == 0) {
53
+ loop();
54
+ }
55
+ }
56
+
57
+ int EmbeddedExecutor::StartError() const {
58
+ return startError_;
59
+ }
60
+
61
+ void EmbeddedExecutor::RunTasks() {
62
+ std::unique_lock<std::mutex> lock(mutex_);
63
+ // dns_sd calls need the responder initialized
64
+ changed_.wait(lock, [this] { return started_ || stopping_; });
65
+ while (true) {
66
+ Task task;
67
+ if (!tasks_.empty()) {
68
+ task = std::move(tasks_.front());
69
+ tasks_.pop_front();
70
+ } else {
71
+ auto next = timers_.end();
72
+ for (auto it = timers_.begin(); it != timers_.end(); ++it) {
73
+ if (next == timers_.end() || it->second.due < next->second.due) {
74
+ next = it;
75
+ }
76
+ }
77
+ if (stopping_) {
78
+ return;
79
+ }
80
+ if (next == timers_.end()) {
81
+ changed_.wait(lock);
82
+ continue;
83
+ }
84
+ if (Clock::now() < next->second.due) {
85
+ changed_.wait_until(lock, next->second.due);
86
+ continue;
87
+ }
88
+ task = std::move(next->second.task);
89
+ timers_.erase(next);
90
+ }
91
+ lock.unlock();
92
+ lockCore();
93
+ task();
94
+ // What the task holds is released under the core lock, outside the queue's
95
+ task = nullptr;
96
+ unlockCore();
97
+ lock.lock();
98
+ }
99
+ }
100
+
101
+ void EmbeddedExecutor::Post(Task task) {
102
+ {
103
+ std::lock_guard<std::mutex> lock(mutex_);
104
+ tasks_.push_back(std::move(task));
105
+ }
106
+ changed_.notify_all();
107
+ }
108
+
109
+ Executor::TimerId EmbeddedExecutor::PostDelayed(double seconds, Task task) {
110
+ TimerId id = ++nextTimer_;
111
+ {
112
+ std::lock_guard<std::mutex> lock(mutex_);
113
+ timers_[id] = Timer{Clock::now() + std::chrono::milliseconds(static_cast<int64_t>(seconds * 1000)), std::move(task)};
114
+ }
115
+ changed_.notify_all();
116
+ return id;
117
+ }
118
+
119
+ void EmbeddedExecutor::Cancel(TimerId timer) {
120
+ std::lock_guard<std::mutex> lock(mutex_);
121
+ timers_.erase(timer);
122
+ }
123
+
124
+ } // namespace rnzeroconf
@@ -0,0 +1,57 @@
1
+ // Executor for the mDNSResponder embedded in the library (Android DNSSD). The responder runs its event
2
+ // loop on a thread of its own and delivers dns_sd callbacks there; the backend runs on a second thread,
3
+ // each task holding the responder's core lock, which every call into it requires.
4
+ #pragma once
5
+
6
+ #include "../dnssd/Executor.h"
7
+
8
+ #include <atomic>
9
+ #include <chrono>
10
+ #include <condition_variable>
11
+ #include <deque>
12
+ #include <map>
13
+ #include <memory>
14
+ #include <mutex>
15
+ #include <thread>
16
+
17
+ namespace rnzeroconf {
18
+
19
+ class EmbeddedExecutor : public Executor {
20
+ public:
21
+ // The responder is a process-wide singleton, started by the first use
22
+ static std::shared_ptr<EmbeddedExecutor> Shared();
23
+ ~EmbeddedExecutor() override;
24
+
25
+ void Post(Task task) override;
26
+ TimerId PostDelayed(double seconds, Task task) override;
27
+ void Cancel(TimerId timer) override;
28
+ // The responder delivers callbacks by itself
29
+ void Attach(DNSServiceRef) override {}
30
+
31
+ // The error of the responder's start, 0 when it runs
32
+ int StartError() const;
33
+
34
+ private:
35
+ using Clock = std::chrono::steady_clock;
36
+ struct Timer {
37
+ Clock::time_point due;
38
+ Task task;
39
+ };
40
+
41
+ EmbeddedExecutor();
42
+ void RunResponder();
43
+ void RunTasks();
44
+
45
+ std::mutex mutex_;
46
+ std::condition_variable changed_;
47
+ std::deque<Task> tasks_;
48
+ std::map<TimerId, Timer> timers_;
49
+ std::atomic<TimerId> nextTimer_{0};
50
+ bool started_ = false;
51
+ int startError_ = 0;
52
+ bool stopping_ = false;
53
+ std::thread responder_;
54
+ std::thread worker_;
55
+ };
56
+
57
+ } // namespace rnzeroconf
@@ -0,0 +1,34 @@
1
+ // Registers the C++ module on Apple platforms: one dns_sd backend on a private queue, and the
2
+ // Local Network check of Network.framework
3
+ #import <Foundation/Foundation.h>
4
+ #import <ReactCommon/CxxTurboModuleUtils.h>
5
+
6
+ #include "../cpp/ZeroconfModule.h"
7
+ #include "../cpp/apple/DispatchExecutor.h"
8
+ #include "../cpp/apple/LocalNetworkAccess.h"
9
+ #include "../cpp/dnssd/DnssdBackend.h"
10
+
11
+ using namespace facebook::react;
12
+
13
+ @interface ZeroconfOnLoad : NSObject
14
+ @end
15
+
16
+ @implementation ZeroconfOnLoad
17
+
18
+ + (void)load
19
+ {
20
+ registerCxxModuleToGlobalModuleMap(
21
+ std::string(ZeroconfModule::kModuleName),
22
+ [](std::shared_ptr<CallInvoker> jsInvoker) {
23
+ ZeroconfPlatform platform;
24
+ // One mDNS stack on Apple platforms, implType is Android's
25
+ platform.backendKey = [](const std::string &) { return std::string("dnssd"); };
26
+ platform.createBackend = [](const std::string &, rnzeroconf::Events events) -> std::shared_ptr<rnzeroconf::Backend> {
27
+ return rnzeroconf::DnssdBackend::Create(std::make_shared<rnzeroconf::DispatchExecutor>("com.balthazargronon.rnzeroconf"), std::move(events));
28
+ };
29
+ platform.checkLocalNetworkAccess = rnzeroconf::CheckLocalNetworkAccess;
30
+ return std::make_shared<ZeroconfModule>(jsInvoker, std::move(platform));
31
+ });
32
+ }
33
+
34
+ @end
@@ -0,0 +1,140 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleObjCpp
8
+ *
9
+ * We create an umbrella header (and corresponding implementation) here since
10
+ * Cxx compilation in BUCK has a limitation: source-code producing genrule()s
11
+ * must have a single output. More files => more genrule()s => slower builds.
12
+ */
13
+
14
+ #import "RNZeroconfSpec.h"
15
+
16
+
17
+ @implementation NativeZeroconfSpecBase
18
+ - (void)emitOnStart:(NSDictionary *)value
19
+ {
20
+ _eventEmitterCallback("onStart", value);
21
+ }
22
+ - (void)emitOnStop:(NSDictionary *)value
23
+ {
24
+ _eventEmitterCallback("onStop", value);
25
+ }
26
+ - (void)emitOnFound:(NSDictionary *)value
27
+ {
28
+ _eventEmitterCallback("onFound", value);
29
+ }
30
+ - (void)emitOnRemove:(NSDictionary *)value
31
+ {
32
+ _eventEmitterCallback("onRemove", value);
33
+ }
34
+ - (void)emitOnResolved:(NSDictionary *)value
35
+ {
36
+ _eventEmitterCallback("onResolved", value);
37
+ }
38
+ - (void)emitOnError:(NSDictionary *)value
39
+ {
40
+ _eventEmitterCallback("onError", value);
41
+ }
42
+ - (void)emitOnPublished:(NSDictionary *)value
43
+ {
44
+ _eventEmitterCallback("onPublished", value);
45
+ }
46
+ - (void)emitOnUnpublished:(NSDictionary *)value
47
+ {
48
+ _eventEmitterCallback("onUnpublished", value);
49
+ }
50
+
51
+ - (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
52
+ {
53
+ _eventEmitterCallback = std::move(eventEmitterCallbackWrapper->_eventEmitterCallback);
54
+ }
55
+ @end
56
+
57
+ @implementation RCTCxxConvert (NativeZeroconf_NativeScanOptions)
58
+ + (RCTManagedPointer *)JS_NativeZeroconf_NativeScanOptions:(id)json
59
+ {
60
+ return facebook::react::managedPointer<JS::NativeZeroconf::NativeScanOptions>(json);
61
+ }
62
+ @end
63
+ @implementation RCTCxxConvert (NativeZeroconf_NativePublishOptions)
64
+ + (RCTManagedPointer *)JS_NativeZeroconf_NativePublishOptions:(id)json
65
+ {
66
+ return facebook::react::managedPointer<JS::NativeZeroconf::NativePublishOptions>(json);
67
+ }
68
+ @end
69
+ @implementation RCTCxxConvert (NativeZeroconf_NativeResolveOptions)
70
+ + (RCTManagedPointer *)JS_NativeZeroconf_NativeResolveOptions:(id)json
71
+ {
72
+ return facebook::react::managedPointer<JS::NativeZeroconf::NativeResolveOptions>(json);
73
+ }
74
+ @end
75
+ namespace facebook::react {
76
+
77
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_scan(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
78
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "scan", @selector(scan:type:protocol:domain:implType:options:), args, count);
79
+ }
80
+
81
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_stop(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
82
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "stop", @selector(stop:implType:), args, count);
83
+ }
84
+
85
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_registerService(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
86
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "registerService", @selector(registerService:protocol:domain:name:port:txt:implType:options:resolve:reject:), args, count);
87
+ }
88
+
89
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_updateService(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
90
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "updateService", @selector(updateService:txt:implType:resolve:reject:), args, count);
91
+ }
92
+
93
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_unregisterService(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
94
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "unregisterService", @selector(unregisterService:implType:resolve:reject:), args, count);
95
+ }
96
+
97
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_resolveService(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
98
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "resolveService", @selector(resolveService:type:protocol:domain:implType:options:resolve:reject:), args, count);
99
+ }
100
+
101
+ static facebook::jsi::Value __hostFunction_NativeZeroconfSpecJSI_checkLocalNetworkAccess(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
102
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "checkLocalNetworkAccess", @selector(checkLocalNetworkAccess:timeout:resolve:reject:), args, count);
103
+ }
104
+
105
+ NativeZeroconfSpecJSI::NativeZeroconfSpecJSI(const ObjCTurboModule::InitParams &params)
106
+ : ObjCTurboModule(params) {
107
+
108
+ methodMap_["scan"] = MethodMetadata {6, __hostFunction_NativeZeroconfSpecJSI_scan};
109
+ setMethodArgConversionSelector(@"scan", 5, @"JS_NativeZeroconf_NativeScanOptions:");
110
+
111
+ methodMap_["stop"] = MethodMetadata {2, __hostFunction_NativeZeroconfSpecJSI_stop};
112
+
113
+
114
+ methodMap_["registerService"] = MethodMetadata {8, __hostFunction_NativeZeroconfSpecJSI_registerService};
115
+ setMethodArgConversionSelector(@"registerService", 7, @"JS_NativeZeroconf_NativePublishOptions:");
116
+
117
+ methodMap_["updateService"] = MethodMetadata {3, __hostFunction_NativeZeroconfSpecJSI_updateService};
118
+
119
+
120
+ methodMap_["unregisterService"] = MethodMetadata {2, __hostFunction_NativeZeroconfSpecJSI_unregisterService};
121
+
122
+
123
+ methodMap_["resolveService"] = MethodMetadata {6, __hostFunction_NativeZeroconfSpecJSI_resolveService};
124
+ setMethodArgConversionSelector(@"resolveService", 5, @"JS_NativeZeroconf_NativeResolveOptions:");
125
+
126
+ methodMap_["checkLocalNetworkAccess"] = MethodMetadata {2, __hostFunction_NativeZeroconfSpecJSI_checkLocalNetworkAccess};
127
+
128
+ eventEmitterMap_["onStart"] = std::make_shared<AsyncEventEmitter<id>>();
129
+ eventEmitterMap_["onStop"] = std::make_shared<AsyncEventEmitter<id>>();
130
+ eventEmitterMap_["onFound"] = std::make_shared<AsyncEventEmitter<id>>();
131
+ eventEmitterMap_["onRemove"] = std::make_shared<AsyncEventEmitter<id>>();
132
+ eventEmitterMap_["onResolved"] = std::make_shared<AsyncEventEmitter<id>>();
133
+ eventEmitterMap_["onError"] = std::make_shared<AsyncEventEmitter<id>>();
134
+ eventEmitterMap_["onPublished"] = std::make_shared<AsyncEventEmitter<id>>();
135
+ eventEmitterMap_["onUnpublished"] = std::make_shared<AsyncEventEmitter<id>>();
136
+ setEventEmitterCallback([&](const std::string &name, id value) {
137
+ static_cast<AsyncEventEmitter<id> &>(*eventEmitterMap_[name]).emit(value);
138
+ });
139
+ }
140
+ } // namespace facebook::react
@@ -0,0 +1,189 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleObjCpp
8
+ *
9
+ * We create an umbrella header (and corresponding implementation) here since
10
+ * Cxx compilation in BUCK has a limitation: source-code producing genrule()s
11
+ * must have a single output. More files => more genrule()s => slower builds.
12
+ */
13
+
14
+ #ifndef __cplusplus
15
+ #error This file must be compiled as Obj-C++. If you are importing it, you must change your file extension to .mm.
16
+ #endif
17
+
18
+ // Avoid multiple includes of RNZeroconfSpec symbols
19
+ #ifndef RNZeroconfSpec_H
20
+ #define RNZeroconfSpec_H
21
+
22
+ #import <Foundation/Foundation.h>
23
+ #import <RCTRequired/RCTRequired.h>
24
+ #import <RCTTypeSafety/RCTConvertHelpers.h>
25
+ #import <RCTTypeSafety/RCTTypedModuleConstants.h>
26
+ #import <React/RCTBridgeModule.h>
27
+ #import <React/RCTCxxConvert.h>
28
+ #import <React/RCTManagedPointer.h>
29
+ #import <ReactCommon/RCTTurboModule.h>
30
+ #import <optional>
31
+ #import <vector>
32
+
33
+
34
+ NS_ASSUME_NONNULL_BEGIN
35
+ namespace JS {
36
+ namespace NativeZeroconf {
37
+ struct NativeScanOptions {
38
+ std::optional<double> resolveTimeout() const;
39
+ NSString *subtype() const;
40
+ NSString *networkInterface() const;
41
+
42
+ NativeScanOptions(NSDictionary *const v) : _v(v) {}
43
+ private:
44
+ NSDictionary *_v;
45
+ };
46
+ }
47
+ }
48
+
49
+ @interface RCTCxxConvert (NativeZeroconf_NativeScanOptions)
50
+ + (RCTManagedPointer *)JS_NativeZeroconf_NativeScanOptions:(id)json;
51
+ @end
52
+ namespace JS {
53
+ namespace NativeZeroconf {
54
+ struct NativePublishOptions {
55
+ std::optional<facebook::react::LazyVector<NSString *>> subtypes() const;
56
+ NSString *networkInterface() const;
57
+
58
+ NativePublishOptions(NSDictionary *const v) : _v(v) {}
59
+ private:
60
+ NSDictionary *_v;
61
+ };
62
+ }
63
+ }
64
+
65
+ @interface RCTCxxConvert (NativeZeroconf_NativePublishOptions)
66
+ + (RCTManagedPointer *)JS_NativeZeroconf_NativePublishOptions:(id)json;
67
+ @end
68
+ namespace JS {
69
+ namespace NativeZeroconf {
70
+ struct NativeResolveOptions {
71
+ std::optional<double> timeout() const;
72
+ NSString *networkInterface() const;
73
+
74
+ NativeResolveOptions(NSDictionary *const v) : _v(v) {}
75
+ private:
76
+ NSDictionary *_v;
77
+ };
78
+ }
79
+ }
80
+
81
+ @interface RCTCxxConvert (NativeZeroconf_NativeResolveOptions)
82
+ + (RCTManagedPointer *)JS_NativeZeroconf_NativeResolveOptions:(id)json;
83
+ @end
84
+ @protocol NativeZeroconfSpec <RCTBridgeModule, RCTTurboModule>
85
+
86
+ - (void)scan:(NSString *)scanId
87
+ type:(NSString *)type
88
+ protocol:(NSString *)protocol
89
+ domain:(NSString *)domain
90
+ implType:(NSString *)implType
91
+ options:(JS::NativeZeroconf::NativeScanOptions &)options;
92
+ - (void)stop:(NSString *)scanId
93
+ implType:(NSString *)implType;
94
+ - (void)registerService:(NSString *)type
95
+ protocol:(NSString *)protocol
96
+ domain:(NSString *)domain
97
+ name:(NSString *)name
98
+ port:(double)port
99
+ txt:(NSArray *)txt
100
+ implType:(NSString *)implType
101
+ options:(JS::NativeZeroconf::NativePublishOptions &)options
102
+ resolve:(RCTPromiseResolveBlock)resolve
103
+ reject:(RCTPromiseRejectBlock)reject;
104
+ - (void)updateService:(NSString *)name
105
+ txt:(NSArray *)txt
106
+ implType:(NSString *)implType
107
+ resolve:(RCTPromiseResolveBlock)resolve
108
+ reject:(RCTPromiseRejectBlock)reject;
109
+ - (void)unregisterService:(NSString *)name
110
+ implType:(NSString *)implType
111
+ resolve:(RCTPromiseResolveBlock)resolve
112
+ reject:(RCTPromiseRejectBlock)reject;
113
+ - (void)resolveService:(NSString *)name
114
+ type:(NSString *)type
115
+ protocol:(NSString *)protocol
116
+ domain:(NSString *)domain
117
+ implType:(NSString *)implType
118
+ options:(JS::NativeZeroconf::NativeResolveOptions &)options
119
+ resolve:(RCTPromiseResolveBlock)resolve
120
+ reject:(RCTPromiseRejectBlock)reject;
121
+ - (void)checkLocalNetworkAccess:(NSString *)type
122
+ timeout:(double)timeout
123
+ resolve:(RCTPromiseResolveBlock)resolve
124
+ reject:(RCTPromiseRejectBlock)reject;
125
+
126
+ @end
127
+
128
+ @interface NativeZeroconfSpecBase : NSObject {
129
+ @protected
130
+ facebook::react::EventEmitterCallback _eventEmitterCallback;
131
+ }
132
+ - (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper;
133
+
134
+ - (void)emitOnStart:(NSDictionary *)value;
135
+ - (void)emitOnStop:(NSDictionary *)value;
136
+ - (void)emitOnFound:(NSDictionary *)value;
137
+ - (void)emitOnRemove:(NSDictionary *)value;
138
+ - (void)emitOnResolved:(NSDictionary *)value;
139
+ - (void)emitOnError:(NSDictionary *)value;
140
+ - (void)emitOnPublished:(NSDictionary *)value;
141
+ - (void)emitOnUnpublished:(NSDictionary *)value;
142
+ @end
143
+
144
+ namespace facebook::react {
145
+ /**
146
+ * ObjC++ class for module 'NativeZeroconf'
147
+ */
148
+ class JSI_EXPORT NativeZeroconfSpecJSI : public ObjCTurboModule {
149
+ public:
150
+ NativeZeroconfSpecJSI(const ObjCTurboModule::InitParams &params);
151
+ };
152
+ } // namespace facebook::react
153
+ inline std::optional<double> JS::NativeZeroconf::NativeScanOptions::resolveTimeout() const
154
+ {
155
+ id const p = _v[@"resolveTimeout"];
156
+ return RCTBridgingToOptionalDouble(p);
157
+ }
158
+ inline NSString *JS::NativeZeroconf::NativeScanOptions::subtype() const
159
+ {
160
+ id const p = _v[@"subtype"];
161
+ return RCTBridgingToOptionalString(p);
162
+ }
163
+ inline NSString *JS::NativeZeroconf::NativeScanOptions::networkInterface() const
164
+ {
165
+ id const p = _v[@"networkInterface"];
166
+ return RCTBridgingToOptionalString(p);
167
+ }
168
+ inline std::optional<facebook::react::LazyVector<NSString *>> JS::NativeZeroconf::NativePublishOptions::subtypes() const
169
+ {
170
+ id const p = _v[@"subtypes"];
171
+ return RCTBridgingToOptionalVec(p, ^NSString *(id itemValue_0) { return RCTBridgingToString(itemValue_0); });
172
+ }
173
+ inline NSString *JS::NativeZeroconf::NativePublishOptions::networkInterface() const
174
+ {
175
+ id const p = _v[@"networkInterface"];
176
+ return RCTBridgingToOptionalString(p);
177
+ }
178
+ inline std::optional<double> JS::NativeZeroconf::NativeResolveOptions::timeout() const
179
+ {
180
+ id const p = _v[@"timeout"];
181
+ return RCTBridgingToOptionalDouble(p);
182
+ }
183
+ inline NSString *JS::NativeZeroconf::NativeResolveOptions::networkInterface() const
184
+ {
185
+ id const p = _v[@"networkInterface"];
186
+ return RCTBridgingToOptionalString(p);
187
+ }
188
+ NS_ASSUME_NONNULL_END
189
+ #endif // RNZeroconfSpec_H