@depup/react-native-worklets 0.12.2-depup.0 → 0.13.0-depup.0
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/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +1 -2
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +1 -1
- package/Common/cpp/worklets/Compat/StableApi.cpp +24 -8
- package/Common/cpp/worklets/Compat/StableApi.h +1 -1
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +113 -50
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -1
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +95 -37
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +57 -7
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.cpp +94 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.h +58 -0
- package/Common/cpp/worklets/Networking/Networking.cpp +283 -0
- package/Common/cpp/worklets/Networking/Networking.h +51 -0
- package/Common/cpp/worklets/Networking/NetworkingBackend.h +47 -0
- package/Common/cpp/worklets/Networking/NetworkingInstaller.cpp +127 -0
- package/Common/cpp/worklets/Networking/NetworkingInstaller.h +19 -0
- package/Common/cpp/worklets/Networking/NetworkingTypes.h +33 -0
- package/Common/cpp/worklets/Networking/TextDecoding.cpp +189 -0
- package/Common/cpp/worklets/Networking/TextDecoding.h +29 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +28 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +9 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +6 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +19 -4
- package/Common/cpp/worklets/RunLoop/EventLoop.h +3 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +2 -1
- package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.cpp +37 -0
- package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.h +33 -0
- package/Common/cpp/worklets/SharedItems/Serializable/RetainingSerializable.h +112 -0
- package/Common/cpp/worklets/SharedItems/Serializable/Serializable.cpp +129 -0
- package/Common/cpp/worklets/SharedItems/Serializable/Serializable.h +121 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.cpp +38 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.h +39 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.cpp +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.h +43 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.cpp +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.h +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.cpp +38 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.h +30 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.cpp +24 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.h +32 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.cpp +19 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.cpp +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.cpp +44 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.cpp +80 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.h +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.cpp +22 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.h +25 -0
- package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.cpp → Serializable/SerializableRemoteFunction.cpp} +30 -2
- package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.h → Serializable/SerializableRemoteFunction.h} +24 -10
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.cpp +46 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.h +41 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.cpp +36 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.h +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.cpp +19 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.h +22 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.cpp +26 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.h +33 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.cpp +31 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.h +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +21 -409
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/Shareable.h +1 -1
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +43 -20
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +24 -26
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +5 -7
- package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.cpp +36 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.h +27 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableFixed.cpp +76 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableFixed.h +48 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +0 -5
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +16 -30
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +27 -30
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +4 -3
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +2 -1
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +79 -29
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +34 -19
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +13 -86
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +1 -7
- package/Package.swift +147 -0
- package/README.md +5 -5
- package/RNWorklets.podspec +1 -2
- package/android/CMakeLists.txt +7 -26
- package/android/build.gradle.kts +5 -31
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +46 -129
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +21 -11
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -4
- package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.cpp +82 -0
- package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.h +32 -0
- package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.cpp +73 -0
- package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.h +38 -0
- package/android/src/{no-networking → main/java}/com/swmansion/worklets/WorkletsModule.kt +39 -28
- package/android/src/main/java/com/swmansion/worklets/networking/NetworkRequestListener.kt +37 -0
- package/android/src/main/java/com/swmansion/worklets/networking/Networking.kt +244 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +3 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +9 -1
- package/apple/worklets/apple/AssertJavaScriptQueue.h +3 -2
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +4 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +3 -0
- package/apple/worklets/apple/Networking/AppleNetworkingBackend.h +29 -0
- package/apple/worklets/apple/Networking/AppleNetworkingBackend.mm +93 -0
- package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.h +37 -0
- package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.mm +447 -0
- package/apple/worklets/apple/WorkletsModule.h +3 -2
- package/apple/worklets/apple/WorkletsModule.mm +82 -74
- package/bundleMode/index.js +10 -47
- package/bundleMode/polyfills/prepareBundleMode.js +16 -0
- package/changes.json +4 -4
- package/compatibility.json +4 -1
- package/lib/module/WorkletsModule/NativeWorklets.native.js +12 -9
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/featureFlags/staticFlags.json +0 -1
- package/lib/module/featureFlags/types.js +0 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers/initializers.native.js +5 -12
- package/lib/module/initializers/initializers.native.js.map +1 -1
- package/lib/module/memory/bundleUnpacker.native.js +2 -10
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
- package/lib/module/memory/serializable.native.js +1 -29
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/synchronizable.js +1 -1
- package/lib/module/memory/synchronizable.js.map +1 -1
- package/lib/module/memory/synchronizable.native.js +7 -3
- package/lib/module/memory/synchronizable.native.js.map +1 -1
- package/lib/module/memory/synchronizableUnpacker.native.js +7 -2
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
- package/lib/module/memory/valueUnpacker.native.js +0 -8
- package/lib/module/memory/valueUnpacker.native.js.map +1 -1
- package/lib/module/mock.js +22 -1
- package/lib/module/mock.js.map +1 -1
- package/lib/module/networking/AbortController.js +43 -0
- package/lib/module/networking/AbortController.js.map +1 -0
- package/lib/module/networking/Blob.js +60 -0
- package/lib/module/networking/Blob.js.map +1 -0
- package/lib/module/networking/DOMException.js +35 -0
- package/lib/module/networking/DOMException.js.map +1 -0
- package/lib/module/networking/FileReader.js +83 -0
- package/lib/module/networking/FileReader.js.map +1 -0
- package/lib/module/networking/FormData.js +105 -0
- package/lib/module/networking/FormData.js.map +1 -0
- package/lib/module/networking/XMLHttpRequest.js +450 -0
- package/lib/module/networking/XMLHttpRequest.js.map +1 -0
- package/lib/module/networking/bytes.js +6 -0
- package/lib/module/networking/bytes.js.map +1 -0
- package/lib/module/networking/events.js +44 -0
- package/lib/module/networking/events.js.map +1 -0
- package/lib/module/networking/http.js +100 -0
- package/lib/module/networking/http.js.map +1 -0
- package/lib/module/networking/install.js +37 -0
- package/lib/module/networking/install.js.map +1 -0
- package/lib/module/networking/utf8.js +99 -0
- package/lib/module/networking/utf8.js.map +1 -0
- package/lib/module/privateGlobals.d.js +0 -1
- package/lib/module/privateGlobals.d.js.map +1 -1
- package/lib/module/runLoop/common/queueMicrotaskPolyfill.js +9 -0
- package/lib/module/runLoop/common/queueMicrotaskPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +7 -3
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/index.js +1 -1
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +1 -1
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -13
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -1
- package/lib/module/runtimes.native.js +8 -1
- package/lib/module/runtimes.native.js.map +1 -1
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -1
- package/lib/module/threads.js +11 -0
- package/lib/module/threads.js.map +1 -1
- package/lib/module/threads.native.js +35 -42
- package/lib/module/threads.native.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +6 -5
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/lib/typescript/featureFlags/types.d.ts +0 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizable.d.ts +6 -2
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizable.native.d.ts +6 -2
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/types.d.ts +6 -0
- package/lib/typescript/memory/types.d.ts.map +1 -1
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/networking/AbortController.d.ts +16 -0
- package/lib/typescript/networking/AbortController.d.ts.map +1 -0
- package/lib/typescript/networking/Blob.d.ts +16 -0
- package/lib/typescript/networking/Blob.d.ts.map +1 -0
- package/lib/typescript/networking/DOMException.d.ts +5 -0
- package/lib/typescript/networking/DOMException.d.ts.map +1 -0
- package/lib/typescript/networking/FileReader.d.ts +19 -0
- package/lib/typescript/networking/FileReader.d.ts.map +1 -0
- package/lib/typescript/networking/FormData.d.ts +30 -0
- package/lib/typescript/networking/FormData.d.ts.map +1 -0
- package/lib/typescript/networking/XMLHttpRequest.d.ts +77 -0
- package/lib/typescript/networking/XMLHttpRequest.d.ts.map +1 -0
- package/lib/typescript/networking/bytes.d.ts +2 -0
- package/lib/typescript/networking/bytes.d.ts.map +1 -0
- package/lib/typescript/networking/events.d.ts +18 -0
- package/lib/typescript/networking/events.d.ts.map +1 -0
- package/lib/typescript/networking/http.d.ts +14 -0
- package/lib/typescript/networking/http.d.ts.map +1 -0
- package/lib/typescript/networking/install.d.ts +2 -0
- package/lib/typescript/networking/install.d.ts.map +1 -0
- package/lib/typescript/networking/utf8.d.ts +4 -0
- package/lib/typescript/networking/utf8.d.ts.map +1 -0
- package/lib/typescript/runLoop/{workletRuntime/queueMicrotask.d.ts → common/queueMicrotaskPolyfill.d.ts} +1 -1
- package/lib/typescript/runLoop/common/queueMicrotaskPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -1
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +0 -2
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -1
- package/lib/typescript/runtimes.native.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -1
- package/lib/typescript/threads.native.d.ts +8 -1
- package/lib/typescript/threads.native.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +9 -5
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +32 -18
- package/plugin/index.js +63 -93
- package/plugin-oxc/babel.d.ts +7 -0
- package/plugin-oxc/babel.js +200 -0
- package/plugin-oxc/index.d.ts +33 -0
- package/plugin-oxc/index.js +36 -0
- package/plugin-oxc/worklets-oxc-plugin.darwin-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.darwin-x64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.linux-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.linux-x64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.win32-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.win32-x64.node +0 -0
- package/react-native.config.js +5 -0
- package/scripts/worklets_utils.rb +0 -10
- package/src/WorkletsModule/NativeWorklets.native.ts +26 -9
- package/src/WorkletsModule/workletsModuleProxy.ts +15 -5
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +0 -1
- package/src/featureFlags/types.ts +0 -1
- package/src/index.ts +3 -0
- package/src/initializers/initializers.native.ts +5 -13
- package/src/memory/bundleUnpacker.native.ts +6 -13
- package/src/memory/serializable.native.ts +1 -44
- package/src/memory/synchronizable.native.ts +38 -4
- package/src/memory/synchronizable.ts +22 -2
- package/src/memory/synchronizableUnpacker.native.ts +23 -4
- package/src/memory/types.ts +9 -0
- package/src/memory/valueUnpacker.native.ts +0 -8
- package/src/mock.ts +28 -1
- package/src/networking/AbortController.ts +57 -0
- package/src/networking/Blob.ts +74 -0
- package/src/networking/DOMException.ts +37 -0
- package/src/networking/FileReader.ts +99 -0
- package/src/networking/FormData.ts +135 -0
- package/src/networking/XMLHttpRequest.ts +557 -0
- package/src/networking/bytes.ts +8 -0
- package/src/networking/events.ts +61 -0
- package/src/networking/http.ts +173 -0
- package/src/networking/install.ts +38 -0
- package/src/networking/utf8.ts +122 -0
- package/src/privateGlobals.d.ts +20 -13
- package/src/runLoop/common/queueMicrotaskPolyfill.ts +12 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +7 -4
- package/src/runLoop/workletRuntime/index.ts +1 -1
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +1 -1
- package/src/runLoop/workletRuntime/taskQueue.ts +0 -15
- package/src/runtimes.native.ts +10 -1
- package/src/specs/NativeWorkletsModule.ts +1 -0
- package/src/threads.native.ts +49 -54
- package/src/threads.ts +11 -0
- package/src/types.ts +9 -5
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +0 -389
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +0 -172
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +0 -85
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +0 -59
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +0 -51
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +0 -43
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +0 -27
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +0 -30
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +0 -204
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +0 -272
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +0 -1124
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +0 -40
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +0 -13
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +0 -98
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +0 -60
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +0 -87
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +0 -181
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +0 -25
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +0 -707
- package/bundleMode/shims/turboModuleRegistryShim.js +0 -47
- package/lib/module/bundleMode/network.native.js +0 -44
- package/lib/module/bundleMode/network.native.js.map +0 -1
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +0 -1
- package/lib/typescript/bundleMode/network.native.d.ts +0 -7
- package/lib/typescript/bundleMode/network.native.d.ts.map +0 -1
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +0 -1
- package/src/bundleMode/network.native.ts +0 -63
- package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#import <worklets/apple/Networking/AppleNetworkingBackend.h>
|
|
2
|
+
#import <worklets/apple/Networking/WorkletsURLSessionDelegate.h>
|
|
3
|
+
|
|
4
|
+
#import <algorithm>
|
|
5
|
+
#import <optional>
|
|
6
|
+
#import <string>
|
|
7
|
+
#import <utility>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
NSString *decodeLossy(const uint8_t *data, size_t size, NSStringEncoding encoding, CFStringEncoding cfEncoding);
|
|
13
|
+
} // namespace
|
|
14
|
+
|
|
15
|
+
AppleNetworkingBackend::AppleNetworkingBackend() : delegate_([WorkletsURLSessionDelegate new]) {}
|
|
16
|
+
|
|
17
|
+
AppleNetworkingBackend::~AppleNetworkingBackend()
|
|
18
|
+
{
|
|
19
|
+
[delegate_ invalidate];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void AppleNetworkingBackend::sendRequest(
|
|
23
|
+
const uint64_t requestId,
|
|
24
|
+
RequestConfig &&config,
|
|
25
|
+
const std::shared_ptr<NetworkRequestListener> &listener)
|
|
26
|
+
{
|
|
27
|
+
[delegate_ sendRequest:std::move(config) requestId:requestId listener:listener];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void AppleNetworkingBackend::abortRequest(const uint64_t requestId)
|
|
31
|
+
{
|
|
32
|
+
[delegate_ abortRequest:requestId];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
std::optional<std::string>
|
|
36
|
+
AppleNetworkingBackend::decodeText(const uint8_t *data, const size_t size, const std::string &label)
|
|
37
|
+
{
|
|
38
|
+
NSString *charsetName = [NSString stringWithUTF8String:label.c_str()];
|
|
39
|
+
if (charsetName == nil) {
|
|
40
|
+
return std::nullopt;
|
|
41
|
+
}
|
|
42
|
+
const CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)charsetName);
|
|
43
|
+
if (cfEncoding == kCFStringEncodingInvalidId) {
|
|
44
|
+
return std::nullopt;
|
|
45
|
+
}
|
|
46
|
+
NSString *decoded = decodeLossy(data, size, CFStringConvertEncodingToNSStringEncoding(cfEncoding), cfEncoding);
|
|
47
|
+
if (decoded == nil) {
|
|
48
|
+
return std::nullopt;
|
|
49
|
+
}
|
|
50
|
+
const char *utf8 = decoded.UTF8String;
|
|
51
|
+
if (utf8 == nullptr) {
|
|
52
|
+
return std::nullopt;
|
|
53
|
+
}
|
|
54
|
+
return std::string(utf8, [decoded lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
namespace {
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* https://encoding.spec.whatwg.org/#concept-encoding-process - a decoder never
|
|
61
|
+
* fails, it emits U+FFFD for every byte it cannot decode. `NSString` instead
|
|
62
|
+
* returns nil for the whole buffer, so a body truncated mid-character is
|
|
63
|
+
* retried without its trailing bytes and each dropped byte becomes U+FFFD.
|
|
64
|
+
*/
|
|
65
|
+
NSString *
|
|
66
|
+
decodeLossy(const uint8_t *data, const size_t size, const NSStringEncoding encoding, const CFStringEncoding cfEncoding)
|
|
67
|
+
{
|
|
68
|
+
NSData *bytes = [NSData dataWithBytesNoCopy:(void *)data length:size freeWhenDone:NO];
|
|
69
|
+
NSString *decoded = [[NSString alloc] initWithData:bytes encoding:encoding];
|
|
70
|
+
if (decoded != nil) {
|
|
71
|
+
return decoded;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const CFIndex maxCharLength = CFStringGetMaximumSizeForEncoding(2, cfEncoding);
|
|
75
|
+
const size_t limit = std::min(maxCharLength > 0 ? static_cast<size_t>(maxCharLength) : 1, size);
|
|
76
|
+
for (size_t trimmed = 1; trimmed <= limit; trimmed++) {
|
|
77
|
+
NSData *prefix = [NSData dataWithBytesNoCopy:(void *)data length:size - trimmed freeWhenDone:NO];
|
|
78
|
+
NSString *prefixDecoded = [[NSString alloc] initWithData:prefix encoding:encoding];
|
|
79
|
+
if (prefixDecoded == nil) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
NSMutableString *result = [prefixDecoded mutableCopy];
|
|
83
|
+
for (size_t index = 0; index < trimmed; index++) {
|
|
84
|
+
[result appendString:@"\uFFFD"];
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
return nil;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
} // namespace
|
|
92
|
+
|
|
93
|
+
} // namespace worklets
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
typedef NSURLSessionConfiguration *_Nullable (^WorkletsURLSessionConfigurationProvider)(void);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Installs a provider for the `NSURLSessionConfiguration` used by Worklet
|
|
7
|
+
* Runtime networking. Use it to apply certificate pinning, custom protocol
|
|
8
|
+
* classes or proxy settings to requests made from Worklet Runtimes, the same
|
|
9
|
+
* way `RCTSetCustomNSURLSessionConfigurationProvider` does for React Native.
|
|
10
|
+
* Must be called before the first request is sent.
|
|
11
|
+
*/
|
|
12
|
+
#if __cplusplus
|
|
13
|
+
extern "C"
|
|
14
|
+
#endif
|
|
15
|
+
void WorkletsSetCustomNSURLSessionConfigurationProvider(WorkletsURLSessionConfigurationProvider _Nullable provider);
|
|
16
|
+
|
|
17
|
+
#if __cplusplus
|
|
18
|
+
|
|
19
|
+
#import <worklets/Networking/NetworkingBackend.h>
|
|
20
|
+
|
|
21
|
+
#import <memory>
|
|
22
|
+
|
|
23
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
24
|
+
|
|
25
|
+
@interface WorkletsURLSessionDelegate : NSObject <NSURLSessionDataDelegate>
|
|
26
|
+
|
|
27
|
+
- (void)sendRequest:(worklets::RequestConfig &&)config
|
|
28
|
+
requestId:(uint64_t)requestId
|
|
29
|
+
listener:(std::shared_ptr<worklets::NetworkRequestListener>)listener;
|
|
30
|
+
- (void)abortRequest:(uint64_t)requestId;
|
|
31
|
+
- (void)invalidate;
|
|
32
|
+
|
|
33
|
+
@end
|
|
34
|
+
|
|
35
|
+
NS_ASSUME_NONNULL_END
|
|
36
|
+
|
|
37
|
+
#endif // __cplusplus
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
#import <worklets/apple/Networking/WorkletsURLSessionDelegate.h>
|
|
2
|
+
|
|
3
|
+
#import <stdatomic.h>
|
|
4
|
+
|
|
5
|
+
#import <algorithm>
|
|
6
|
+
#import <optional>
|
|
7
|
+
#import <string>
|
|
8
|
+
#import <vector>
|
|
9
|
+
|
|
10
|
+
using namespace worklets;
|
|
11
|
+
|
|
12
|
+
static const NSTimeInterval kNoTimeoutInterval = 60 * 60 * 24 * 7;
|
|
13
|
+
static const CFAbsoluteTime kProgressThrottleInterval = 0.05;
|
|
14
|
+
|
|
15
|
+
static WorkletsURLSessionConfigurationProvider _Nullable sessionConfigurationProvider = nil;
|
|
16
|
+
|
|
17
|
+
void WorkletsSetCustomNSURLSessionConfigurationProvider(WorkletsURLSessionConfigurationProvider _Nullable provider)
|
|
18
|
+
{
|
|
19
|
+
sessionConfigurationProvider = provider;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@interface WorkletsRequestState : NSObject {
|
|
23
|
+
@public
|
|
24
|
+
std::shared_ptr<NetworkRequestListener> listener;
|
|
25
|
+
NSMutableData *data;
|
|
26
|
+
uint64_t requestId;
|
|
27
|
+
CFAbsoluteTime lastProgressTime;
|
|
28
|
+
int64_t expectedContentLength;
|
|
29
|
+
BOOL timedOut;
|
|
30
|
+
}
|
|
31
|
+
@end
|
|
32
|
+
|
|
33
|
+
@implementation WorkletsRequestState
|
|
34
|
+
@end
|
|
35
|
+
|
|
36
|
+
// NSURLSession exposes no reason phrase, so the status text is reconstructed
|
|
37
|
+
// from the IANA HTTP status code registry. It is not localized, matching what
|
|
38
|
+
// a server would have sent on the status line.
|
|
39
|
+
static std::string reasonPhraseForStatusCode(const NSInteger statusCode)
|
|
40
|
+
{
|
|
41
|
+
switch (statusCode) {
|
|
42
|
+
case 100:
|
|
43
|
+
return "Continue";
|
|
44
|
+
case 101:
|
|
45
|
+
return "Switching Protocols";
|
|
46
|
+
case 102:
|
|
47
|
+
return "Processing";
|
|
48
|
+
case 103:
|
|
49
|
+
return "Early Hints";
|
|
50
|
+
case 200:
|
|
51
|
+
return "OK";
|
|
52
|
+
case 201:
|
|
53
|
+
return "Created";
|
|
54
|
+
case 202:
|
|
55
|
+
return "Accepted";
|
|
56
|
+
case 203:
|
|
57
|
+
return "Non-Authoritative Information";
|
|
58
|
+
case 204:
|
|
59
|
+
return "No Content";
|
|
60
|
+
case 205:
|
|
61
|
+
return "Reset Content";
|
|
62
|
+
case 206:
|
|
63
|
+
return "Partial Content";
|
|
64
|
+
case 207:
|
|
65
|
+
return "Multi-Status";
|
|
66
|
+
case 208:
|
|
67
|
+
return "Already Reported";
|
|
68
|
+
case 226:
|
|
69
|
+
return "IM Used";
|
|
70
|
+
case 300:
|
|
71
|
+
return "Multiple Choices";
|
|
72
|
+
case 301:
|
|
73
|
+
return "Moved Permanently";
|
|
74
|
+
case 302:
|
|
75
|
+
return "Found";
|
|
76
|
+
case 303:
|
|
77
|
+
return "See Other";
|
|
78
|
+
case 304:
|
|
79
|
+
return "Not Modified";
|
|
80
|
+
case 305:
|
|
81
|
+
return "Use Proxy";
|
|
82
|
+
case 307:
|
|
83
|
+
return "Temporary Redirect";
|
|
84
|
+
case 308:
|
|
85
|
+
return "Permanent Redirect";
|
|
86
|
+
case 400:
|
|
87
|
+
return "Bad Request";
|
|
88
|
+
case 401:
|
|
89
|
+
return "Unauthorized";
|
|
90
|
+
case 402:
|
|
91
|
+
return "Payment Required";
|
|
92
|
+
case 403:
|
|
93
|
+
return "Forbidden";
|
|
94
|
+
case 404:
|
|
95
|
+
return "Not Found";
|
|
96
|
+
case 405:
|
|
97
|
+
return "Method Not Allowed";
|
|
98
|
+
case 406:
|
|
99
|
+
return "Not Acceptable";
|
|
100
|
+
case 407:
|
|
101
|
+
return "Proxy Authentication Required";
|
|
102
|
+
case 408:
|
|
103
|
+
return "Request Timeout";
|
|
104
|
+
case 409:
|
|
105
|
+
return "Conflict";
|
|
106
|
+
case 410:
|
|
107
|
+
return "Gone";
|
|
108
|
+
case 411:
|
|
109
|
+
return "Length Required";
|
|
110
|
+
case 412:
|
|
111
|
+
return "Precondition Failed";
|
|
112
|
+
case 413:
|
|
113
|
+
return "Content Too Large";
|
|
114
|
+
case 414:
|
|
115
|
+
return "URI Too Long";
|
|
116
|
+
case 415:
|
|
117
|
+
return "Unsupported Media Type";
|
|
118
|
+
case 416:
|
|
119
|
+
return "Range Not Satisfiable";
|
|
120
|
+
case 417:
|
|
121
|
+
return "Expectation Failed";
|
|
122
|
+
case 421:
|
|
123
|
+
return "Misdirected Request";
|
|
124
|
+
case 422:
|
|
125
|
+
return "Unprocessable Content";
|
|
126
|
+
case 423:
|
|
127
|
+
return "Locked";
|
|
128
|
+
case 424:
|
|
129
|
+
return "Failed Dependency";
|
|
130
|
+
case 425:
|
|
131
|
+
return "Too Early";
|
|
132
|
+
case 426:
|
|
133
|
+
return "Upgrade Required";
|
|
134
|
+
case 428:
|
|
135
|
+
return "Precondition Required";
|
|
136
|
+
case 429:
|
|
137
|
+
return "Too Many Requests";
|
|
138
|
+
case 431:
|
|
139
|
+
return "Request Header Fields Too Large";
|
|
140
|
+
case 451:
|
|
141
|
+
return "Unavailable For Legal Reasons";
|
|
142
|
+
case 500:
|
|
143
|
+
return "Internal Server Error";
|
|
144
|
+
case 501:
|
|
145
|
+
return "Not Implemented";
|
|
146
|
+
case 502:
|
|
147
|
+
return "Bad Gateway";
|
|
148
|
+
case 503:
|
|
149
|
+
return "Service Unavailable";
|
|
150
|
+
case 504:
|
|
151
|
+
return "Gateway Timeout";
|
|
152
|
+
case 505:
|
|
153
|
+
return "HTTP Version Not Supported";
|
|
154
|
+
case 506:
|
|
155
|
+
return "Variant Also Negotiates";
|
|
156
|
+
case 507:
|
|
157
|
+
return "Insufficient Storage";
|
|
158
|
+
case 508:
|
|
159
|
+
return "Loop Detected";
|
|
160
|
+
case 510:
|
|
161
|
+
return "Not Extended";
|
|
162
|
+
case 511:
|
|
163
|
+
return "Network Authentication Required";
|
|
164
|
+
default:
|
|
165
|
+
return "";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Matches `METHODS_REQUIRING_BODY` in
|
|
170
|
+
// `android/src/main/java/com/swmansion/worklets/networking/Networking.kt`, so a
|
|
171
|
+
// bodyless POST carries `Content-Length: 0` on both platforms.
|
|
172
|
+
static BOOL methodRequiresBody(NSString *method)
|
|
173
|
+
{
|
|
174
|
+
NSString *uppercasedMethod = method.uppercaseString;
|
|
175
|
+
return [uppercasedMethod isEqualToString:@"POST"] || [uppercasedMethod isEqualToString:@"PUT"] ||
|
|
176
|
+
[uppercasedMethod isEqualToString:@"PATCH"];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static NSInteger effectivePort(NSURL *url)
|
|
180
|
+
{
|
|
181
|
+
if (url.port != nil) {
|
|
182
|
+
return url.port.integerValue;
|
|
183
|
+
}
|
|
184
|
+
return [url.scheme caseInsensitiveCompare:@"https"] == NSOrderedSame ? 443 : 80;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static BOOL isSameOrigin(NSURL *lhs, NSURL *rhs)
|
|
188
|
+
{
|
|
189
|
+
if (lhs == nil || rhs == nil || lhs.scheme == nil || rhs.scheme == nil || lhs.host == nil || rhs.host == nil) {
|
|
190
|
+
return NO;
|
|
191
|
+
}
|
|
192
|
+
return [lhs.scheme caseInsensitiveCompare:rhs.scheme] == NSOrderedSame &&
|
|
193
|
+
[lhs.host caseInsensitiveCompare:rhs.host] == NSOrderedSame && effectivePort(lhs) == effectivePort(rhs);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@implementation WorkletsURLSessionDelegate {
|
|
197
|
+
NSURLSession *_session;
|
|
198
|
+
NSURLSession *_credentiallessSession;
|
|
199
|
+
NSOperationQueue *_delegateQueue;
|
|
200
|
+
NSMapTable<NSURLSessionTask *, WorkletsRequestState *> *_statesByTask;
|
|
201
|
+
NSMutableDictionary<NSNumber *, NSURLSessionDataTask *> *_tasksByRequestId;
|
|
202
|
+
atomic_bool _invalidated;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
- (instancetype)init
|
|
206
|
+
{
|
|
207
|
+
if (self = [super init]) {
|
|
208
|
+
_delegateQueue = [NSOperationQueue new];
|
|
209
|
+
_delegateQueue.maxConcurrentOperationCount = 1;
|
|
210
|
+
_statesByTask = [NSMapTable strongToStrongObjectsMapTable];
|
|
211
|
+
_tasksByRequestId = [NSMutableDictionary new];
|
|
212
|
+
}
|
|
213
|
+
return self;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
- (NSURLSessionConfiguration *)configuration
|
|
217
|
+
{
|
|
218
|
+
WorkletsURLSessionConfigurationProvider provider = sessionConfigurationProvider;
|
|
219
|
+
NSURLSessionConfiguration *configuration = provider != nil ? provider() : nil;
|
|
220
|
+
if (configuration != nil) {
|
|
221
|
+
return [configuration copy];
|
|
222
|
+
}
|
|
223
|
+
return [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
- (NSURLSession *)sessionWithCredentials:(BOOL)withCredentials
|
|
227
|
+
{
|
|
228
|
+
if (withCredentials) {
|
|
229
|
+
if (_session == nil) {
|
|
230
|
+
_session = [NSURLSession sessionWithConfiguration:[self configuration]
|
|
231
|
+
delegate:self
|
|
232
|
+
delegateQueue:_delegateQueue];
|
|
233
|
+
}
|
|
234
|
+
return _session;
|
|
235
|
+
}
|
|
236
|
+
if (_credentiallessSession == nil) {
|
|
237
|
+
NSURLSessionConfiguration *configuration = [self configuration];
|
|
238
|
+
configuration.HTTPCookieStorage = nil;
|
|
239
|
+
configuration.HTTPShouldSetCookies = NO;
|
|
240
|
+
configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyNever;
|
|
241
|
+
configuration.URLCredentialStorage = nil;
|
|
242
|
+
_credentiallessSession = [NSURLSession sessionWithConfiguration:configuration
|
|
243
|
+
delegate:self
|
|
244
|
+
delegateQueue:_delegateQueue];
|
|
245
|
+
}
|
|
246
|
+
return _credentiallessSession;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
- (void)sendRequest:(RequestConfig &&)config
|
|
250
|
+
requestId:(uint64_t)requestId
|
|
251
|
+
listener:(std::shared_ptr<NetworkRequestListener>)listener
|
|
252
|
+
{
|
|
253
|
+
NSString *urlString = [NSString stringWithUTF8String:config.url.c_str()];
|
|
254
|
+
NSURL *url = urlString != nil ? [NSURL URLWithString:urlString] : nil;
|
|
255
|
+
if (url == nil) {
|
|
256
|
+
listener->onError(RequestError::Network, "Invalid URL: " + config.url);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if ([url.scheme caseInsensitiveCompare:@"http"] != NSOrderedSame &&
|
|
260
|
+
[url.scheme caseInsensitiveCompare:@"https"] != NSOrderedSame) {
|
|
261
|
+
listener->onError(RequestError::Network, "Unsupported URL scheme: " + config.url);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
NSString *method = [NSString stringWithUTF8String:config.method.c_str()];
|
|
266
|
+
if (method == nil) {
|
|
267
|
+
listener->onError(RequestError::Network, "Invalid HTTP method: " + config.method);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
|
272
|
+
request.HTTPMethod = method;
|
|
273
|
+
for (const auto &[name, value] : config.headers) {
|
|
274
|
+
NSString *headerName = [NSString stringWithUTF8String:name.c_str()];
|
|
275
|
+
NSString *headerValue = [NSString stringWithUTF8String:value.c_str()];
|
|
276
|
+
if (headerName == nil || headerValue == nil) {
|
|
277
|
+
listener->onError(RequestError::Network, "Invalid header: " + name);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
[request addValue:headerValue forHTTPHeaderField:headerName];
|
|
281
|
+
}
|
|
282
|
+
if (config.body.has_value()) {
|
|
283
|
+
request.HTTPBody = [NSData dataWithBytes:config.body->data() length:config.body->size()];
|
|
284
|
+
} else if (methodRequiresBody(method)) {
|
|
285
|
+
request.HTTPBody = [NSData data];
|
|
286
|
+
}
|
|
287
|
+
request.HTTPShouldHandleCookies = config.withCredentials;
|
|
288
|
+
request.timeoutInterval = config.timeoutMs > 0 ? config.timeoutMs / 1000.0 : kNoTimeoutInterval;
|
|
289
|
+
|
|
290
|
+
const auto timeoutMs = config.timeoutMs;
|
|
291
|
+
const auto withCredentials = config.withCredentials;
|
|
292
|
+
|
|
293
|
+
[_delegateQueue addOperationWithBlock:^{
|
|
294
|
+
if (atomic_load(&self->_invalidated)) {
|
|
295
|
+
listener->onError(RequestError::Aborted, "The networking session was invalidated.");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
NSURLSessionDataTask *task = [[self sessionWithCredentials:withCredentials] dataTaskWithRequest:request];
|
|
299
|
+
if (task == nil) {
|
|
300
|
+
listener->onError(RequestError::Network, "Failed to create a data task for the request.");
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
WorkletsRequestState *state = [WorkletsRequestState new];
|
|
304
|
+
state->listener = listener;
|
|
305
|
+
state->data = [NSMutableData new];
|
|
306
|
+
state->requestId = requestId;
|
|
307
|
+
state->expectedContentLength = -1;
|
|
308
|
+
[self->_statesByTask setObject:state forKey:task];
|
|
309
|
+
self->_tasksByRequestId[@(requestId)] = task;
|
|
310
|
+
[task resume];
|
|
311
|
+
}];
|
|
312
|
+
|
|
313
|
+
if (timeoutMs > 0) {
|
|
314
|
+
__weak WorkletsURLSessionDelegate *weakSelf = self;
|
|
315
|
+
dispatch_after(
|
|
316
|
+
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeoutMs * NSEC_PER_MSEC)),
|
|
317
|
+
dispatch_get_global_queue(QOS_CLASS_UTILITY, 0),
|
|
318
|
+
^{ [weakSelf timeoutRequest:requestId]; });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
- (void)timeoutRequest:(uint64_t)requestId
|
|
323
|
+
{
|
|
324
|
+
[_delegateQueue addOperationWithBlock:^{
|
|
325
|
+
NSURLSessionDataTask *task = self->_tasksByRequestId[@(requestId)];
|
|
326
|
+
if (task == nil) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
WorkletsRequestState *state = [self->_statesByTask objectForKey:task];
|
|
330
|
+
if (state != nil) {
|
|
331
|
+
state->timedOut = YES;
|
|
332
|
+
}
|
|
333
|
+
[task cancel];
|
|
334
|
+
}];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
- (void)abortRequest:(uint64_t)requestId
|
|
338
|
+
{
|
|
339
|
+
[_delegateQueue addOperationWithBlock:^{ [self->_tasksByRequestId[@(requestId)] cancel]; }];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
- (void)invalidate
|
|
343
|
+
{
|
|
344
|
+
atomic_store(&_invalidated, true);
|
|
345
|
+
[_delegateQueue addOperationWithBlock:^{
|
|
346
|
+
[self->_session invalidateAndCancel];
|
|
347
|
+
[self->_credentiallessSession invalidateAndCancel];
|
|
348
|
+
}];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
- (void)URLSession:(NSURLSession *)session
|
|
352
|
+
task:(NSURLSessionTask *)task
|
|
353
|
+
willPerformHTTPRedirection:(NSHTTPURLResponse *)response
|
|
354
|
+
newRequest:(NSURLRequest *)request
|
|
355
|
+
completionHandler:(void (^)(NSURLRequest *_Nullable))completionHandler
|
|
356
|
+
{
|
|
357
|
+
if (isSameOrigin(task.currentRequest.URL ?: task.originalRequest.URL, request.URL)) {
|
|
358
|
+
completionHandler(request);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
NSMutableURLRequest *nextRequest = [request mutableCopy];
|
|
362
|
+
for (NSString *header in @[ @"Authorization", @"Cookie", @"Cookie2", @"Proxy-Authorization", @"WWW-Authenticate" ]) {
|
|
363
|
+
[nextRequest setValue:nil forHTTPHeaderField:header];
|
|
364
|
+
}
|
|
365
|
+
completionHandler(nextRequest);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
- (void)URLSession:(NSURLSession *)session
|
|
369
|
+
dataTask:(NSURLSessionDataTask *)dataTask
|
|
370
|
+
didReceiveResponse:(NSURLResponse *)response
|
|
371
|
+
completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler
|
|
372
|
+
{
|
|
373
|
+
WorkletsRequestState *state = [_statesByTask objectForKey:dataTask];
|
|
374
|
+
if (state != nil) {
|
|
375
|
+
int status = 200;
|
|
376
|
+
std::string statusText;
|
|
377
|
+
std::vector<std::pair<std::string, std::string>> headers;
|
|
378
|
+
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
|
|
379
|
+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
|
380
|
+
status = (int)httpResponse.statusCode;
|
|
381
|
+
statusText = reasonPhraseForStatusCode(httpResponse.statusCode);
|
|
382
|
+
for (NSString *name in httpResponse.allHeaderFields) {
|
|
383
|
+
NSString *value = httpResponse.allHeaderFields[name];
|
|
384
|
+
headers.emplace_back(name.UTF8String ?: "", value.UTF8String ?: "");
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
state->expectedContentLength = response.expectedContentLength;
|
|
388
|
+
state->listener->onResponse(ResponseInfo{
|
|
389
|
+
.status = status,
|
|
390
|
+
.statusText = std::move(statusText),
|
|
391
|
+
.headers = std::move(headers),
|
|
392
|
+
.url = response.URL.absoluteString.UTF8String ?: ""});
|
|
393
|
+
}
|
|
394
|
+
completionHandler(NSURLSessionResponseAllow);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
|
|
398
|
+
{
|
|
399
|
+
WorkletsRequestState *state = [_statesByTask objectForKey:dataTask];
|
|
400
|
+
if (state == nil) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
[state->data appendData:data];
|
|
404
|
+
const CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
|
|
405
|
+
if (now - state->lastProgressTime >= kProgressThrottleInterval) {
|
|
406
|
+
state->lastProgressTime = now;
|
|
407
|
+
state->listener->onDownloadProgress((int64_t)state->data.length, state->expectedContentLength);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
- (void)URLSession:(NSURLSession *)session
|
|
412
|
+
task:(NSURLSessionTask *)task
|
|
413
|
+
didSendBodyData:(int64_t)bytesSent
|
|
414
|
+
totalBytesSent:(int64_t)totalBytesSent
|
|
415
|
+
totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
|
|
416
|
+
{
|
|
417
|
+
WorkletsRequestState *state = [_statesByTask objectForKey:task];
|
|
418
|
+
if (state != nil) {
|
|
419
|
+
state->listener->onUploadProgress(totalBytesSent, totalBytesExpectedToSend);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
|
|
424
|
+
{
|
|
425
|
+
WorkletsRequestState *state = [_statesByTask objectForKey:task];
|
|
426
|
+
if (state == nil) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
[_statesByTask removeObjectForKey:task];
|
|
430
|
+
[_tasksByRequestId removeObjectForKey:@(state->requestId)];
|
|
431
|
+
|
|
432
|
+
if (error != nil) {
|
|
433
|
+
auto kind = RequestError::Network;
|
|
434
|
+
if (state->timedOut || error.code == NSURLErrorTimedOut) {
|
|
435
|
+
kind = RequestError::Timeout;
|
|
436
|
+
} else if (error.code == NSURLErrorCancelled) {
|
|
437
|
+
kind = RequestError::Aborted;
|
|
438
|
+
}
|
|
439
|
+
state->listener->onError(kind, error.localizedDescription.UTF8String ?: "");
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const auto *bytes = static_cast<const uint8_t *>(state->data.bytes);
|
|
444
|
+
state->listener->onComplete(std::vector<uint8_t>(bytes, bytes + state->data.length));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
@end
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
1
2
|
#import <React/RCTCallInvokerModule.h>
|
|
2
|
-
#import <React/
|
|
3
|
+
#import <React/RCTInitializing.h>
|
|
3
4
|
#import <React/RCTInvalidating.h>
|
|
4
5
|
|
|
5
6
|
#import <rnworklets/rnworklets.h>
|
|
6
7
|
|
|
7
8
|
#import <worklets/NativeModules/WorkletsModuleProxy.h>
|
|
8
9
|
|
|
9
|
-
@interface WorkletsModule :
|
|
10
|
+
@interface WorkletsModule : NSObject <NativeWorkletsModuleSpec, RCTCallInvokerModule, RCTInitializing, RCTInvalidating>
|
|
10
11
|
|
|
11
12
|
- (std::shared_ptr<worklets::WorkletsModuleProxy>)getWorkletsModuleProxy;
|
|
12
13
|
|