uws-react-native 0.0.4 → 0.0.6

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.
package/README.md CHANGED
@@ -9,6 +9,10 @@ The port of [**uWebSockets**](https://github.com/uNetworking/uWebSockets) librar
9
9
 
10
10
  ## Installation
11
11
 
12
+ We provide two registry homes where this library lives which can be used for your project. You can use either it's from NPM registry or GitHub Packages
13
+
14
+ ### From NPM Registry
15
+
12
16
  npm
13
17
  ```
14
18
  npm install uws-react-native
@@ -24,6 +28,41 @@ pnpm
24
28
  pnpm install uws-react-native
25
29
  ```
26
30
 
31
+ ### From GitHub Packages
32
+
33
+ First, create your GitHub personal token (classic) with `read:packages` access
34
+ > **Skip if you already have it**
35
+ 1. In the upper-right corner of any page on GitHub, click your profile picture, then click Settings
36
+ 2. In the left sidebar, click **<> Developer settings**
37
+ 3. In the left sidebar, under **🔑 Personal access tokens**, click **Tokens (classic)**
38
+ 4. Select Generate new token, then click **Generate new token (classic)**
39
+ 5. Fill your descriptive note, fill / check the `read:packages` access, and click **Generate token**
40
+ 6. Copy the generated token, or save it to somewhere else
41
+
42
+ After that, in the same directory as your `package.json` file, create or edit an `.npmrc` file with this snippet
43
+ ```
44
+ @rakadoank:registry=https://npm.pkg.github.com
45
+ //npm.pkg.github.com/:_authToken=YOUR_GITHUB_PERSONAL_TOKEN
46
+ ```
47
+
48
+ Finally, do the regular installation with the CLI, but with the scope name
49
+
50
+ npm
51
+ ```
52
+ npm install @rakadoank/uws-react-native
53
+ ```
54
+
55
+ yarn
56
+ ```
57
+ yarn add @rakadoank/uws-react-native
58
+ ```
59
+
60
+ pnpm
61
+ ```
62
+ pnpm install @rakadoank/uws-react-native
63
+ ```
64
+
65
+
27
66
  ## Usage
28
67
 
29
68
  Since uws-react-native is a port of uWebSockets library for JavaScript, this library is really similar of how to use the [uWebSockets](https://github.com/uNetworking/uWebSockets) in C++, or the [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) for Node.js.
@@ -135,7 +135,6 @@ target_compile_options(uWebSockets INTERFACE -Wno-deprecated-declarations)
135
135
  # ----- uWebSockets -----
136
136
 
137
137
  add_subdirectory(app)
138
- add_subdirectory(bridging)
139
138
  add_subdirectory(jsi)
140
139
 
141
140
  # Link Libraries
@@ -149,6 +148,5 @@ target_link_libraries(
149
148
  android
150
149
  log
151
150
  uws_react_native::app
152
- uws_react_native::bridging
153
151
  uws_react_native::jsi
154
152
  )
@@ -34,6 +34,5 @@ target_link_libraries(
34
34
  uWebSockets
35
35
  android
36
36
  log
37
- uws_react_native::bridging
38
37
  uws_react_native::jsi
39
38
  )
@@ -2,11 +2,7 @@
2
2
 
3
3
  #include <ReactCommon/CallInvoker.h>
4
4
  #include <ReactCommon/SchedulerPriority.h>
5
- #include <algorithm>
6
5
  #include <jsi/jsi.h>
7
- #include <mutex>
8
- #include <sstream>
9
- #include <utility>
10
6
  #include "AppRunner.h"
11
7
  #include "HttpRequestObject.h"
12
8
  #include "HttpResponseObject.h"
@@ -101,10 +97,12 @@ private:
101
97
  auto httpResponseObjectProvider = std::make_shared<HttpResponseObjectProvider>(res);
102
98
  auto sharedRequest = std::make_shared<uWS::HttpRequest>(*req);
103
99
 
104
- asyncCallback.callWithPriority(facebook::react::SchedulerPriority::ImmediatePriority, [httpResponseObjectProvider, &sharedRequest, &jsInvoker](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) {
105
- cb.call(rt_1,
106
- HttpResponseObject(rt_1, httpResponseObjectProvider, jsInvoker),
107
- HttpRequestObject(rt_1, sharedRequest));
100
+ asyncCallback.callWithPriority(facebook::react::SchedulerPriority::ImmediatePriority, [httpResponseObjectProvider, sharedRequest, &jsInvoker](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) {
101
+ if(httpResponseObjectProvider && sharedRequest) {
102
+ cb.call(rt_1,
103
+ HttpResponseObject(rt_1, httpResponseObjectProvider, jsInvoker),
104
+ HttpRequestObject(rt_1, sharedRequest));
105
+ }
108
106
  });
109
107
 
110
108
  /// We have to make JS call asynchronously because the uWebSockets app run at different thread.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "uws-react-native",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "The port of uWebSockets library for React Native",
5
- "license": "MIT",
5
+ "license": "Apache-2.0",
6
6
  "author": "RakaDoank <rakaaudira@gmail.com> (https://github.com/RakaDoank)",
7
7
  "homepage": "https://github.com/RakaDoank/uws-react-native",
8
8
  "repository": {
@@ -35,6 +35,8 @@
35
35
  "!android/local.properties",
36
36
  "!ios/build"
37
37
  ],
38
+ "main": "./lib/module/index.js",
39
+ "types": "./lib/typescript/module/index.d.ts",
38
40
  "exports": {
39
41
  ".": {
40
42
  "import": {
@@ -1,150 +0,0 @@
1
- /**
2
- * This file is entirely copied from this PR
3
- * https://github.com/facebook/react-native/pull/56729
4
- *
5
- * Consider this bridging is temporary until the bridging support
6
- * has been officially supported by React Native.
7
- */
8
-
9
- #pragma once
10
-
11
- namespace facebook::react {
12
-
13
- template <>
14
- struct Bridging<jsi::ArrayBuffer> {
15
- static jsi::ArrayBuffer fromJs(jsi::Runtime& rt, const jsi::Object& obj) {
16
- if (!obj.isArrayBuffer(rt)) {
17
- throw jsi::JSError(rt, "Expected ArrayBuffer");
18
- }
19
- return obj.getArrayBuffer(rt);
20
- }
21
-
22
- static jsi::Value toJs(jsi::Runtime& rt, jsi::ArrayBuffer buf) {
23
- return jsi::Value(rt, std::move(buf));
24
- }
25
- };
26
-
27
- // Holds ArrayBuffer bytes for use off the JS thread. Move-only.
28
- //
29
- // Stores either a native-backed MutableBuffer or an owned copy.
30
- // May outlive the TurboModule call and be transferred across threads.
31
- // Thread synchronization must be enforced externally.
32
- class AsyncArrayBuffer {
33
- public:
34
- AsyncArrayBuffer(const AsyncArrayBuffer&) = delete;
35
- AsyncArrayBuffer& operator=(const AsyncArrayBuffer&) = delete;
36
- AsyncArrayBuffer(AsyncArrayBuffer&&) noexcept = default;
37
- AsyncArrayBuffer& operator=(AsyncArrayBuffer&&) noexcept = default;
38
- ~AsyncArrayBuffer() = default;
39
-
40
- // Zero-copy if native-backed, copies otherwise.
41
- static AsyncArrayBuffer acquire(
42
- jsi::Runtime& rt,
43
- const jsi::ArrayBuffer& buffer) {
44
- if (buffer.detached(rt)) {
45
- throw jsi::JSError(
46
- rt, "AsyncArrayBuffer::acquire: ArrayBuffer is detached");
47
- }
48
- auto mutableBuf = buffer.tryGetMutableBuffer(rt);
49
- if (mutableBuf) {
50
- return AsyncArrayBuffer(std::move(mutableBuf));
51
- }
52
- auto n = buffer.size(rt);
53
- auto src = buffer.data(rt);
54
- return AsyncArrayBuffer(std::vector<uint8_t>(src, src + n));
55
- }
56
-
57
- // Zero-copy. Throws if not native-backed.
58
- static AsyncArrayBuffer borrow(
59
- jsi::Runtime& rt,
60
- const jsi::ArrayBuffer& buffer) {
61
- if (buffer.detached(rt)) {
62
- throw jsi::JSError(
63
- rt, "AsyncArrayBuffer::borrow: ArrayBuffer is detached");
64
- }
65
- auto mutableBuf = buffer.tryGetMutableBuffer(rt);
66
- if (!mutableBuf) {
67
- throw jsi::JSError(
68
- rt,
69
- "AsyncArrayBuffer::borrow: ArrayBuffer is not native-backed. "
70
- "Use AsyncArrayBuffer::acquire(rt, buffer) when the buffer origin is unknown.");
71
- }
72
- return AsyncArrayBuffer(std::move(mutableBuf));
73
- }
74
-
75
- // Always copies.
76
- static AsyncArrayBuffer copy(
77
- jsi::Runtime& rt,
78
- const jsi::ArrayBuffer& buffer) {
79
- if (buffer.detached(rt)) {
80
- throw jsi::JSError(rt, "AsyncArrayBuffer::copy: ArrayBuffer is detached");
81
- }
82
- auto src = buffer.data(rt);
83
- auto n = buffer.size(rt);
84
- return AsyncArrayBuffer(std::vector<uint8_t>(src, src + n));
85
- }
86
-
87
- // Wraps a native MutableBuffer. Safe to call from any thread.
88
- static AsyncArrayBuffer wrap(
89
- std::shared_ptr<jsi::MutableBuffer> buffer) noexcept {
90
- return AsyncArrayBuffer(std::move(buffer));
91
- }
92
-
93
- // Takes ownership of a byte vector. Safe to call from any thread.
94
- static AsyncArrayBuffer wrap(std::vector<uint8_t> bytes) noexcept {
95
- return AsyncArrayBuffer(std::move(bytes));
96
- }
97
-
98
- bool isNativeBacked() const noexcept {
99
- return mutableBuffer_ != nullptr;
100
- }
101
-
102
- uint8_t* data() noexcept {
103
- return mutableBuffer_ ? mutableBuffer_->data() : ownedCopy_.data();
104
- }
105
-
106
- const uint8_t* data() const noexcept {
107
- return mutableBuffer_ ? mutableBuffer_->data() : ownedCopy_.data();
108
- }
109
-
110
- size_t size() const noexcept {
111
- return mutableBuffer_ ? mutableBuffer_->size() : ownedCopy_.size();
112
- }
113
-
114
- std::shared_ptr<jsi::MutableBuffer> getMutableBuffer() const noexcept {
115
- return mutableBuffer_;
116
- }
117
-
118
- private:
119
- explicit AsyncArrayBuffer(std::shared_ptr<jsi::MutableBuffer> buffer) noexcept
120
- : mutableBuffer_{std::move(buffer)} {}
121
-
122
- explicit AsyncArrayBuffer(std::vector<uint8_t> bytes) noexcept
123
- : ownedCopy_{std::move(bytes)} {}
124
-
125
- std::shared_ptr<jsi::MutableBuffer> mutableBuffer_;
126
- std::vector<uint8_t> ownedCopy_;
127
- };
128
-
129
- template <>
130
- struct Bridging<AsyncArrayBuffer> {
131
- static jsi::Value toJs(jsi::Runtime& rt, AsyncArrayBuffer buffer) {
132
- if (auto mutableBuf = buffer.getMutableBuffer()) {
133
- return jsi::Value(rt, rt.createArrayBuffer(std::move(mutableBuf)));
134
- }
135
- struct OwnedBuffer final : jsi::MutableBuffer {
136
- explicit OwnedBuffer(AsyncArrayBuffer b) noexcept : buf_(std::move(b)) {}
137
- size_t size() const override {
138
- return buf_.size();
139
- }
140
- uint8_t* data() override {
141
- return buf_.data();
142
- }
143
- AsyncArrayBuffer buf_;
144
- };
145
- auto owned = std::make_shared<OwnedBuffer>(std::move(buffer));
146
- return jsi::Value(rt, rt.createArrayBuffer(std::move(owned)));
147
- }
148
- };
149
-
150
- } // namespace facebook::react
@@ -1,34 +0,0 @@
1
- project("uws_react_native__bridging")
2
-
3
- file(
4
- GLOB_RECURSE
5
- LIB_HEADER_SRCS
6
- RELATIVE
7
- ${CMAKE_CURRENT_SOURCE_DIR}
8
- "./*.h"
9
- )
10
-
11
- add_library(
12
- ${PROJECT_NAME}
13
- INTERFACE
14
- ${LIB_HEADER_SRCS}
15
- )
16
-
17
- add_library(
18
- "uws_react_native::bridging"
19
- ALIAS
20
- ${PROJECT_NAME}
21
- )
22
-
23
- target_include_directories(
24
- ${PROJECT_NAME}
25
- INTERFACE
26
- "."
27
- )
28
-
29
- target_link_libraries(
30
- ${PROJECT_NAME}
31
- INTERFACE
32
- reactnative
33
- jsi
34
- )