react-native-nitro-sse 3.0.0-beta.2 → 3.1.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.
Files changed (50) hide show
  1. package/NitroSse.podspec +0 -1
  2. package/README.md +44 -24
  3. package/android/build.gradle +0 -1
  4. package/android/src/main/java/com/margelo/nitro/nitrosse/JsonUtils.kt +33 -10
  5. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +464 -130
  6. package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +420 -88
  7. package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +23 -0
  8. package/android/src/main/java/com/margelo/nitro/nitrosse/SseNetworkMonitor.kt +29 -2
  9. package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +9 -0
  10. package/ios/NitroSse.swift +353 -64
  11. package/ios/SseConfig+CopyWith.swift +35 -19
  12. package/ios/SseConnectionHandler.swift +647 -97
  13. package/ios/SseEventBuffer.swift +19 -1
  14. package/ios/SseReconnectStrategy.swift +26 -7
  15. package/lib/module/MockSseEngine.js +72 -8
  16. package/lib/module/NitroSseClient.js +79 -8
  17. package/lib/module/createNitroSse.js +24 -0
  18. package/lib/module/index.js +1 -22
  19. package/lib/module/useNitroSse.js +22 -5
  20. package/lib/typescript/src/MockSseEngine.d.ts +16 -0
  21. package/lib/typescript/src/NitroSse.nitro.d.ts +2 -2
  22. package/lib/typescript/src/NitroSseClient.d.ts +7 -3
  23. package/lib/typescript/src/SseInterface.d.ts +60 -10
  24. package/lib/typescript/src/createNitroSse.d.ts +9 -0
  25. package/lib/typescript/src/index.d.ts +1 -8
  26. package/lib/typescript/src/useNitroSse.d.ts +2 -2
  27. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +12 -8
  28. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.hpp +1 -1
  29. package/nitrogen/generated/android/c++/JSseConfig.hpp +1 -18
  30. package/nitrogen/generated/android/c++/JSseDisconnectReason.hpp +67 -0
  31. package/nitrogen/generated/android/c++/JSseStats.hpp +87 -1
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/HybridNitroSseSpec.kt +4 -3
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +4 -13
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseDisconnectReason.kt +26 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +108 -3
  36. package/nitrogen/generated/android/nitrosseOnLoad.cpp +2 -2
  37. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +8 -8
  38. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +114 -96
  39. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +3 -0
  40. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +7 -4
  41. package/nitrogen/generated/ios/swift/HybridNitroSseSpec.swift +1 -1
  42. package/nitrogen/generated/ios/swift/HybridNitroSseSpec_cxx.swift +34 -1
  43. package/nitrogen/generated/ios/swift/SseConfig.swift +1 -48
  44. package/nitrogen/generated/ios/swift/SseDisconnectReason.swift +52 -0
  45. package/nitrogen/generated/ios/swift/SseStats.swift +217 -2
  46. package/nitrogen/generated/shared/c++/HybridNitroSseSpec.hpp +3 -1
  47. package/nitrogen/generated/shared/c++/SseConfig.hpp +2 -8
  48. package/nitrogen/generated/shared/c++/SseDisconnectReason.hpp +88 -0
  49. package/nitrogen/generated/shared/c++/SseStats.hpp +88 -2
  50. package/package.json +2 -2
@@ -1,13 +1,6 @@
1
- import type { SseClient } from './SseInterface';
2
1
  export * from './SseInterface';
3
2
  export * from './useNitroSse';
4
3
  export * from './NitroSseClient';
5
4
  export * from './NitroSseError';
6
- /**
7
- * Creates a high-performance SSE client that supports typed event listeners (`addEventListener`) and legacy batching.
8
- *
9
- * @returns An SseClient instance wrapping the native NitroSse implementation.
10
- * @throws {NitroSseModuleNotFoundError} If the native NitroSse module cannot be found. Ensure the library is linked and the app is built for iOS/Android.
11
- */
12
- export declare function createNitroSse(): SseClient;
5
+ export * from './createNitroSse';
13
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- import type { SseClient, SseConfig, SseEvent, SseState, SseStats } from './SseInterface';
1
+ import type { SseClient, SseClientOptions, SseEvent, SseState, SseStats } from './SseInterface';
2
2
  import type { AnyMap } from 'react-native-nitro-modules';
3
3
  type SseEventMap = object;
4
- export interface UseNitroSseOptions<TEvents extends SseEventMap = Record<string, AnyMap>, TMessage = AnyMap> extends SseConfig {
4
+ export interface UseNitroSseOptions<TEvents extends SseEventMap = Record<string, AnyMap>, TMessage = AnyMap> extends SseClientOptions {
5
5
  /**
6
6
  * Whether to automatically start streaming on mount or when URL changes.
7
7
  * @default true
@@ -9,6 +9,8 @@
9
9
 
10
10
  // Forward declaration of `SseStats` to properly resolve imports.
11
11
  namespace margelo::nitro::nitrosse { struct SseStats; }
12
+ // Forward declaration of `SseDisconnectReason` to properly resolve imports.
13
+ namespace margelo::nitro::nitrosse { enum class SseDisconnectReason; }
12
14
  // Forward declaration of `SseState` to properly resolve imports.
13
15
  namespace margelo::nitro::nitrosse { enum class SseState; }
14
16
  // Forward declaration of `SseConfig` to properly resolve imports.
@@ -29,6 +31,8 @@ namespace margelo::nitro::nitrosse { struct SseEvent; }
29
31
  #include "SseStats.hpp"
30
32
  #include "JSseStats.hpp"
31
33
  #include <optional>
34
+ #include "SseDisconnectReason.hpp"
35
+ #include "JSseDisconnectReason.hpp"
32
36
  #include <string>
33
37
  #include "SseState.hpp"
34
38
  #include "JSseState.hpp"
@@ -37,11 +41,6 @@ namespace margelo::nitro::nitrosse { struct SseEvent; }
37
41
  #include "HttpMethod.hpp"
38
42
  #include "JHttpMethod.hpp"
39
43
  #include <unordered_map>
40
- #include <NitroModules/Promise.hpp>
41
- #include <functional>
42
- #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
43
- #include <NitroModules/JNICallable.hpp>
44
- #include <NitroModules/JPromise.hpp>
45
44
  #include "SseMockConfig.hpp"
46
45
  #include "JSseMockConfig.hpp"
47
46
  #include "SseMockMode.hpp"
@@ -54,8 +53,13 @@ namespace margelo::nitro::nitrosse { struct SseEvent; }
54
53
  #include <NitroModules/AnyMap.hpp>
55
54
  #include <NitroModules/JAnyMap.hpp>
56
55
  #include "SseEvent.hpp"
56
+ #include <functional>
57
57
  #include "JFunc_void_std__vector_SseEvent_.hpp"
58
+ #include <NitroModules/JNICallable.hpp>
58
59
  #include "JSseEvent.hpp"
60
+ #include <NitroModules/Promise.hpp>
61
+ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
62
+ #include <NitroModules/JPromise.hpp>
59
63
 
60
64
  namespace margelo::nitro::nitrosse {
61
65
 
@@ -90,9 +94,9 @@ namespace margelo::nitro::nitrosse {
90
94
 
91
95
 
92
96
  // Methods
93
- void JHybridNitroSseSpec::setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent) {
94
- static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JSseConfig> /* config */, jni::alias_ref<JFunc_void_std__vector_SseEvent_::javaobject> /* onEvent */)>("setup_cxx");
95
- method(_javaPart, JSseConfig::fromCpp(config), JFunc_void_std__vector_SseEvent__cxx::fromCpp(onEvent));
97
+ void JHybridNitroSseSpec::setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent, const std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>& onBeforeRequest) {
98
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JSseConfig> /* config */, jni::alias_ref<JFunc_void_std__vector_SseEvent_::javaobject> /* onEvent */, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject> /* onBeforeRequest */)>("setup_cxx");
99
+ method(_javaPart, JSseConfig::fromCpp(config), JFunc_void_std__vector_SseEvent__cxx::fromCpp(onEvent), onBeforeRequest.has_value() ? JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::fromCpp(onBeforeRequest.value()) : nullptr);
96
100
  }
97
101
  void JHybridNitroSseSpec::start() {
98
102
  static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("start");
@@ -54,7 +54,7 @@ namespace margelo::nitro::nitrosse {
54
54
 
55
55
  public:
56
56
  // Methods
57
- void setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent) override;
57
+ void setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent, const std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>& onBeforeRequest) override;
58
58
  void start() override;
59
59
  void stop() override;
60
60
  void setLastProcessedId(const std::string& id) override;
@@ -11,7 +11,6 @@
11
11
  #include "SseConfig.hpp"
12
12
 
13
13
  #include "HttpMethod.hpp"
14
- #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
15
14
  #include "JHttpMethod.hpp"
16
15
  #include "JSseEventType.hpp"
17
16
  #include "JSseMockConfig.hpp"
@@ -25,10 +24,6 @@
25
24
  #include "SseState.hpp"
26
25
  #include <NitroModules/AnyMap.hpp>
27
26
  #include <NitroModules/JAnyMap.hpp>
28
- #include <NitroModules/JNICallable.hpp>
29
- #include <NitroModules/JPromise.hpp>
30
- #include <NitroModules/Promise.hpp>
31
- #include <functional>
32
27
  #include <optional>
33
28
  #include <string>
34
29
  #include <unordered_map>
@@ -85,8 +80,6 @@ namespace margelo::nitro::nitrosse {
85
80
  jni::local_ref<jni::JBoolean> autoParseJSON = this->getFieldValue(fieldAutoParseJSON);
86
81
  static const auto fieldMonitorNetwork = clazz->getField<jni::JBoolean>("monitorNetwork");
87
82
  jni::local_ref<jni::JBoolean> monitorNetwork = this->getFieldValue(fieldMonitorNetwork);
88
- static const auto fieldOnBeforeRequest = clazz->getField<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>("onBeforeRequest");
89
- jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject> onBeforeRequest = this->getFieldValue(fieldOnBeforeRequest);
90
83
  static const auto fieldMock = clazz->getField<JSseMockConfig>("mock");
91
84
  jni::local_ref<JSseMockConfig> mock = this->getFieldValue(fieldMock);
92
85
  return SseConfig(
@@ -113,15 +106,6 @@ namespace margelo::nitro::nitrosse {
113
106
  maxAuthRetries != nullptr ? std::make_optional(maxAuthRetries->value()) : std::nullopt,
114
107
  autoParseJSON != nullptr ? std::make_optional(static_cast<bool>(autoParseJSON->value())) : std::nullopt,
115
108
  monitorNetwork != nullptr ? std::make_optional(static_cast<bool>(monitorNetwork->value())) : std::nullopt,
116
- onBeforeRequest != nullptr ? std::make_optional([&]() -> std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> {
117
- if (onBeforeRequest->isInstanceOf(JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaClassStatic())) [[likely]] {
118
- auto downcast = jni::static_ref_cast<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaobject>(onBeforeRequest);
119
- return downcast->cthis()->getFunction();
120
- } else {
121
- auto onBeforeRequestRef = jni::make_global(onBeforeRequest);
122
- return JNICallable<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____, std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>(std::move(onBeforeRequestRef));
123
- }
124
- }()) : std::nullopt,
125
109
  mock != nullptr ? std::make_optional(mock->toCpp()) : std::nullopt
126
110
  );
127
111
  }
@@ -132,7 +116,7 @@ namespace margelo::nitro::nitrosse {
132
116
  */
133
117
  [[maybe_unused]]
134
118
  static jni::local_ref<JSseConfig::javaobject> fromCpp(const SseConfig& value) {
135
- using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>, jni::alias_ref<JSseMockConfig>);
119
+ using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JSseMockConfig>);
136
120
  static const auto clazz = javaClassStatic();
137
121
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
138
122
  return create(
@@ -159,7 +143,6 @@ namespace margelo::nitro::nitrosse {
159
143
  value.maxAuthRetries.has_value() ? jni::JDouble::valueOf(value.maxAuthRetries.value()) : nullptr,
160
144
  value.autoParseJSON.has_value() ? jni::JBoolean::valueOf(value.autoParseJSON.value()) : nullptr,
161
145
  value.monitorNetwork.has_value() ? jni::JBoolean::valueOf(value.monitorNetwork.value()) : nullptr,
162
- value.onBeforeRequest.has_value() ? JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::fromCpp(value.onBeforeRequest.value()) : nullptr,
163
146
  value.mock.has_value() ? JSseMockConfig::fromCpp(value.mock.value()) : nullptr
164
147
  );
165
148
  }
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// JSseDisconnectReason.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
+ #include <fbjni/fbjni.h>
11
+ #include "SseDisconnectReason.hpp"
12
+
13
+ namespace margelo::nitro::nitrosse {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "SseDisconnectReason" and the Kotlin enum "SseDisconnectReason".
19
+ */
20
+ struct JSseDisconnectReason final: public jni::JavaClass<JSseDisconnectReason> {
21
+ public:
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/SseDisconnectReason;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum SseDisconnectReason.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ SseDisconnectReason toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<SseDisconnectReason>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JSseDisconnectReason> fromCpp(SseDisconnectReason value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case SseDisconnectReason::USER_STOP:
46
+ static const auto fieldUSER_STOP = clazz->getStaticField<JSseDisconnectReason>("USER_STOP");
47
+ return clazz->getStaticFieldValue(fieldUSER_STOP);
48
+ case SseDisconnectReason::NETWORK_ERROR:
49
+ static const auto fieldNETWORK_ERROR = clazz->getStaticField<JSseDisconnectReason>("NETWORK_ERROR");
50
+ return clazz->getStaticFieldValue(fieldNETWORK_ERROR);
51
+ case SseDisconnectReason::SERVER_ERROR:
52
+ static const auto fieldSERVER_ERROR = clazz->getStaticField<JSseDisconnectReason>("SERVER_ERROR");
53
+ return clazz->getStaticFieldValue(fieldSERVER_ERROR);
54
+ case SseDisconnectReason::PARSER_ERROR:
55
+ static const auto fieldPARSER_ERROR = clazz->getStaticField<JSseDisconnectReason>("PARSER_ERROR");
56
+ return clazz->getStaticFieldValue(fieldPARSER_ERROR);
57
+ case SseDisconnectReason::TIMEOUT:
58
+ static const auto fieldTIMEOUT = clazz->getStaticField<JSseDisconnectReason>("TIMEOUT");
59
+ return clazz->getStaticFieldValue(fieldTIMEOUT);
60
+ default:
61
+ std::string stringValue = std::to_string(static_cast<int>(value));
62
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
63
+ }
64
+ }
65
+ };
66
+
67
+ } // namespace margelo::nitro::nitrosse
@@ -10,6 +10,8 @@
10
10
  #include <fbjni/fbjni.h>
11
11
  #include "SseStats.hpp"
12
12
 
13
+ #include "JSseDisconnectReason.hpp"
14
+ #include "SseDisconnectReason.hpp"
13
15
  #include <optional>
14
16
  #include <string>
15
17
 
@@ -32,17 +34,80 @@ namespace margelo::nitro::nitrosse {
32
34
  [[nodiscard]]
33
35
  SseStats toCpp() const {
34
36
  static const auto clazz = javaClassStatic();
37
+ static const auto fieldRawBytesReceived = clazz->getField<double>("rawBytesReceived");
38
+ double rawBytesReceived = this->getFieldValue(fieldRawBytesReceived);
39
+ static const auto fieldDecompressedBytesReceived = clazz->getField<jni::JDouble>("decompressedBytesReceived");
40
+ jni::local_ref<jni::JDouble> decompressedBytesReceived = this->getFieldValue(fieldDecompressedBytesReceived);
35
41
  static const auto fieldTotalBytesReceived = clazz->getField<double>("totalBytesReceived");
36
42
  double totalBytesReceived = this->getFieldValue(fieldTotalBytesReceived);
43
+ static const auto fieldChunksReceived = clazz->getField<double>("chunksReceived");
44
+ double chunksReceived = this->getFieldValue(fieldChunksReceived);
45
+ static const auto fieldLastStatusCode = clazz->getField<jni::JDouble>("lastStatusCode");
46
+ jni::local_ref<jni::JDouble> lastStatusCode = this->getFieldValue(fieldLastStatusCode);
47
+ static const auto fieldTotalEventsReceived = clazz->getField<double>("totalEventsReceived");
48
+ double totalEventsReceived = this->getFieldValue(fieldTotalEventsReceived);
49
+ static const auto fieldCommentsReceived = clazz->getField<double>("commentsReceived");
50
+ double commentsReceived = this->getFieldValue(fieldCommentsReceived);
51
+ static const auto fieldLinesParsed = clazz->getField<double>("linesParsed");
52
+ double linesParsed = this->getFieldValue(fieldLinesParsed);
53
+ static const auto fieldParseErrors = clazz->getField<double>("parseErrors");
54
+ double parseErrors = this->getFieldValue(fieldParseErrors);
55
+ static const auto fieldServerRetryDelayMs = clazz->getField<jni::JDouble>("serverRetryDelayMs");
56
+ jni::local_ref<jni::JDouble> serverRetryDelayMs = this->getFieldValue(fieldServerRetryDelayMs);
57
+ static const auto fieldConnectedAt = clazz->getField<jni::JDouble>("connectedAt");
58
+ jni::local_ref<jni::JDouble> connectedAt = this->getFieldValue(fieldConnectedAt);
59
+ static const auto fieldTimeToFirstByteMs = clazz->getField<jni::JDouble>("timeToFirstByteMs");
60
+ jni::local_ref<jni::JDouble> timeToFirstByteMs = this->getFieldValue(fieldTimeToFirstByteMs);
61
+ static const auto fieldLastEventTime = clazz->getField<jni::JDouble>("lastEventTime");
62
+ jni::local_ref<jni::JDouble> lastEventTime = this->getFieldValue(fieldLastEventTime);
63
+ static const auto fieldLastHeartbeatTime = clazz->getField<jni::JDouble>("lastHeartbeatTime");
64
+ jni::local_ref<jni::JDouble> lastHeartbeatTime = this->getFieldValue(fieldLastHeartbeatTime);
65
+ static const auto fieldMaxEventGapMs = clazz->getField<double>("maxEventGapMs");
66
+ double maxEventGapMs = this->getFieldValue(fieldMaxEventGapMs);
67
+ static const auto fieldEventsBuffered = clazz->getField<double>("eventsBuffered");
68
+ double eventsBuffered = this->getFieldValue(fieldEventsBuffered);
69
+ static const auto fieldPeakBufferedEvents = clazz->getField<double>("peakBufferedEvents");
70
+ double peakBufferedEvents = this->getFieldValue(fieldPeakBufferedEvents);
71
+ static const auto fieldBufferFlushCount = clazz->getField<double>("bufferFlushCount");
72
+ double bufferFlushCount = this->getFieldValue(fieldBufferFlushCount);
73
+ static const auto fieldBufferOverflowCount = clazz->getField<double>("bufferOverflowCount");
74
+ double bufferOverflowCount = this->getFieldValue(fieldBufferOverflowCount);
75
+ static const auto fieldConnectionAttempts = clazz->getField<double>("connectionAttempts");
76
+ double connectionAttempts = this->getFieldValue(fieldConnectionAttempts);
37
77
  static const auto fieldReconnectCount = clazz->getField<double>("reconnectCount");
38
78
  double reconnectCount = this->getFieldValue(fieldReconnectCount);
79
+ static const auto fieldLastReconnectDelayMs = clazz->getField<jni::JDouble>("lastReconnectDelayMs");
80
+ jni::local_ref<jni::JDouble> lastReconnectDelayMs = this->getFieldValue(fieldLastReconnectDelayMs);
81
+ static const auto fieldDisconnectReason = clazz->getField<JSseDisconnectReason>("disconnectReason");
82
+ jni::local_ref<JSseDisconnectReason> disconnectReason = this->getFieldValue(fieldDisconnectReason);
39
83
  static const auto fieldLastErrorTime = clazz->getField<jni::JDouble>("lastErrorTime");
40
84
  jni::local_ref<jni::JDouble> lastErrorTime = this->getFieldValue(fieldLastErrorTime);
41
85
  static const auto fieldLastErrorCode = clazz->getField<jni::JString>("lastErrorCode");
42
86
  jni::local_ref<jni::JString> lastErrorCode = this->getFieldValue(fieldLastErrorCode);
43
87
  return SseStats(
88
+ rawBytesReceived,
89
+ decompressedBytesReceived != nullptr ? std::make_optional(decompressedBytesReceived->value()) : std::nullopt,
44
90
  totalBytesReceived,
91
+ chunksReceived,
92
+ lastStatusCode != nullptr ? std::make_optional(lastStatusCode->value()) : std::nullopt,
93
+ totalEventsReceived,
94
+ commentsReceived,
95
+ linesParsed,
96
+ parseErrors,
97
+ serverRetryDelayMs != nullptr ? std::make_optional(serverRetryDelayMs->value()) : std::nullopt,
98
+ connectedAt != nullptr ? std::make_optional(connectedAt->value()) : std::nullopt,
99
+ timeToFirstByteMs != nullptr ? std::make_optional(timeToFirstByteMs->value()) : std::nullopt,
100
+ lastEventTime != nullptr ? std::make_optional(lastEventTime->value()) : std::nullopt,
101
+ lastHeartbeatTime != nullptr ? std::make_optional(lastHeartbeatTime->value()) : std::nullopt,
102
+ maxEventGapMs,
103
+ eventsBuffered,
104
+ peakBufferedEvents,
105
+ bufferFlushCount,
106
+ bufferOverflowCount,
107
+ connectionAttempts,
45
108
  reconnectCount,
109
+ lastReconnectDelayMs != nullptr ? std::make_optional(lastReconnectDelayMs->value()) : std::nullopt,
110
+ disconnectReason != nullptr ? std::make_optional(disconnectReason->toCpp()) : std::nullopt,
46
111
  lastErrorTime != nullptr ? std::make_optional(lastErrorTime->value()) : std::nullopt,
47
112
  lastErrorCode != nullptr ? std::make_optional(lastErrorCode->toStdString()) : std::nullopt
48
113
  );
@@ -54,13 +119,34 @@ namespace margelo::nitro::nitrosse {
54
119
  */
55
120
  [[maybe_unused]]
56
121
  static jni::local_ref<JSseStats::javaobject> fromCpp(const SseStats& value) {
57
- using JSignature = JSseStats(double, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
122
+ using JSignature = JSseStats(double, jni::alias_ref<jni::JDouble>, double, double, jni::alias_ref<jni::JDouble>, double, double, double, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, double, double, double, double, double, double, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<JSseDisconnectReason>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
58
123
  static const auto clazz = javaClassStatic();
59
124
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
60
125
  return create(
61
126
  clazz,
127
+ value.rawBytesReceived,
128
+ value.decompressedBytesReceived.has_value() ? jni::JDouble::valueOf(value.decompressedBytesReceived.value()) : nullptr,
62
129
  value.totalBytesReceived,
130
+ value.chunksReceived,
131
+ value.lastStatusCode.has_value() ? jni::JDouble::valueOf(value.lastStatusCode.value()) : nullptr,
132
+ value.totalEventsReceived,
133
+ value.commentsReceived,
134
+ value.linesParsed,
135
+ value.parseErrors,
136
+ value.serverRetryDelayMs.has_value() ? jni::JDouble::valueOf(value.serverRetryDelayMs.value()) : nullptr,
137
+ value.connectedAt.has_value() ? jni::JDouble::valueOf(value.connectedAt.value()) : nullptr,
138
+ value.timeToFirstByteMs.has_value() ? jni::JDouble::valueOf(value.timeToFirstByteMs.value()) : nullptr,
139
+ value.lastEventTime.has_value() ? jni::JDouble::valueOf(value.lastEventTime.value()) : nullptr,
140
+ value.lastHeartbeatTime.has_value() ? jni::JDouble::valueOf(value.lastHeartbeatTime.value()) : nullptr,
141
+ value.maxEventGapMs,
142
+ value.eventsBuffered,
143
+ value.peakBufferedEvents,
144
+ value.bufferFlushCount,
145
+ value.bufferOverflowCount,
146
+ value.connectionAttempts,
63
147
  value.reconnectCount,
148
+ value.lastReconnectDelayMs.has_value() ? jni::JDouble::valueOf(value.lastReconnectDelayMs.value()) : nullptr,
149
+ value.disconnectReason.has_value() ? JSseDisconnectReason::fromCpp(value.disconnectReason.value()) : nullptr,
64
150
  value.lastErrorTime.has_value() ? jni::JDouble::valueOf(value.lastErrorTime.value()) : nullptr,
65
151
  value.lastErrorCode.has_value() ? jni::make_jstring(value.lastErrorCode.value()) : nullptr
66
152
  );
@@ -11,6 +11,7 @@ import androidx.annotation.Keep
11
11
  import com.facebook.jni.HybridData
12
12
  import com.facebook.proguard.annotations.DoNotStrip
13
13
  import dalvik.annotation.optimization.FastNative
14
+ import com.margelo.nitro.core.Promise
14
15
  import com.margelo.nitro.core.HybridObject
15
16
 
16
17
  /**
@@ -29,12 +30,12 @@ abstract class HybridNitroSseSpec: HybridObject() {
29
30
 
30
31
 
31
32
  // Methods
32
- abstract fun setup(config: SseConfig, onEvent: (events: Array<SseEvent>) -> Unit): Unit
33
+ abstract fun setup(config: SseConfig, onEvent: (events: Array<SseEvent>) -> Unit, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?): Unit
33
34
 
34
35
  @DoNotStrip
35
36
  @Keep
36
- private fun setup_cxx(config: SseConfig, onEvent: Func_void_std__vector_SseEvent_): Unit {
37
- val __result = setup(config, onEvent)
37
+ private fun setup_cxx(config: SseConfig, onEvent: Func_void_std__vector_SseEvent_, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?): Unit {
38
+ val __result = setup(config, onEvent, onBeforeRequest?.let { it })
38
39
  return __result
39
40
  }
40
41
 
@@ -10,7 +10,7 @@ package com.margelo.nitro.nitrosse
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
12
  import java.util.Objects
13
- import com.margelo.nitro.core.Promise
13
+
14
14
 
15
15
  /**
16
16
  * Represents the JavaScript object/struct "SseConfig".
@@ -68,16 +68,9 @@ data class SseConfig(
68
68
  val monitorNetwork: Boolean?,
69
69
  @DoNotStrip
70
70
  @Keep
71
- val onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?,
72
- @DoNotStrip
73
- @Keep
74
71
  val mock: SseMockConfig?
75
72
  ) {
76
- /**
77
- * Create a new instance of SseConfig from Kotlin
78
- */
79
- constructor(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?, mock: SseMockConfig?):
80
- this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, maxAuthRetries, autoParseJSON, monitorNetwork, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) }, mock)
73
+ /* primary constructor */
81
74
 
82
75
  override fun equals(other: Any?): Boolean {
83
76
  if (this === other) return true
@@ -98,7 +91,6 @@ data class SseConfig(
98
91
  && Objects.deepEquals(this.maxAuthRetries, other.maxAuthRetries)
99
92
  && Objects.deepEquals(this.autoParseJSON, other.autoParseJSON)
100
93
  && Objects.deepEquals(this.monitorNetwork, other.monitorNetwork)
101
- && Objects.deepEquals(this.onBeforeRequest, other.onBeforeRequest)
102
94
  && Objects.deepEquals(this.mock, other.mock)
103
95
  }
104
96
 
@@ -120,7 +112,6 @@ data class SseConfig(
120
112
  maxAuthRetries,
121
113
  autoParseJSON,
122
114
  monitorNetwork,
123
- onBeforeRequest,
124
115
  mock
125
116
  ).contentDeepHashCode()
126
117
  }
@@ -133,8 +124,8 @@ data class SseConfig(
133
124
  @Keep
134
125
  @Suppress("unused")
135
126
  @JvmStatic
136
- private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?, mock: SseMockConfig?): SseConfig {
137
- return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, maxAuthRetries, autoParseJSON, monitorNetwork, onBeforeRequest, mock)
127
+ private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, mock: SseMockConfig?): SseConfig {
128
+ return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, maxAuthRetries, autoParseJSON, monitorNetwork, mock)
138
129
  }
139
130
  }
140
131
  }
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// SseDisconnectReason.kt
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
+ package com.margelo.nitro.nitrosse
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "SseDisconnectReason".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class SseDisconnectReason(@DoNotStrip @Keep val value: Int) {
19
+ USER_STOP(0),
20
+ NETWORK_ERROR(1),
21
+ SERVER_ERROR(2),
22
+ PARSER_ERROR(3),
23
+ TIMEOUT(4);
24
+
25
+ companion object
26
+ }
@@ -18,14 +18,77 @@ import java.util.Objects
18
18
  @DoNotStrip
19
19
  @Keep
20
20
  data class SseStats(
21
+ @DoNotStrip
22
+ @Keep
23
+ val rawBytesReceived: Double,
24
+ @DoNotStrip
25
+ @Keep
26
+ val decompressedBytesReceived: Double?,
21
27
  @DoNotStrip
22
28
  @Keep
23
29
  val totalBytesReceived: Double,
24
30
  @DoNotStrip
25
31
  @Keep
32
+ val chunksReceived: Double,
33
+ @DoNotStrip
34
+ @Keep
35
+ val lastStatusCode: Double?,
36
+ @DoNotStrip
37
+ @Keep
38
+ val totalEventsReceived: Double,
39
+ @DoNotStrip
40
+ @Keep
41
+ val commentsReceived: Double,
42
+ @DoNotStrip
43
+ @Keep
44
+ val linesParsed: Double,
45
+ @DoNotStrip
46
+ @Keep
47
+ val parseErrors: Double,
48
+ @DoNotStrip
49
+ @Keep
50
+ val serverRetryDelayMs: Double?,
51
+ @DoNotStrip
52
+ @Keep
53
+ val connectedAt: Double?,
54
+ @DoNotStrip
55
+ @Keep
56
+ val timeToFirstByteMs: Double?,
57
+ @DoNotStrip
58
+ @Keep
59
+ val lastEventTime: Double?,
60
+ @DoNotStrip
61
+ @Keep
62
+ val lastHeartbeatTime: Double?,
63
+ @DoNotStrip
64
+ @Keep
65
+ val maxEventGapMs: Double,
66
+ @DoNotStrip
67
+ @Keep
68
+ val eventsBuffered: Double,
69
+ @DoNotStrip
70
+ @Keep
71
+ val peakBufferedEvents: Double,
72
+ @DoNotStrip
73
+ @Keep
74
+ val bufferFlushCount: Double,
75
+ @DoNotStrip
76
+ @Keep
77
+ val bufferOverflowCount: Double,
78
+ @DoNotStrip
79
+ @Keep
80
+ val connectionAttempts: Double,
81
+ @DoNotStrip
82
+ @Keep
26
83
  val reconnectCount: Double,
27
84
  @DoNotStrip
28
85
  @Keep
86
+ val lastReconnectDelayMs: Double?,
87
+ @DoNotStrip
88
+ @Keep
89
+ val disconnectReason: SseDisconnectReason?,
90
+ @DoNotStrip
91
+ @Keep
29
92
  val lastErrorTime: Double?,
30
93
  @DoNotStrip
31
94
  @Keep
@@ -36,16 +99,58 @@ data class SseStats(
36
99
  override fun equals(other: Any?): Boolean {
37
100
  if (this === other) return true
38
101
  if (other !is SseStats) return false
39
- return Objects.deepEquals(this.totalBytesReceived, other.totalBytesReceived)
102
+ return Objects.deepEquals(this.rawBytesReceived, other.rawBytesReceived)
103
+ && Objects.deepEquals(this.decompressedBytesReceived, other.decompressedBytesReceived)
104
+ && Objects.deepEquals(this.totalBytesReceived, other.totalBytesReceived)
105
+ && Objects.deepEquals(this.chunksReceived, other.chunksReceived)
106
+ && Objects.deepEquals(this.lastStatusCode, other.lastStatusCode)
107
+ && Objects.deepEquals(this.totalEventsReceived, other.totalEventsReceived)
108
+ && Objects.deepEquals(this.commentsReceived, other.commentsReceived)
109
+ && Objects.deepEquals(this.linesParsed, other.linesParsed)
110
+ && Objects.deepEquals(this.parseErrors, other.parseErrors)
111
+ && Objects.deepEquals(this.serverRetryDelayMs, other.serverRetryDelayMs)
112
+ && Objects.deepEquals(this.connectedAt, other.connectedAt)
113
+ && Objects.deepEquals(this.timeToFirstByteMs, other.timeToFirstByteMs)
114
+ && Objects.deepEquals(this.lastEventTime, other.lastEventTime)
115
+ && Objects.deepEquals(this.lastHeartbeatTime, other.lastHeartbeatTime)
116
+ && Objects.deepEquals(this.maxEventGapMs, other.maxEventGapMs)
117
+ && Objects.deepEquals(this.eventsBuffered, other.eventsBuffered)
118
+ && Objects.deepEquals(this.peakBufferedEvents, other.peakBufferedEvents)
119
+ && Objects.deepEquals(this.bufferFlushCount, other.bufferFlushCount)
120
+ && Objects.deepEquals(this.bufferOverflowCount, other.bufferOverflowCount)
121
+ && Objects.deepEquals(this.connectionAttempts, other.connectionAttempts)
40
122
  && Objects.deepEquals(this.reconnectCount, other.reconnectCount)
123
+ && Objects.deepEquals(this.lastReconnectDelayMs, other.lastReconnectDelayMs)
124
+ && Objects.deepEquals(this.disconnectReason, other.disconnectReason)
41
125
  && Objects.deepEquals(this.lastErrorTime, other.lastErrorTime)
42
126
  && Objects.deepEquals(this.lastErrorCode, other.lastErrorCode)
43
127
  }
44
128
 
45
129
  override fun hashCode(): Int {
46
130
  return arrayOf<Any?>(
131
+ rawBytesReceived,
132
+ decompressedBytesReceived,
47
133
  totalBytesReceived,
134
+ chunksReceived,
135
+ lastStatusCode,
136
+ totalEventsReceived,
137
+ commentsReceived,
138
+ linesParsed,
139
+ parseErrors,
140
+ serverRetryDelayMs,
141
+ connectedAt,
142
+ timeToFirstByteMs,
143
+ lastEventTime,
144
+ lastHeartbeatTime,
145
+ maxEventGapMs,
146
+ eventsBuffered,
147
+ peakBufferedEvents,
148
+ bufferFlushCount,
149
+ bufferOverflowCount,
150
+ connectionAttempts,
48
151
  reconnectCount,
152
+ lastReconnectDelayMs,
153
+ disconnectReason,
49
154
  lastErrorTime,
50
155
  lastErrorCode
51
156
  ).contentDeepHashCode()
@@ -59,8 +164,8 @@ data class SseStats(
59
164
  @Keep
60
165
  @Suppress("unused")
61
166
  @JvmStatic
62
- private fun fromCpp(totalBytesReceived: Double, reconnectCount: Double, lastErrorTime: Double?, lastErrorCode: String?): SseStats {
63
- return SseStats(totalBytesReceived, reconnectCount, lastErrorTime, lastErrorCode)
167
+ private fun fromCpp(rawBytesReceived: Double, decompressedBytesReceived: Double?, totalBytesReceived: Double, chunksReceived: Double, lastStatusCode: Double?, totalEventsReceived: Double, commentsReceived: Double, linesParsed: Double, parseErrors: Double, serverRetryDelayMs: Double?, connectedAt: Double?, timeToFirstByteMs: Double?, lastEventTime: Double?, lastHeartbeatTime: Double?, maxEventGapMs: Double, eventsBuffered: Double, peakBufferedEvents: Double, bufferFlushCount: Double, bufferOverflowCount: Double, connectionAttempts: Double, reconnectCount: Double, lastReconnectDelayMs: Double?, disconnectReason: SseDisconnectReason?, lastErrorTime: Double?, lastErrorCode: String?): SseStats {
168
+ return SseStats(rawBytesReceived, decompressedBytesReceived, totalBytesReceived, chunksReceived, lastStatusCode, totalEventsReceived, commentsReceived, linesParsed, parseErrors, serverRetryDelayMs, connectedAt, timeToFirstByteMs, lastEventTime, lastHeartbeatTime, maxEventGapMs, eventsBuffered, peakBufferedEvents, bufferFlushCount, bufferOverflowCount, connectionAttempts, reconnectCount, lastReconnectDelayMs, disconnectReason, lastErrorTime, lastErrorCode)
64
169
  }
65
170
  }
66
171
  }
@@ -16,8 +16,8 @@
16
16
  #include <NitroModules/HybridObjectRegistry.hpp>
17
17
 
18
18
  #include "JHybridNitroSseSpec.hpp"
19
- #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
20
19
  #include "JFunc_void_std__vector_SseEvent_.hpp"
20
+ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
21
21
  #include <NitroModules/DefaultConstructableObject.hpp>
22
22
 
23
23
  namespace margelo::nitro::nitrosse {
@@ -43,8 +43,8 @@ void registerAllNatives() {
43
43
 
44
44
  // Register native JNI methods
45
45
  margelo::nitro::nitrosse::JHybridNitroSseSpec::CxxPart::registerNatives();
46
- margelo::nitro::nitrosse::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::registerNatives();
47
46
  margelo::nitro::nitrosse::JFunc_void_std__vector_SseEvent__cxx::registerNatives();
47
+ margelo::nitro::nitrosse::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::registerNatives();
48
48
 
49
49
  // Register Nitro Hybrid Objects
50
50
  HybridObjectRegistry::registerHybridObjectConstructor(