react-native-nitro-sse 2.0.0 → 2.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.
Files changed (27) hide show
  1. package/NitroSse.podspec +1 -1
  2. package/README.md +4 -0
  3. package/android/build.gradle +1 -0
  4. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +226 -36
  5. package/ios/NitroSse.swift +147 -29
  6. package/lib/module/SseInterface.js +2 -0
  7. package/lib/typescript/src/SseInterface.d.ts +17 -1
  8. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  9. package/nitrogen/generated/android/c++/JFunc_void_std__vector_SseEvent_.hpp +2 -0
  10. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +2 -0
  11. package/nitrogen/generated/android/c++/JSseConfig.hpp +9 -1
  12. package/nitrogen/generated/android/c++/JSseEvent.hpp +7 -1
  13. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +10 -4
  14. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +6 -3
  15. package/nitrogen/generated/ios/NitroSse+autolinking.rb +2 -0
  16. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +16 -0
  17. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
  18. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +1 -0
  19. package/nitrogen/generated/ios/swift/SseConfig.swift +37 -1
  20. package/nitrogen/generated/ios/swift/SseEvent.swift +19 -1
  21. package/nitrogen/generated/shared/c++/SseConfig.hpp +9 -1
  22. package/nitrogen/generated/shared/c++/SseEvent.hpp +6 -1
  23. package/package.json +11 -6
  24. package/src/SseInterface.ts +17 -1
  25. package/android/src/test/java/com/margelo/nitro/nitrosse/HeartbeatScannerTest.kt +0 -98
  26. package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +0 -238
  27. package/ios/Tests/NitroSseTests.swift +0 -242
@@ -1,6 +1,10 @@
1
1
  import Foundation
2
2
  import NitroModules
3
3
  import LDSwiftEventSource
4
+ import Network
5
+ #if os(iOS)
6
+ import UIKit
7
+ #endif
4
8
 
5
9
  /**
6
10
  * NitroSse implements a high-performance SSE client for iOS using LDSwiftEventSource.
@@ -20,11 +24,14 @@ class NitroSse: HybridNitroSseSpec {
20
24
  deinit {
21
25
  if DispatchQueue.getSpecific(key: NitroSse.sseQueueKey) != nil {
22
26
  self.stopInternal()
27
+ self.stopNetworkMonitoring()
23
28
  } else {
24
29
  sseQueue.sync {
25
30
  self.stopInternal()
31
+ self.stopNetworkMonitoring()
26
32
  }
27
33
  }
34
+ NotificationCenter.default.removeObserver(self)
28
35
  }
29
36
  private var eventSource: EventSource?
30
37
  private var config: SseConfig?
@@ -51,8 +58,15 @@ class NitroSse: HybridNitroSseSpec {
51
58
  return queue
52
59
  }()
53
60
  private var connectionAttemptVersion: Int = 0
61
+ #if os(iOS)
54
62
  private var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = .invalid
63
+ #endif
55
64
  private var wasRunningBeforeHibernation: Bool = false
65
+ private var isAppInBackground: Bool = false
66
+
67
+ private var pathMonitor: NWPathMonitor?
68
+ private var lastPathInterface: NWInterface.InterfaceType?
69
+ private var wasRunningBeforeNetworkLoss: Bool = false
56
70
 
57
71
  /**
58
72
  * Set up the NitroSse instance with configuration and an event callback.
@@ -68,24 +82,107 @@ class NitroSse: HybridNitroSseSpec {
68
82
  self.onEventsCallback = onEvent
69
83
 
70
84
  NotificationCenter.default.removeObserver(self)
85
+ #if os(iOS)
71
86
  NotificationCenter.default.addObserver(self, selector: #selector(self.handleAppDidEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
72
87
  NotificationCenter.default.addObserver(self, selector: #selector(self.handleAppWillEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
88
+ #endif
89
+
90
+ if config.monitorNetwork != false {
91
+ self.startNetworkMonitoring()
92
+ } else {
93
+ self.stopNetworkMonitoring()
94
+ }
95
+ }
96
+ }
97
+
98
+ private func stopNetworkMonitoring() {
99
+ dispatchPrecondition(condition: .onQueue(sseQueue))
100
+ pathMonitor?.cancel()
101
+ pathMonitor = nil
102
+ lastPathInterface = nil
103
+ }
104
+
105
+ private func startNetworkMonitoring() {
106
+ dispatchPrecondition(condition: .onQueue(sseQueue))
107
+ guard pathMonitor == nil else { return }
108
+
109
+ let monitor = NWPathMonitor()
110
+ monitor.pathUpdateHandler = { [weak self] path in
111
+ self?.sseQueue.async {
112
+ self?.handleNetworkChange(path: path)
113
+ }
114
+ }
115
+ self.pathMonitor = monitor
116
+ monitor.start(queue: sseQueue)
117
+ }
118
+
119
+ private func handleNetworkChange(path: NWPath) {
120
+ dispatchPrecondition(condition: .onQueue(sseQueue))
121
+ let isSatisfied = path.status == .satisfied
122
+
123
+ var interfaceType: NWInterface.InterfaceType? = nil
124
+ if path.usesInterfaceType(.wifi) {
125
+ interfaceType = .wifi
126
+ } else if path.usesInterfaceType(.cellular) {
127
+ interfaceType = .cellular
128
+ } else if path.usesInterfaceType(.wiredEthernet) {
129
+ interfaceType = .wiredEthernet
130
+ } else {
131
+ interfaceType = path.availableInterfaces.first?.type
132
+ }
133
+
134
+ print("[NitroSse] Network path changed: status=\(path.status), interface=\(String(describing: interfaceType))")
135
+
136
+ if isSatisfied {
137
+ if wasRunningBeforeNetworkLoss {
138
+ print("[NitroSse] Network restored. Resuming stream.")
139
+ wasRunningBeforeNetworkLoss = false
140
+ if self.isAppInBackground && self.config?.backgroundExecution != true {
141
+ self.wasRunningBeforeHibernation = true
142
+ } else if isRunning {
143
+ self.restart()
144
+ } else {
145
+ try? self.start()
146
+ }
147
+ } else if isRunning {
148
+ if let lastInterface = lastPathInterface, let currentInterface = interfaceType, lastInterface != currentInterface {
149
+ print("[NitroSse] Network interface changed (\(lastInterface) -> \(currentInterface)). Restarting stream.")
150
+ self.restart()
151
+ } else if lastPathInterface == nil {
152
+ print("[NitroSse] Network interface acquired. Restarting stream.")
153
+ self.restart()
154
+ }
155
+ }
156
+ } else {
157
+ if isRunning {
158
+ print("[NitroSse] Network lost. Hibernating.")
159
+ wasRunningBeforeNetworkLoss = true
160
+ self.hibernateConnection()
161
+ }
162
+ }
163
+
164
+ if isSatisfied {
165
+ self.lastPathInterface = interfaceType
73
166
  }
74
167
  }
75
168
 
76
169
  @objc private func handleAppDidEnterBackground() {
77
170
  sseQueue.async {
171
+ self.isAppInBackground = true
78
172
  guard self.isRunning, let config = self.config else { return }
79
173
 
80
174
  if config.backgroundExecution == true {
81
175
  print("[NitroSse] App backgrounded. backgroundExecution is true, keeping connection alive.")
176
+ #if os(iOS)
82
177
  // Start a background task to tell the OS we want to keep running
178
+ self.cleanupBackgroundTask()
83
179
  self.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(withName: "NitroSse-KeepAlive") { [weak self] in
84
180
  self?.sseQueue.async {
85
181
  print("[NitroSse] Background task expired. Hibernating now.")
86
182
  self?.hibernateConnection()
87
183
  }
88
184
  }
185
+ #endif
89
186
  return
90
187
  }
91
188
 
@@ -115,6 +212,7 @@ class NitroSse: HybridNitroSseSpec {
115
212
 
116
213
  @objc private func handleAppWillEnterForeground() {
117
214
  sseQueue.async {
215
+ self.isAppInBackground = false
118
216
  self.cleanupBackgroundTask()
119
217
  if self.wasRunningBeforeHibernation {
120
218
  print("[NitroSse] App foregrounded. Resuming stream.")
@@ -126,10 +224,12 @@ class NitroSse: HybridNitroSseSpec {
126
224
 
127
225
  private func cleanupBackgroundTask() {
128
226
  dispatchPrecondition(condition: .onQueue(sseQueue))
227
+ #if os(iOS)
129
228
  if self.backgroundTaskIdentifier != .invalid {
130
229
  UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier)
131
230
  self.backgroundTaskIdentifier = .invalid
132
231
  }
232
+ #endif
133
233
  }
134
234
 
135
235
  private func pushEventToBuffer(_ event: SseEvent) {
@@ -152,20 +252,30 @@ class NitroSse: HybridNitroSseSpec {
152
252
  }
153
253
  }
154
254
  }
155
-
156
255
  private func flushEventsToJs() {
157
256
  dispatchPrecondition(condition: .onQueue(sseQueue))
158
- guard !eventBuffer.isEmpty else {
159
- isFlushPending = false
160
- return
161
- }
257
+ guard !eventBuffer.isEmpty else { return }
162
258
 
163
259
  let batch = eventBuffer
164
260
  eventBuffer.removeAll()
165
261
  isFlushPending = false
262
+
166
263
  onEventsCallback?(batch)
167
264
  }
168
265
 
266
+ internal func parseJsonToAnyMap(_ data: String) -> AnyMap? {
267
+ guard let jsonData = data.data(using: .utf8) else { return nil }
268
+ do {
269
+ if let dictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any?] {
270
+ return AnyMap.fromDictionaryIgnoreIncompatible(dictionary)
271
+ }
272
+ } catch {
273
+ // Non-fatal, just log and return nil
274
+ print("[NitroSse] Failed to parse JSON: \(error.localizedDescription)")
275
+ }
276
+ return nil
277
+ }
278
+
169
279
  /**
170
280
  * Manually set the last seen event ID.
171
281
  * This will be used as the 'Last-Event-ID' header on the next connection attempt.
@@ -196,6 +306,8 @@ class NitroSse: HybridNitroSseSpec {
196
306
  maxRetryIntervalMs: config.maxRetryIntervalMs,
197
307
  jitterFactor: config.jitterFactor,
198
308
  maxReconnectAttempts: config.maxReconnectAttempts,
309
+ autoParseJSON: config.autoParseJSON,
310
+ monitorNetwork: config.monitorNetwork,
199
311
  onBeforeRequest: config.onBeforeRequest
200
312
  )
201
313
  print("[NitroSse] Headers updated for subsequent connections.")
@@ -226,7 +338,7 @@ class NitroSse: HybridNitroSseSpec {
226
338
 
227
339
  // Critical check: Ensure config is available before starting
228
340
  guard self.config != nil else {
229
- throw NSError(domain: "NitroSse", code: -1, userInfo: [NSLocalizedDescriptionKey: "NitroSse not configured. Call setup() first."])
341
+ throw RuntimeError("NitroSse not configured. Call setup() first.")
230
342
  }
231
343
 
232
344
  self.isRunning = true
@@ -265,8 +377,8 @@ class NitroSse: HybridNitroSseSpec {
265
377
 
266
378
  sseQueue.asyncAfter(deadline: .now() + (timeoutMs / 1000.0)) { [weak self] in
267
379
  guard let self = self else { return }
268
- self.sseQueue.async {
269
- guard self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
380
+ self.sseQueue.async { [weak self] in
381
+ guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
270
382
  if !flag.isCompleted {
271
383
  flag.isCompleted = true
272
384
  let error = NSError(domain: "NitroSse", code: -1, userInfo: [NSLocalizedDescriptionKey: "onBeforeRequest interceptor timed out after \(timeoutMs) ms"])
@@ -277,7 +389,7 @@ class NitroSse: HybridNitroSseSpec {
277
389
 
278
390
  interceptor().then { [weak self] promise2 in
279
391
  promise2.then { [weak self] newHeaders in
280
- self?.sseQueue.async {
392
+ self?.sseQueue.async { [weak self] in
281
393
  guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
282
394
  if !flag.isCompleted {
283
395
  flag.isCompleted = true
@@ -300,13 +412,15 @@ class NitroSse: HybridNitroSseSpec {
300
412
  maxRetryIntervalMs: currentConfig.maxRetryIntervalMs,
301
413
  jitterFactor: currentConfig.jitterFactor,
302
414
  maxReconnectAttempts: currentConfig.maxReconnectAttempts,
415
+ autoParseJSON: currentConfig.autoParseJSON,
416
+ monitorNetwork: currentConfig.monitorNetwork,
303
417
  onBeforeRequest: currentConfig.onBeforeRequest
304
418
  )
305
419
  self.performEstablishConnection(attemptVersion: attemptVersion)
306
420
  }
307
421
  }
308
422
  }.catch { [weak self] error in
309
- self?.sseQueue.async {
423
+ self?.sseQueue.async { [weak self] in
310
424
  guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
311
425
  if !flag.isCompleted {
312
426
  flag.isCompleted = true
@@ -315,7 +429,7 @@ class NitroSse: HybridNitroSseSpec {
315
429
  }
316
430
  }
317
431
  }.catch { [weak self] error in
318
- self?.sseQueue.async {
432
+ self?.sseQueue.async { [weak self] in
319
433
  guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
320
434
  if !flag.isCompleted {
321
435
  flag.isCompleted = true
@@ -332,7 +446,7 @@ class NitroSse: HybridNitroSseSpec {
332
446
  dispatchPrecondition(condition: .onQueue(sseQueue))
333
447
  guard self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
334
448
  print("[NitroSse] Interceptor failed: \(error.localizedDescription)")
335
- self.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Interceptor Error: \(error.localizedDescription)", statusCode: -1, retry: nil))
449
+ self.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Interceptor Error: \(error.localizedDescription)", statusCode: -1, retry: nil))
336
450
  // Reconnect after delay
337
451
  self.scheduleAutomaticReconnect(isError: true, attemptVersion: attemptVersion)
338
452
  }
@@ -387,6 +501,8 @@ class NitroSse: HybridNitroSseSpec {
387
501
  private func stopInternal() {
388
502
  dispatchPrecondition(condition: .onQueue(sseQueue))
389
503
  self.isRunning = false
504
+ self.wasRunningBeforeNetworkLoss = false
505
+ self.wasRunningBeforeHibernation = false
390
506
  self.eventSource?.stop()
391
507
  self.eventSource = nil
392
508
  if let rid = self.requestId {
@@ -480,7 +596,7 @@ class NitroSse: HybridNitroSseSpec {
480
596
  let maxAttempts = Int(config?.maxReconnectAttempts ?? -1.0)
481
597
  if maxAttempts != -1 && currentReconnectAttempts >= maxAttempts {
482
598
  print("[NitroSse] Max reconnection attempts reached (\(maxAttempts)). Stopping.")
483
- self.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Max reconnection attempts reached (\(maxAttempts)).", statusCode: nil, retry: nil))
599
+ self.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Max reconnection attempts reached (\(maxAttempts)).", statusCode: nil, retry: nil))
484
600
  self.stopInternal()
485
601
  return
486
602
  }
@@ -522,18 +638,18 @@ class NitroSse: HybridNitroSseSpec {
522
638
  ///
523
639
  /// If this handler corresponds to the active connection and its attempt version matches the parent's current connectionAttemptVersion, resets `backoffCounter`, `currentReconnectAttempts`, and `consecutiveAuthErrors`, and enqueues an `.open` `SseEvent` with status code 200.
524
640
  func onOpened() {
525
- guard let parent = parent, source === parent.eventSource else { return }
641
+ guard let parent = self.parent, source === parent.eventSource else { return }
526
642
  parent.sseQueue.async { [weak parent] in
527
643
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
528
644
  parent.backoffCounter = 0
529
645
  parent.currentReconnectAttempts = 0
530
646
  parent.consecutiveAuthErrors = 0
531
- parent.pushEventToBuffer(SseEvent(type: .open, data: nil, id: nil, event: nil, message: nil, statusCode: 200, retry: nil))
647
+ parent.pushEventToBuffer(SseEvent(type: .open, data: nil, parsedData: nil, id: nil, event: nil, message: nil, statusCode: 200, retry: nil))
532
648
  }
533
649
  }
534
650
 
535
651
  func onClosed() {
536
- guard let parent = parent, source === parent.eventSource else { return }
652
+ guard let parent = self.parent, source === parent.eventSource else { return }
537
653
  parent.sseQueue.async { [weak parent] in
538
654
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
539
655
  if let rid = parent.requestId {
@@ -547,7 +663,7 @@ class NitroSse: HybridNitroSseSpec {
547
663
  }
548
664
 
549
665
  func onMessage(eventType: String, messageEvent: MessageEvent) {
550
- guard let parent = parent, source === parent.eventSource else { return }
666
+ guard let parent = self.parent, source === parent.eventSource else { return }
551
667
  parent.sseQueue.async { [weak parent] in
552
668
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
553
669
  let encodedDataSize = Double(messageEvent.data.utf8.count)
@@ -558,21 +674,23 @@ class NitroSse: HybridNitroSseSpec {
558
674
  parent.lastProcessedId = messageEvent.lastEventId
559
675
  }
560
676
 
561
- parent.pushEventToBuffer(SseEvent(type: .message, data: messageEvent.data, id: messageEvent.lastEventId, event: eventType, message: nil, statusCode: 200, retry: nil))
677
+ let parsedData = (parent.config?.autoParseJSON == true) ? parent.parseJsonToAnyMap(messageEvent.data) : nil
678
+
679
+ parent.pushEventToBuffer(SseEvent(type: .message, data: messageEvent.data, parsedData: parsedData, id: messageEvent.lastEventId, event: eventType, message: nil, statusCode: 200, retry: nil))
562
680
  }
563
681
  }
564
682
 
565
683
  func onComment(comment: String) {
566
- guard let parent = parent, source === parent.eventSource else { return }
684
+ guard let parent = self.parent, source === parent.eventSource else { return }
567
685
  parent.sseQueue.async { [weak parent] in
568
686
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
569
687
  parent.totalBytesReceived += Double(comment.utf8.count)
570
- parent.pushEventToBuffer(SseEvent(type: .heartbeat, data: nil, id: nil, event: nil, message: comment, statusCode: nil, retry: nil))
688
+ parent.pushEventToBuffer(SseEvent(type: .heartbeat, data: nil, parsedData: nil, id: nil, event: nil, message: comment, statusCode: nil, retry: nil))
571
689
  }
572
690
  }
573
691
 
574
692
  func onError(error: Error) {
575
- guard let parent = parent, source === parent.eventSource else { return }
693
+ guard let parent = self.parent, source === parent.eventSource else { return }
576
694
  parent.sseQueue.async { [weak parent] in
577
695
  guard let parent = parent, parent.isRunning, self.attemptVersion == parent.connectionAttemptVersion else { return }
578
696
  let nsError = error as NSError
@@ -586,33 +704,33 @@ class NitroSse: HybridNitroSseSpec {
586
704
  parent.requestId = nil
587
705
 
588
706
  if statusCode == 204 {
589
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "No Content (204). Stopping.", statusCode: 204, retry: nil))
707
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "No Content (204). Stopping.", statusCode: 204, retry: nil))
590
708
  parent.stopInternal()
591
709
  return
592
710
  }
593
711
 
594
712
  if statusCode == 401 || statusCode == 403 {
595
713
  if parent.config?.onBeforeRequest == nil {
596
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - No interceptor provided. Stopping.", statusCode: Double(statusCode), retry: nil))
714
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - No interceptor provided. Stopping.", statusCode: Double(statusCode), retry: nil))
597
715
  parent.stopInternal()
598
716
  return
599
717
  }
600
718
 
601
719
  parent.consecutiveAuthErrors += 1
602
720
  if parent.consecutiveAuthErrors >= parent.maxAuthRetries {
603
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - Retry limit reached (\(parent.maxAuthRetries)). Stopping.", statusCode: Double(statusCode), retry: nil))
721
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - Retry limit reached (\(parent.maxAuthRetries)). Stopping.", statusCode: Double(statusCode), retry: nil))
604
722
  parent.stopInternal()
605
723
  return
606
724
  }
607
725
 
608
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - Retry \(parent.consecutiveAuthErrors)/\(parent.maxAuthRetries). Refreshing token...", statusCode: Double(statusCode), retry: nil))
726
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - Retry \(parent.consecutiveAuthErrors)/\(parent.maxAuthRetries). Refreshing token...", statusCode: Double(statusCode), retry: nil))
609
727
  parent.scheduleAutomaticReconnect(isError: true, attemptVersion: self.attemptVersion)
610
728
  return
611
729
  }
612
730
 
613
731
  let isFatal = (statusCode == 400)
614
732
  if isFatal {
615
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Fatal Error (\(statusCode)). Stopping.", statusCode: Double(statusCode), retry: nil))
733
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Fatal Error (\(statusCode)). Stopping.", statusCode: Double(statusCode), retry: nil))
616
734
  parent.stopInternal()
617
735
  return
618
736
  }
@@ -621,18 +739,18 @@ class NitroSse: HybridNitroSseSpec {
621
739
  if (statusCode == 429 || statusCode == 503), let retryAfter = retryAfterSeconds {
622
740
  let jitter = Double.random(in: 0.5...1.5)
623
741
  let totalDelay = retryAfter + jitter
624
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Retry-After received: \(Int(totalDelay))s", statusCode: Double(statusCode), retry: totalDelay * 1000.0))
742
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Retry-After received: \(Int(totalDelay))s", statusCode: Double(statusCode), retry: totalDelay * 1000.0))
625
743
  parent.scheduleAutomaticReconnectWithFixedDelay(totalDelay, attemptVersion: self.attemptVersion)
626
744
  return
627
745
  }
628
746
 
629
747
  if statusCode == 429 {
630
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Rate Limited (429) without Retry-After. Stopping.", statusCode: 429, retry: nil))
748
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Rate Limited (429) without Retry-After. Stopping.", statusCode: 429, retry: nil))
631
749
  parent.stopInternal()
632
750
  return
633
751
  }
634
752
 
635
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: error.localizedDescription, statusCode: Double(statusCode), retry: nil))
753
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: error.localizedDescription, statusCode: Double(statusCode), retry: nil))
636
754
  parent.scheduleAutomaticReconnect(isError: true, attemptVersion: self.attemptVersion)
637
755
  }
638
756
  }
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
+
3
+ export {};
2
4
  //# sourceMappingURL=SseInterface.js.map
@@ -1,3 +1,4 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules';
1
2
  /**
2
3
  * HTTP method to use for the SSE connection.
3
4
  */
@@ -78,6 +79,19 @@ export interface SseConfig {
78
79
  * @default -1
79
80
  */
80
81
  maxReconnectAttempts?: number;
82
+ /**
83
+ * Whether to automatically parse message data as JSON in a background native thread.
84
+ * If true, and parsing succeeds, the result will be available in the 'parsedData' field.
85
+ * @default false
86
+ */
87
+ autoParseJSON?: boolean;
88
+ /**
89
+ * Whether to automatically monitor network connectivity changes.
90
+ * If true, the client will proactively reconnect when switching networks (WiFi <-> Cellular)
91
+ * and pause/resume based on internet availability.
92
+ * @default true
93
+ */
94
+ monitorNetwork?: boolean;
81
95
  /**
82
96
  * Async interceptor called before every connection attempt (including auto-reconnects).
83
97
  * Use this to refresh tokens or calculate dynamic headers.
@@ -91,8 +105,10 @@ export interface SseConfig {
91
105
  export interface SseEvent {
92
106
  /** The type of the event. */
93
107
  type: SseEventType;
94
- /** The data payload of the event. */
108
+ /** The data payload of the event as a raw string. */
95
109
  data?: string;
110
+ /** The parsed JSON data, if autoParseJSON is enabled and parsing succeeds. */
111
+ parsedData?: AnyMap;
96
112
  /** The event ID, if provided. */
97
113
  id?: string;
98
114
  /** The event name, if provided (internal 'event' field in SSE). */
@@ -1 +1 @@
1
- {"version":3,"file":"SseInterface.d.ts","sourceRoot":"","sources":["../../../src/SseInterface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,kBAAkB,CAA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
22
+ #include <NitroModules/AnyMap.hpp>
23
+ #include <NitroModules/JAnyMap.hpp>
22
24
 
23
25
  namespace margelo::nitro::nitrosse {
24
26
 
@@ -38,6 +38,8 @@ namespace margelo::nitro::nitrosse { enum class SseEventType; }
38
38
  #include "JSseEvent.hpp"
39
39
  #include "SseEventType.hpp"
40
40
  #include "JSseEventType.hpp"
41
+ #include <NitroModules/AnyMap.hpp>
42
+ #include <NitroModules/JAnyMap.hpp>
41
43
 
42
44
  namespace margelo::nitro::nitrosse {
43
45
 
@@ -66,6 +66,10 @@ namespace margelo::nitro::nitrosse {
66
66
  jni::local_ref<jni::JDouble> jitterFactor = this->getFieldValue(fieldJitterFactor);
67
67
  static const auto fieldMaxReconnectAttempts = clazz->getField<jni::JDouble>("maxReconnectAttempts");
68
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);
71
+ static const auto fieldMonitorNetwork = clazz->getField<jni::JBoolean>("monitorNetwork");
72
+ jni::local_ref<jni::JBoolean> monitorNetwork = this->getFieldValue(fieldMonitorNetwork);
69
73
  static const auto fieldOnBeforeRequest = clazz->getField<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>("onBeforeRequest");
70
74
  jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject> onBeforeRequest = this->getFieldValue(fieldOnBeforeRequest);
71
75
  return SseConfig(
@@ -89,6 +93,8 @@ namespace margelo::nitro::nitrosse {
89
93
  maxRetryIntervalMs != nullptr ? std::make_optional(maxRetryIntervalMs->value()) : std::nullopt,
90
94
  jitterFactor != nullptr ? std::make_optional(jitterFactor->value()) : std::nullopt,
91
95
  maxReconnectAttempts != nullptr ? std::make_optional(maxReconnectAttempts->value()) : std::nullopt,
96
+ autoParseJSON != nullptr ? std::make_optional(static_cast<bool>(autoParseJSON->value())) : std::nullopt,
97
+ monitorNetwork != nullptr ? std::make_optional(static_cast<bool>(monitorNetwork->value())) : std::nullopt,
92
98
  onBeforeRequest != nullptr ? std::make_optional([&]() -> std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> {
93
99
  if (onBeforeRequest->isInstanceOf(JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaClassStatic())) [[likely]] {
94
100
  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);
@@ -107,7 +113,7 @@ namespace margelo::nitro::nitrosse {
107
113
  */
108
114
  [[maybe_unused]]
109
115
  static jni::local_ref<JSseConfig::javaobject> fromCpp(const SseConfig& value) {
110
- 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<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>);
116
+ 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<jni::JBoolean>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>);
111
117
  static const auto clazz = javaClassStatic();
112
118
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
113
119
  return create(
@@ -131,6 +137,8 @@ namespace margelo::nitro::nitrosse {
131
137
  value.maxRetryIntervalMs.has_value() ? jni::JDouble::valueOf(value.maxRetryIntervalMs.value()) : nullptr,
132
138
  value.jitterFactor.has_value() ? jni::JDouble::valueOf(value.jitterFactor.value()) : nullptr,
133
139
  value.maxReconnectAttempts.has_value() ? jni::JDouble::valueOf(value.maxReconnectAttempts.value()) : nullptr,
140
+ value.autoParseJSON.has_value() ? jni::JBoolean::valueOf(value.autoParseJSON.value()) : nullptr,
141
+ value.monitorNetwork.has_value() ? jni::JBoolean::valueOf(value.monitorNetwork.value()) : nullptr,
134
142
  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
135
143
  );
136
144
  }
@@ -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,
@@ -58,13 +58,19 @@ data class SseConfig(
58
58
  val maxReconnectAttempts: Double?,
59
59
  @DoNotStrip
60
60
  @Keep
61
+ val autoParseJSON: Boolean?,
62
+ @DoNotStrip
63
+ @Keep
64
+ val monitorNetwork: Boolean?,
65
+ @DoNotStrip
66
+ @Keep
61
67
  val onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?
62
68
  ) {
63
69
  /**
64
70
  * Create a new instance of SseConfig from Kotlin
65
71
  */
66
- 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?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?):
67
- this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) })
72
+ 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?, monitorNetwork: Boolean?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?):
73
+ this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, autoParseJSON, monitorNetwork, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) })
68
74
 
69
75
  companion object {
70
76
  /**
@@ -74,8 +80,8 @@ data class SseConfig(
74
80
  @Keep
75
81
  @Suppress("unused")
76
82
  @JvmStatic
77
- 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?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?): SseConfig {
78
- return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, onBeforeRequest)
83
+ 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?, monitorNetwork: Boolean?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?): SseConfig {
84
+ return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, autoParseJSON, monitorNetwork, onBeforeRequest)
79
85
  }
80
86
  }
81
87
  }
@@ -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
  }
@@ -56,5 +56,7 @@ def add_nitrogen_files(spec)
56
56
  "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
57
  # Enables stricter modular headers
58
58
  "DEFINES_MODULE" => "YES",
59
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
60
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
59
61
  })
60
62
  end