react-native-nitro-sse 1.4.1 → 1.6.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 (33) hide show
  1. package/README.md +33 -34
  2. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +265 -84
  3. package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +60 -13
  4. package/ios/NitroSse.swift +288 -81
  5. package/ios/Tests/NitroSseTests.swift +36 -0
  6. package/lib/module/index.js +3 -2
  7. package/lib/module/index.js.map +1 -1
  8. package/lib/typescript/src/SseInterface.d.ts +31 -4
  9. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  10. package/lib/typescript/src/index.d.ts.map +1 -1
  11. package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp +138 -0
  12. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +5 -2
  13. package/nitrogen/generated/android/c++/JSseConfig.hpp +28 -3
  14. package/nitrogen/generated/android/c++/JSseEvent.hpp +11 -3
  15. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.kt +80 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +18 -5
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +9 -3
  18. package/nitrogen/generated/android/nitrosseOnLoad.cpp +2 -0
  19. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +33 -0
  20. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +130 -0
  21. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
  22. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +2 -1
  23. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.swift +67 -0
  24. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  25. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___.swift +66 -0
  26. package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__std__string_.swift +54 -0
  27. package/nitrogen/generated/ios/swift/SseConfig.swift +84 -1
  28. package/nitrogen/generated/ios/swift/SseEvent.swift +37 -1
  29. package/nitrogen/generated/shared/c++/SseConfig.hpp +17 -3
  30. package/nitrogen/generated/shared/c++/SseEvent.hpp +10 -2
  31. package/package.json +1 -1
  32. package/src/SseInterface.ts +31 -4
  33. package/src/{index.tsx → index.ts} +4 -3
@@ -47,10 +47,12 @@ namespace margelo::nitro::nitrosse {
47
47
  std::optional<std::string> id SWIFT_PRIVATE;
48
48
  std::optional<std::string> event SWIFT_PRIVATE;
49
49
  std::optional<std::string> message SWIFT_PRIVATE;
50
+ std::optional<double> statusCode SWIFT_PRIVATE;
51
+ std::optional<double> retry SWIFT_PRIVATE;
50
52
 
51
53
  public:
52
54
  SseEvent() = default;
53
- explicit SseEvent(SseEventType type, std::optional<std::string> data, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message): type(type), data(data), id(id), event(event), message(message) {}
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) {}
54
56
 
55
57
  public:
56
58
  friend bool operator==(const SseEvent& lhs, const SseEvent& rhs) = default;
@@ -70,7 +72,9 @@ namespace margelo::nitro {
70
72
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data"))),
71
73
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
72
74
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event"))),
73
- JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))
75
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
76
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode"))),
77
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))
74
78
  );
75
79
  }
76
80
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseEvent& arg) {
@@ -80,6 +84,8 @@ namespace margelo::nitro {
80
84
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.id));
81
85
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "event"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.event));
82
86
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.message));
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "statusCode"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.statusCode));
88
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "retry"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retry));
83
89
  return obj;
84
90
  }
85
91
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -95,6 +101,8 @@ namespace margelo::nitro {
95
101
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
96
102
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event")))) return false;
97
103
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
104
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode")))) return false;
105
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))) return false;
98
106
  return true;
99
107
  }
100
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-sse",
3
- "version": "1.4.1",
3
+ "version": "1.6.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",
@@ -27,19 +27,42 @@ export interface SseConfig {
27
27
  body?: string;
28
28
  /**
29
29
  * Whether to continue processing events when the app is in the background.
30
- * Note: OS limitations may restrict background execution time.
30
+ * Note: On iOS, this uses background tasks which are limited in time by the OS.
31
31
  * @default false
32
32
  */
33
33
  backgroundExecution?: boolean;
34
34
  /**
35
- * Interval in milliseconds to batch events before sending them to JS.
36
- * Set to 0 to disable batching (real-time mode).
35
+ * How long (in ms) to wait and group multiple events before sending them to the JS side.
36
+ * High-frequency streams should use this to reduce JS bridge overhead and improve UI performance.
37
+ * Set to 0 to deliver events immediately one-by-one.
38
+ * @default 0
37
39
  */
38
40
  batchingIntervalMs?: number;
39
41
  /**
40
- * Maximum number of events to hold in the buffer before forced flushing.
42
+ * Maximum number of events to keep in the native buffer before forcing a flush to JS,
43
+ * regardless of the `batchingIntervalMs`. Prevents memory pressure.
44
+ * @default 1000
41
45
  */
42
46
  maxBufferSize?: number;
47
+ /**
48
+ * Maximum time (in ms) to wait for the initial server connection and handshake to complete.
49
+ * Effectively the "Connect Timeout".
50
+ * @default 15000
51
+ */
52
+ connectionTimeoutMs?: number;
53
+ /**
54
+ * Maximum idle time (in ms) allowed between receiving data packets or heartbeats.
55
+ * If the server remains silent longer than this, the connection is considered stalled and will reconnect.
56
+ * Increase this for streams that transmit data infrequently.
57
+ * @default 300000
58
+ */
59
+ readTimeoutMs?: number;
60
+ /**
61
+ * Async interceptor called before every connection attempt (including auto-reconnects).
62
+ * Use this to refresh tokens or calculate dynamic headers.
63
+ * Note: This is protected by a native timeout to prevent the app from hanging.
64
+ */
65
+ onBeforeRequest?: () => Promise<Record<string, string>>;
43
66
  }
44
67
 
45
68
  /**
@@ -56,6 +79,10 @@ export interface SseEvent {
56
79
  event?: string;
57
80
  /** System message or error description. */
58
81
  message?: string;
82
+ /** HTTP status code if applicable. */
83
+ statusCode?: number;
84
+ /** Server-requested retry delay in milliseconds. */
85
+ retry?: number;
59
86
  }
60
87
 
61
88
  /**
@@ -8,12 +8,13 @@ export function createNitroSse(): NitroSse {
8
8
  let nativeSse: NitroSse | undefined;
9
9
  try {
10
10
  nativeSse = NitroModules.createHybridObject<NitroSse>('NitroSse');
11
- } catch {}
12
-
13
- if (!nativeSse) {
11
+ } catch {
14
12
  console.debug(
15
13
  'Native NitroSse not found. This might be a test environment or web.'
16
14
  );
15
+ }
16
+
17
+ if (!nativeSse) {
17
18
  throw new Error(
18
19
  'NitroSse: Native module not found. Ensure you have linked the library and built the app for iOS/Android.'
19
20
  );