uws-react-native 0.0.11 → 0.1.0-beta.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.
- package/README.md +1 -1
- package/cpp/UwsReactNativeModule.cpp +4 -0
- package/cpp/app/HttpResponseObject.h +116 -40
- package/cpp/app/RecognizedString.h +20 -14
- package/cpp/app/TemplatedAppObject.h +61 -36
- package/cpp/app/WebSocketBehaviorImpl.h +269 -11
- package/cpp/app/WebSocketObject.h +354 -16
- package/cpp/app/WebSocketUserData.h +227 -0
- package/lib/commonjs/modules/WebSocketSendStatus.js +22 -0
- package/lib/commonjs/modules/WebSocketSendStatus.js.map +1 -0
- package/lib/commonjs/modules/index.js +22 -0
- package/lib/commonjs/modules/index.js.map +1 -1
- package/lib/commonjs/types/WebSocketUserData.js +2 -0
- package/lib/commonjs/types/WebSocketUserData.js.map +1 -0
- package/lib/module/modules/WebSocketSendStatus.js +18 -0
- package/lib/module/modules/WebSocketSendStatus.js.map +1 -0
- package/lib/module/modules/index.js +2 -1
- package/lib/module/modules/index.js.map +1 -1
- package/lib/module/types/WebSocketUserData.js +2 -0
- package/lib/module/types/WebSocketUserData.js.map +1 -0
- package/lib/typescript/commonjs/modules/WebSocketSendStatus.d.ts +15 -0
- package/lib/typescript/commonjs/modules/WebSocketSendStatus.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/index.d.ts +2 -0
- package/lib/typescript/commonjs/modules/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/types/HttpResponse.d.ts +35 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -1
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +1 -1
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts +5 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -1
- package/lib/typescript/commonjs/types/WebSocket.d.ts +18 -8
- package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -1
- package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts +9 -9
- package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts.map +1 -1
- package/lib/typescript/commonjs/types/WebSocketUserData.d.ts +9 -0
- package/lib/typescript/commonjs/types/WebSocketUserData.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +3 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +2 -3
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -2
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/modules/App.d.ts +1 -1
- package/lib/typescript/module/modules/App.d.ts.map +1 -1
- package/lib/typescript/module/modules/WebSocketSendStatus.d.ts +15 -0
- package/lib/typescript/module/modules/WebSocketSendStatus.d.ts.map +1 -0
- package/lib/typescript/module/modules/getParts.d.ts +1 -1
- package/lib/typescript/module/modules/getParts.d.ts.map +1 -1
- package/lib/typescript/module/modules/index.d.ts +7 -5
- package/lib/typescript/module/modules/index.d.ts.map +1 -1
- package/lib/typescript/module/types/HttpRequest.d.ts +1 -1
- package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -1
- package/lib/typescript/module/types/HttpResponse.d.ts +36 -1
- package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -1
- package/lib/typescript/module/types/HttpRouterOptions.d.ts +1 -1
- package/lib/typescript/module/types/TemplatedApp.d.ts +10 -5
- package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -1
- package/lib/typescript/module/types/WebSocket.d.ts +19 -9
- package/lib/typescript/module/types/WebSocket.d.ts.map +1 -1
- package/lib/typescript/module/types/WebSocketBehavior.d.ts +14 -14
- package/lib/typescript/module/types/WebSocketBehavior.d.ts.map +1 -1
- package/lib/typescript/module/types/WebSocketUserData.d.ts +9 -0
- package/lib/typescript/module/types/WebSocketUserData.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +8 -5
- package/lib/typescript/module/types/index.d.ts.map +1 -1
- package/lib/typescript/module/types/us_socket_context_t.d.ts +2 -3
- package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/modules/WebSocketSendStatus.ts +14 -0
- package/src/modules/index.ts +2 -1
- package/src/types/HttpResponse.ts +46 -29
- package/src/types/HttpRouterOptions.ts +1 -1
- package/src/types/TemplatedApp.ts +10 -10
- package/src/types/WebSocket.ts +24 -8
- package/src/types/WebSocketBehavior.ts +9 -9
- package/src/types/WebSocketUserData.ts +28 -0
- package/src/types/index.ts +3 -2
- package/src/types/us_socket_context_t.ts +2 -3
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <ReactCommon/CallInvoker.h>
|
|
4
|
+
#include <ReactCommon/SchedulerPriority.h>
|
|
3
5
|
#include <memory>
|
|
4
6
|
#include <jsi/jsi.h>
|
|
7
|
+
#include <react/bridging/Function.h>
|
|
5
8
|
#include "WebSocketObject.h"
|
|
9
|
+
#include "WebSocketUserData.h"
|
|
6
10
|
#include "jsi/Buffer.h"
|
|
7
11
|
#include "uWebSockets/App.h"
|
|
8
12
|
|
|
@@ -14,26 +18,20 @@ public:
|
|
|
14
18
|
WebSocketBehaviorImpl(facebook::jsi::Runtime &rt,
|
|
15
19
|
std::shared_ptr<facebook::react::CallInvoker> &jsInvoker,
|
|
16
20
|
facebook::jsi::Object &&object) {
|
|
17
|
-
|
|
18
21
|
// AppRunner thread
|
|
19
22
|
{
|
|
20
23
|
auto prop = object.getProperty(rt, "close");
|
|
21
|
-
#ifdef REACT_NATIVE_DEBUG
|
|
22
24
|
if(!prop.isObject()) {
|
|
23
|
-
|
|
25
|
+
return;
|
|
24
26
|
}
|
|
25
|
-
#endif
|
|
26
27
|
|
|
27
28
|
auto obj = prop.asObject(rt);
|
|
28
|
-
|
|
29
|
-
#ifdef REACT_NATIVE_DEBUG
|
|
30
29
|
if(!obj.isFunction(rt)) {
|
|
31
|
-
|
|
30
|
+
return;
|
|
32
31
|
}
|
|
33
|
-
#endif
|
|
34
32
|
|
|
35
33
|
this->close = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws, int code, std::string_view message) {
|
|
36
|
-
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true,
|
|
34
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws), code, message](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
37
35
|
cb.call(rt_1,
|
|
38
36
|
WebSocketObject(rt_1, sharedWs),
|
|
39
37
|
code,
|
|
@@ -42,7 +40,267 @@ public:
|
|
|
42
40
|
});
|
|
43
41
|
};
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
auto prop = object.getProperty(rt, "closeOnBackpressureLimit");
|
|
46
|
+
if(!prop.isBool()) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this->closeOnBackpressureLimit = prop.asBool();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
auto prop = object.getProperty(rt, "compression");
|
|
55
|
+
if(!prop.isNumber()) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this->compression = (uWS::CompressOptions) prop.asNumber();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// AppRunner thread
|
|
63
|
+
{
|
|
64
|
+
auto prop = object.getProperty(rt, "drain");
|
|
65
|
+
if(!prop.isObject()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
auto obj = prop.asObject(rt);
|
|
70
|
+
if(!obj.isFunction(rt)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this->drain = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws) -> void {
|
|
75
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws)](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
76
|
+
cb.call(rt_1,
|
|
77
|
+
WebSocketObject(rt_1, sharedWs));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// AppRunner thread
|
|
83
|
+
{
|
|
84
|
+
auto prop = object.getProperty(rt, "dropped");
|
|
85
|
+
if(!prop.isObject()) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
auto obj = prop.asObject(rt);
|
|
90
|
+
if(!obj.isFunction(rt)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this->dropped = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws, std::string_view message, uWS::OpCode opCode) -> void {
|
|
95
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws), message, opCode](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
96
|
+
cb.call(rt_1,
|
|
97
|
+
WebSocketObject(rt_1, sharedWs),
|
|
98
|
+
facebook::jsi::ArrayBuffer(rt_1, std::make_shared<StringViewMutableBuffer>(message)),
|
|
99
|
+
opCode == uWS::OpCode::BINARY);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
auto prop = object.getProperty(rt, "idleTimeout");
|
|
106
|
+
if(!prop.isNumber()) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
auto number = prop.asNumber();
|
|
111
|
+
if(number < 0 || number > USHRT_MAX) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this->idleTimeout = static_cast<unsigned short>(number);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
{
|
|
119
|
+
auto prop = object.getProperty(rt, "maxBackpressure");
|
|
120
|
+
if(!prop.isNumber()) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
auto number = prop.asNumber();
|
|
125
|
+
if(number < 0 || number > UINT_MAX) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this->maxBackpressure = static_cast<unsigned int>(number);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
{
|
|
133
|
+
auto prop = object.getProperty(rt, "maxLifetime");
|
|
134
|
+
if(!prop.isNumber()) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
auto number = prop.asNumber();
|
|
139
|
+
if(number < 0 || number > USHRT_MAX) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this->maxLifetime = static_cast<unsigned short>(number);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
{
|
|
147
|
+
auto prop = object.getProperty(rt, "maxPayloadLength");
|
|
148
|
+
if(!prop.isNumber()) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
auto number = prop.asNumber();
|
|
153
|
+
if(number < 0 || number > UINT_MAX) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this->maxPayloadLength = static_cast<unsigned int>(number);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// AppRunner thread
|
|
161
|
+
{
|
|
162
|
+
auto prop = object.getProperty(rt, "message");
|
|
163
|
+
if(!prop.isObject()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
auto obj = prop.asObject(rt);
|
|
168
|
+
if(!obj.isFunction(rt)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this->message = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws, std::string_view message, uWS::OpCode opCode) -> void {
|
|
173
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws), message, opCode](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
174
|
+
cb.call(rt_1,
|
|
175
|
+
WebSocketObject(rt_1, sharedWs),
|
|
176
|
+
facebook::jsi::ArrayBuffer(rt_1, std::make_shared<StringViewMutableBuffer>(message)),
|
|
177
|
+
opCode == uWS::OpCode::BINARY);
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// AppRunner thread
|
|
183
|
+
{
|
|
184
|
+
auto prop = object.getProperty(rt, "open");
|
|
185
|
+
if(!prop.isObject()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
auto obj = prop.asObject(rt);
|
|
190
|
+
if(!obj.isFunction(rt)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this->open = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws) -> void {
|
|
195
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws)](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
196
|
+
cb.call(rt_1,
|
|
197
|
+
WebSocketObject(rt_1, sharedWs));
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// AppRunner thread
|
|
203
|
+
{
|
|
204
|
+
auto prop = object.getProperty(rt, "ping");
|
|
205
|
+
if(!prop.isObject()) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
auto obj = prop.asObject(rt);
|
|
210
|
+
if(!obj.isFunction(rt)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this->ping = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws, std::string_view message) -> void {
|
|
215
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws), message](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
216
|
+
cb.call(rt_1,
|
|
217
|
+
WebSocketObject(rt_1, sharedWs),
|
|
218
|
+
facebook::jsi::ArrayBuffer(rt_1, std::make_shared<StringViewMutableBuffer>(message)));
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// AppRunner thread
|
|
224
|
+
{
|
|
225
|
+
auto prop = object.getProperty(rt, "pong");
|
|
226
|
+
if(!prop.isObject()) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
auto obj = prop.asObject(rt);
|
|
231
|
+
if(!obj.isFunction(rt)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this->pong = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws, std::string_view message) -> void {
|
|
236
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws), message](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
237
|
+
cb.call(rt_1,
|
|
238
|
+
WebSocketObject(rt_1, sharedWs),
|
|
239
|
+
facebook::jsi::ArrayBuffer(rt_1, std::make_shared<StringViewMutableBuffer>(message)));
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
{
|
|
245
|
+
auto prop = object.getProperty(rt, "sendPingsAutomatically");
|
|
246
|
+
if(!prop.isBool()) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
this->sendPingsAutomatically = prop.asBool();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// AppRunner thread
|
|
254
|
+
{
|
|
255
|
+
auto prop = object.getProperty(rt, "subscription");
|
|
256
|
+
if(!prop.isObject()) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
auto obj = prop.asObject(rt);
|
|
261
|
+
if(!obj.isFunction(rt)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this->subscription = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker)](auto *ws, std::string_view topic, int newCount, int oldCount) -> void {
|
|
266
|
+
fn.call([sharedWs = std::make_shared<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>>(*ws), topic, newCount, oldCount](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) -> void {
|
|
267
|
+
cb.call(rt_1,
|
|
268
|
+
WebSocketObject(rt_1, sharedWs),
|
|
269
|
+
facebook::jsi::ArrayBuffer(rt_1, std::make_shared<StringViewMutableBuffer>(topic)),
|
|
270
|
+
newCount,
|
|
271
|
+
oldCount);
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// AppRunner thread
|
|
277
|
+
{
|
|
278
|
+
auto prop = object.getProperty(rt, "upgrade");
|
|
279
|
+
if(!prop.isObject()) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
auto obj = prop.asObject(rt);
|
|
284
|
+
if(!obj.isFunction(rt)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
this->upgrade = [fn = facebook::react::AsyncCallback(rt, std::move(obj).asFunction(rt), jsInvoker), &jsInvoker](auto *res, auto *req, us_socket_context_t *context) -> void {
|
|
289
|
+
auto httpResponseObjectProvider = std::make_shared<HttpResponseObjectProvider>(res);
|
|
290
|
+
auto httpRequestShared = std::make_shared<uWS::HttpRequest>(*req);
|
|
291
|
+
|
|
292
|
+
fn.callWithPriority(facebook::react::SchedulerPriority::ImmediatePriority, [httpResponseObjectProvider, httpRequestShared, &jsInvoker, contextAddress = reinterpret_cast<uintptr_t>(context)](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) {
|
|
293
|
+
// React Native JS runtime
|
|
294
|
+
if(httpResponseObjectProvider && httpRequestShared) {
|
|
295
|
+
cb.call(rt_1,
|
|
296
|
+
HttpResponseObject(rt_1, httpResponseObjectProvider, jsInvoker),
|
|
297
|
+
HttpRequestObject(rt_1, httpRequestShared),
|
|
298
|
+
facebook::jsi::BigInt::fromUint64(rt_1, contextAddress));
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
} // WebSocketBehaviorImpl
|
|
304
|
+
}; // WebSocketBehaviorImpl
|
|
47
305
|
|
|
48
306
|
}
|