react-native-nitro-sse 1.6.2 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +2 -0
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +256 -95
  4. package/ios/NitroSse.swift +90 -39
  5. package/lib/module/NitroSseClient.js +75 -0
  6. package/lib/module/NitroSseClient.js.map +1 -0
  7. package/lib/module/SseInterface.js +2 -0
  8. package/lib/module/index.js +9 -1
  9. package/lib/module/index.js.map +1 -1
  10. package/lib/typescript/src/NitroSseClient.d.ts +21 -0
  11. package/lib/typescript/src/NitroSseClient.d.ts.map +1 -0
  12. package/lib/typescript/src/SseInterface.d.ts +74 -2
  13. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  14. package/lib/typescript/src/index.d.ts +8 -2
  15. package/lib/typescript/src/index.d.ts.map +1 -1
  16. package/nitrogen/generated/android/c++/JFunc_void_std__vector_SseEvent_.hpp +2 -0
  17. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +2 -0
  18. package/nitrogen/generated/android/c++/JSseConfig.hpp +21 -1
  19. package/nitrogen/generated/android/c++/JSseEvent.hpp +7 -1
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +19 -4
  21. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +6 -3
  22. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +16 -0
  23. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
  24. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +1 -0
  25. package/nitrogen/generated/ios/swift/SseConfig.swift +91 -1
  26. package/nitrogen/generated/ios/swift/SseEvent.swift +19 -1
  27. package/nitrogen/generated/shared/c++/SseConfig.hpp +21 -1
  28. package/nitrogen/generated/shared/c++/SseEvent.hpp +6 -1
  29. package/package.json +9 -4
  30. package/src/NitroSseClient.ts +96 -0
  31. package/src/SseInterface.ts +79 -2
  32. package/src/index.ts +10 -2
  33. package/android/src/test/java/com/margelo/nitro/nitrosse/HeartbeatScannerTest.kt +0 -98
  34. package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +0 -157
  35. package/ios/Tests/NitroSseTests.swift +0 -122
@@ -58,6 +58,16 @@ namespace margelo::nitro::nitrosse {
58
58
  jni::local_ref<jni::JDouble> connectionTimeoutMs = this->getFieldValue(fieldConnectionTimeoutMs);
59
59
  static const auto fieldReadTimeoutMs = clazz->getField<jni::JDouble>("readTimeoutMs");
60
60
  jni::local_ref<jni::JDouble> readTimeoutMs = this->getFieldValue(fieldReadTimeoutMs);
61
+ static const auto fieldRetryIntervalMs = clazz->getField<jni::JDouble>("retryIntervalMs");
62
+ jni::local_ref<jni::JDouble> retryIntervalMs = this->getFieldValue(fieldRetryIntervalMs);
63
+ static const auto fieldMaxRetryIntervalMs = clazz->getField<jni::JDouble>("maxRetryIntervalMs");
64
+ jni::local_ref<jni::JDouble> maxRetryIntervalMs = this->getFieldValue(fieldMaxRetryIntervalMs);
65
+ static const auto fieldJitterFactor = clazz->getField<jni::JDouble>("jitterFactor");
66
+ jni::local_ref<jni::JDouble> jitterFactor = this->getFieldValue(fieldJitterFactor);
67
+ static const auto fieldMaxReconnectAttempts = clazz->getField<jni::JDouble>("maxReconnectAttempts");
68
+ jni::local_ref<jni::JDouble> maxReconnectAttempts = this->getFieldValue(fieldMaxReconnectAttempts);
69
+ static const auto fieldAutoParseJSON = clazz->getField<jni::JBoolean>("autoParseJSON");
70
+ jni::local_ref<jni::JBoolean> autoParseJSON = this->getFieldValue(fieldAutoParseJSON);
61
71
  static const auto fieldOnBeforeRequest = clazz->getField<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>("onBeforeRequest");
62
72
  jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject> onBeforeRequest = this->getFieldValue(fieldOnBeforeRequest);
63
73
  return SseConfig(
@@ -77,6 +87,11 @@ namespace margelo::nitro::nitrosse {
77
87
  maxBufferSize != nullptr ? std::make_optional(maxBufferSize->value()) : std::nullopt,
78
88
  connectionTimeoutMs != nullptr ? std::make_optional(connectionTimeoutMs->value()) : std::nullopt,
79
89
  readTimeoutMs != nullptr ? std::make_optional(readTimeoutMs->value()) : std::nullopt,
90
+ retryIntervalMs != nullptr ? std::make_optional(retryIntervalMs->value()) : std::nullopt,
91
+ maxRetryIntervalMs != nullptr ? std::make_optional(maxRetryIntervalMs->value()) : std::nullopt,
92
+ jitterFactor != nullptr ? std::make_optional(jitterFactor->value()) : std::nullopt,
93
+ maxReconnectAttempts != nullptr ? std::make_optional(maxReconnectAttempts->value()) : std::nullopt,
94
+ autoParseJSON != nullptr ? std::make_optional(static_cast<bool>(autoParseJSON->value())) : std::nullopt,
80
95
  onBeforeRequest != nullptr ? std::make_optional([&]() -> std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> {
81
96
  if (onBeforeRequest->isInstanceOf(JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaClassStatic())) [[likely]] {
82
97
  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);
@@ -95,7 +110,7 @@ namespace margelo::nitro::nitrosse {
95
110
  */
96
111
  [[maybe_unused]]
97
112
  static jni::local_ref<JSseConfig::javaobject> fromCpp(const SseConfig& value) {
98
- 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<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>);
113
+ 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::JBoolean>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>);
99
114
  static const auto clazz = javaClassStatic();
100
115
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
101
116
  return create(
@@ -115,6 +130,11 @@ namespace margelo::nitro::nitrosse {
115
130
  value.maxBufferSize.has_value() ? jni::JDouble::valueOf(value.maxBufferSize.value()) : nullptr,
116
131
  value.connectionTimeoutMs.has_value() ? jni::JDouble::valueOf(value.connectionTimeoutMs.value()) : nullptr,
117
132
  value.readTimeoutMs.has_value() ? jni::JDouble::valueOf(value.readTimeoutMs.value()) : nullptr,
133
+ value.retryIntervalMs.has_value() ? jni::JDouble::valueOf(value.retryIntervalMs.value()) : nullptr,
134
+ value.maxRetryIntervalMs.has_value() ? jni::JDouble::valueOf(value.maxRetryIntervalMs.value()) : nullptr,
135
+ value.jitterFactor.has_value() ? jni::JDouble::valueOf(value.jitterFactor.value()) : nullptr,
136
+ value.maxReconnectAttempts.has_value() ? jni::JDouble::valueOf(value.maxReconnectAttempts.value()) : nullptr,
137
+ value.autoParseJSON.has_value() ? jni::JBoolean::valueOf(value.autoParseJSON.value()) : nullptr,
118
138
  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
119
139
  );
120
140
  }
@@ -12,6 +12,8 @@
12
12
 
13
13
  #include "JSseEventType.hpp"
14
14
  #include "SseEventType.hpp"
15
+ #include <NitroModules/AnyMap.hpp>
16
+ #include <NitroModules/JAnyMap.hpp>
15
17
  #include <optional>
16
18
  #include <string>
17
19
 
@@ -38,6 +40,8 @@ namespace margelo::nitro::nitrosse {
38
40
  jni::local_ref<JSseEventType> type = this->getFieldValue(fieldType);
39
41
  static const auto fieldData = clazz->getField<jni::JString>("data");
40
42
  jni::local_ref<jni::JString> data = this->getFieldValue(fieldData);
43
+ static const auto fieldParsedData = clazz->getField<JAnyMap::javaobject>("parsedData");
44
+ jni::local_ref<JAnyMap::javaobject> parsedData = this->getFieldValue(fieldParsedData);
41
45
  static const auto fieldId = clazz->getField<jni::JString>("id");
42
46
  jni::local_ref<jni::JString> id = this->getFieldValue(fieldId);
43
47
  static const auto fieldEvent = clazz->getField<jni::JString>("event");
@@ -51,6 +55,7 @@ namespace margelo::nitro::nitrosse {
51
55
  return SseEvent(
52
56
  type->toCpp(),
53
57
  data != nullptr ? std::make_optional(data->toStdString()) : std::nullopt,
58
+ parsedData != nullptr ? std::make_optional(parsedData->cthis()->getMap()) : std::nullopt,
54
59
  id != nullptr ? std::make_optional(id->toStdString()) : std::nullopt,
55
60
  event != nullptr ? std::make_optional(event->toStdString()) : std::nullopt,
56
61
  message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt,
@@ -65,13 +70,14 @@ namespace margelo::nitro::nitrosse {
65
70
  */
66
71
  [[maybe_unused]]
67
72
  static jni::local_ref<JSseEvent::javaobject> fromCpp(const SseEvent& value) {
68
- using JSignature = JSseEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
73
+ using JSignature = JSseEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<JAnyMap::javaobject>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
69
74
  static const auto clazz = javaClassStatic();
70
75
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
71
76
  return create(
72
77
  clazz,
73
78
  JSseEventType::fromCpp(value.type),
74
79
  value.data.has_value() ? jni::make_jstring(value.data.value()) : nullptr,
80
+ value.parsedData.has_value() ? JAnyMap::create(value.parsedData.value()) : nullptr,
75
81
  value.id.has_value() ? jni::make_jstring(value.id.value()) : nullptr,
76
82
  value.event.has_value() ? jni::make_jstring(value.event.value()) : nullptr,
77
83
  value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr,
@@ -46,13 +46,28 @@ data class SseConfig(
46
46
  val readTimeoutMs: Double?,
47
47
  @DoNotStrip
48
48
  @Keep
49
+ val retryIntervalMs: Double?,
50
+ @DoNotStrip
51
+ @Keep
52
+ val maxRetryIntervalMs: Double?,
53
+ @DoNotStrip
54
+ @Keep
55
+ val jitterFactor: Double?,
56
+ @DoNotStrip
57
+ @Keep
58
+ val maxReconnectAttempts: Double?,
59
+ @DoNotStrip
60
+ @Keep
61
+ val autoParseJSON: Boolean?,
62
+ @DoNotStrip
63
+ @Keep
49
64
  val onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?
50
65
  ) {
51
66
  /**
52
67
  * Create a new instance of SseConfig from Kotlin
53
68
  */
54
- constructor(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?):
55
- this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) })
69
+ 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?, autoParseJSON: Boolean?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?):
70
+ this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, autoParseJSON, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) })
56
71
 
57
72
  companion object {
58
73
  /**
@@ -62,8 +77,8 @@ data class SseConfig(
62
77
  @Keep
63
78
  @Suppress("unused")
64
79
  @JvmStatic
65
- private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?): SseConfig {
66
- return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, onBeforeRequest)
80
+ 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?, autoParseJSON: Boolean?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?): SseConfig {
81
+ return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, autoParseJSON, onBeforeRequest)
67
82
  }
68
83
  }
69
84
  }
@@ -9,7 +9,7 @@ package com.margelo.nitro.nitrosse
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
-
12
+ import com.margelo.nitro.core.AnyMap
13
13
 
14
14
  /**
15
15
  * Represents the JavaScript object/struct "SseEvent".
@@ -25,6 +25,9 @@ data class SseEvent(
25
25
  val data: String?,
26
26
  @DoNotStrip
27
27
  @Keep
28
+ val parsedData: AnyMap?,
29
+ @DoNotStrip
30
+ @Keep
28
31
  val id: String?,
29
32
  @DoNotStrip
30
33
  @Keep
@@ -49,8 +52,8 @@ data class SseEvent(
49
52
  @Keep
50
53
  @Suppress("unused")
51
54
  @JvmStatic
52
- private fun fromCpp(type: SseEventType, data: String?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?): SseEvent {
53
- return SseEvent(type, data, id, event, message, statusCode, retry)
55
+ private fun fromCpp(type: SseEventType, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?): SseEvent {
56
+ return SseEvent(type, data, parsedData, id, event, message, statusCode, retry)
54
57
  }
55
58
  }
56
59
  }
@@ -29,6 +29,7 @@ namespace NitroSse { class HybridNitroSseSpec_cxx; }
29
29
  #include "SseEvent.hpp"
30
30
  #include "SseEventType.hpp"
31
31
  #include "SseStats.hpp"
32
+ #include <NitroModules/AnyMap.hpp>
32
33
  #include <NitroModules/Promise.hpp>
33
34
  #include <NitroModules/PromiseHolder.hpp>
34
35
  #include <NitroModules/Result.hpp>
@@ -274,6 +275,21 @@ namespace margelo::nitro::nitrosse::bridge::swift {
274
275
  return optional.value();
275
276
  }
276
277
 
278
+ // pragma MARK: std::optional<std::shared_ptr<AnyMap>>
279
+ /**
280
+ * Specialized version of `std::optional<std::shared_ptr<AnyMap>>`.
281
+ */
282
+ using std__optional_std__shared_ptr_AnyMap__ = std::optional<std::shared_ptr<AnyMap>>;
283
+ inline std::optional<std::shared_ptr<AnyMap>> create_std__optional_std__shared_ptr_AnyMap__(const std::shared_ptr<AnyMap>& value) noexcept {
284
+ return std::optional<std::shared_ptr<AnyMap>>(value);
285
+ }
286
+ inline bool has_value_std__optional_std__shared_ptr_AnyMap__(const std::optional<std::shared_ptr<AnyMap>>& optional) noexcept {
287
+ return optional.has_value();
288
+ }
289
+ inline std::shared_ptr<AnyMap> get_std__optional_std__shared_ptr_AnyMap__(const std::optional<std::shared_ptr<AnyMap>>& optional) noexcept {
290
+ return optional.value();
291
+ }
292
+
277
293
  // pragma MARK: std::vector<SseEvent>
278
294
  /**
279
295
  * Specialized version of `std::vector<SseEvent>`.
@@ -28,6 +28,7 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
28
28
  #include "SseEvent.hpp"
29
29
  #include "SseEventType.hpp"
30
30
  #include "SseStats.hpp"
31
+ #include <NitroModules/AnyMap.hpp>
31
32
  #include <NitroModules/Promise.hpp>
32
33
  #include <NitroModules/Result.hpp>
33
34
  #include <exception>
@@ -33,6 +33,7 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
33
33
  #include "SseEvent.hpp"
34
34
  #include <vector>
35
35
  #include "SseEventType.hpp"
36
+ #include <NitroModules/AnyMap.hpp>
36
37
  #include "SseStats.hpp"
37
38
 
38
39
  #include "NitroSse-Swift-Cxx-Umbrella.hpp"
@@ -18,7 +18,7 @@ public extension SseConfig {
18
18
  /**
19
19
  * Create a new instance of `SseConfig`.
20
20
  */
21
- init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?) {
21
+ init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, autoParseJSON: Bool?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?) {
22
22
  self.init(std.string(url), { () -> bridge.std__optional_HttpMethod_ in
23
23
  if let __unwrappedValue = method {
24
24
  return bridge.create_std__optional_HttpMethod_(__unwrappedValue)
@@ -73,6 +73,36 @@ public extension SseConfig {
73
73
  } else {
74
74
  return .init()
75
75
  }
76
+ }(), { () -> bridge.std__optional_double_ in
77
+ if let __unwrappedValue = retryIntervalMs {
78
+ return bridge.create_std__optional_double_(__unwrappedValue)
79
+ } else {
80
+ return .init()
81
+ }
82
+ }(), { () -> bridge.std__optional_double_ in
83
+ if let __unwrappedValue = maxRetryIntervalMs {
84
+ return bridge.create_std__optional_double_(__unwrappedValue)
85
+ } else {
86
+ return .init()
87
+ }
88
+ }(), { () -> bridge.std__optional_double_ in
89
+ if let __unwrappedValue = jitterFactor {
90
+ return bridge.create_std__optional_double_(__unwrappedValue)
91
+ } else {
92
+ return .init()
93
+ }
94
+ }(), { () -> bridge.std__optional_double_ in
95
+ if let __unwrappedValue = maxReconnectAttempts {
96
+ return bridge.create_std__optional_double_(__unwrappedValue)
97
+ } else {
98
+ return .init()
99
+ }
100
+ }(), { () -> bridge.std__optional_bool_ in
101
+ if let __unwrappedValue = autoParseJSON {
102
+ return bridge.create_std__optional_bool_(__unwrappedValue)
103
+ } else {
104
+ return .init()
105
+ }
76
106
  }(), { () -> bridge.std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________ in
77
107
  if let __unwrappedValue = onBeforeRequest {
78
108
  return bridge.create_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________({ () -> bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ in
@@ -187,6 +217,66 @@ public extension SseConfig {
187
217
  }()
188
218
  }
189
219
 
220
+ @inline(__always)
221
+ var retryIntervalMs: Double? {
222
+ return { () -> Double? in
223
+ if bridge.has_value_std__optional_double_(self.__retryIntervalMs) {
224
+ let __unwrapped = bridge.get_std__optional_double_(self.__retryIntervalMs)
225
+ return __unwrapped
226
+ } else {
227
+ return nil
228
+ }
229
+ }()
230
+ }
231
+
232
+ @inline(__always)
233
+ var maxRetryIntervalMs: Double? {
234
+ return { () -> Double? in
235
+ if bridge.has_value_std__optional_double_(self.__maxRetryIntervalMs) {
236
+ let __unwrapped = bridge.get_std__optional_double_(self.__maxRetryIntervalMs)
237
+ return __unwrapped
238
+ } else {
239
+ return nil
240
+ }
241
+ }()
242
+ }
243
+
244
+ @inline(__always)
245
+ var jitterFactor: Double? {
246
+ return { () -> Double? in
247
+ if bridge.has_value_std__optional_double_(self.__jitterFactor) {
248
+ let __unwrapped = bridge.get_std__optional_double_(self.__jitterFactor)
249
+ return __unwrapped
250
+ } else {
251
+ return nil
252
+ }
253
+ }()
254
+ }
255
+
256
+ @inline(__always)
257
+ var maxReconnectAttempts: Double? {
258
+ return { () -> Double? in
259
+ if bridge.has_value_std__optional_double_(self.__maxReconnectAttempts) {
260
+ let __unwrapped = bridge.get_std__optional_double_(self.__maxReconnectAttempts)
261
+ return __unwrapped
262
+ } else {
263
+ return nil
264
+ }
265
+ }()
266
+ }
267
+
268
+ @inline(__always)
269
+ var autoParseJSON: Bool? {
270
+ return { () -> Bool? in
271
+ if bridge.has_value_std__optional_bool_(self.__autoParseJSON) {
272
+ let __unwrapped = bridge.get_std__optional_bool_(self.__autoParseJSON)
273
+ return __unwrapped
274
+ } else {
275
+ return nil
276
+ }
277
+ }()
278
+ }
279
+
190
280
  @inline(__always)
191
281
  var onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)? {
192
282
  return { () -> (() -> Promise<Promise<Dictionary<String, String>>>)? in
@@ -18,13 +18,19 @@ public extension SseEvent {
18
18
  /**
19
19
  * Create a new instance of `SseEvent`.
20
20
  */
21
- init(type: SseEventType, data: String?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?) {
21
+ init(type: SseEventType, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?) {
22
22
  self.init(type, { () -> bridge.std__optional_std__string_ in
23
23
  if let __unwrappedValue = data {
24
24
  return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
25
25
  } else {
26
26
  return .init()
27
27
  }
28
+ }(), { () -> bridge.std__optional_std__shared_ptr_AnyMap__ in
29
+ if let __unwrappedValue = parsedData {
30
+ return bridge.create_std__optional_std__shared_ptr_AnyMap__(__unwrappedValue.cppPart)
31
+ } else {
32
+ return .init()
33
+ }
28
34
  }(), { () -> bridge.std__optional_std__string_ in
29
35
  if let __unwrappedValue = id {
30
36
  return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
@@ -75,6 +81,18 @@ public extension SseEvent {
75
81
  }()
76
82
  }
77
83
 
84
+ @inline(__always)
85
+ var parsedData: AnyMap? {
86
+ return { () -> AnyMap? in
87
+ if bridge.has_value_std__optional_std__shared_ptr_AnyMap__(self.__parsedData) {
88
+ let __unwrapped = bridge.get_std__optional_std__shared_ptr_AnyMap__(self.__parsedData)
89
+ return AnyMap(withCppPart: __unwrapped)
90
+ } else {
91
+ return nil
92
+ }
93
+ }()
94
+ }
95
+
78
96
  @inline(__always)
79
97
  var id: String? {
80
98
  return { () -> String? in
@@ -54,11 +54,16 @@ namespace margelo::nitro::nitrosse {
54
54
  std::optional<double> maxBufferSize SWIFT_PRIVATE;
55
55
  std::optional<double> connectionTimeoutMs SWIFT_PRIVATE;
56
56
  std::optional<double> readTimeoutMs SWIFT_PRIVATE;
57
+ std::optional<double> retryIntervalMs SWIFT_PRIVATE;
58
+ std::optional<double> maxRetryIntervalMs SWIFT_PRIVATE;
59
+ std::optional<double> jitterFactor SWIFT_PRIVATE;
60
+ std::optional<double> maxReconnectAttempts SWIFT_PRIVATE;
61
+ std::optional<bool> autoParseJSON SWIFT_PRIVATE;
57
62
  std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest SWIFT_PRIVATE;
58
63
 
59
64
  public:
60
65
  SseConfig() = default;
61
- explicit SseConfig(std::string url, std::optional<HttpMethod> method, std::optional<std::unordered_map<std::string, std::string>> headers, std::optional<std::string> body, std::optional<bool> backgroundExecution, std::optional<double> batchingIntervalMs, std::optional<double> maxBufferSize, std::optional<double> connectionTimeoutMs, std::optional<double> readTimeoutMs, std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest): url(url), method(method), headers(headers), body(body), backgroundExecution(backgroundExecution), batchingIntervalMs(batchingIntervalMs), maxBufferSize(maxBufferSize), connectionTimeoutMs(connectionTimeoutMs), readTimeoutMs(readTimeoutMs), onBeforeRequest(onBeforeRequest) {}
66
+ explicit SseConfig(std::string url, std::optional<HttpMethod> method, std::optional<std::unordered_map<std::string, std::string>> headers, std::optional<std::string> body, std::optional<bool> backgroundExecution, std::optional<double> batchingIntervalMs, std::optional<double> maxBufferSize, std::optional<double> connectionTimeoutMs, std::optional<double> readTimeoutMs, std::optional<double> retryIntervalMs, std::optional<double> maxRetryIntervalMs, std::optional<double> jitterFactor, std::optional<double> maxReconnectAttempts, std::optional<bool> autoParseJSON, std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest): url(url), method(method), headers(headers), body(body), backgroundExecution(backgroundExecution), batchingIntervalMs(batchingIntervalMs), maxBufferSize(maxBufferSize), connectionTimeoutMs(connectionTimeoutMs), readTimeoutMs(readTimeoutMs), retryIntervalMs(retryIntervalMs), maxRetryIntervalMs(maxRetryIntervalMs), jitterFactor(jitterFactor), maxReconnectAttempts(maxReconnectAttempts), autoParseJSON(autoParseJSON), onBeforeRequest(onBeforeRequest) {}
62
67
 
63
68
  public:
64
69
  // SseConfig is not equatable because these properties are not equatable: onBeforeRequest
@@ -83,6 +88,11 @@ namespace margelo::nitro {
83
88
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize"))),
84
89
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs"))),
85
90
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs"))),
91
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retryIntervalMs"))),
92
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxRetryIntervalMs"))),
93
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jitterFactor"))),
94
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts"))),
95
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"))),
86
96
  JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest")))
87
97
  );
88
98
  }
@@ -97,6 +107,11 @@ namespace margelo::nitro {
97
107
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxBufferSize));
98
108
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.connectionTimeoutMs));
99
109
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.readTimeoutMs));
110
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "retryIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retryIntervalMs));
111
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxRetryIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxRetryIntervalMs));
112
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "jitterFactor"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.jitterFactor));
113
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxReconnectAttempts));
114
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.autoParseJSON));
100
115
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest"), JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::toJSI(runtime, arg.onBeforeRequest));
101
116
  return obj;
102
117
  }
@@ -117,6 +132,11 @@ namespace margelo::nitro {
117
132
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize")))) return false;
118
133
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs")))) return false;
119
134
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs")))) return false;
135
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retryIntervalMs")))) return false;
136
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxRetryIntervalMs")))) return false;
137
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jitterFactor")))) return false;
138
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts")))) return false;
139
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON")))) return false;
120
140
  if (!JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest")))) return false;
121
141
  return true;
122
142
  }
@@ -34,6 +34,7 @@ namespace margelo::nitro::nitrosse { enum class SseEventType; }
34
34
  #include "SseEventType.hpp"
35
35
  #include <string>
36
36
  #include <optional>
37
+ #include <NitroModules/AnyMap.hpp>
37
38
 
38
39
  namespace margelo::nitro::nitrosse {
39
40
 
@@ -44,6 +45,7 @@ namespace margelo::nitro::nitrosse {
44
45
  public:
45
46
  SseEventType type SWIFT_PRIVATE;
46
47
  std::optional<std::string> data SWIFT_PRIVATE;
48
+ std::optional<std::shared_ptr<AnyMap>> parsedData SWIFT_PRIVATE;
47
49
  std::optional<std::string> id SWIFT_PRIVATE;
48
50
  std::optional<std::string> event SWIFT_PRIVATE;
49
51
  std::optional<std::string> message SWIFT_PRIVATE;
@@ -52,7 +54,7 @@ namespace margelo::nitro::nitrosse {
52
54
 
53
55
  public:
54
56
  SseEvent() = default;
55
- explicit SseEvent(SseEventType type, std::optional<std::string> data, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message, std::optional<double> statusCode, std::optional<double> retry): type(type), data(data), id(id), event(event), message(message), statusCode(statusCode), retry(retry) {}
57
+ explicit SseEvent(SseEventType type, std::optional<std::string> data, std::optional<std::shared_ptr<AnyMap>> parsedData, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message, std::optional<double> statusCode, std::optional<double> retry): type(type), data(data), parsedData(parsedData), id(id), event(event), message(message), statusCode(statusCode), retry(retry) {}
56
58
 
57
59
  public:
58
60
  friend bool operator==(const SseEvent& lhs, const SseEvent& rhs) = default;
@@ -70,6 +72,7 @@ namespace margelo::nitro {
70
72
  return margelo::nitro::nitrosse::SseEvent(
71
73
  JSIConverter<margelo::nitro::nitrosse::SseEventType>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
72
74
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data"))),
75
+ JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parsedData"))),
73
76
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
74
77
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event"))),
75
78
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
@@ -81,6 +84,7 @@ namespace margelo::nitro {
81
84
  jsi::Object obj(runtime);
82
85
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<margelo::nitro::nitrosse::SseEventType>::toJSI(runtime, arg.type));
83
86
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "data"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.data));
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "parsedData"), JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::toJSI(runtime, arg.parsedData));
84
88
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.id));
85
89
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "event"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.event));
86
90
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.message));
@@ -98,6 +102,7 @@ namespace margelo::nitro {
98
102
  }
99
103
  if (!JSIConverter<margelo::nitro::nitrosse::SseEventType>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
100
104
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))) return false;
105
+ if (!JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parsedData")))) return false;
101
106
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
102
107
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event")))) return false;
103
108
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-sse",
3
- "version": "1.6.2",
3
+ "version": "2.1.1",
4
4
  "description": "High-performance Server-Sent Events (SSE) for React Native, powered by Nitro Modules.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -23,7 +23,9 @@
23
23
  "*.podspec",
24
24
  "react-native.config.js",
25
25
  "!ios/build",
26
+ "!ios/Tests",
26
27
  "!android/build",
28
+ "!android/src/test",
27
29
  "!android/gradle",
28
30
  "!android/gradlew",
29
31
  "!android/gradlew.bat",
@@ -40,6 +42,9 @@
40
42
  "nitrogen": "nitrogen",
41
43
  "typecheck": "tsc",
42
44
  "test": "jest",
45
+ "test:android": "cd example/android && ./gradlew :react-native-nitro-sse:testDebugUnitTest",
46
+ "test:ios": "cd example/ios && xcodebuild test -workspace NitroSseExample.xcworkspace -scheme NitroSse -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16'",
47
+ "test:native": "yarn test:android && yarn test:ios",
43
48
  "release": "release-it --only-version",
44
49
  "server": "node example/sse-server.js",
45
50
  "lint": "eslint \"**/*.{js,ts,tsx}\""
@@ -72,8 +77,8 @@
72
77
  "@eslint/compat": "^1.3.2",
73
78
  "@eslint/eslintrc": "^3.3.1",
74
79
  "@eslint/js": "^9.35.0",
75
- "@react-native/babel-preset": "0.83.0",
76
- "@react-native/eslint-config": "0.83.0",
80
+ "@react-native/babel-preset": "0.83.4",
81
+ "@react-native/eslint-config": "0.83.4",
77
82
  "@release-it/conventional-changelog": "^10.0.1",
78
83
  "@types/jest": "^29.5.14",
79
84
  "@types/react": "^19.2.0",
@@ -87,7 +92,7 @@
87
92
  "nitrogen": "0.35.2",
88
93
  "prettier": "^2.8.8",
89
94
  "react": "19.2.0",
90
- "react-native": "0.83.0",
95
+ "react-native": "0.83.4",
91
96
  "react-native-builder-bob": "^0.40.17",
92
97
  "react-native-nitro-modules": "0.35.2",
93
98
  "release-it": "^19.0.4",
@@ -0,0 +1,96 @@
1
+ import type { NitroSse } from './NitroSse.nitro';
2
+ import type {
3
+ SseClient,
4
+ SseConfig,
5
+ SseEvent,
6
+ SseListener,
7
+ SseStats,
8
+ } from './SseInterface';
9
+
10
+ export class NitroSseClient implements SseClient {
11
+ private _native: NitroSse;
12
+ private _listeners: Map<string, Set<SseListener>> = new Map();
13
+ private _legacyCallback?: (events: SseEvent[]) => void;
14
+
15
+ constructor(native: NitroSse) {
16
+ this._native = native;
17
+ }
18
+
19
+ setup(config: SseConfig, onEvent?: (events: SseEvent[]) => void): void {
20
+ this._legacyCallback = onEvent;
21
+
22
+ // We wrap the native setup to dispatch events to typed listeners
23
+ this._native.setup(config, (events) => {
24
+ // 1. Call legacy batch callback if provided
25
+ this._legacyCallback?.(events);
26
+
27
+ // 2. Dispatch individual events to registered listeners
28
+ for (const event of events) {
29
+ // Dispatch basic types: 'open', 'message', 'error', 'close', 'heartbeat'
30
+ this._emit(event.type, event);
31
+
32
+ // Dispatch by SSE event name if it's different from the type
33
+ // e.g., if type is 'message' but event name is 'update'
34
+ if (event.event && event.event !== event.type) {
35
+ this._emit(event.event, event);
36
+ }
37
+ }
38
+ });
39
+ }
40
+
41
+ addEventListener(type: string, listener: SseListener): void {
42
+ if (!this._listeners.has(type)) {
43
+ this._listeners.set(type, new Set());
44
+ }
45
+ this._listeners.get(type)!.add(listener);
46
+ }
47
+
48
+ removeEventListener(type: string, listener: SseListener): void {
49
+ this._listeners.get(type)?.delete(listener);
50
+ }
51
+
52
+ private _emit(type: string, event: SseEvent): void {
53
+ const listeners = this._listeners.get(type);
54
+ if (listeners) {
55
+ listeners.forEach((listener) => {
56
+ try {
57
+ listener(event);
58
+ } catch (e) {
59
+ console.error(`[NitroSse] Error in event listener for "${type}":`, e);
60
+ }
61
+ });
62
+ }
63
+ }
64
+
65
+ start(): void {
66
+ this._native.start();
67
+ }
68
+
69
+ stop(): void {
70
+ this._native.stop();
71
+ }
72
+
73
+ restart(): void {
74
+ this._native.restart();
75
+ }
76
+
77
+ flush(): void {
78
+ this._native.flush();
79
+ }
80
+
81
+ isConnected(): boolean {
82
+ return this._native.isConnected();
83
+ }
84
+
85
+ getStats(): SseStats {
86
+ return this._native.getStats();
87
+ }
88
+
89
+ updateHeaders(headers: Record<string, string>): void {
90
+ this._native.updateHeaders(headers);
91
+ }
92
+
93
+ setLastProcessedId(id: string): void {
94
+ this._native.setLastProcessedId(id);
95
+ }
96
+ }