uws-react-native 0.0.10 → 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.
Files changed (78) hide show
  1. package/README.md +108 -3
  2. package/cpp/UwsReactNativeModule.cpp +4 -0
  3. package/cpp/app/HttpResponseObject.h +116 -40
  4. package/cpp/app/RecognizedString.h +20 -14
  5. package/cpp/app/TemplatedAppObject.h +61 -36
  6. package/cpp/app/WebSocketBehaviorImpl.h +269 -11
  7. package/cpp/app/WebSocketObject.h +354 -16
  8. package/cpp/app/WebSocketUserData.h +227 -0
  9. package/lib/commonjs/modules/WebSocketSendStatus.js +22 -0
  10. package/lib/commonjs/modules/WebSocketSendStatus.js.map +1 -0
  11. package/lib/commonjs/modules/index.js +22 -0
  12. package/lib/commonjs/modules/index.js.map +1 -1
  13. package/lib/commonjs/types/WebSocketUserData.js +2 -0
  14. package/lib/commonjs/types/WebSocketUserData.js.map +1 -0
  15. package/lib/module/modules/WebSocketSendStatus.js +18 -0
  16. package/lib/module/modules/WebSocketSendStatus.js.map +1 -0
  17. package/lib/module/modules/index.js +2 -1
  18. package/lib/module/modules/index.js.map +1 -1
  19. package/lib/module/types/WebSocketUserData.js +2 -0
  20. package/lib/module/types/WebSocketUserData.js.map +1 -0
  21. package/lib/typescript/commonjs/modules/WebSocketSendStatus.d.ts +15 -0
  22. package/lib/typescript/commonjs/modules/WebSocketSendStatus.d.ts.map +1 -0
  23. package/lib/typescript/commonjs/modules/index.d.ts +2 -0
  24. package/lib/typescript/commonjs/modules/index.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/types/HttpResponse.d.ts +39 -4
  26. package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +1 -1
  28. package/lib/typescript/commonjs/types/TemplatedApp.d.ts +5 -0
  29. package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -1
  30. package/lib/typescript/commonjs/types/WebSocket.d.ts +18 -8
  31. package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts +9 -9
  33. package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/types/WebSocketUserData.d.ts +9 -0
  35. package/lib/typescript/commonjs/types/WebSocketUserData.d.ts.map +1 -0
  36. package/lib/typescript/commonjs/types/index.d.ts +3 -0
  37. package/lib/typescript/commonjs/types/index.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +2 -3
  39. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -1
  40. package/lib/typescript/module/index.d.ts +2 -2
  41. package/lib/typescript/module/index.d.ts.map +1 -1
  42. package/lib/typescript/module/modules/App.d.ts +1 -1
  43. package/lib/typescript/module/modules/App.d.ts.map +1 -1
  44. package/lib/typescript/module/modules/WebSocketSendStatus.d.ts +15 -0
  45. package/lib/typescript/module/modules/WebSocketSendStatus.d.ts.map +1 -0
  46. package/lib/typescript/module/modules/getParts.d.ts +1 -1
  47. package/lib/typescript/module/modules/getParts.d.ts.map +1 -1
  48. package/lib/typescript/module/modules/index.d.ts +7 -5
  49. package/lib/typescript/module/modules/index.d.ts.map +1 -1
  50. package/lib/typescript/module/types/HttpRequest.d.ts +1 -1
  51. package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -1
  52. package/lib/typescript/module/types/HttpResponse.d.ts +40 -5
  53. package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -1
  54. package/lib/typescript/module/types/HttpRouterOptions.d.ts +1 -1
  55. package/lib/typescript/module/types/TemplatedApp.d.ts +10 -5
  56. package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -1
  57. package/lib/typescript/module/types/WebSocket.d.ts +19 -9
  58. package/lib/typescript/module/types/WebSocket.d.ts.map +1 -1
  59. package/lib/typescript/module/types/WebSocketBehavior.d.ts +14 -14
  60. package/lib/typescript/module/types/WebSocketBehavior.d.ts.map +1 -1
  61. package/lib/typescript/module/types/WebSocketUserData.d.ts +9 -0
  62. package/lib/typescript/module/types/WebSocketUserData.d.ts.map +1 -0
  63. package/lib/typescript/module/types/index.d.ts +8 -5
  64. package/lib/typescript/module/types/index.d.ts.map +1 -1
  65. package/lib/typescript/module/types/us_socket_context_t.d.ts +2 -3
  66. package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -1
  67. package/lib/typescript/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +4 -3
  69. package/src/modules/WebSocketSendStatus.ts +14 -0
  70. package/src/modules/index.ts +2 -1
  71. package/src/types/HttpResponse.ts +50 -33
  72. package/src/types/HttpRouterOptions.ts +1 -1
  73. package/src/types/TemplatedApp.ts +10 -10
  74. package/src/types/WebSocket.ts +24 -8
  75. package/src/types/WebSocketBehavior.ts +9 -9
  76. package/src/types/WebSocketUserData.ts +28 -0
  77. package/src/types/index.ts +3 -2
  78. package/src/types/us_socket_context_t.ts +2 -3
@@ -2,6 +2,12 @@
2
2
 
3
3
  #include <memory>
4
4
  #include <jsi/jsi.h>
5
+ #include <string>
6
+ #include <string_view>
7
+ #include <vector>
8
+ #include "RecognizedString.h"
9
+ #include "WebSocketUserData.h"
10
+ #include "jsi/Buffer.h"
5
11
  #include "uWebSockets/App.h"
6
12
 
7
13
  namespace uws_react_native {
@@ -11,7 +17,8 @@ struct WebSocketObject : public facebook::jsi::Object {
11
17
 
12
18
  public:
13
19
  WebSocketObject(facebook::jsi::Runtime &rt,
14
- const std::shared_ptr<uWS::WebSocket<false, true, facebook::jsi::Object>> &ws) : facebook::jsi::Object(rt) {
20
+ const std::shared_ptr<uWS::WebSocket<false, true, std::shared_ptr<WebSocketUserData>>> &ws) : facebook::jsi::Object(rt) {
21
+
15
22
  this->setProperty(rt,
16
23
  "close",
17
24
  facebook::jsi::Function::createFromHostFunction(rt,
@@ -34,30 +41,361 @@ public:
34
41
  const facebook::jsi::Value &thisValue,
35
42
  const facebook::jsi::Value *arguments,
36
43
  size_t count) -> facebook::jsi::Value {
37
- #ifdef REACT_NATIVE_DEBUG
44
+ ws->cork([&rt_1, callback = arguments[0].asObject(rt_1).asFunction(rt_1)] {
45
+ callback.call(rt_1);
46
+ });
47
+
48
+ return {rt_1, thisValue};
49
+ }));
50
+
51
+ this->setProperty(rt,
52
+ "end",
53
+ facebook::jsi::Function::createFromHostFunction(rt,
54
+ facebook::jsi::PropNameID::forUtf8(rt, "end"),
55
+ 2,
56
+ [ws](facebook::jsi::Runtime &rt_1,
57
+ const facebook::jsi::Value &thisValue,
58
+ const facebook::jsi::Value *arguments,
59
+ size_t count) -> facebook::jsi::Value {
38
60
  if(!arguments) {
39
- throw facebook::jsi::JSError(rt_1, "Expected a function from the first argument");
61
+ ws->end();
62
+ return facebook::jsi::Value::undefined();
40
63
  }
41
- if(!arguments[0].isObject()) {
42
- throw facebook::jsi::JSError(rt_1, "Expected a function from the first argument");
43
- }
44
- #endif
45
64
 
46
- auto obj = arguments[0].asObject(rt_1);
65
+ int code = 0;
47
66
 
48
- #ifdef REACT_NATIVE_DEBUG
49
- if(!obj.isFunction(rt_1)) {
50
- throw facebook::jsi::JSError(rt_1, "Expected a function from the first argument");
67
+ if(arguments[0].isNumber()) {
68
+ code = static_cast<int>(arguments[0].asNumber());
51
69
  }
52
- #endif
53
70
 
54
- ws->cork([&rt_1, callback = std::move(obj).asFunction(rt_1)] {
55
- callback.call(rt_1);
71
+ auto message = RecognizedString(rt_1, arguments[1]);
72
+ if(!message.isValid()) {
73
+ ws->end(code, {});
74
+ return facebook::jsi::Value::undefined();
75
+ }
76
+
77
+ ws->end(code, message.getStringView());
78
+ return facebook::jsi::Value::undefined();
79
+ }));
80
+
81
+ this->setProperty(rt,
82
+ "getBufferedAmount",
83
+ facebook::jsi::Function::createFromHostFunction(rt,
84
+ facebook::jsi::PropNameID::forUtf8(rt, "getBufferedAmount"),
85
+ 0,
86
+ [ws](facebook::jsi::Runtime &rt_1,
87
+ const facebook::jsi::Value &thisValue,
88
+ const facebook::jsi::Value *arguments,
89
+ size_t count) -> facebook::jsi::Value {
90
+ return {rt_1, static_cast<double>(ws->getBufferedAmount())};
91
+ }));
92
+
93
+ this->setProperty(rt,
94
+ "getRemoteAddress",
95
+ facebook::jsi::Function::createFromHostFunction(rt,
96
+ facebook::jsi::PropNameID::forUtf8(rt, "getRemoteAddress"),
97
+ 0,
98
+ [ws](facebook::jsi::Runtime &rt_1,
99
+ const facebook::jsi::Value &thisValue,
100
+ const facebook::jsi::Value *arguments,
101
+ size_t count) -> facebook::jsi::Value {
102
+ auto remoteAddress = ws->getRemoteAddress();
103
+ return facebook::jsi::ArrayBuffer(rt_1,
104
+ std::make_shared<uws_react_native::StringViewMutableBuffer>(remoteAddress));
105
+ }));
106
+
107
+ this->setProperty(rt,
108
+ "getRemoteAddressAsText",
109
+ facebook::jsi::Function::createFromHostFunction(rt,
110
+ facebook::jsi::PropNameID::forUtf8(rt, "getRemoteAddressAsText"),
111
+ 0,
112
+ [ws](facebook::jsi::Runtime &rt_1,
113
+ const facebook::jsi::Value &thisValue,
114
+ const facebook::jsi::Value *arguments,
115
+ size_t count) -> facebook::jsi::Value {
116
+ return facebook::jsi::String::createFromAscii(rt_1, ws->getRemoteAddressAsText().data());
117
+ }));
118
+
119
+ this->setProperty(rt,
120
+ "getRemotePort",
121
+ facebook::jsi::Function::createFromHostFunction(rt,
122
+ facebook::jsi::PropNameID::forUtf8(rt, "getRemotePort"),
123
+ 0,
124
+ [ws](facebook::jsi::Runtime &rt_1,
125
+ const facebook::jsi::Value &thisValue,
126
+ const facebook::jsi::Value *arguments,
127
+ size_t count) -> facebook::jsi::Value {
128
+ return {rt_1, static_cast<double>(ws->getRemotePort())};
129
+ }));
130
+
131
+ this->setProperty(rt,
132
+ "getTopics",
133
+ facebook::jsi::Function::createFromHostFunction(rt,
134
+ facebook::jsi::PropNameID::forUtf8(rt, "getTopics"),
135
+ 0,
136
+ [ws](facebook::jsi::Runtime &rt_1,
137
+ const facebook::jsi::Value &thisValue,
138
+ const facebook::jsi::Value *arguments,
139
+ size_t count) -> facebook::jsi::Value {
140
+ /// Using jsi Array with zero element and "push" it later
141
+ /// is only supported in React Native >= 0.86
142
+
143
+ auto vec = std::vector<std::string_view>();
144
+
145
+ ws->iterateTopics([&vec](std::string_view topic) -> void {
146
+ vec.emplace_back(topic);
56
147
  });
57
148
 
58
- return {rt_1, thisValue};
149
+ auto topics = facebook::jsi::Array(rt_1, vec.size());
150
+
151
+ std::for_each(vec.begin(), vec.end(), [&rt_1, &topics, i = 0](auto topic) mutable -> void {
152
+ topics.setValueAtIndex(rt_1,
153
+ i,
154
+ facebook::jsi::String::createFromAscii(rt_1, topic.data()));
155
+ i++;
156
+ });
157
+
158
+ return topics;
159
+ }));
160
+
161
+ this->setProperty(rt,
162
+ "getUserData",
163
+ facebook::jsi::Function::createFromHostFunction(rt,
164
+ facebook::jsi::PropNameID::forUtf8(rt, "getUserData"),
165
+ 0,
166
+ [ws](facebook::jsi::Runtime &rt_1,
167
+ const facebook::jsi::Value &thisValue,
168
+ const facebook::jsi::Value *arguments,
169
+ size_t count) -> facebook::jsi::Value {
170
+ return facebook::jsi::Object::createFromHostObject(rt_1,
171
+ *(ws->getUserData()));
172
+ }));
173
+
174
+ this->setProperty(rt,
175
+ "isSubscribed",
176
+ facebook::jsi::Function::createFromHostFunction(rt,
177
+ facebook::jsi::PropNameID::forUtf8(rt, "isSubscribed"),
178
+ 1,
179
+ [ws](facebook::jsi::Runtime &rt_1,
180
+ const facebook::jsi::Value &thisValue,
181
+ const facebook::jsi::Value *arguments,
182
+ size_t count) -> facebook::jsi::Value {
183
+ if(!arguments) {
184
+ return {rt_1, false};
185
+ }
186
+
187
+ auto topic = RecognizedString(rt_1, arguments[0]);
188
+ if(!topic.isValid()) {
189
+ return {rt_1, false};
190
+ }
191
+
192
+ return {rt_1, ws->isSubscribed(topic.getStringView())};
193
+ }));
194
+
195
+ this->setProperty(rt,
196
+ "ping",
197
+ facebook::jsi::Function::createFromHostFunction(rt,
198
+ facebook::jsi::PropNameID::forUtf8(rt, "ping"),
199
+ 1,
200
+ [ws](facebook::jsi::Runtime &rt_1,
201
+ const facebook::jsi::Value &thisValue,
202
+ const facebook::jsi::Value *arguments,
203
+ size_t count) -> facebook::jsi::Value {
204
+ if(!arguments) {
205
+ return {rt_1, int(0)};
206
+ }
207
+
208
+ auto message = RecognizedString(rt_1, arguments[0]);
209
+ if(!message.isValid()){
210
+ return {rt_1, int(0)};
211
+ }
212
+
213
+ auto sendStatus = ws->send(message.getStringView(), uWS::OpCode::PING);
214
+ return {rt_1, sendStatus};
215
+ }));
216
+
217
+ this->setProperty(rt,
218
+ "publish",
219
+ facebook::jsi::Function::createFromHostFunction(rt,
220
+ facebook::jsi::PropNameID::forUtf8(rt, "publish"),
221
+ 4,
222
+ [ws](facebook::jsi::Runtime &rt_1,
223
+ const facebook::jsi::Value &thisValue,
224
+ const facebook::jsi::Value *arguments,
225
+ size_t count) -> facebook::jsi::Value {
226
+ if(!arguments) {
227
+ return {rt_1, false};
228
+ }
229
+
230
+ auto topic = RecognizedString(rt_1, arguments[0]);
231
+ if(!topic.isValid()) {
232
+ return {rt_1, false};
233
+ }
234
+
235
+ auto message = RecognizedString(rt_1, arguments[1]);
236
+ if(!message.isValid()) {
237
+ return {rt_1, false};
238
+ }
239
+
240
+ auto isBinary = arguments[2].isBool() && arguments[2].asBool();
241
+ auto compress = arguments[3].isBool() && arguments[3].asBool();
242
+
243
+ bool success = ws->publish(topic.getStringView(),
244
+ message.getStringView(),
245
+ isBinary ? uWS::OpCode::BINARY : uWS::OpCode::TEXT,
246
+ compress);
247
+ return {rt_1, success};
248
+ }));
249
+
250
+ this->setProperty(rt,
251
+ "send",
252
+ facebook::jsi::Function::createFromHostFunction(rt,
253
+ facebook::jsi::PropNameID::forUtf8(rt, "send"),
254
+ 3,
255
+ [ws](facebook::jsi::Runtime &rt_1,
256
+ const facebook::jsi::Value &thisValue,
257
+ const facebook::jsi::Value *arguments,
258
+ size_t count) -> facebook::jsi::Value {
259
+ if(!arguments) {
260
+ return facebook::jsi::Value::undefined();
261
+ }
262
+
263
+ auto message = RecognizedString(rt_1, arguments[0]);
264
+ if(!message.isValid()) {
265
+ return facebook::jsi::Value::undefined();
266
+ }
267
+
268
+ auto isBinary = arguments[1].isBool() && arguments[1].asBool();
269
+ auto compress = arguments[2].isBool() && arguments[2].asBool();
270
+
271
+ double sendStatus = ws->send(message.getStringView(),
272
+ isBinary ? uWS::OpCode::BINARY : uWS::OpCode::TEXT,
273
+ compress);
274
+ return {rt_1, sendStatus};
275
+ }));
276
+
277
+ this->setProperty(rt,
278
+ "sendFirstFragment",
279
+ facebook::jsi::Function::createFromHostFunction(rt,
280
+ facebook::jsi::PropNameID::forUtf8(rt, "sendFirstFragment"),
281
+ 3,
282
+ [ws](facebook::jsi::Runtime &rt_1,
283
+ const facebook::jsi::Value &thisValue,
284
+ const facebook::jsi::Value *arguments,
285
+ size_t count) -> facebook::jsi::Value {
286
+ if(!arguments) {
287
+ return facebook::jsi::Value::undefined();
288
+ }
289
+
290
+ auto message = RecognizedString(rt_1, arguments[0]);
291
+ if(!message.isValid()) {
292
+ return facebook::jsi::Value::undefined();
293
+ }
294
+
295
+ auto isBinary = arguments[1].isBool() && arguments[1].asBool();
296
+ auto compress = arguments[2].isBool() && arguments[2].asBool();
297
+
298
+ double sendStatus = ws->sendFirstFragment(message.getStringView(),
299
+ isBinary ? uWS::OpCode::BINARY : uWS::OpCode::TEXT,
300
+ compress);
301
+ return {rt_1, sendStatus};
59
302
  }));
60
- }
303
+
304
+ this->setProperty(rt,
305
+ "sendFragment",
306
+ facebook::jsi::Function::createFromHostFunction(rt,
307
+ facebook::jsi::PropNameID::forUtf8(rt, "sendFragment"),
308
+ 2,
309
+ [ws](facebook::jsi::Runtime &rt_1,
310
+ const facebook::jsi::Value &thisValue,
311
+ const facebook::jsi::Value *arguments,
312
+ size_t count) -> facebook::jsi::Value {
313
+ if(!arguments) {
314
+ return facebook::jsi::Value::undefined();
315
+ }
316
+
317
+ auto message = RecognizedString(rt_1, arguments[0]);
318
+ if(!message.isValid()) {
319
+ return facebook::jsi::Value::undefined();
320
+ }
321
+
322
+ auto compress = arguments[2].isBool() && arguments[2].asBool();
323
+
324
+ double sendStatus = ws->sendFragment(message.getStringView(),
325
+ compress);
326
+ return {rt_1, sendStatus};
327
+ }));
328
+
329
+ this->setProperty(rt,
330
+ "sendLastFragment",
331
+ facebook::jsi::Function::createFromHostFunction(rt,
332
+ facebook::jsi::PropNameID::forUtf8(rt, "sendLastFragment"),
333
+ 2,
334
+ [ws](facebook::jsi::Runtime &rt_1,
335
+ const facebook::jsi::Value &thisValue,
336
+ const facebook::jsi::Value *arguments,
337
+ size_t count) -> facebook::jsi::Value {
338
+ if(!arguments) {
339
+ return facebook::jsi::Value::undefined();
340
+ }
341
+
342
+ auto message = RecognizedString(rt_1, arguments[0]);
343
+ if(!message.isValid()) {
344
+ return facebook::jsi::Value::undefined();
345
+ }
346
+
347
+ auto compress = arguments[2].isBool() && arguments[2].asBool();
348
+
349
+ double sendStatus = ws->sendLastFragment(message.getStringView(),
350
+ compress);
351
+ return {rt_1, sendStatus};
352
+ }));
353
+
354
+ this->setProperty(rt,
355
+ "subscribe",
356
+ facebook::jsi::Function::createFromHostFunction(rt,
357
+ facebook::jsi::PropNameID::forUtf8(rt, "subscribe"),
358
+ 1,
359
+ [ws](facebook::jsi::Runtime &rt_1,
360
+ const facebook::jsi::Value &thisValue,
361
+ const facebook::jsi::Value *arguments,
362
+ size_t count) -> facebook::jsi::Value {
363
+ if(!arguments) {
364
+ return {rt_1, false};
365
+ }
366
+
367
+ auto topic = RecognizedString(rt_1, arguments[0]);
368
+ if(!topic.isValid()) {
369
+ return {rt_1, false};
370
+ }
371
+
372
+ bool success = ws->subscribe(topic.getStringView());
373
+ return {rt_1, success};
374
+ }));
375
+
376
+ this->setProperty(rt,
377
+ "unsubscribe",
378
+ facebook::jsi::Function::createFromHostFunction(rt,
379
+ facebook::jsi::PropNameID::forUtf8(rt, "unsubscribe"),
380
+ 1,
381
+ [ws](facebook::jsi::Runtime &rt_1,
382
+ const facebook::jsi::Value &thisValue,
383
+ const facebook::jsi::Value *arguments,
384
+ size_t count) -> facebook::jsi::Value {
385
+ if(!arguments) {
386
+ return {rt_1, false};
387
+ }
388
+
389
+ auto topic = RecognizedString(rt_1, arguments[0]);
390
+ if(!topic.isValid()) {
391
+ return {rt_1, false};
392
+ }
393
+
394
+ bool success = ws->unsubscribe(topic.getStringView());
395
+ return {rt_1, success};
396
+ }));
397
+
398
+ } // WebSocketObject
61
399
 
62
400
  };
63
401
 
@@ -0,0 +1,227 @@
1
+ #pragma once
2
+
3
+ #include <algorithm>
4
+ #include <functional>
5
+ #include <jsi/jsi.h>
6
+ #include <vector>
7
+
8
+ namespace uws_react_native {
9
+
10
+ class WebSocketUserData : public facebook::jsi::HostObject {
11
+
12
+ public:
13
+ WebSocketUserData &operator=(WebSocketUserData &) = delete;
14
+
15
+ facebook::jsi::Value get(facebook::jsi::Runtime &rt,
16
+ const facebook::jsi::PropNameID &name) override {
17
+ auto nameStr = name.utf8(rt);
18
+
19
+ // getBoolean
20
+ if(nameStr == this->propertyNames[0]) {
21
+ return facebook::jsi::Function::createFromHostFunction(rt,
22
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[0]),
23
+ 2,
24
+ [this](facebook::jsi::Runtime &rt_1,
25
+ const facebook::jsi::Value &thisValue,
26
+ const facebook::jsi::Value *arguments,
27
+ size_t count) -> facebook::jsi::Value {
28
+ if(this->booleans == nullptr || !arguments || !arguments[0].isString()) {
29
+ return facebook::jsi::Value::undefined();
30
+ }
31
+
32
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
33
+ return {rt_1, this->booleans->at(key)};
34
+ });
35
+ }
36
+
37
+ // setBoolean
38
+ if(nameStr == this->propertyNames[1]) {
39
+ return facebook::jsi::Function::createFromHostFunction(rt,
40
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[1]),
41
+ 2,
42
+ [this](facebook::jsi::Runtime &rt_1,
43
+ const facebook::jsi::Value &thisValue,
44
+ const facebook::jsi::Value *arguments,
45
+ size_t count) -> facebook::jsi::Value {
46
+ if(!arguments || !arguments[0].isString() || !arguments[1].isBool()) {
47
+ return facebook::jsi::Value::undefined();
48
+ }
49
+
50
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
51
+ auto boolean = arguments[1].asBool();
52
+
53
+ if(this->booleans == nullptr) {
54
+ this->booleans = std::make_unique<std::unordered_map<std::string, bool>>();
55
+ }
56
+ this->booleans->insert({ key, boolean });
57
+
58
+ return facebook::jsi::Value::undefined();
59
+ });
60
+ }
61
+
62
+ // getNumber
63
+ if(nameStr == this->propertyNames[2]) {
64
+ return facebook::jsi::Function::createFromHostFunction(rt,
65
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[2]),
66
+ 2,
67
+ [this](facebook::jsi::Runtime &rt_1,
68
+ const facebook::jsi::Value &thisValue,
69
+ const facebook::jsi::Value *arguments,
70
+ size_t count) -> facebook::jsi::Value {
71
+ if(this->numbers == nullptr || !arguments || !arguments[0].isString()) {
72
+ return facebook::jsi::Value::undefined();
73
+ }
74
+
75
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
76
+ return {rt_1, this->numbers->at(key)};
77
+ });
78
+ }
79
+
80
+ // setNumber
81
+ if(nameStr == this->propertyNames[3]) {
82
+ return facebook::jsi::Function::createFromHostFunction(rt,
83
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[3]),
84
+ 2,
85
+ [this](facebook::jsi::Runtime &rt_1,
86
+ const facebook::jsi::Value &thisValue,
87
+ const facebook::jsi::Value *arguments,
88
+ size_t count) -> facebook::jsi::Value {
89
+ if(!arguments || !arguments[0].isString() || !arguments[1].isNumber()) {
90
+ return facebook::jsi::Value::undefined();
91
+ }
92
+
93
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
94
+ auto number = arguments[1].asNumber();
95
+
96
+ if(this->numbers == nullptr) {
97
+ this->numbers = std::make_unique<std::unordered_map<std::string, double>>();
98
+ }
99
+ this->numbers->insert({ key, number });
100
+
101
+ return facebook::jsi::Value::undefined();
102
+ });
103
+ }
104
+
105
+ // getString
106
+ if(nameStr == this->propertyNames[4]) {
107
+ return facebook::jsi::Function::createFromHostFunction(rt,
108
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[4]),
109
+ 2,
110
+ [this](facebook::jsi::Runtime &rt_1,
111
+ const facebook::jsi::Value &thisValue,
112
+ const facebook::jsi::Value *arguments,
113
+ size_t count) -> facebook::jsi::Value {
114
+ if(this->strings == nullptr || !arguments || !arguments[0].isString()) {
115
+ return facebook::jsi::Value::undefined();
116
+ }
117
+
118
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
119
+ auto it = this->strings->find(key);
120
+
121
+ if(it == this->strings->end()) {
122
+ return facebook::jsi::Value::undefined();
123
+ }
124
+
125
+ return facebook::jsi::String::createFromAscii(rt_1, it->second);
126
+ });
127
+ }
128
+
129
+ // setString
130
+ if(nameStr == this->propertyNames[5]) {
131
+ return facebook::jsi::Function::createFromHostFunction(rt,
132
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[5]),
133
+ 2,
134
+ [this](facebook::jsi::Runtime &rt_1,
135
+ const facebook::jsi::Value &thisValue,
136
+ const facebook::jsi::Value *arguments,
137
+ size_t count) -> facebook::jsi::Value {
138
+ if(!arguments || !arguments[0].isString() || !arguments[1].isString()) {
139
+ return facebook::jsi::Value::undefined();
140
+ }
141
+
142
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
143
+ auto string = arguments[1].asString(rt_1).utf8(rt_1);
144
+
145
+ if(this->strings == nullptr) {
146
+ this->strings = std::make_unique<std::unordered_map<std::string, std::string>>();
147
+ }
148
+ this->strings->insert({ key, std::move(string) });
149
+
150
+ return facebook::jsi::Value::undefined();
151
+ });
152
+ }
153
+
154
+ // remove
155
+ if(nameStr == this->propertyNames[6]) {
156
+ return facebook::jsi::Function::createFromHostFunction(rt,
157
+ facebook::jsi::PropNameID::forUtf8(rt, this->propertyNames[5]),
158
+ 1,
159
+ [this](facebook::jsi::Runtime &rt_1,
160
+ const facebook::jsi::Value &thisValue,
161
+ const facebook::jsi::Value *arguments,
162
+ size_t count) -> facebook::jsi::Value {
163
+ if(this->isEmpty() || !arguments || !arguments[0].isString()) {
164
+ return facebook::jsi::Value::undefined();
165
+ }
166
+
167
+ auto key = arguments[0].asString(rt_1).utf8(rt_1);
168
+
169
+ if(this->booleans != nullptr) {
170
+ this->booleans->erase(key);
171
+ }
172
+
173
+ if(this->numbers != nullptr) {
174
+ this->numbers->erase(key);
175
+ }
176
+
177
+ if(this->strings != nullptr) {
178
+ this->strings->erase(key);
179
+ }
180
+
181
+ return facebook::jsi::Value::undefined();
182
+ });
183
+ }
184
+
185
+ return facebook::jsi::Value::undefined();
186
+ }
187
+
188
+ void set(facebook::jsi::Runtime &rt,
189
+ const facebook::jsi::PropNameID &name,
190
+ const facebook::jsi::Value &value) override {
191
+ throw facebook::jsi::JSError(rt, "User data object is read-only.");
192
+ }
193
+
194
+ std::vector<facebook::jsi::PropNameID> getPropertyNames(facebook::jsi::Runtime& rt) override {
195
+ std::vector<facebook::jsi::PropNameID> names = {};
196
+ names.reserve(this->propertyNames.size());
197
+
198
+ std::for_each(propertyNames.begin(), propertyNames.end(), [&rt, &names](std::string &name) -> void {
199
+ names.emplace_back(facebook::jsi::PropNameID::forUtf8(rt, name));
200
+ });
201
+
202
+ return names;
203
+ }
204
+
205
+ [[nodiscard]] bool isEmpty() const {
206
+ return this->booleans == nullptr && this->numbers == nullptr && this->strings == nullptr;
207
+ }
208
+
209
+ private:
210
+ std::unique_ptr<std::unordered_map<std::string, bool>> booleans = nullptr;
211
+ std::unique_ptr<std::unordered_map<std::string, double>> numbers = nullptr;
212
+ std::unique_ptr<std::unordered_map<std::string, std::string>> strings = nullptr;
213
+
214
+ std::array<std::string, 7> propertyNames = {"getBoolean",
215
+ "setBoolean",
216
+
217
+ "getNumber",
218
+ "setBoolean",
219
+
220
+ "getString",
221
+ "setString",
222
+
223
+ "remove"};
224
+
225
+ };
226
+
227
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WebSocketSendStatus = void 0;
7
+ let WebSocketSendStatus = exports.WebSocketSendStatus = /*#__PURE__*/function (WebSocketSendStatus) {
8
+ /**
9
+ * For built up backpressure that will drain over time.
10
+ */
11
+ WebSocketSendStatus[WebSocketSendStatus["BACKPRESSURE"] = 0] = "BACKPRESSURE";
12
+ /**
13
+ * Success
14
+ */
15
+ WebSocketSendStatus[WebSocketSendStatus["SUCCESS"] = 1] = "SUCCESS";
16
+ /**
17
+ * Dropped due to backpressure limit
18
+ */
19
+ WebSocketSendStatus[WebSocketSendStatus["DROPPED"] = 2] = "DROPPED";
20
+ return WebSocketSendStatus;
21
+ }({});
22
+ //# sourceMappingURL=WebSocketSendStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WebSocketSendStatus","exports"],"sourceRoot":"../../../src","sources":["modules/WebSocketSendStatus.ts"],"mappings":";;;;;;IAAYA,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,0BAAnBA,mBAAmB;EAC9B;AACD;AACA;EAHYA,mBAAmB,CAAnBA,mBAAmB;EAK9B;AACD;AACA;EAPYA,mBAAmB,CAAnBA,mBAAmB;EAS9B;AACD;AACA;EAXYA,mBAAmB,CAAnBA,mBAAmB;EAAA,OAAnBA,mBAAmB;AAAA","ignoreList":[]}