react-native-nitro-sse 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # react-native-nitro-sse
2
2
 
3
- Server-Sent Events (SSE) client for React Native built on Nitro Modules (JSI).
3
+ Server-Sent Events (SSE) client for React Native built on Nitro Modules (JSI) with seamless Web support.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Features
8
8
 
9
- - **JSI Execution**: Direct synchronous JS-to-native calls via Nitro Modules.
9
+ - **JSI Execution (Native)**: Direct synchronous JS-to-native calls via Nitro Modules on iOS and Android.
10
+ - **Universal Web Support**: Pure JS driver powered by the Fetch & ReadableStream API for React Native Web and Web browsers.
10
11
  - **Reconnection**: Exponential backoff with jitter and HTTP 429 (`Retry-After`) handling.
11
12
  - **Event Batching**: Configurable batch interval and buffer size limits.
12
13
  - **Lifecycle & Network**: Automatic pause and resume on app state or network transitions.
@@ -15,6 +16,16 @@ Server-Sent Events (SSE) client for React Native built on Nitro Modules (JSI).
15
16
 
16
17
  ---
17
18
 
19
+ ## Platform Support
20
+
21
+ | Platform | Implementation |
22
+ | :------- | :------------- |
23
+ | **iOS** | Nitro Modules (JSI) + URLSession |
24
+ | **Android** | Nitro Modules (JSI) + OkHttp |
25
+ | **Web** | Pure JS `FetchSseDriver` (Fetch Streams) |
26
+
27
+ ---
28
+
18
29
  ## Installation
19
30
 
20
31
  ```sh
@@ -23,7 +34,7 @@ npm install react-native-nitro-sse react-native-nitro-modules
23
34
  yarn add react-native-nitro-sse react-native-nitro-modules
24
35
  ```
25
36
 
26
- > **Note**: `react-native-nitro-modules` is a peer dependency.
37
+ > **Note**: `react-native-nitro-modules` is a peer dependency required for iOS and Android native compilation. On Web, the library uses the pure JS Fetch driver and does not invoke native binaries.
27
38
 
28
39
  <details>
29
40
  <summary><b>Compatibility Matrix</b></summary>
@@ -238,7 +249,7 @@ try {
238
249
 
239
250
  | Error Class | Error Code | Description |
240
251
  | :---------------------------- | :------------------------------------- | :-------------------------------------------------------------------- |
241
- | `NitroSseModuleNotFoundError` | `NATIVE_MODULE_NOT_FOUND` | Native Nitro module binary is missing. |
252
+ | `NitroSseModuleNotFoundError` | `NATIVE_MODULE_NOT_FOUND` | Native Nitro module binary is missing (iOS/Android only). |
242
253
  | `NitroSseValidationError` | `INVALID_CONFIG` \| `INVALID_ARGUMENT` | Invalid argument or configuration parameter. |
243
254
  | `NitroSseStateError` | `INVALID_STATE` | Method invoked in an invalid state (e.g. `start()` before `setup()`). |
244
255
  | `NitroSseDisposedError` | `CLIENT_DISPOSED` | Method invoked on an already disposed client instance. |
@@ -32,7 +32,9 @@ def reactNativeArchitectures() {
32
32
  }
33
33
 
34
34
  apply plugin: "com.android.library"
35
- apply plugin: "kotlin-android"
35
+ if (project.extensions.findByName('kotlin') == null) {
36
+ apply plugin: "kotlin-android"
37
+ }
36
38
  apply from: '../nitrogen/generated/android/nitrosse+autolinking.gradle'
37
39
 
38
40
  apply plugin: "com.facebook.react"
@@ -799,13 +799,14 @@ class NitroSse @DoNotStrip constructor() : HybridNitroSseSpec(), SseConnectionDe
799
799
  updateState(SseState.STALE)
800
800
  }
801
801
 
802
+ val reportedStatusCode = if (statusCode >= 400 || statusCode == 204) statusCode.toDouble() else null
802
803
  val defaultErrorMsg = when {
803
804
  statusCode >= 500 && !errorBody.isNullOrBlank() -> "Server Error ($statusCode): ${errorBody.trim()}"
804
- else -> t?.message ?: "Link lost ($statusCode)"
805
+ else -> t?.message ?: if (reportedStatusCode != null) "Link lost (${reportedStatusCode.toInt()})" else "Link lost"
805
806
  }
806
807
 
807
808
  // Teardown and reconnect on stream or socket failure.
808
- eventBuffer.push(SseEvent(SseEventType.ERROR, null, null, null, null, defaultErrorMsg, if (statusCode != -1) statusCode.toDouble() else null, null, null))
809
+ eventBuffer.push(SseEvent(SseEventType.ERROR, null, null, null, null, defaultErrorMsg, reportedStatusCode, null, null))
809
810
  scheduleReconnect(true, connectionAttemptVersion.get())
810
811
  }
811
812
  }