react-native-nitro-net 0.4.1 → 0.4.3
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/android/libs/arm64-v8a/librust_c_net.so +0 -0
- package/android/libs/armeabi-v7a/librust_c_net.so +0 -0
- package/android/libs/x86/librust_c_net.so +0 -0
- package/android/libs/x86_64/librust_c_net.so +0 -0
- package/cpp/HybridHttpParser.hpp +44 -16
- package/cpp/NetBindings.hpp +192 -96
- package/cpp/NetManager.hpp +16 -10
- package/ios/Frameworks/RustCNet.xcframework/Info.plist +5 -5
- package/ios/Frameworks/RustCNet.xcframework/ios-arm64/RustCNet.framework/RustCNet +0 -0
- package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet +0 -0
- package/lib/Logger.d.ts +16 -0
- package/lib/Logger.d.ts.map +1 -0
- package/lib/Logger.js +28 -0
- package/lib/Net.nitro.d.ts +6 -2
- package/lib/Net.nitro.d.ts.map +1 -1
- package/lib/http.d.ts.map +1 -1
- package/lib/http.js +38 -23
- package/lib/net.d.ts +1 -2
- package/lib/net.d.ts.map +1 -1
- package/lib/net.js +22 -22
- package/lib/tls.d.ts.map +1 -1
- package/lib/tls.js +3 -5
- package/nitrogen/generated/android/RustCNet+autolinking.cmake +1 -1
- package/nitrogen/generated/android/RustCNet+autolinking.gradle +1 -1
- package/nitrogen/generated/android/RustCNetOnLoad.cpp +27 -22
- package/nitrogen/generated/android/RustCNetOnLoad.hpp +14 -5
- package/nitrogen/generated/android/c++/JFunc_void_double_std__shared_ptr_ArrayBuffer_.hpp +1 -1
- package/nitrogen/generated/android/c++/JHttpParsedMessage.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridHttpParserSpec.cpp +28 -23
- package/nitrogen/generated/android/c++/JHybridHttpParserSpec.hpp +21 -23
- package/nitrogen/generated/android/c++/JHybridNetDriverSpec.cpp +35 -34
- package/nitrogen/generated/android/c++/JHybridNetDriverSpec.hpp +20 -22
- package/nitrogen/generated/android/c++/JHybridNetServerDriverSpec.cpp +31 -30
- package/nitrogen/generated/android/c++/JHybridNetServerDriverSpec.hpp +20 -22
- package/nitrogen/generated/android/c++/JHybridNetSocketDriverSpec.cpp +53 -52
- package/nitrogen/generated/android/c++/JHybridNetSocketDriverSpec.hpp +20 -22
- package/nitrogen/generated/android/c++/JNetConfig.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/Func_void_double_std__shared_ptr_ArrayBuffer_.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HttpParsedMessage.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridHttpParserSpec.kt +15 -18
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetDriverSpec.kt +16 -19
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetServerDriverSpec.kt +16 -19
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetSocketDriverSpec.kt +16 -19
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/NetConfig.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/RustCNetOnLoad.kt +1 -1
- package/nitrogen/generated/ios/RustCNet+autolinking.rb +1 -1
- package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Bridge.hpp +17 -5
- package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Umbrella.hpp +4 -1
- package/nitrogen/generated/ios/RustCNetAutolinking.mm +1 -1
- package/nitrogen/generated/ios/RustCNetAutolinking.swift +5 -1
- package/nitrogen/generated/ios/c++/HybridHttpParserSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridHttpParserSpecSwift.hpp +12 -2
- package/nitrogen/generated/ios/c++/HybridNetDriverSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNetDriverSpecSwift.hpp +7 -1
- package/nitrogen/generated/ios/c++/HybridNetServerDriverSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNetServerDriverSpecSwift.hpp +7 -1
- package/nitrogen/generated/ios/c++/HybridNetSocketDriverSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNetSocketDriverSpecSwift.hpp +7 -1
- package/nitrogen/generated/ios/swift/Func_void_double_std__shared_ptr_ArrayBuffer_.swift +1 -2
- package/nitrogen/generated/ios/swift/HttpParsedMessage.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridHttpParserSpec.swift +4 -5
- package/nitrogen/generated/ios/swift/HybridHttpParserSpec_cxx.swift +13 -6
- package/nitrogen/generated/ios/swift/HybridNetDriverSpec.swift +3 -4
- package/nitrogen/generated/ios/swift/HybridNetDriverSpec_cxx.swift +9 -2
- package/nitrogen/generated/ios/swift/HybridNetServerDriverSpec.swift +3 -4
- package/nitrogen/generated/ios/swift/HybridNetServerDriverSpec_cxx.swift +49 -7
- package/nitrogen/generated/ios/swift/HybridNetSocketDriverSpec.swift +3 -4
- package/nitrogen/generated/ios/swift/HybridNetSocketDriverSpec_cxx.swift +25 -4
- package/nitrogen/generated/ios/swift/NetConfig.swift +9 -3
- package/nitrogen/generated/shared/c++/HttpParsedMessage.hpp +89 -0
- package/nitrogen/generated/shared/c++/HybridHttpParserSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridHttpParserSpec.hpp +5 -4
- package/nitrogen/generated/shared/c++/HybridNetDriverSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNetDriverSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNetServerDriverSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNetServerDriverSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNetSocketDriverSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNetSocketDriverSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNitroBufferSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNitroBufferSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/NetConfig.hpp +1 -1
- package/package.json +4 -5
- package/src/Logger.ts +31 -0
- package/src/Net.nitro.ts +6 -2
- package/src/http.ts +42 -25
- package/src/net.ts +23 -22
- package/src/tls.ts +3 -5
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// HybridNetSocketDriverSpec_cxx.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -96,6 +95,14 @@ open class HybridNetSocketDriverSpec_cxx {
|
|
|
96
95
|
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
96
|
}
|
|
98
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Compares this object with the given [other] object for reference equality.
|
|
100
|
+
*/
|
|
101
|
+
@inline(__always)
|
|
102
|
+
public func equals(other: HybridNetSocketDriverSpec_cxx) -> Bool {
|
|
103
|
+
return self.__implementation === other.__implementation
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
/**
|
|
100
107
|
* Call dispose() on the Swift class.
|
|
101
108
|
* This _may_ be called manually from JS.
|
|
@@ -194,7 +201,14 @@ open class HybridNetSocketDriverSpec_cxx {
|
|
|
194
201
|
} else {
|
|
195
202
|
return nil
|
|
196
203
|
}
|
|
197
|
-
}(), secureContextId:
|
|
204
|
+
}(), secureContextId: { () -> Double? in
|
|
205
|
+
if bridge.has_value_std__optional_double_(secureContextId) {
|
|
206
|
+
let __unwrapped = bridge.get_std__optional_double_(secureContextId)
|
|
207
|
+
return __unwrapped
|
|
208
|
+
} else {
|
|
209
|
+
return nil
|
|
210
|
+
}
|
|
211
|
+
}())
|
|
198
212
|
return bridge.create_Result_void_()
|
|
199
213
|
} catch (let __error) {
|
|
200
214
|
let __exceptionPtr = __error.toCpp()
|
|
@@ -422,7 +436,14 @@ open class HybridNetSocketDriverSpec_cxx {
|
|
|
422
436
|
} else {
|
|
423
437
|
return nil
|
|
424
438
|
}
|
|
425
|
-
}(), secureContextId:
|
|
439
|
+
}(), secureContextId: { () -> Double? in
|
|
440
|
+
if bridge.has_value_std__optional_double_(secureContextId) {
|
|
441
|
+
let __unwrapped = bridge.get_std__optional_double_(secureContextId)
|
|
442
|
+
return __unwrapped
|
|
443
|
+
} else {
|
|
444
|
+
return nil
|
|
445
|
+
}
|
|
446
|
+
}())
|
|
426
447
|
return bridge.create_Result_void_()
|
|
427
448
|
} catch (let __error) {
|
|
428
449
|
let __exceptionPtr = __error.toCpp()
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
/// NetConfig.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
import Foundation
|
|
9
8
|
import NitroModules
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -37,7 +36,14 @@ public extension NetConfig {
|
|
|
37
36
|
|
|
38
37
|
@inline(__always)
|
|
39
38
|
var workerThreads: Double? {
|
|
40
|
-
return
|
|
39
|
+
return { () -> Double? in
|
|
40
|
+
if bridge.has_value_std__optional_double_(self.__workerThreads) {
|
|
41
|
+
let __unwrapped = bridge.get_std__optional_double_(self.__workerThreads)
|
|
42
|
+
return __unwrapped
|
|
43
|
+
} else {
|
|
44
|
+
return nil
|
|
45
|
+
}
|
|
46
|
+
}()
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
@inline(__always)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HttpParsedMessage.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
35
|
+
#include <optional>
|
|
36
|
+
|
|
37
|
+
namespace margelo::nitro::net {
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A struct which can be represented as a JavaScript object (HttpParsedMessage).
|
|
41
|
+
*/
|
|
42
|
+
struct HttpParsedMessage final {
|
|
43
|
+
public:
|
|
44
|
+
std::string metadata SWIFT_PRIVATE;
|
|
45
|
+
std::optional<std::shared_ptr<ArrayBuffer>> body SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
HttpParsedMessage() = default;
|
|
49
|
+
explicit HttpParsedMessage(std::string metadata, std::optional<std::shared_ptr<ArrayBuffer>> body): metadata(metadata), body(body) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const HttpParsedMessage& lhs, const HttpParsedMessage& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::net
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ HttpParsedMessage <> JS HttpParsedMessage (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::net::HttpParsedMessage> final {
|
|
62
|
+
static inline margelo::nitro::net::HttpParsedMessage fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::net::HttpParsedMessage(
|
|
65
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata"))),
|
|
66
|
+
JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body")))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::net::HttpParsedMessage& arg) {
|
|
70
|
+
jsi::Object obj(runtime);
|
|
71
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "metadata"), JSIConverter<std::string>::toJSI(runtime, arg.metadata));
|
|
72
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "body"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.body));
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
76
|
+
if (!value.isObject()) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
jsi::Object obj = value.getObject(runtime);
|
|
80
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata")))) return false;
|
|
84
|
+
if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body")))) return false;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
} // namespace margelo::nitro
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridHttpParserSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridHttpParserSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridHttpParserSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
+
// Forward declaration of `HttpParsedMessage` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::net { struct HttpParsedMessage; }
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
#include <string>
|
|
19
|
+
#include "HttpParsedMessage.hpp"
|
|
19
20
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
20
21
|
|
|
21
22
|
namespace margelo::nitro::net {
|
|
@@ -49,7 +50,7 @@ namespace margelo::nitro::net {
|
|
|
49
50
|
|
|
50
51
|
public:
|
|
51
52
|
// Methods
|
|
52
|
-
virtual
|
|
53
|
+
virtual HttpParsedMessage feed(const std::shared_ptr<ArrayBuffer>& data) = 0;
|
|
53
54
|
|
|
54
55
|
protected:
|
|
55
56
|
// Hybrid Setup
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridNetDriverSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridNetDriverSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridNetServerDriverSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridNetServerDriverSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridNetSocketDriverSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridNetSocketDriverSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridNitroBufferSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridNitroBufferSpec.hpp"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-net",
|
|
3
3
|
"description": "Ultra-high-performance networking to React Native by combining a memory-safe Rust core with the zero-overhead Nitro Modules JSI bridge. Provides Node.js-compatible net, tls, http(s) API.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"module": "./lib/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"one": "yarn copy-clib && yarn build && yarn pack",
|
|
30
|
-
"build": "npx nitrogen@0.
|
|
30
|
+
"build": "npx nitrogen@0.35.0 && tsc",
|
|
31
31
|
"prepare": "npm run build",
|
|
32
32
|
"copy-clib": "npm run copy-clib-android && npm run copy-clib-ios && npm run copy-clib-mac",
|
|
33
33
|
"copy-clib-android": "mkdir -p android/libs/arm64-v8a android/libs/armeabi-v7a android/libs/x86 android/libs/x86_64 && cp ../rust_c_net/target/aarch64-linux-android/release/librust_c_net.so android/libs/arm64-v8a/ && cp ../rust_c_net/target/armv7-linux-androideabi/release/librust_c_net.so android/libs/armeabi-v7a/ && cp ../rust_c_net/target/i686-linux-android/release/librust_c_net.so android/libs/x86/ && cp ../rust_c_net/target/x86_64-linux-android/release/librust_c_net.so android/libs/x86_64/ && cp ../rust_c_net/include/NetBindings.hpp cpp/",
|
|
@@ -42,13 +42,12 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "*",
|
|
44
44
|
"@types/readable-stream": "^4.0.23",
|
|
45
|
-
"
|
|
46
|
-
"react-native-nitro-modules": "^0.32.0",
|
|
45
|
+
"react-native-nitro-modules": "0.35.0",
|
|
47
46
|
"typescript": "^5.3.3"
|
|
48
47
|
},
|
|
49
48
|
"peerDependencies": {
|
|
50
49
|
"react-native": "*",
|
|
51
|
-
"react-native-nitro-modules": "
|
|
50
|
+
"react-native-nitro-modules": "0.35.0"
|
|
52
51
|
},
|
|
53
52
|
"packageManager": "yarn@4.12.0",
|
|
54
53
|
"files": [
|
package/src/Logger.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global verbosity state for debugging.
|
|
3
|
+
*/
|
|
4
|
+
let _isVerbose = false;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Checks if verbose debugging is enabled.
|
|
8
|
+
*/
|
|
9
|
+
export function isVerbose(): boolean {
|
|
10
|
+
return _isVerbose;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Enables or disables verbose debugging.
|
|
15
|
+
*/
|
|
16
|
+
export function setVerbose(enabled: boolean): void {
|
|
17
|
+
_isVerbose = enabled;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Logs a debug message with a timestamp and tag if verbosity is enabled.
|
|
22
|
+
*
|
|
23
|
+
* @param tag The tag to identify the source (e.g., 'HTTP', 'NET', 'TLS')
|
|
24
|
+
* @param message The message to log
|
|
25
|
+
*/
|
|
26
|
+
export function debugLog(tag: string, message: string) {
|
|
27
|
+
if (_isVerbose) {
|
|
28
|
+
const timestamp = new Date().toISOString().split('T')[1].split('Z')[0];
|
|
29
|
+
console.log(`[${tag} DEBUG ${timestamp}] ${message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/Net.nitro.ts
CHANGED
|
@@ -82,14 +82,18 @@ export interface NetServerDriver extends HybridObject<{ ios: 'swift', android: '
|
|
|
82
82
|
maxConnections: number
|
|
83
83
|
close(): void
|
|
84
84
|
}
|
|
85
|
+
export interface HttpParsedMessage {
|
|
86
|
+
metadata: string
|
|
87
|
+
body?: ArrayBuffer
|
|
88
|
+
}
|
|
85
89
|
|
|
86
90
|
export interface HttpParser extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
|
|
87
91
|
/**
|
|
88
92
|
* Feed data to the parser
|
|
89
93
|
* @param data Raw byte data from the network
|
|
90
|
-
* @returns
|
|
94
|
+
* @returns HttpParsedMessage containing the JSON metadata and optional binary body
|
|
91
95
|
*/
|
|
92
|
-
feed(data: ArrayBuffer):
|
|
96
|
+
feed(data: ArrayBuffer): HttpParsedMessage
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
/**
|
package/src/http.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Writable, Readable } from 'readable-stream'
|
|
2
2
|
import { EventEmitter } from 'eventemitter3'
|
|
3
|
+
import { Buffer } from 'react-native-nitro-buffer'
|
|
4
|
+
|
|
3
5
|
import { Driver } from './Driver'
|
|
4
|
-
import { Socket
|
|
6
|
+
import { Socket } from './net'
|
|
5
7
|
import { TLSSocket } from './tls'
|
|
6
|
-
import {
|
|
8
|
+
import { debugLog as loggerDebugLog } from './Logger'
|
|
7
9
|
|
|
8
10
|
function debugLog(message: string) {
|
|
9
|
-
|
|
10
|
-
const timestamp = new Date().toISOString().split('T')[1].split('Z')[0];
|
|
11
|
-
debugLog(`[HTTP DEBUG ${timestamp}] ${message}`);
|
|
12
|
-
}
|
|
11
|
+
loggerDebugLog('HTTP', message)
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
// ========== STATUS_CODES ==========
|
|
@@ -146,9 +145,6 @@ export class OutgoingMessage extends Writable {
|
|
|
146
145
|
constructor() {
|
|
147
146
|
// @ts-ignore - disable autoDestroy to prevent socket from being destroyed when stream ends
|
|
148
147
|
super({ autoDestroy: false });
|
|
149
|
-
this.once('finish', () => {
|
|
150
|
-
this.emit('close');
|
|
151
|
-
});
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
public destroy(error?: Error): this {
|
|
@@ -320,6 +316,16 @@ export class ServerResponse extends OutgoingMessage {
|
|
|
320
316
|
constructor(socket: Socket) {
|
|
321
317
|
super();
|
|
322
318
|
this.socket = socket;
|
|
319
|
+
|
|
320
|
+
const onClose = () => {
|
|
321
|
+
if (this.socket) {
|
|
322
|
+
this.socket.removeListener('close', onClose);
|
|
323
|
+
}
|
|
324
|
+
this.removeListener('finish', onClose);
|
|
325
|
+
this.emit('close');
|
|
326
|
+
};
|
|
327
|
+
this.once('finish', onClose);
|
|
328
|
+
this.socket.once('close', onClose);
|
|
323
329
|
}
|
|
324
330
|
|
|
325
331
|
writeHead(statusCode: number, statusMessage?: string | Record<string, any>, headers?: Record<string, any>): this {
|
|
@@ -469,14 +475,18 @@ export class Server extends EventEmitter {
|
|
|
469
475
|
}
|
|
470
476
|
|
|
471
477
|
const onData = (data: Buffer) => {
|
|
472
|
-
const handleParsedResult = (result:
|
|
473
|
-
|
|
478
|
+
const handleParsedResult = (result: any) => {
|
|
479
|
+
const metadata = result.metadata;
|
|
480
|
+
if (metadata.startsWith('ERROR:')) {
|
|
474
481
|
if (headersTimer) clearTimeout(headersTimer);
|
|
475
|
-
this.emit('error', new Error(
|
|
482
|
+
this.emit('error', new Error(metadata));
|
|
476
483
|
socket.destroy();
|
|
477
484
|
return;
|
|
478
485
|
}
|
|
479
|
-
const parsed = JSON.parse(
|
|
486
|
+
const parsed = JSON.parse(metadata);
|
|
487
|
+
if (result.body) {
|
|
488
|
+
parsed.body = Buffer.from(result.body);
|
|
489
|
+
}
|
|
480
490
|
|
|
481
491
|
if (parsed.is_headers) {
|
|
482
492
|
if (headersTimer) {
|
|
@@ -568,14 +578,15 @@ export class Server extends EventEmitter {
|
|
|
568
578
|
|
|
569
579
|
let input: ArrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
570
580
|
let iterations = 0;
|
|
571
|
-
const maxIterations =
|
|
581
|
+
const maxIterations = 2000; // Safety limit
|
|
572
582
|
while (iterations < maxIterations) {
|
|
573
583
|
iterations++;
|
|
574
584
|
const result = parser.feed(input);
|
|
575
|
-
|
|
585
|
+
const metadata = result.metadata;
|
|
586
|
+
if (!metadata || metadata === '' || metadata.startsWith('ERROR:')) {
|
|
576
587
|
// Empty result (partial) or error - exit loop
|
|
577
|
-
if (
|
|
578
|
-
debugLog(`[HTTP] Server: Parser error: ${
|
|
588
|
+
if (metadata && metadata.startsWith('ERROR:')) {
|
|
589
|
+
debugLog(`[HTTP] Server: Parser error: ${metadata}`);
|
|
579
590
|
}
|
|
580
591
|
break;
|
|
581
592
|
}
|
|
@@ -1026,13 +1037,17 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1026
1037
|
const parser = Driver.createHttpParser(1); // 1 = Response mode
|
|
1027
1038
|
|
|
1028
1039
|
const onData = (data: Buffer) => {
|
|
1029
|
-
const handleParsedResult = (result:
|
|
1030
|
-
|
|
1031
|
-
|
|
1040
|
+
const handleParsedResult = (result: any) => {
|
|
1041
|
+
const metadata = result.metadata;
|
|
1042
|
+
if (metadata.startsWith('ERROR:')) {
|
|
1043
|
+
this.emit('error', new Error(metadata));
|
|
1032
1044
|
this.socket!.destroy();
|
|
1033
1045
|
return;
|
|
1034
1046
|
}
|
|
1035
|
-
const parsed = JSON.parse(
|
|
1047
|
+
const parsed = JSON.parse(metadata);
|
|
1048
|
+
if (result.body) {
|
|
1049
|
+
parsed.body = Buffer.from(result.body);
|
|
1050
|
+
}
|
|
1036
1051
|
debugLog(`[HTTP] _connect: Parser result: ${parsed.is_headers ? 'HEADERS' : 'DATA'}${parsed.complete ? ' (COMPLETE)' : ''}`);
|
|
1037
1052
|
|
|
1038
1053
|
if (parsed.is_headers) {
|
|
@@ -1098,14 +1113,15 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1098
1113
|
|
|
1099
1114
|
let input: ArrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1100
1115
|
let iterations = 0;
|
|
1101
|
-
const maxIterations =
|
|
1116
|
+
const maxIterations = 2000; // Safety limit
|
|
1102
1117
|
while (iterations < maxIterations) {
|
|
1103
1118
|
iterations++;
|
|
1104
1119
|
const result = parser.feed(input);
|
|
1105
|
-
|
|
1120
|
+
const metadata = result.metadata;
|
|
1121
|
+
if (!metadata || metadata === '' || metadata.startsWith('ERROR:')) {
|
|
1106
1122
|
// Empty result (partial) or error - exit loop
|
|
1107
|
-
if (
|
|
1108
|
-
debugLog(`[HTTP] ClientRequest: Parser error: ${
|
|
1123
|
+
if (metadata && metadata.startsWith('ERROR:')) {
|
|
1124
|
+
debugLog(`[HTTP] ClientRequest: Parser error: ${metadata}`);
|
|
1109
1125
|
}
|
|
1110
1126
|
break;
|
|
1111
1127
|
}
|
|
@@ -1152,6 +1168,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1152
1168
|
const socket = this.socket;
|
|
1153
1169
|
this._cleanupSocket();
|
|
1154
1170
|
if (socket) agent.releaseSocket(socket, this._options);
|
|
1171
|
+
this.emit('close');
|
|
1155
1172
|
}
|
|
1156
1173
|
|
|
1157
1174
|
private _flushPendingWrites() {
|
package/src/net.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Duplex, DuplexOptions } from 'readable-stream'
|
|
2
2
|
import { EventEmitter } from 'eventemitter3'
|
|
3
|
+
import { Buffer } from 'react-native-nitro-buffer'
|
|
4
|
+
|
|
3
5
|
import { Driver } from './Driver'
|
|
4
6
|
import type { NetSocketDriver, NetServerDriver, NetConfig } from './Net.nitro'
|
|
5
7
|
import { NetSocketEvent, NetServerEvent } from './Net.nitro'
|
|
6
|
-
import {
|
|
8
|
+
import { isVerbose, setVerbose, debugLog as loggerDebugLog } from './Logger'
|
|
7
9
|
|
|
8
10
|
// -----------------------------------------------------------------------------
|
|
9
11
|
// Utils
|
|
@@ -25,27 +27,29 @@ function isIPv4(input: string): boolean {
|
|
|
25
27
|
function isIPv6(input: string): boolean {
|
|
26
28
|
return isIP(input) === 6;
|
|
27
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Decodes an ArrayBuffer to a string.
|
|
33
|
+
* Prioritizes TextDecoder if available, otherwise falls back to Buffer.
|
|
34
|
+
*/
|
|
35
|
+
function decodeArrayBuffer(data: ArrayBuffer | undefined): string {
|
|
36
|
+
if (!data || data.byteLength === 0) return '';
|
|
37
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
38
|
+
return new TextDecoder().decode(data);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.from(data).toString();
|
|
41
|
+
}
|
|
28
42
|
// -----------------------------------------------------------------------------
|
|
29
43
|
// Global Configuration
|
|
30
44
|
// -----------------------------------------------------------------------------
|
|
31
45
|
|
|
32
46
|
let _autoSelectFamilyDefault = 4; // Node default is usually 4/6 independent, but we mock it.
|
|
33
|
-
let _isVerbose = false;
|
|
34
47
|
let _isInitialized = false;
|
|
35
48
|
|
|
36
|
-
function isVerbose(): boolean {
|
|
37
|
-
return _isVerbose;
|
|
38
|
-
}
|
|
39
49
|
|
|
40
|
-
function setVerbose(enabled: boolean): void {
|
|
41
|
-
_isVerbose = enabled;
|
|
42
|
-
}
|
|
43
50
|
|
|
44
51
|
function debugLog(message: string) {
|
|
45
|
-
|
|
46
|
-
const timestamp = new Date().toISOString().split('T')[1].split('Z')[0];
|
|
47
|
-
console.log(`[NET DEBUG ${timestamp}] ${message}`);
|
|
48
|
-
}
|
|
52
|
+
loggerDebugLog('NET', message)
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
function getDefaultAutoSelectFamily(): number {
|
|
@@ -343,9 +347,6 @@ export class Socket extends Duplex {
|
|
|
343
347
|
// resume() will be called after 'connect' event in _connect()
|
|
344
348
|
}
|
|
345
349
|
|
|
346
|
-
this.on('finish', () => {
|
|
347
|
-
// Writable side finished
|
|
348
|
-
});
|
|
349
350
|
}
|
|
350
351
|
|
|
351
352
|
on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
@@ -366,11 +367,11 @@ export class Socket extends Duplex {
|
|
|
366
367
|
const id = (this._driver as any).id ?? (this._driver as any)._id;
|
|
367
368
|
this._driver.onEvent = (eventType: number, data: ArrayBuffer) => {
|
|
368
369
|
this.emit('event', eventType, data);
|
|
369
|
-
if (eventType ===
|
|
370
|
-
const msg =
|
|
370
|
+
if (eventType === NetSocketEvent.ERROR) {
|
|
371
|
+
const msg = decodeArrayBuffer(data) || 'Unknown error';
|
|
371
372
|
debugLog(`Socket (id: ${id}) NATIVE ERROR: ${msg}`);
|
|
372
373
|
}
|
|
373
|
-
if (eventType ===
|
|
374
|
+
if (eventType === NetSocketEvent.SESSION) { // SESSION/DEBUG
|
|
374
375
|
debugLog(`Socket (id: ${id}) NATIVE SESSION EVENT RECEIVED`);
|
|
375
376
|
this.emit('session', data);
|
|
376
377
|
return;
|
|
@@ -398,7 +399,7 @@ export class Socket extends Duplex {
|
|
|
398
399
|
break;
|
|
399
400
|
case NetSocketEvent.ERROR: {
|
|
400
401
|
this._hadError = true;
|
|
401
|
-
const errorMsg =
|
|
402
|
+
const errorMsg = decodeArrayBuffer(data) || 'Unknown socket error';
|
|
402
403
|
const error = new Error(errorMsg);
|
|
403
404
|
|
|
404
405
|
if (this.connecting && this._autoSelectFamily) {
|
|
@@ -439,7 +440,7 @@ export class Socket extends Duplex {
|
|
|
439
440
|
break;
|
|
440
441
|
case NetSocketEvent.LOOKUP: {
|
|
441
442
|
if (data) {
|
|
442
|
-
const lookupStr =
|
|
443
|
+
const lookupStr = decodeArrayBuffer(data);
|
|
443
444
|
const parts = lookupStr.split(',');
|
|
444
445
|
if (parts.length >= 2) {
|
|
445
446
|
const [ip, family] = parts;
|
|
@@ -778,7 +779,7 @@ export class Server extends EventEmitter {
|
|
|
778
779
|
this._driver.onEvent = (eventType: number, data: ArrayBuffer) => {
|
|
779
780
|
switch (eventType) {
|
|
780
781
|
case NetServerEvent.CONNECTION: {
|
|
781
|
-
const payload =
|
|
782
|
+
const payload = decodeArrayBuffer(data);
|
|
782
783
|
if (payload === 'success') {
|
|
783
784
|
this.emit('listening');
|
|
784
785
|
} else {
|
|
@@ -836,7 +837,7 @@ export class Server extends EventEmitter {
|
|
|
836
837
|
break;
|
|
837
838
|
}
|
|
838
839
|
case NetServerEvent.ERROR:
|
|
839
|
-
this.emit('error', new Error(
|
|
840
|
+
this.emit('error', new Error(decodeArrayBuffer(data) || 'Unknown server error'));
|
|
840
841
|
break;
|
|
841
842
|
case NetServerEvent.DEBUG: {
|
|
842
843
|
debugLog(`Server NATIVE SESSION/DEBUG EVENT RECEIVED`);
|