uws-react-native 0.0.1-alpha.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/LICENSE +201 -0
- package/README.md +84 -0
- package/UwsReactNative.podspec +71 -0
- package/android/build.gradle.kts +138 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/id/sufeni/oss/uwsreactnative/UwsReactNativePackage.kt +18 -0
- package/apple/OnLoad.mm +17 -0
- package/cpp/CMakeLists.txt +154 -0
- package/cpp/UwsReactNativeModule.cpp +191 -0
- package/cpp/UwsReactNativeModule.h +30 -0
- package/cpp/app/AppHost.h +37 -0
- package/cpp/app/AppRunner.h +88 -0
- package/cpp/app/CMakeLists.txt +39 -0
- package/cpp/app/HttpRequestObject.h +173 -0
- package/cpp/app/HttpResponseObject.h +623 -0
- package/cpp/app/RecognizedString.h +71 -0
- package/cpp/app/TemplatedAppObject.h +472 -0
- package/cpp/bridging/ArrayBuffer.h +150 -0
- package/cpp/bridging/CMakeLists.txt +34 -0
- package/cpp/jsi/Buffer.h +91 -0
- package/cpp/jsi/CMakeLists.txt +34 -0
- package/cpp/uSockets/bsd.c +767 -0
- package/cpp/uSockets/context.c +524 -0
- package/cpp/uSockets/crypto/openssl.c +858 -0
- package/cpp/uSockets/crypto/sni_tree.cpp +218 -0
- package/cpp/uSockets/eventing/asio.cpp +475 -0
- package/cpp/uSockets/eventing/epoll_kqueue.c +458 -0
- package/cpp/uSockets/eventing/gcd.c +278 -0
- package/cpp/uSockets/eventing/libuv.c +305 -0
- package/cpp/uSockets/internal/eventing/asio.h +45 -0
- package/cpp/uSockets/internal/eventing/epoll_kqueue.h +67 -0
- package/cpp/uSockets/internal/eventing/gcd.h +40 -0
- package/cpp/uSockets/internal/eventing/libuv.h +45 -0
- package/cpp/uSockets/internal/internal.h +224 -0
- package/cpp/uSockets/internal/loop_data.h +38 -0
- package/cpp/uSockets/internal/networking/bsd.h +109 -0
- package/cpp/uSockets/io_uring/internal.h +98 -0
- package/cpp/uSockets/io_uring/io_context.c +302 -0
- package/cpp/uSockets/io_uring/io_loop.c +422 -0
- package/cpp/uSockets/io_uring/io_socket.c +139 -0
- package/cpp/uSockets/libusockets.h +350 -0
- package/cpp/uSockets/loop.c +396 -0
- package/cpp/uSockets/quic.c +1071 -0
- package/cpp/uSockets/quic.h +68 -0
- package/cpp/uSockets/socket.c +231 -0
- package/cpp/uSockets/udp.c +151 -0
- package/cpp/uWebSockets/uWebSockets/App.h +676 -0
- package/cpp/uWebSockets/uWebSockets/AsyncSocket.h +376 -0
- package/cpp/uWebSockets/uWebSockets/AsyncSocketData.h +94 -0
- package/cpp/uWebSockets/uWebSockets/BloomFilter.h +83 -0
- package/cpp/uWebSockets/uWebSockets/CachingApp.h +115 -0
- package/cpp/uWebSockets/uWebSockets/ChunkedEncoding.h +237 -0
- package/cpp/uWebSockets/uWebSockets/ClientApp.h +36 -0
- package/cpp/uWebSockets/uWebSockets/Http3App.h +140 -0
- package/cpp/uWebSockets/uWebSockets/Http3Context.h +157 -0
- package/cpp/uWebSockets/uWebSockets/Http3ContextData.h +21 -0
- package/cpp/uWebSockets/uWebSockets/Http3Request.h +22 -0
- package/cpp/uWebSockets/uWebSockets/Http3Response.h +120 -0
- package/cpp/uWebSockets/uWebSockets/Http3ResponseData.h +25 -0
- package/cpp/uWebSockets/uWebSockets/HttpContext.h +521 -0
- package/cpp/uWebSockets/uWebSockets/HttpContextData.h +60 -0
- package/cpp/uWebSockets/uWebSockets/HttpErrors.h +53 -0
- package/cpp/uWebSockets/uWebSockets/HttpParser.h +747 -0
- package/cpp/uWebSockets/uWebSockets/HttpResponse.h +605 -0
- package/cpp/uWebSockets/uWebSockets/HttpResponseData.h +123 -0
- package/cpp/uWebSockets/uWebSockets/HttpRouter.h +384 -0
- package/cpp/uWebSockets/uWebSockets/LocalCluster.h +64 -0
- package/cpp/uWebSockets/uWebSockets/Loop.h +238 -0
- package/cpp/uWebSockets/uWebSockets/LoopData.h +113 -0
- package/cpp/uWebSockets/uWebSockets/MessageParser.h +64 -0
- package/cpp/uWebSockets/uWebSockets/MoveOnlyFunction.h +389 -0
- package/cpp/uWebSockets/uWebSockets/Multipart.h +231 -0
- package/cpp/uWebSockets/uWebSockets/PerMessageDeflate.h +303 -0
- package/cpp/uWebSockets/uWebSockets/ProxyParser.h +187 -0
- package/cpp/uWebSockets/uWebSockets/QueryParser.h +120 -0
- package/cpp/uWebSockets/uWebSockets/TopicTree.h +364 -0
- package/cpp/uWebSockets/uWebSockets/Utilities.h +66 -0
- package/cpp/uWebSockets/uWebSockets/WebSocket.h +407 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketContext.h +436 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketContextData.h +109 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketData.h +86 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketExtensions.h +256 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketHandshake.h +145 -0
- package/cpp/uWebSockets/uWebSockets/WebSocketProtocol.h +525 -0
- package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js +12 -0
- package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/App.js +17 -0
- package/lib/commonjs/modules/App.js.map +1 -0
- package/lib/commonjs/modules/CompressOptions.js +103 -0
- package/lib/commonjs/modules/CompressOptions.js.map +1 -0
- package/lib/commonjs/modules/EnvironmentVariables.js +17 -0
- package/lib/commonjs/modules/EnvironmentVariables.js.map +1 -0
- package/lib/commonjs/modules/ListenOptions.js +12 -0
- package/lib/commonjs/modules/ListenOptions.js.map +1 -0
- package/lib/commonjs/modules/SSLApp.js +15 -0
- package/lib/commonjs/modules/SSLApp.js.map +1 -0
- package/lib/commonjs/modules/getParts.js +28 -0
- package/lib/commonjs/modules/getParts.js.map +1 -0
- package/lib/commonjs/modules/index.js +61 -0
- package/lib/commonjs/modules/index.js.map +1 -0
- package/lib/commonjs/modules/us_listen_socket_close.js +21 -0
- package/lib/commonjs/modules/us_listen_socket_close.js.map +1 -0
- package/lib/commonjs/modules/us_socket_local_port.js +22 -0
- package/lib/commonjs/modules/us_socket_local_port.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/AppDescriptor.js +2 -0
- package/lib/commonjs/types/AppDescriptor.js.map +1 -0
- package/lib/commonjs/types/AppOptions.js +2 -0
- package/lib/commonjs/types/AppOptions.js.map +1 -0
- package/lib/commonjs/types/HttpRequest.js +6 -0
- package/lib/commonjs/types/HttpRequest.js.map +1 -0
- package/lib/commonjs/types/HttpResponse.js +6 -0
- package/lib/commonjs/types/HttpResponse.js.map +1 -0
- package/lib/commonjs/types/HttpRouterOptions.js +2 -0
- package/lib/commonjs/types/HttpRouterOptions.js.map +1 -0
- package/lib/commonjs/types/MultipartField.js +2 -0
- package/lib/commonjs/types/MultipartField.js.map +1 -0
- package/lib/commonjs/types/RecognizedString.js +2 -0
- package/lib/commonjs/types/RecognizedString.js.map +1 -0
- package/lib/commonjs/types/TemplatedApp.js +6 -0
- package/lib/commonjs/types/TemplatedApp.js.map +1 -0
- package/lib/commonjs/types/WebSocket.js +6 -0
- package/lib/commonjs/types/WebSocket.js.map +1 -0
- package/lib/commonjs/types/WebSocketBehaviour.js +139 -0
- package/lib/commonjs/types/WebSocketBehaviour.js.map +1 -0
- package/lib/commonjs/types/index.js +2 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/us_listen_socket.js +2 -0
- package/lib/commonjs/types/us_listen_socket.js.map +1 -0
- package/lib/commonjs/types/us_socket.js +2 -0
- package/lib/commonjs/types/us_socket.js.map +1 -0
- package/lib/commonjs/types/us_socket_context_t.js +2 -0
- package/lib/commonjs/types/us_socket_context_t.js.map +1 -0
- package/lib/module/_internal/native-modules/NativeReactNativeUws.js +10 -0
- package/lib/module/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/App.js +12 -0
- package/lib/module/modules/App.js.map +1 -0
- package/lib/module/modules/CompressOptions.js +103 -0
- package/lib/module/modules/CompressOptions.js.map +1 -0
- package/lib/module/modules/EnvironmentVariables.js +13 -0
- package/lib/module/modules/EnvironmentVariables.js.map +1 -0
- package/lib/module/modules/ListenOptions.js +8 -0
- package/lib/module/modules/ListenOptions.js.map +1 -0
- package/lib/module/modules/SSLApp.js +15 -0
- package/lib/module/modules/SSLApp.js.map +1 -0
- package/lib/module/modules/getParts.js +23 -0
- package/lib/module/modules/getParts.js.map +1 -0
- package/lib/module/modules/index.js +11 -0
- package/lib/module/modules/index.js.map +1 -0
- package/lib/module/modules/us_listen_socket_close.js +17 -0
- package/lib/module/modules/us_listen_socket_close.js.map +1 -0
- package/lib/module/modules/us_socket_local_port.js +18 -0
- package/lib/module/modules/us_socket_local_port.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/AppDescriptor.js +2 -0
- package/lib/module/types/AppDescriptor.js.map +1 -0
- package/lib/module/types/AppOptions.js +2 -0
- package/lib/module/types/AppOptions.js.map +1 -0
- package/lib/module/types/HttpRequest.js +4 -0
- package/lib/module/types/HttpRequest.js.map +1 -0
- package/lib/module/types/HttpResponse.js +4 -0
- package/lib/module/types/HttpResponse.js.map +1 -0
- package/lib/module/types/HttpRouterOptions.js +2 -0
- package/lib/module/types/HttpRouterOptions.js.map +1 -0
- package/lib/module/types/MultipartField.js +2 -0
- package/lib/module/types/MultipartField.js.map +1 -0
- package/lib/module/types/RecognizedString.js +2 -0
- package/lib/module/types/RecognizedString.js.map +1 -0
- package/lib/module/types/TemplatedApp.js +4 -0
- package/lib/module/types/TemplatedApp.js.map +1 -0
- package/lib/module/types/WebSocket.js +4 -0
- package/lib/module/types/WebSocket.js.map +1 -0
- package/lib/module/types/WebSocketBehaviour.js +139 -0
- package/lib/module/types/WebSocketBehaviour.js.map +1 -0
- package/lib/module/types/index.js +2 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/us_listen_socket.js +2 -0
- package/lib/module/types/us_listen_socket.js.map +1 -0
- package/lib/module/types/us_socket.js +2 -0
- package/lib/module/types/us_socket.js.map +1 -0
- package/lib/module/types/us_socket_context_t.js +2 -0
- package/lib/module/types/us_socket_context_t.js.map +1 -0
- package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
- package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +3 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/App.d.ts +7 -0
- package/lib/typescript/commonjs/modules/App.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/CompressOptions.d.ts +1 -0
- package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts +16 -0
- package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/ListenOptions.d.ts +5 -0
- package/lib/typescript/commonjs/modules/ListenOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/SSLApp.d.ts +1 -0
- package/lib/typescript/commonjs/modules/SSLApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/getParts.d.ts +6 -0
- package/lib/typescript/commonjs/modules/getParts.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/index.d.ts +6 -0
- package/lib/typescript/commonjs/modules/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts +5 -0
- package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts +5 -0
- package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/types/AppDescriptor.d.ts +8 -0
- package/lib/typescript/commonjs/types/AppDescriptor.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/AppOptions.d.ts +17 -0
- package/lib/typescript/commonjs/types/AppOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpRequest.d.ts +54 -0
- package/lib/typescript/commonjs/types/HttpRequest.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts +169 -0
- package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +24 -0
- package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/MultipartField.d.ts +7 -0
- package/lib/typescript/commonjs/types/MultipartField.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/RecognizedString.d.ts +10 -0
- package/lib/typescript/commonjs/types/RecognizedString.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts +108 -0
- package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/WebSocket.d.ts +96 -0
- package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +1 -0
- package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/index.d.ts +6 -0
- package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_listen_socket.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_listen_socket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_socket.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_socket.d.ts.map +1 -0
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +7 -0
- package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -0
- package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
- package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +3 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/App.d.ts +7 -0
- package/lib/typescript/module/modules/App.d.ts.map +1 -0
- package/lib/typescript/module/modules/CompressOptions.d.ts +1 -0
- package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -0
- package/lib/typescript/module/modules/EnvironmentVariables.d.ts +16 -0
- package/lib/typescript/module/modules/EnvironmentVariables.d.ts.map +1 -0
- package/lib/typescript/module/modules/ListenOptions.d.ts +5 -0
- package/lib/typescript/module/modules/ListenOptions.d.ts.map +1 -0
- package/lib/typescript/module/modules/SSLApp.d.ts +1 -0
- package/lib/typescript/module/modules/SSLApp.d.ts.map +1 -0
- package/lib/typescript/module/modules/getParts.d.ts +6 -0
- package/lib/typescript/module/modules/getParts.d.ts.map +1 -0
- package/lib/typescript/module/modules/index.d.ts +6 -0
- package/lib/typescript/module/modules/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/us_listen_socket_close.d.ts +5 -0
- package/lib/typescript/module/modules/us_listen_socket_close.d.ts.map +1 -0
- package/lib/typescript/module/modules/us_socket_local_port.d.ts +5 -0
- package/lib/typescript/module/modules/us_socket_local_port.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/types/AppDescriptor.d.ts +8 -0
- package/lib/typescript/module/types/AppDescriptor.d.ts.map +1 -0
- package/lib/typescript/module/types/AppOptions.d.ts +17 -0
- package/lib/typescript/module/types/AppOptions.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpRequest.d.ts +54 -0
- package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpResponse.d.ts +169 -0
- package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -0
- package/lib/typescript/module/types/HttpRouterOptions.d.ts +24 -0
- package/lib/typescript/module/types/HttpRouterOptions.d.ts.map +1 -0
- package/lib/typescript/module/types/MultipartField.d.ts +7 -0
- package/lib/typescript/module/types/MultipartField.d.ts.map +1 -0
- package/lib/typescript/module/types/RecognizedString.d.ts +10 -0
- package/lib/typescript/module/types/RecognizedString.d.ts.map +1 -0
- package/lib/typescript/module/types/TemplatedApp.d.ts +108 -0
- package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -0
- package/lib/typescript/module/types/WebSocket.d.ts +96 -0
- package/lib/typescript/module/types/WebSocket.d.ts.map +1 -0
- package/lib/typescript/module/types/WebSocketBehaviour.d.ts +1 -0
- package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +1 -0
- package/lib/typescript/module/types/index.d.ts +6 -0
- package/lib/typescript/module/types/index.d.ts.map +1 -0
- package/lib/typescript/module/types/us_listen_socket.d.ts +7 -0
- package/lib/typescript/module/types/us_listen_socket.d.ts.map +1 -0
- package/lib/typescript/module/types/us_socket.d.ts +7 -0
- package/lib/typescript/module/types/us_socket.d.ts.map +1 -0
- package/lib/typescript/module/types/us_socket_context_t.d.ts +7 -0
- package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -0
- package/lib/typescript/tsconfig.tsbuildinfo +1 -0
- package/package.json +62 -0
- package/src/_internal/native-modules/NativeUwsReactNative.ts +40 -0
- package/src/index.ts +2 -0
- package/src/modules/App.ts +14 -0
- package/src/modules/CompressOptions.ts +101 -0
- package/src/modules/EnvironmentVariables.ts +16 -0
- package/src/modules/ListenOptions.ts +4 -0
- package/src/modules/SSLApp.ts +13 -0
- package/src/modules/getParts.ts +29 -0
- package/src/modules/index.ts +8 -0
- package/src/modules/us_listen_socket_close.ts +15 -0
- package/src/modules/us_socket_local_port.ts +16 -0
- package/src/types/AppDescriptor.ts +7 -0
- package/src/types/AppOptions.ts +22 -0
- package/src/types/HttpRequest.ts +74 -0
- package/src/types/HttpResponse.ts +309 -0
- package/src/types/HttpRouterOptions.ts +24 -0
- package/src/types/MultipartField.ts +6 -0
- package/src/types/RecognizedString.ts +11 -0
- package/src/types/TemplatedApp.ts +285 -0
- package/src/types/WebSocket.ts +147 -0
- package/src/types/WebSocketBehaviour.ts +137 -0
- package/src/types/index.ts +12 -0
- package/src/types/us_listen_socket.ts +6 -0
- package/src/types/us_socket.ts +6 -0
- package/src/types/us_socket_context_t.ts +6 -0
|
@@ -0,0 +1,150 @@
|
|
|
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
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
)
|
package/cpp/jsi/Buffer.h
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <utility>
|
|
5
|
+
|
|
6
|
+
namespace uws_react_native {
|
|
7
|
+
|
|
8
|
+
// Probably bad name and usage.
|
|
9
|
+
// I can't figure it how create JS ArrayBuffer with faster buffer
|
|
10
|
+
|
|
11
|
+
class StringMutableBuffer : public facebook::jsi::MutableBuffer {
|
|
12
|
+
|
|
13
|
+
private:
|
|
14
|
+
std::string *s;
|
|
15
|
+
|
|
16
|
+
public:
|
|
17
|
+
StringMutableBuffer(std::string *s) {
|
|
18
|
+
this->s = s;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
size_t size() const override {
|
|
22
|
+
return this->s->size();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
uint8_t *data() override {
|
|
26
|
+
return (uint8_t *)this->s->data();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}; // StringMutableBuffer
|
|
30
|
+
|
|
31
|
+
class CharsMutableBuffer : public facebook::jsi::MutableBuffer {
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
std::vector<char> *c;
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
CharsMutableBuffer(std::vector<char> *c) {
|
|
38
|
+
this->c = c;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
CharsMutableBuffer(const std::shared_ptr<std::vector<char>> &c) {
|
|
42
|
+
this->c = c.get();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
size_t size() const override {
|
|
46
|
+
return this->c->size();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
uint8_t *data() override {
|
|
50
|
+
return reinterpret_cast<uint8_t *>(this->c->data());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
class StringViewBuffer : public facebook::jsi::Buffer {
|
|
56
|
+
|
|
57
|
+
private:
|
|
58
|
+
std::string_view sv;
|
|
59
|
+
|
|
60
|
+
public:
|
|
61
|
+
StringViewBuffer(std::string_view s) : sv(s) {}
|
|
62
|
+
|
|
63
|
+
size_t size() const override {
|
|
64
|
+
return this->sv.size();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const uint8_t *data() const override {
|
|
68
|
+
return reinterpret_cast<const uint8_t *>(this->sv.data());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}; // StringViewBuffer
|
|
72
|
+
|
|
73
|
+
class StringViewMutableBuffer : public facebook::jsi::MutableBuffer {
|
|
74
|
+
|
|
75
|
+
private:
|
|
76
|
+
std::string sv;
|
|
77
|
+
|
|
78
|
+
public:
|
|
79
|
+
StringViewMutableBuffer(std::string_view sv) : sv(sv) {}
|
|
80
|
+
|
|
81
|
+
size_t size() const override {
|
|
82
|
+
return this->sv.size();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
uint8_t *data() override {
|
|
86
|
+
return reinterpret_cast<uint8_t *>(this->sv.data());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
} // namespace facebook::jsi
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
project("uws_react_native__jsi")
|
|
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::jsi"
|
|
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
|
+
)
|