-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCxxNodeApiHostModule.hpp
More file actions
40 lines (30 loc) · 1.33 KB
/
CxxNodeApiHostModule.hpp
File metadata and controls
40 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <ReactCommon/TurboModule.h>
#include <jsi/jsi.h>
#include <node_api.h>
#include "AddonLoaders.hpp"
namespace callstack::react_native_node_api {
class JSI_EXPORT CxxNodeApiHostModule : public facebook::react::TurboModule {
public:
static constexpr const char *kModuleName = "NodeApiHost";
CxxNodeApiHostModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
static facebook::jsi::Value
requireNodeAddon(facebook::jsi::Runtime &rt,
facebook::react::TurboModule &turboModule,
const facebook::jsi::Value args[], size_t count);
facebook::jsi::Value requireNodeAddon(facebook::jsi::Runtime &rt,
const facebook::jsi::String path);
protected:
struct NodeAddon {
void *moduleHandle;
napi_addon_register_func init;
std::string generatedName;
};
std::unordered_map<std::string, NodeAddon> nodeAddons_;
std::shared_ptr<facebook::react::CallInvoker> callInvoker_;
using LoaderPolicy = PosixLoader; // FIXME: HACK: This is temporary workaround
// for my lazyness (work on iOS and Android)
bool loadNodeAddon(NodeAddon &addon, const std::string &path) const;
bool initializeNodeModule(facebook::jsi::Runtime &rt, NodeAddon &addon);
};
} // namespace callstack::react_native_node_api