react-native-nitro-sse 2.3.0 → 2.3.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.
@@ -60,6 +60,7 @@ class NitroSse: HybridNitroSseSpec {
60
60
  private var connectionAttemptVersion: Int = 0
61
61
  #if os(iOS)
62
62
  private var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = .invalid
63
+ private var isBackgroundTaskActive: Bool = false
63
64
  #endif
64
65
  private var wasRunningBeforeHibernation: Bool = false
65
66
  private var isAppInBackground: Bool = false
@@ -174,12 +175,29 @@ class NitroSse: HybridNitroSseSpec {
174
175
  if config.backgroundExecution == true {
175
176
  print("[NitroSse] App backgrounded. backgroundExecution is true, keeping connection alive.")
176
177
  #if os(iOS)
177
- // Start a background task to tell the OS we want to keep running
178
178
  self.cleanupBackgroundTask()
179
- self.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(withName: "NitroSse-KeepAlive") { [weak self] in
179
+ self.isBackgroundTaskActive = true
180
+
181
+ DispatchQueue.main.async { [weak self] in
182
+ let taskId = UIApplication.shared.beginBackgroundTask(withName: "NitroSse-KeepAlive") {
183
+ self?.sseQueue.async {
184
+ print("[NitroSse] Background task expired. Hibernating now.")
185
+ self?.hibernateConnection()
186
+ }
187
+ }
180
188
  self?.sseQueue.async {
181
- print("[NitroSse] Background task expired. Hibernating now.")
182
- self?.hibernateConnection()
189
+ if self?.isBackgroundTaskActive == true {
190
+ if let oldTaskId = self?.backgroundTaskIdentifier, oldTaskId != .invalid {
191
+ DispatchQueue.main.async {
192
+ UIApplication.shared.endBackgroundTask(oldTaskId)
193
+ }
194
+ }
195
+ self?.backgroundTaskIdentifier = taskId
196
+ } else {
197
+ DispatchQueue.main.async {
198
+ UIApplication.shared.endBackgroundTask(taskId)
199
+ }
200
+ }
183
201
  }
184
202
  }
185
203
  #endif
@@ -225,9 +243,13 @@ class NitroSse: HybridNitroSseSpec {
225
243
  private func cleanupBackgroundTask() {
226
244
  dispatchPrecondition(condition: .onQueue(sseQueue))
227
245
  #if os(iOS)
228
- if self.backgroundTaskIdentifier != .invalid {
229
- UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier)
246
+ self.isBackgroundTaskActive = false
247
+ let taskId = self.backgroundTaskIdentifier
248
+ if taskId != .invalid {
230
249
  self.backgroundTaskIdentifier = .invalid
250
+ DispatchQueue.main.async {
251
+ UIApplication.shared.endBackgroundTask(taskId)
252
+ }
231
253
  }
232
254
  #endif
233
255
  }
@@ -646,6 +668,15 @@ class NitroSse: HybridNitroSseSpec {
646
668
  parent.backoffCounter = 0
647
669
  parent.currentReconnectAttempts = 0
648
670
  parent.consecutiveAuthErrors = 0
671
+
672
+ NitroSseNetworkInspector.reportResponseStart(
673
+ parent.requestId,
674
+ url: parent.config?.url,
675
+ response: nil,
676
+ statusCode: 200,
677
+ headers: parent.config?.headers ?? [:]
678
+ )
679
+
649
680
  parent.pushEventToBuffer(SseEvent(type: .open, data: nil, parsedData: nil, id: nil, event: nil, message: nil, statusCode: 200, retry: nil))
650
681
  }
651
682
  }
@@ -695,13 +726,26 @@ class NitroSse: HybridNitroSseSpec {
695
726
  guard let parent = self.parent, source === parent.eventSource else { return }
696
727
  parent.sseQueue.async { [weak parent] in
697
728
  guard let parent = parent, parent.isRunning, self.attemptVersion == parent.connectionAttemptVersion else { return }
729
+
698
730
  let nsError = error as NSError
699
- let statusCode = nsError.code
731
+ var statusCode = nsError.code
732
+ if let responseError = error as? UnsuccessfulResponseError {
733
+ statusCode = responseError.responseCode
734
+ }
700
735
 
701
736
  parent.reconnectCount += 1
702
737
  parent.lastErrorTime = Date().timeIntervalSince1970 * 1000
703
738
  parent.lastErrorCode = "\(nsError.domain)(\(statusCode))"
704
739
 
740
+ if statusCode >= 100 && statusCode < 600 {
741
+ NitroSseNetworkInspector.reportResponseStart(
742
+ parent.requestId,
743
+ url: parent.config?.url,
744
+ response: nil,
745
+ statusCode: statusCode,
746
+ headers: [:]
747
+ )
748
+ }
705
749
  NitroSseNetworkInspector.reportRequestFailed(parent.requestId, cancelled: false)
706
750
  parent.requestId = nil
707
751
 
@@ -99,7 +99,7 @@ data class SseConfig(
99
99
  }
100
100
 
101
101
  override fun hashCode(): Int {
102
- return arrayOf(
102
+ return arrayOf<Any?>(
103
103
  url,
104
104
  method,
105
105
  headers,
@@ -59,7 +59,7 @@ data class SseEvent(
59
59
  }
60
60
 
61
61
  override fun hashCode(): Int {
62
- return arrayOf(
62
+ return arrayOf<Any?>(
63
63
  type,
64
64
  data,
65
65
  parsedData,
@@ -47,7 +47,7 @@ data class SseMockConfig(
47
47
  }
48
48
 
49
49
  override fun hashCode(): Int {
50
- return arrayOf(
50
+ return arrayOf<Any?>(
51
51
  mode,
52
52
  data,
53
53
  eventsPerSecond,
@@ -63,7 +63,7 @@ data class SseMockEvent(
63
63
  }
64
64
 
65
65
  override fun hashCode(): Int {
66
- return arrayOf(
66
+ return arrayOf<Any?>(
67
67
  type,
68
68
  data,
69
69
  parsedData,
@@ -43,7 +43,7 @@ data class SseStats(
43
43
  }
44
44
 
45
45
  override fun hashCode(): Int {
46
- return arrayOf(
46
+ return arrayOf<Any?>(
47
47
  totalBytesReceived,
48
48
  reconnectCount,
49
49
  lastErrorTime,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-sse",
3
- "version": "2.3.0",
3
+ "version": "2.3.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",
@@ -43,8 +43,9 @@
43
43
  "typecheck": "tsc",
44
44
  "test": "jest",
45
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'",
46
+ "test:ios": "cd example/ios && xcodebuild test -workspace NitroSseExample.xcworkspace -scheme NitroSse -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16e'",
47
47
  "test:native": "yarn test:android && yarn test:ios",
48
+ "ci": "yarn lint && yarn typecheck && yarn test && yarn prepare && yarn test:native && yarn turbo run build:android build:ios",
48
49
  "release": "release-it --only-version",
49
50
  "server": "node example/sse-server.js",
50
51
  "lint": "eslint \"**/*.{js,ts,tsx}\""
@@ -77,8 +78,9 @@
77
78
  "@eslint/compat": "^1.3.2",
78
79
  "@eslint/eslintrc": "^3.3.1",
79
80
  "@eslint/js": "^9.35.0",
80
- "@react-native/babel-preset": "0.83.4",
81
- "@react-native/eslint-config": "0.83.4",
81
+ "@react-native/babel-preset": "0.85.3",
82
+ "@react-native/eslint-config": "0.85.3",
83
+ "@react-native/jest-preset": "0.85.3",
82
84
  "@release-it/conventional-changelog": "^10.0.1",
83
85
  "@types/jest": "^29.5.14",
84
86
  "@types/react": "^19.2.0",
@@ -89,12 +91,12 @@
89
91
  "eslint-plugin-prettier": "^5.5.4",
90
92
  "jest": "^29.7.0",
91
93
  "lefthook": "^2.0.3",
92
- "nitrogen": "0.35.6",
94
+ "nitrogen": "0.35.9",
93
95
  "prettier": "^2.8.8",
94
- "react": "19.2.0",
95
- "react-native": "0.83.4",
96
+ "react": "19.2.3",
97
+ "react-native": "0.85.3",
96
98
  "react-native-builder-bob": "^0.40.17",
97
- "react-native-nitro-modules": "0.35.6",
99
+ "react-native-nitro-modules": "0.35.9",
98
100
  "release-it": "^19.0.4",
99
101
  "turbo": "^2.5.6",
100
102
  "typescript": "^5.9.2"
@@ -102,7 +104,7 @@
102
104
  "peerDependencies": {
103
105
  "react": "*",
104
106
  "react-native": "*",
105
- "react-native-nitro-modules": ">= 0.35.6"
107
+ "react-native-nitro-modules": ">= 0.35.9"
106
108
  },
107
109
  "workspaces": [
108
110
  "example"
@@ -134,7 +136,7 @@
134
136
  ]
135
137
  },
136
138
  "jest": {
137
- "preset": "react-native",
139
+ "preset": "@react-native/jest-preset",
138
140
  "modulePathIgnorePatterns": [
139
141
  "<rootDir>/example/node_modules",
140
142
  "<rootDir>/lib/"