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.
- package/ios/NitroSse.swift +51 -7
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockConfig.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +1 -1
- package/package.json +12 -10
package/ios/NitroSse.swift
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
182
|
-
|
|
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
|
-
|
|
229
|
-
|
|
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
|
-
|
|
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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-sse",
|
|
3
|
-
"version": "2.3.
|
|
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
|
|
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.
|
|
81
|
-
"@react-native/eslint-config": "0.
|
|
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.
|
|
94
|
+
"nitrogen": "0.35.9",
|
|
93
95
|
"prettier": "^2.8.8",
|
|
94
|
-
"react": "19.2.
|
|
95
|
-
"react-native": "0.
|
|
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.
|
|
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.
|
|
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/"
|