uws-react-native 0.0.9 → 0.0.11

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 (51) hide show
  1. package/README.md +134 -9
  2. package/cpp/UwsReactNativeModule.h +77 -0
  3. package/cpp/app/TemplatedAppObject.h +28 -0
  4. package/cpp/app/WebSocketBehaviorImpl.h +48 -0
  5. package/cpp/app/WebSocketObject.h +64 -0
  6. package/lib/commonjs/_internal/native-modules/NativeUwsReactNative.js.map +1 -1
  7. package/lib/commonjs/modules/CompressOptions.js +89 -101
  8. package/lib/commonjs/modules/CompressOptions.js.map +1 -1
  9. package/lib/commonjs/types/WebSocketBehavior.js +6 -0
  10. package/lib/commonjs/types/WebSocketBehavior.js.map +1 -0
  11. package/lib/module/_internal/native-modules/NativeUwsReactNative.js.map +1 -1
  12. package/lib/module/modules/CompressOptions.js +85 -101
  13. package/lib/module/modules/CompressOptions.js.map +1 -1
  14. package/lib/module/types/WebSocketBehavior.js +4 -0
  15. package/lib/module/types/WebSocketBehavior.js.map +1 -0
  16. package/lib/typescript/commonjs/_internal/native-modules/NativeUwsReactNative.d.ts +76 -0
  17. package/lib/typescript/commonjs/_internal/native-modules/NativeUwsReactNative.d.ts.map +1 -1
  18. package/lib/typescript/commonjs/modules/CompressOptions.d.ts +81 -0
  19. package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -1
  20. package/lib/typescript/commonjs/types/HttpResponse.d.ts +4 -4
  21. package/lib/typescript/commonjs/types/WebSocket.d.ts +42 -43
  22. package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts +101 -0
  24. package/lib/typescript/commonjs/types/WebSocketBehavior.d.ts.map +1 -0
  25. package/lib/typescript/module/_internal/native-modules/NativeUwsReactNative.d.ts +76 -0
  26. package/lib/typescript/module/_internal/native-modules/NativeUwsReactNative.d.ts.map +1 -1
  27. package/lib/typescript/module/modules/CompressOptions.d.ts +81 -0
  28. package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -1
  29. package/lib/typescript/module/types/HttpResponse.d.ts +4 -4
  30. package/lib/typescript/module/types/WebSocket.d.ts +42 -43
  31. package/lib/typescript/module/types/WebSocket.d.ts.map +1 -1
  32. package/lib/typescript/module/types/WebSocketBehavior.d.ts +101 -0
  33. package/lib/typescript/module/types/WebSocketBehavior.d.ts.map +1 -0
  34. package/lib/typescript/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +1 -1
  36. package/src/_internal/native-modules/NativeUwsReactNative.ts +95 -0
  37. package/src/modules/CompressOptions.ts +101 -101
  38. package/src/types/HttpResponse.ts +4 -4
  39. package/src/types/TemplatedApp.ts +3 -3
  40. package/src/types/WebSocket.ts +59 -60
  41. package/src/types/WebSocketBehavior.ts +161 -0
  42. package/src/types/index.ts +1 -1
  43. package/lib/commonjs/types/WebSocketBehaviour.js +0 -139
  44. package/lib/commonjs/types/WebSocketBehaviour.js.map +0 -1
  45. package/lib/module/types/WebSocketBehaviour.js +0 -139
  46. package/lib/module/types/WebSocketBehaviour.js.map +0 -1
  47. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +0 -1
  48. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +0 -1
  49. package/lib/typescript/module/types/WebSocketBehaviour.d.ts +0 -1
  50. package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +0 -1
  51. package/src/types/WebSocketBehaviour.ts +0 -137
package/README.md CHANGED
@@ -5,11 +5,23 @@ The port of [**uWebSockets**](https://github.com/uNetworking/uWebSockets) librar
5
5
  - **uWebSockets** is simple, secure & standards compliant web server for the most demanding of applications. See [**uWebSockets**](https://github.com/uNetworking/uWebSockets) for more information
6
6
  - **uws-react-native** is library that allows you to easily use **uWebSockets** in your React Native through new architecture with JSI to the native C++
7
7
 
8
- > ⚠️ uws-react-native is still in heavy development and research. All the uWebSockets instances are not fully implemented yet.
8
+ > ⚠️ WebSocket server is not implemented yet
9
+
10
+ - [Installation](#installation)
11
+ - [From NPM Registry](#from-npm-registry)
12
+ - [From GitHub Release](#from-github-release)
13
+ - [From GitHub Packages](#from-github-packages)
14
+ - [Usage](#usage)
15
+ - [Compatibility](#compatibility)
16
+ - [Platform](#platform)
17
+ - [Unsupported APIs](#unsupported-apis)
18
+ - [New APIs](#new-apis)
19
+ - [Contributing](#contributing)
20
+ - [Development & Research](#development--research)
9
21
 
10
22
  ## Installation
11
23
 
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
24
+ We provide three registry homes where this library is available for use in your project. You can use either it is from NPM registry, or GitHub Release, or GitHub Packages. It has absolutely **no external JavaScript dependencies**
13
25
 
14
26
  ### From NPM Registry
15
27
 
@@ -28,6 +40,31 @@ pnpm
28
40
  pnpm install uws-react-native
29
41
  ```
30
42
 
43
+ ### From GitHub Release
44
+
45
+ To install this library from GitHub release
46
+
47
+ 1. Go to this project's [GitHub Release](https://github.com/RakaDoank/uws-react-native/releases)
48
+ 2. Find the `uws-react-native-X.X.X.tgz` asset from one of the release versions
49
+ 3. Copy the asset URL or link (Right click at the asset file name in your browser)
50
+
51
+ Finally, do the regular installation with the CLI, but with the asset URL
52
+
53
+ npm
54
+ ```
55
+ npm install https://github.com/.../uws-react-native-X.X.X.tgz
56
+ ```
57
+ yarn
58
+ ```
59
+ yarn add https://github.com/.../uws-react-native-X.X.X.tgz
60
+ ```
61
+ pnpm
62
+ ```
63
+ pnpm install https://github.com/.../uws-react-native-X.X.X.tgz
64
+ ```
65
+
66
+ > You can also do an offline installation by downloading the tarball file first, and do the regular installation with the CLI, but with the local file path.
67
+
31
68
  ### From GitHub Packages
32
69
 
33
70
  First, create your GitHub personal token (classic) with `read:packages` access
@@ -66,9 +103,88 @@ pnpm install @rakadoank/uws-react-native
66
103
  ## Usage
67
104
 
68
105
  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.
69
- You can refer to the [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) example.
70
-
71
- This repository does also contain the [example](https://github.com/RakaDoank/uws-react-native/blob/main/example/src/app/index.tsx) app. You can also refer to it, but it is currently for library development playground rather than proper example.
106
+ You can refer to the [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) example, but **we recommend to create a server in `useEffect`**.
107
+
108
+ This repository does also contain the [server example](https://github.com/RakaDoank/uws-react-native/blob/main/examples/app/src/screens/home/_use-server.ts). You can also refer to it, but it is currently for library development playground rather than proper example.
109
+
110
+ A simple server example
111
+
112
+ ```tsx
113
+ import { useEffect } from "react"
114
+ import * as uWS from "uws-react-native"
115
+
116
+ export function Component() {
117
+
118
+ // useEffect is perfect tool for production and even in development mode.
119
+ // In the development mode, any changes below will restart the server automatically because of the useEffect cycle
120
+ useEffect(() => {
121
+ const app = uWS.App()
122
+
123
+ app.get("/data/:foo/:bar", (res, req) => {
124
+ const fooSlug = req.getParameter("foo")
125
+ const barSlug = req.getParameter("bar")
126
+
127
+ res.writeHeader("content-type", "application/json")
128
+ res.end(
129
+ JSON.stringify({
130
+ foo: fooSlug,
131
+ bar: barSlug,
132
+ });
133
+ )
134
+ })
135
+
136
+ app.get("/about", res => {
137
+ res.write("<html><body>")
138
+ res.write("<h2>Hello World</h2>")
139
+ res.end("</body></html>")
140
+ })
141
+
142
+ app.post("/data", (res, req) => {
143
+ let isAborted = false
144
+ res.onAborted(() => {
145
+ isAborted = true
146
+ })
147
+
148
+ res.onFullData(data => {
149
+ const textDecoder = new TextDecoder("utf-8")
150
+ const text = textDecoder.decode(data)
151
+
152
+ try {
153
+ const json = JSON.parse(text)
154
+
155
+ if(!isAborted) {
156
+ // send the json back
157
+ res.writeHeader("content-type", "application/json")
158
+ res.end(
159
+ JSON.stringify(json)
160
+ )
161
+ }
162
+ } catch {
163
+ // not a valid json
164
+ res.end(
165
+ JSON.stringify({
166
+ message: "Something went wrong",
167
+ })
168
+ )
169
+ }
170
+ })
171
+ })
172
+
173
+ app.listen("127.0.0.1", 5000, token => {
174
+ if(token) {
175
+ console.log("Listening at port 5000")
176
+ } else {
177
+ console.log("Failed to listen")
178
+ }
179
+ })
180
+
181
+ return () => {
182
+ app.close()
183
+ }
184
+ }, [])
185
+
186
+ }
187
+ ```
72
188
 
73
189
  ## Compatibility
74
190
 
@@ -94,6 +210,11 @@ There are some new APIs in uws-react-native. The most reason is because of the d
94
210
 
95
211
  ---
96
212
 
213
+ ## Contributing
214
+
215
+ Thank you for your support to this project.
216
+ See [Contributing](https://github.com/RakaDoank/uws-react-native?tab=contributing-ov-file#contributing) for more information to help you get started with your contributions.
217
+
97
218
  ## Development & Research
98
219
 
99
220
  uws-react-native is still in heavy development and research. All the uWebSockets instances are not fully implemented yet.
@@ -106,11 +227,11 @@ We are embracing the main chaos of supporting uWebSockets in React Native archit
106
227
 
107
228
  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.
108
229
 
109
- 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.
230
+ Yet, we only use one dedicated thread per uWebSockets runner. I am in my own research to find better way to improve this by maximizing it to the hardware concurrency limit. Basically, if you run the `App` with two instance or more in JavaScript side, and with the same port listening number, you actually run the uWebSockets in multiple thread, but the JavaScript is still in single thread. It is single thread by default in React Native, we have no control of it.
110
231
 
111
232
  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.
112
233
 
113
- There some topics you may to read regarding this threading research
234
+ There some topics regarding the threading
114
235
 
115
236
  #### Predefined Instances
116
237
 
@@ -126,6 +247,10 @@ For the `onData` and `onDataV2`, we have predefined it with a single `onDataV2`
126
247
 
127
248
  #### About Worker Thread
128
249
 
129
- In theory, we can create another JavaScript runtime with [react-native-worklets](https://docs.swmansion.com/react-native-worklets/) and tie with our uWebSockets runner. It would solve a lot of late communication problem between uWebSockets runner and JavaScript thread that we embrace right now, but it also introduces new major issue, which is developer experience. It sounds like not a big problem, but it may bigger than you think.
250
+ In theory, we can create another JavaScript runtime with [react-native-worklets](https://docs.swmansion.com/react-native-worklets/) and tie with our uWebSockets runner. It would solve a lot of late communication problem between uWebSockets runner and JavaScript thread that we embrace right now, but it also introduces new major issue, which is making other native libraries unavailable.
251
+
252
+ Think of this sample case, you want to use `uws-react-native` server for a simple CRUD with a local database in an app. You probably know SQLite can be used in Android, iOS, macOS, even Windows app, with your own adapter or a known library that support SQLite integration in React Native such as [op-sqlite](https://github.com/OP-Engineering/op-sqlite), and [Expo SQLite](https://docs.expo.dev/versions/latest/sdk/sqlite). If you want to use that known library, this case would not works at all, because [op-sqlite](https://github.com/OP-Engineering/op-sqlite) and/or [Expo SQLite](https://docs.expo.dev/versions/latest/sdk/sqlite) is tied to the default JavaScript runtime. Even, you cannot use any React Native native libraries in arbitrary JavaScript thread that has created by [react-native-worklets](https://docs.swmansion.com/react-native-worklets/) if the library you want to use is using the default JavaScript runtime. If you really want to achieve the goal of this case, you have to create your own library for the SQLite database by yourself and tie-up with the JavaScript runtime. Probably, in the future we would still provide that worker thread with [react-native-worklets](https://docs.swmansion.com/react-native-worklets/).
253
+
254
+ ##### Possibility Fixes
130
255
 
131
- Think of this sample case, you want to use uws-react-native server for a simple CRUD with a local database in an app. You probably know SQLite can be used in Android, iOS, macOS, even Windows app, with your own adapter or a known library that support SQLite integration in React Native such as [op-sqlite](https://github.com/OP-Engineering/op-sqlite), and [Expo SQLite](https://docs.expo.dev/versions/latest/sdk/sqlite). If you want to use that known library, this case would not works at all, because op-sqlite and/or Expo SQLite is tied to the default JavaScript runtime. Even, you cannot use any React Native non-JS-only libraries in arbitrary JavaScript thread that has created by react-native-worklets if the library you want to use is using the default JavaScript runtime. If you really want to achieve the goal of this case, you have to create your own library for the SQLite database by yourself and tie-up with the JavaScript runtime. Probably, in the future we would still provide that worker thread with react-native-worklets.
256
+ If the native library you want to use is using [react-native-nitro-modules](https://github.com/mrousavy/nitro), you can use the library in arbitrary JavaScript thread that created by [react-native-worklets](https://docs.swmansion.com/react-native-worklets/), because the [Nitro itself is fully runtime-agnostic](https://nitro.margelo.com/docs/guides/worklets). In short, our uWebSockets runner can run in truly multiple threads approach by making your JavaScript thread also run in multiple threads with [react-native-worklets](https://docs.swmansion.com/react-native-worklets/).
@@ -2,6 +2,7 @@
2
2
 
3
3
  #include <UwsReactNativeSpecsJSI.h>
4
4
  #include "app/TemplatedAppObject.h"
5
+ #include "uWebSockets/PerMessageDeflate.h"
5
6
 
6
7
  namespace facebook::react {
7
8
 
@@ -25,6 +26,82 @@ public:
25
26
  double id
26
27
  /*facebook::jsi::Object socket*/);
27
28
 
29
+ double DISABLED(facebook::jsi::Runtime &rt) {
30
+ return uWS::DISABLED;
31
+ }
32
+
33
+ double SHARED_COMPRESSOR(facebook::jsi::Runtime &rt) {
34
+ return uWS::SHARED_COMPRESSOR;
35
+ }
36
+
37
+ double SHARED_DECOMPRESSOR(facebook::jsi::Runtime &rt) {
38
+ return uWS::SHARED_DECOMPRESSOR;
39
+ }
40
+
41
+ double DEDICATED_COMPRESSOR_3KB(facebook::jsi::Runtime &rt) {
42
+ return uWS::DEDICATED_COMPRESSOR_3KB;
43
+ }
44
+
45
+ double DEDICATED_COMPRESSOR_4KB(facebook::jsi::Runtime &rt) {
46
+ return uWS::DEDICATED_COMPRESSOR_4KB;
47
+ }
48
+
49
+ double DEDICATED_COMPRESSOR_8KB(facebook::jsi::Runtime &rt) {
50
+ return uWS::DEDICATED_COMPRESSOR_8KB;
51
+ }
52
+
53
+ double DEDICATED_COMPRESSOR_16KB(facebook::jsi::Runtime &rt) {
54
+ return uWS::DEDICATED_COMPRESSOR_16KB;
55
+ }
56
+
57
+ double DEDICATED_COMPRESSOR_32KB(facebook::jsi::Runtime &rt) {
58
+ return uWS::DEDICATED_COMPRESSOR_32KB;
59
+ }
60
+
61
+ double DEDICATED_COMPRESSOR_64KB(facebook::jsi::Runtime &rt) {
62
+ return uWS::DEDICATED_COMPRESSOR_64KB;
63
+ }
64
+
65
+ double DEDICATED_COMPRESSOR_128KB(facebook::jsi::Runtime &rt) {
66
+ return uWS::DEDICATED_COMPRESSOR_128KB;
67
+ }
68
+
69
+ double DEDICATED_COMPRESSOR_256KB(facebook::jsi::Runtime &rt) {
70
+ return uWS::DEDICATED_COMPRESSOR_256KB;
71
+ }
72
+
73
+ double DEDICATED_DECOMPRESSOR_32KB(facebook::jsi::Runtime &rt) {
74
+ return uWS::DEDICATED_DECOMPRESSOR_32KB;
75
+ }
76
+
77
+ double DEDICATED_DECOMPRESSOR_16KB(facebook::jsi::Runtime &rt) {
78
+ return uWS::DEDICATED_DECOMPRESSOR_16KB;
79
+ }
80
+
81
+ double DEDICATED_DECOMPRESSOR_8KB(facebook::jsi::Runtime &rt) {
82
+ return uWS::DEDICATED_DECOMPRESSOR_8KB;
83
+ }
84
+
85
+ double DEDICATED_DECOMPRESSOR_4KB(facebook::jsi::Runtime &rt) {
86
+ return uWS::DEDICATED_DECOMPRESSOR_4KB;
87
+ }
88
+
89
+ double DEDICATED_DECOMPRESSOR_2KB(facebook::jsi::Runtime &rt) {
90
+ return uWS::DEDICATED_DECOMPRESSOR_2KB;
91
+ }
92
+
93
+ double DEDICATED_DECOMPRESSOR_1KB(facebook::jsi::Runtime &rt) {
94
+ return uWS::DEDICATED_DECOMPRESSOR_1KB;
95
+ }
96
+
97
+ double DEDICATED_DECOMPRESSOR_512B(facebook::jsi::Runtime &rt) {
98
+ return uWS::DEDICATED_DECOMPRESSOR_512B;
99
+ }
100
+
101
+ double DEDICATED_DECOMPRESSOR(facebook::jsi::Runtime &rt) {
102
+ return uWS::DEDICATED_DECOMPRESSOR;
103
+ }
104
+
28
105
  };
29
106
 
30
107
  }
@@ -8,6 +8,7 @@
8
8
  #include "HttpResponseObject.h"
9
9
  #include "HttpResponseObjectProvider.h"
10
10
  #include "RecognizedString.h"
11
+ #include "WebSocketBehaviorImpl.h"
11
12
  #include "uWebSockets/App.h"
12
13
 
13
14
  namespace uws_react_native {
@@ -369,6 +370,33 @@ public:
369
370
  compress);
370
371
  }));
371
372
 
373
+ // TODO `WebSocketObject` and `WebSocketBehaviorImpl` are not properly implemented yet
374
+ // this->setProperty(rt,
375
+ // "ws",
376
+ // facebook::jsi::Function::createFromHostFunction(rt,
377
+ // facebook::jsi::PropNameID::forUtf8(rt, "ws"),
378
+ // 2,
379
+ // [&appRunner, &jsInvoker](facebook::jsi::Runtime &rt_1,
380
+ // const facebook::jsi::Value &thisValue,
381
+ // const facebook::jsi::Value *arguments,
382
+ // size_t count) -> facebook::jsi::Value {
383
+ //#ifdef REACT_NATIVE_DEBUG
384
+ // if(!arguments) {
385
+ // throw facebook::jsi::JSError(rt_1, "Expected pattern and WebSocketBehaviour argument");
386
+ // }
387
+ // if(!arguments[1].isObject()) {
388
+ // throw facebook::jsi::JSError(rt_1, "Expected a WebSocketBehaviour object in the second argument");
389
+ // }
390
+ //#endif
391
+ //
392
+ // auto pattern = RecognizedString(rt_1, arguments[0]).getString();
393
+ // auto behavior = WebSocketBehaviorImpl(rt_1, jsInvoker, arguments[1].asObject(rt_1));
394
+ //
395
+ // appRunner.app.ws(pattern, std::move(behavior));
396
+ //
397
+ // return {rt_1, thisValue};
398
+ // }));
399
+
372
400
  // +++++ ROUTER +++++
373
401
 
374
402
  this->setProperty(rt,
@@ -0,0 +1,48 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <jsi/jsi.h>
5
+ #include "WebSocketObject.h"
6
+ #include "jsi/Buffer.h"
7
+ #include "uWebSockets/App.h"
8
+
9
+ namespace uws_react_native {
10
+
11
+ struct WebSocketBehaviorImpl : uWS::App::WebSocketBehavior<facebook::jsi::Value> {
12
+
13
+ public:
14
+ WebSocketBehaviorImpl(facebook::jsi::Runtime &rt,
15
+ std::shared_ptr<facebook::react::CallInvoker> &jsInvoker,
16
+ facebook::jsi::Object &&object) {
17
+
18
+ // AppRunner thread
19
+ {
20
+ auto prop = object.getProperty(rt, "close");
21
+ #ifdef REACT_NATIVE_DEBUG
22
+ if(!prop.isObject()) {
23
+ throw facebook::jsi::JSError(rt, "The \"close\" property must be a function");
24
+ }
25
+ #endif
26
+
27
+ auto obj = prop.asObject(rt);
28
+
29
+ #ifdef REACT_NATIVE_DEBUG
30
+ if(!obj.isFunction(rt)) {
31
+ throw facebook::jsi::JSError(rt, "The \"close\" property must be a function");
32
+ }
33
+ #endif
34
+
35
+ 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, facebook::jsi::Object>>(*ws), code, message](facebook::jsi::Runtime &rt_1, facebook::jsi::Function &cb) {
37
+ cb.call(rt_1,
38
+ WebSocketObject(rt_1, sharedWs),
39
+ code,
40
+ facebook::jsi::ArrayBuffer(rt_1,
41
+ std::make_shared<StringViewMutableBuffer>(message)));
42
+ });
43
+ };
44
+ }
45
+ }
46
+ };
47
+
48
+ }
@@ -0,0 +1,64 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <jsi/jsi.h>
5
+ #include "uWebSockets/App.h"
6
+
7
+ namespace uws_react_native {
8
+
9
+ /// Only use this in the JavaScript thread
10
+ struct WebSocketObject : public facebook::jsi::Object {
11
+
12
+ public:
13
+ WebSocketObject(facebook::jsi::Runtime &rt,
14
+ const std::shared_ptr<uWS::WebSocket<false, true, facebook::jsi::Object>> &ws) : facebook::jsi::Object(rt) {
15
+ this->setProperty(rt,
16
+ "close",
17
+ facebook::jsi::Function::createFromHostFunction(rt,
18
+ facebook::jsi::PropNameID::forUtf8(rt, "close"),
19
+ 0,
20
+ [ws](facebook::jsi::Runtime &rt_1,
21
+ const facebook::jsi::Value &thisValue,
22
+ const facebook::jsi::Value *arguments,
23
+ size_t count) -> facebook::jsi::Value {
24
+ ws->close();
25
+ return {rt_1, thisValue};
26
+ }));
27
+
28
+ this->setProperty(rt,
29
+ "cork",
30
+ facebook::jsi::Function::createFromHostFunction(rt,
31
+ facebook::jsi::PropNameID::forUtf8(rt, "cork"),
32
+ 1,
33
+ [ws](facebook::jsi::Runtime &rt_1,
34
+ const facebook::jsi::Value &thisValue,
35
+ const facebook::jsi::Value *arguments,
36
+ size_t count) -> facebook::jsi::Value {
37
+ #ifdef REACT_NATIVE_DEBUG
38
+ if(!arguments) {
39
+ throw facebook::jsi::JSError(rt_1, "Expected a function from the first argument");
40
+ }
41
+ if(!arguments[0].isObject()) {
42
+ throw facebook::jsi::JSError(rt_1, "Expected a function from the first argument");
43
+ }
44
+ #endif
45
+
46
+ auto obj = arguments[0].asObject(rt_1);
47
+
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");
51
+ }
52
+ #endif
53
+
54
+ ws->cork([&rt_1, callback = std::move(obj).asFunction(rt_1)] {
55
+ callback.call(rt_1);
56
+ });
57
+
58
+ return {rt_1, thisValue};
59
+ }));
60
+ }
61
+
62
+ };
63
+
64
+ }
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../../src","sources":["_internal/native-modules/NativeUwsReactNative.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GA+BeC,gCAAmB,CAACC,YAAY,CAC9C,gBACD,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../../src","sources":["_internal/native-modules/NativeUwsReactNative.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMA;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GA8HeC,gCAAmB,CAACC,YAAY,CAC9C,gBACD,CAAC","ignoreList":[]}
@@ -1,103 +1,91 @@
1
- // import NativeReactNativeEcho from "../_internal/native-modules/NativeUwsReactNative"
2
-
3
- // /**
4
- // * WebSocket compression options. Combine any compressor with any decompressor using bitwise OR.
5
- // */
6
- // export enum CompressOptions {
7
- // /**
8
- // * No compression (always a good idea if you operate using an efficient binary protocol)
9
- // */
10
- // DISABLED = -1,
11
-
12
- // /**
13
- // * Zero memory overhead compression.
14
- // */
15
- // SHARED_COMPRESSOR = -1,
16
-
17
- // /**
18
- // * Zero memory overhead decompression.
19
- // */
20
- // SHARED_DECOMPRESSOR = -1,
21
-
22
- // /**
23
- // * Sliding dedicated compress window, requires 3KB of memory per socket
24
- // */
25
- // DEDICATED_COMPRESSOR_3KB = -1,
26
-
27
- // /**
28
- // * Sliding dedicated compress window, requires 4KB of memory per socket
29
- // */
30
- // DEDICATED_COMPRESSOR_4KB = -1,
31
-
32
- // /**
33
- // * Sliding dedicated compress window, requires 8KB of memory per socket
34
- // */
35
- // DEDICATED_COMPRESSOR_8KB = -1,
36
-
37
- // /**
38
- // * Sliding dedicated compress window, requires 16KB of memory per socket
39
- // */
40
- // DEDICATED_COMPRESSOR_16KB = -1,
41
-
42
- // /**
43
- // * Sliding dedicated compress window, requires 32KB of memory per socket
44
- // */
45
- // DEDICATED_COMPRESSOR_32KB = -1,
46
-
47
- // /**
48
- // * Sliding dedicated compress window, requires 64KB of memory per socket
49
- // */
50
- // DEDICATED_COMPRESSOR_64KB = -1,
51
-
52
- // /**
53
- // * Sliding dedicated compress window, requires 128KB of memory per socket
54
- // */
55
- // DEDICATED_COMPRESSOR_128KB = -1,
56
-
57
- // /**
58
- // * Sliding dedicated compress window, requires 256KB of memory per socket
59
- // */
60
- // DEDICATED_COMPRESSOR_256KB = -1,
61
-
62
- // /**
63
- // * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
64
- // */
65
- // DEDICATED_DECOMPRESSOR_32KB = -1,
66
-
67
- // /**
68
- // * Sliding dedicated decompress window, requires 16KB of memory per socket (plus about 23KB)
69
- // */
70
- // DEDICATED_DECOMPRESSOR_16KB = -1,
71
-
72
- // /**
73
- // * Sliding dedicated decompress window, requires 8KB of memory per socket (plus about 23KB)
74
- // */
75
- // DEDICATED_DECOMPRESSOR_8KB = -1,
76
-
77
- // /**
78
- // * Sliding dedicated decompress window, requires 4KB of memory per socket (plus about 23KB)
79
- // */
80
- // DEDICATED_DECOMPRESSOR_4KB = -1,
81
-
82
- // /**
83
- // * Sliding dedicated decompress window, requires 2KB of memory per socket (plus about 23KB)
84
- // */
85
- // DEDICATED_DECOMPRESSOR_2KB = -1,
86
-
87
- // /**
88
- // * Sliding dedicated decompress window, requires 1KB of memory per socket (plus about 23KB)
89
- // */
90
- // DEDICATED_DECOMPRESSOR_1KB = -1,
91
-
92
- // /**
93
- // * Sliding dedicated decompress window, requires 512B of memory per socket (plus about 23KB)
94
- // */
95
- // DEDICATED_DECOMPRESSOR_512B = -1,
96
-
97
- // /**
98
- // * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
99
- // */
100
- // DEDICATED_DECOMPRESSOR = -1,
101
- // }
102
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CompressOptions = void 0;
7
+ var _NativeUwsReactNative = _interopRequireDefault(require("../_internal/native-modules/NativeUwsReactNative.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ /**
10
+ * WebSocket compression options. Combine any compressor with any decompressor using bitwise OR.
11
+ */
12
+ let CompressOptions = exports.CompressOptions = function (CompressOptions) {
13
+ /**
14
+ * No compression (always a good idea if you operate using an efficient binary protocol)
15
+ */
16
+ CompressOptions[CompressOptions["DISABLED"] = _NativeUwsReactNative.default.DISABLED()] = "DISABLED";
17
+ /**
18
+ * Zero memory overhead compression.
19
+ */
20
+ CompressOptions[CompressOptions["SHARED_COMPRESSOR"] = _NativeUwsReactNative.default.SHARED_COMPRESSOR()] = "SHARED_COMPRESSOR";
21
+ /**
22
+ * Zero memory overhead decompression.
23
+ */
24
+ CompressOptions[CompressOptions["SHARED_DECOMPRESSOR"] = _NativeUwsReactNative.default.SHARED_DECOMPRESSOR()] = "SHARED_DECOMPRESSOR";
25
+ /**
26
+ * Sliding dedicated compress window, requires 3KB of memory per socket
27
+ */
28
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_3KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_3KB()] = "DEDICATED_COMPRESSOR_3KB";
29
+ /**
30
+ * Sliding dedicated compress window, requires 4KB of memory per socket
31
+ */
32
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_4KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_4KB()] = "DEDICATED_COMPRESSOR_4KB";
33
+ /**
34
+ * Sliding dedicated compress window, requires 8KB of memory per socket
35
+ */
36
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_8KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_8KB()] = "DEDICATED_COMPRESSOR_8KB";
37
+ /**
38
+ * Sliding dedicated compress window, requires 16KB of memory per socket
39
+ */
40
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_16KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_16KB()] = "DEDICATED_COMPRESSOR_16KB";
41
+ /**
42
+ * Sliding dedicated compress window, requires 32KB of memory per socket
43
+ */
44
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_32KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_32KB()] = "DEDICATED_COMPRESSOR_32KB";
45
+ /**
46
+ * Sliding dedicated compress window, requires 64KB of memory per socket
47
+ */
48
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_64KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_64KB()] = "DEDICATED_COMPRESSOR_64KB";
49
+ /**
50
+ * Sliding dedicated compress window, requires 128KB of memory per socket
51
+ */
52
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_128KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_128KB()] = "DEDICATED_COMPRESSOR_128KB";
53
+ /**
54
+ * Sliding dedicated compress window, requires 256KB of memory per socket
55
+ */
56
+ CompressOptions[CompressOptions["DEDICATED_COMPRESSOR_256KB"] = _NativeUwsReactNative.default.DEDICATED_COMPRESSOR_256KB()] = "DEDICATED_COMPRESSOR_256KB";
57
+ /**
58
+ * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
59
+ */
60
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_32KB"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_32KB()] = "DEDICATED_DECOMPRESSOR_32KB";
61
+ /**
62
+ * Sliding dedicated decompress window, requires 16KB of memory per socket (plus about 23KB)
63
+ */
64
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_16KB"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_16KB()] = "DEDICATED_DECOMPRESSOR_16KB";
65
+ /**
66
+ * Sliding dedicated decompress window, requires 8KB of memory per socket (plus about 23KB)
67
+ */
68
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_8KB"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_8KB()] = "DEDICATED_DECOMPRESSOR_8KB";
69
+ /**
70
+ * Sliding dedicated decompress window, requires 4KB of memory per socket (plus about 23KB)
71
+ */
72
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_4KB"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_4KB()] = "DEDICATED_DECOMPRESSOR_4KB";
73
+ /**
74
+ * Sliding dedicated decompress window, requires 2KB of memory per socket (plus about 23KB)
75
+ */
76
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_2KB"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_2KB()] = "DEDICATED_DECOMPRESSOR_2KB";
77
+ /**
78
+ * Sliding dedicated decompress window, requires 1KB of memory per socket (plus about 23KB)
79
+ */
80
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_1KB"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_1KB()] = "DEDICATED_DECOMPRESSOR_1KB";
81
+ /**
82
+ * Sliding dedicated decompress window, requires 512B of memory per socket (plus about 23KB)
83
+ */
84
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR_512B"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR_512B()] = "DEDICATED_DECOMPRESSOR_512B";
85
+ /**
86
+ * Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB)
87
+ */
88
+ CompressOptions[CompressOptions["DEDICATED_DECOMPRESSOR"] = _NativeUwsReactNative.default.DEDICATED_DECOMPRESSOR()] = "DEDICATED_DECOMPRESSOR";
89
+ return CompressOptions;
90
+ }({});
103
91
  //# sourceMappingURL=CompressOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["modules/CompressOptions.ts"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_NativeUwsReactNative","_interopRequireDefault","require","e","__esModule","default","CompressOptions","exports","NativeUwsReactNative","DISABLED","SHARED_COMPRESSOR","SHARED_DECOMPRESSOR","DEDICATED_COMPRESSOR_3KB","DEDICATED_COMPRESSOR_4KB","DEDICATED_COMPRESSOR_8KB","DEDICATED_COMPRESSOR_16KB","DEDICATED_COMPRESSOR_32KB","DEDICATED_COMPRESSOR_64KB","DEDICATED_COMPRESSOR_128KB","DEDICATED_COMPRESSOR_256KB","DEDICATED_DECOMPRESSOR_32KB","DEDICATED_DECOMPRESSOR_16KB","DEDICATED_DECOMPRESSOR_8KB","DEDICATED_DECOMPRESSOR_4KB","DEDICATED_DECOMPRESSOR_2KB","DEDICATED_DECOMPRESSOR_1KB","DEDICATED_DECOMPRESSOR_512B","DEDICATED_DECOMPRESSOR"],"sourceRoot":"../../../src","sources":["modules/CompressOptions.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAmF,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEnF;AACA;AACA;AAFA,IAGYG,eAAe,GAAAC,OAAA,CAAAD,eAAA,aAAfA,eAAe;EAC1B;AACD;AACA;EAHYA,eAAe,CAAfA,eAAe,eAIXE,6BAAoB,CAACC,QAAQ,CAAC,CAAC;EAE9C;AACD;AACA;EARYH,eAAe,CAAfA,eAAe,wBASJE,6BAAoB,CAACE,iBAAiB,CAAC,CAAC;EAE9D;AACD;AACA;EAbYJ,eAAe,CAAfA,eAAe,0BAcFE,6BAAoB,CAACG,mBAAmB,CAAC,CAAC;EAElE;AACD;AACA;EAlBYL,eAAe,CAAfA,eAAe,+BAmBCE,6BAAoB,CAACI,wBAAwB,CAAC,CAAC;EAE1E;AACD;AACA;EAvBYN,eAAe,CAAfA,eAAe,+BAwBCE,6BAAoB,CAACK,wBAAwB,CAAC,CAAC;EAE1E;AACD;AACA;EA5BYP,eAAe,CAAfA,eAAe,+BA6BCE,6BAAoB,CAACM,wBAAwB,CAAC,CAAC;EAE1E;AACD;AACA;EAjCYR,eAAe,CAAfA,eAAe,gCAkCEE,6BAAoB,CAACO,yBAAyB,CAAC,CAAC;EAE5E;AACD;AACA;EAtCYT,eAAe,CAAfA,eAAe,gCAuCEE,6BAAoB,CAACQ,yBAAyB,CAAC,CAAC;EAE5E;AACD;AACA;EA3CYV,eAAe,CAAfA,eAAe,gCA4CEE,6BAAoB,CAACS,yBAAyB,CAAC,CAAC;EAE5E;AACD;AACA;EAhDYX,eAAe,CAAfA,eAAe,iCAiDGE,6BAAoB,CAACU,0BAA0B,CAAC,CAAC;EAE9E;AACD;AACA;EArDYZ,eAAe,CAAfA,eAAe,iCAsDGE,6BAAoB,CAACW,0BAA0B,CAAC,CAAC;EAE9E;AACD;AACA;EA1DYb,eAAe,CAAfA,eAAe,kCA2DIE,6BAAoB,CAACY,2BAA2B,CAAC,CAAC;EAEhF;AACD;AACA;EA/DYd,eAAe,CAAfA,eAAe,kCAgEIE,6BAAoB,CAACa,2BAA2B,CAAC,CAAC;EAEhF;AACD;AACA;EApEYf,eAAe,CAAfA,eAAe,iCAqEGE,6BAAoB,CAACc,0BAA0B,CAAC,CAAC;EAE9E;AACD;AACA;EAzEYhB,eAAe,CAAfA,eAAe,iCA0EGE,6BAAoB,CAACe,0BAA0B,CAAC,CAAC;EAE9E;AACD;AACA;EA9EYjB,eAAe,CAAfA,eAAe,iCA+EGE,6BAAoB,CAACgB,0BAA0B,CAAC,CAAC;EAE9E;AACD;AACA;EAnFYlB,eAAe,CAAfA,eAAe,iCAoFGE,6BAAoB,CAACiB,0BAA0B,CAAC,CAAC;EAE9E;AACD;AACA;EAxFYnB,eAAe,CAAfA,eAAe,kCAyFIE,6BAAoB,CAACkB,2BAA2B,CAAC,CAAC;EAEhF;AACD;AACA;EA7FYpB,eAAe,CAAfA,eAAe,6BA8FAE,6BAAoB,CAACmB,sBAAsB,CAAC,CAAC;EAAA,OA9F5DrB,eAAe;AAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=WebSocketBehavior.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/WebSocketBehavior.ts"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../../src","sources":["_internal/native-modules/NativeUwsReactNative.ts"],"mappings":";;AAAA,SACCA,mBAAmB,QAGb,cAAc;;AAErB;AACA;AACA;;AA6BA,eAAeA,mBAAmB,CAACC,YAAY,CAC9C,gBACD,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../../../src","sources":["_internal/native-modules/NativeUwsReactNative.ts"],"mappings":";;AAAA,SACCA,mBAAmB,QAGb,cAAc;;AAErB;AACA;AACA;;AA4HA,eAAeA,mBAAmB,CAACC,YAAY,CAC9C,gBACD,CAAC","ignoreList":[]}