uws-react-native 0.0.3 → 0.0.4
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 +2 -8
- package/cpp/UwsReactNativeModule.cpp +6 -2
- package/cpp/app/HttpRequestObject.h +7 -15
- package/cpp/app/HttpResponseObject.h +133 -264
- package/cpp/app/HttpResponseObjectProvider.h +118 -0
- package/cpp/app/TemplatedAppObject.h +30 -23
- package/lib/typescript/commonjs/types/HttpResponse.d.ts +2 -2
- package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -1
- package/lib/typescript/module/types/HttpResponse.d.ts +2 -2
- package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/types/HttpResponse.ts +2 -2
package/README.md
CHANGED
|
@@ -61,21 +61,15 @@ uws-react-native is still in heavy development and research. All the uWebSockets
|
|
|
61
61
|
|
|
62
62
|
There are development and research things that you can read for your informations, especially if you are already familiar with uWebSockets. The most things are because of the React Native's architecture differentiation compared to the casual uWebSockets server program.
|
|
63
63
|
|
|
64
|
-
### Performance & Stability
|
|
65
|
-
|
|
66
|
-
This library is indeed focusing on performance, but we will focus more of it later until we reach the stability of uws-react-native due to [threading](#threading) issue. It does not mean uws-react-native will performs badly in terms of speed, but it is not stable enough in under a stress situation because we run uWebSockets only in one thread.
|
|
67
|
-
|
|
68
|
-
I have tested a stress test in an Android device. A lot of incoming request roughly 100 requests per second in roughly 5 seconds for files uploading (multipart/form-data) may crash the app. We do not have the proper benchmark yet, but it is as we expected from one thread only. I am keeping my eyes on this issue to keep improving the performance.
|
|
69
|
-
|
|
70
64
|
### Threading
|
|
71
65
|
|
|
72
66
|
We are embracing the main chaos of supporting uWebSockets in React Native architecture, which is to prevent UI/Main thread from blocking.
|
|
73
67
|
|
|
74
|
-
Intentionally, we make the uWebSockets runs in another thread, therefore we have to make sure the communication safety between uWebSockets runner thread to the JS thread and vice versa. In theory, we can make uWebSockets runs in the main thread, but the app will be unusable, and then force closing the app is the only way to stop the server.
|
|
68
|
+
Intentionally, we make the uWebSockets will runs in another thread, therefore we have to make sure the communication safety between uWebSockets runner thread to the JS thread and vice versa. In theory, we can make uWebSockets runs in the main thread, but the app will be unusable, and then force closing the app is the only way to stop the server.
|
|
75
69
|
|
|
76
70
|
Yet, we only use one dedicated thread per uWebSockets run. I am in my own research to improve this by maximizing it to the hardware concurrency limit, but also to be careful about JavaScript runtime, because we have no control of it.
|
|
77
71
|
|
|
78
|
-
We have another issue because of the uWebSockets runs in another thread. From the JSI C++ side, we have to assume any
|
|
72
|
+
We have another issue because of the uWebSockets runs in another thread. From the JSI C++ side, we have to assume any JavaScript functions as a callback especially the route method handler are asynchronous. We cannot make a sync call to the JavaScript function from an arbitrary thread to the JavaScript thread, and due to the asynchronous call, it makes the JavaScript call to the uWebSockets instances is late.
|
|
79
73
|
|
|
80
74
|
There some topics you may to read regarding this threading research
|
|
81
75
|
|
|
@@ -68,12 +68,16 @@ facebook::jsi::Object UwsReactNativeModule::getParts(facebook::jsi::Runtime &rt,
|
|
|
68
68
|
/// See /uws-react-native/package/src/modules/getParts.ts
|
|
69
69
|
|
|
70
70
|
if(!body.isArrayBuffer(rt)) {
|
|
71
|
-
|
|
72
|
-
return facebook::jsi::Object(rt);
|
|
71
|
+
throw facebook::jsi::JSError(rt, "First argument of `getParts` has to be an ArrayBuffer");
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
auto arrayBuffer = body.getArrayBuffer(rt);
|
|
76
75
|
|
|
76
|
+
if(arrayBuffer.size(rt) == 0) {
|
|
77
|
+
// undefined
|
|
78
|
+
return facebook::jsi::Object(rt);
|
|
79
|
+
}
|
|
80
|
+
|
|
77
81
|
auto mp = uWS::MultipartParser(contentType.utf8(rt));
|
|
78
82
|
if(mp.isValid()) {
|
|
79
83
|
mp.setBody(std::string_view(reinterpret_cast<char *>(arrayBuffer.data(rt)),
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <ReactCommon/CallInvoker.h>
|
|
4
|
-
#include <algorithm>
|
|
5
|
-
#include <cmath>
|
|
6
3
|
#include <jsi/jsi.h>
|
|
4
|
+
#include <memory>
|
|
7
5
|
#include "RecognizedString.h"
|
|
8
6
|
#include "uWebSockets/HttpContextData.h"
|
|
9
7
|
|
|
10
8
|
namespace uws_react_native {
|
|
11
9
|
|
|
10
|
+
/// Only use this in JavaScript thread
|
|
12
11
|
class HttpRequestObject : public facebook::jsi::Object {
|
|
13
12
|
|
|
14
13
|
public:
|
|
15
14
|
HttpRequestObject(facebook::jsi::Runtime &rt,
|
|
16
|
-
uWS::HttpRequest
|
|
17
|
-
|
|
18
|
-
/// Without shared pointer
|
|
19
|
-
/// uWS::HttpRequest returns weird behaviour for some methods like
|
|
20
|
-
/// getHeader, getUrl, and getParameter
|
|
21
|
-
auto req = std::make_shared<uWS::HttpRequest>(*pReq);
|
|
15
|
+
const std::shared_ptr<uWS::HttpRequest> &req) : facebook::jsi::Object(rt) {
|
|
22
16
|
|
|
23
17
|
this->setProperty(rt,
|
|
24
18
|
"forEach",
|
|
@@ -135,7 +129,7 @@ public:
|
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
return facebook::jsi::String::createFromAscii(rt_1,
|
|
138
|
-
|
|
132
|
+
std::string(query));
|
|
139
133
|
}));
|
|
140
134
|
|
|
141
135
|
this->setProperty(rt,
|
|
@@ -164,10 +158,8 @@ public:
|
|
|
164
158
|
return {rt_1, thisValue};
|
|
165
159
|
}));
|
|
166
160
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
} // HttpRequestObject
|
|
161
|
+
} // HttpResponseObject
|
|
170
162
|
|
|
171
|
-
};
|
|
163
|
+
}; // HttpRequestObject
|
|
172
164
|
|
|
173
|
-
}
|
|
165
|
+
} // namespace uws_react_native
|