react-native-nitro-sse 1.6.2 → 2.1.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 (35) hide show
  1. package/README.md +2 -0
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +256 -95
  4. package/ios/NitroSse.swift +90 -39
  5. package/lib/module/NitroSseClient.js +75 -0
  6. package/lib/module/NitroSseClient.js.map +1 -0
  7. package/lib/module/SseInterface.js +2 -0
  8. package/lib/module/index.js +9 -1
  9. package/lib/module/index.js.map +1 -1
  10. package/lib/typescript/src/NitroSseClient.d.ts +21 -0
  11. package/lib/typescript/src/NitroSseClient.d.ts.map +1 -0
  12. package/lib/typescript/src/SseInterface.d.ts +74 -2
  13. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  14. package/lib/typescript/src/index.d.ts +8 -2
  15. package/lib/typescript/src/index.d.ts.map +1 -1
  16. package/nitrogen/generated/android/c++/JFunc_void_std__vector_SseEvent_.hpp +2 -0
  17. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +2 -0
  18. package/nitrogen/generated/android/c++/JSseConfig.hpp +21 -1
  19. package/nitrogen/generated/android/c++/JSseEvent.hpp +7 -1
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +19 -4
  21. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +6 -3
  22. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +16 -0
  23. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
  24. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +1 -0
  25. package/nitrogen/generated/ios/swift/SseConfig.swift +91 -1
  26. package/nitrogen/generated/ios/swift/SseEvent.swift +19 -1
  27. package/nitrogen/generated/shared/c++/SseConfig.hpp +21 -1
  28. package/nitrogen/generated/shared/c++/SseEvent.hpp +6 -1
  29. package/package.json +9 -4
  30. package/src/NitroSseClient.ts +96 -0
  31. package/src/SseInterface.ts +79 -2
  32. package/src/index.ts +10 -2
  33. package/android/src/test/java/com/margelo/nitro/nitrosse/HeartbeatScannerTest.kt +0 -98
  34. package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +0 -157
  35. package/ios/Tests/NitroSseTests.swift +0 -122
@@ -37,6 +37,7 @@ class NitroSse: HybridNitroSseSpec {
37
37
  private var isFlushPending: Bool = false
38
38
 
39
39
  private var backoffCounter: Int = 0
40
+ private var currentReconnectAttempts: Int = 0
40
41
  private var lastProcessedId: String? = nil
41
42
 
42
43
  private var totalBytesReceived: Double = 0
@@ -44,10 +45,6 @@ class NitroSse: HybridNitroSseSpec {
44
45
  private var lastErrorTime: Double? = nil
45
46
  private var lastErrorCode: String? = nil
46
47
 
47
- private let defaultRetryDelay: TimeInterval = 3.0
48
- private let baseBackoffDelay: TimeInterval = 1.0
49
- private let maxBackoffDelay: TimeInterval = 30.0
50
-
51
48
  private let sseQueue: DispatchQueue = {
52
49
  let queue = DispatchQueue(label: "com.margelo.nitro.sse", qos: .utility)
53
50
  queue.setSpecific(key: NitroSse.sseQueueKey, value: ())
@@ -155,20 +152,30 @@ class NitroSse: HybridNitroSseSpec {
155
152
  }
156
153
  }
157
154
  }
158
-
159
155
  private func flushEventsToJs() {
160
156
  dispatchPrecondition(condition: .onQueue(sseQueue))
161
- guard !eventBuffer.isEmpty else {
162
- isFlushPending = false
163
- return
164
- }
157
+ guard !eventBuffer.isEmpty else { return }
165
158
 
166
159
  let batch = eventBuffer
167
160
  eventBuffer.removeAll()
168
161
  isFlushPending = false
162
+
169
163
  onEventsCallback?(batch)
170
164
  }
171
165
 
166
+ internal func parseJsonToAnyMap(_ data: String) -> AnyMap? {
167
+ guard let jsonData = data.data(using: .utf8) else { return nil }
168
+ do {
169
+ if let dictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any?] {
170
+ return AnyMap.fromDictionaryIgnoreIncompatible(dictionary)
171
+ }
172
+ } catch {
173
+ // Non-fatal, just log and return nil
174
+ print("[NitroSse] Failed to parse JSON: \(error.localizedDescription)")
175
+ }
176
+ return nil
177
+ }
178
+
172
179
  /**
173
180
  * Manually set the last seen event ID.
174
181
  * This will be used as the 'Last-Event-ID' header on the next connection attempt.
@@ -179,9 +186,9 @@ class NitroSse: HybridNitroSseSpec {
179
186
  }
180
187
  }
181
188
 
182
- /**
183
- * Dynamically update the headers for subsequent connection attempts.
184
- */
189
+ /// Update the HTTP headers that will be used for subsequent SSE connections.
190
+ /// - Parameters:
191
+ /// - headers: A dictionary of HTTP header names and values to replace the current headers for future connections.
185
192
  func updateHeaders(headers: [String: String]) throws {
186
193
  sseQueue.async {
187
194
  guard let config = self.config else { return }
@@ -195,6 +202,11 @@ class NitroSse: HybridNitroSseSpec {
195
202
  maxBufferSize: config.maxBufferSize,
196
203
  connectionTimeoutMs: config.connectionTimeoutMs,
197
204
  readTimeoutMs: config.readTimeoutMs,
205
+ retryIntervalMs: config.retryIntervalMs,
206
+ maxRetryIntervalMs: config.maxRetryIntervalMs,
207
+ jitterFactor: config.jitterFactor,
208
+ maxReconnectAttempts: config.maxReconnectAttempts,
209
+ autoParseJSON: config.autoParseJSON,
198
210
  onBeforeRequest: config.onBeforeRequest
199
211
  )
200
212
  print("[NitroSse] Headers updated for subsequent connections.")
@@ -244,6 +256,11 @@ class NitroSse: HybridNitroSseSpec {
244
256
  }
245
257
  }
246
258
 
259
+ /// Initiates a new SSE connection attempt using the current configuration, honoring the provided attempt version to ignore stale async work.
260
+ ///
261
+ /// If a configured `onBeforeRequest` interceptor is present, this method executes it (with a configurable timeout); when the interceptor resolves with additional headers those headers are merged into the active configuration before proceeding. If the interceptor fails or times out, interceptor error handling is invoked. If no interceptor is configured, the connection is established immediately.
262
+ /// - Parameters:
263
+ /// - attemptVersion: A numeric token representing the connection attempt version; the method aborts if this does not match the current `connectionAttemptVersion`, ensuring stale asynchronous results are ignored.
247
264
  private func establishConnection(attemptVersion: Int) {
248
265
  dispatchPrecondition(condition: .onQueue(sseQueue))
249
266
  guard isRunning, let config = config, attemptVersion == self.connectionAttemptVersion else { return }
@@ -259,8 +276,8 @@ class NitroSse: HybridNitroSseSpec {
259
276
 
260
277
  sseQueue.asyncAfter(deadline: .now() + (timeoutMs / 1000.0)) { [weak self] in
261
278
  guard let self = self else { return }
262
- self.sseQueue.async {
263
- guard self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
279
+ self.sseQueue.async { [weak self] in
280
+ guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
264
281
  if !flag.isCompleted {
265
282
  flag.isCompleted = true
266
283
  let error = NSError(domain: "NitroSse", code: -1, userInfo: [NSLocalizedDescriptionKey: "onBeforeRequest interceptor timed out after \(timeoutMs) ms"])
@@ -271,7 +288,7 @@ class NitroSse: HybridNitroSseSpec {
271
288
 
272
289
  interceptor().then { [weak self] promise2 in
273
290
  promise2.then { [weak self] newHeaders in
274
- self?.sseQueue.async {
291
+ self?.sseQueue.async { [weak self] in
275
292
  guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
276
293
  if !flag.isCompleted {
277
294
  flag.isCompleted = true
@@ -290,13 +307,18 @@ class NitroSse: HybridNitroSseSpec {
290
307
  maxBufferSize: currentConfig.maxBufferSize,
291
308
  connectionTimeoutMs: currentConfig.connectionTimeoutMs,
292
309
  readTimeoutMs: currentConfig.readTimeoutMs,
310
+ retryIntervalMs: currentConfig.retryIntervalMs,
311
+ maxRetryIntervalMs: currentConfig.maxRetryIntervalMs,
312
+ jitterFactor: currentConfig.jitterFactor,
313
+ maxReconnectAttempts: currentConfig.maxReconnectAttempts,
314
+ autoParseJSON: currentConfig.autoParseJSON,
293
315
  onBeforeRequest: currentConfig.onBeforeRequest
294
316
  )
295
317
  self.performEstablishConnection(attemptVersion: attemptVersion)
296
318
  }
297
319
  }
298
320
  }.catch { [weak self] error in
299
- self?.sseQueue.async {
321
+ self?.sseQueue.async { [weak self] in
300
322
  guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
301
323
  if !flag.isCompleted {
302
324
  flag.isCompleted = true
@@ -305,7 +327,7 @@ class NitroSse: HybridNitroSseSpec {
305
327
  }
306
328
  }
307
329
  }.catch { [weak self] error in
308
- self?.sseQueue.async {
330
+ self?.sseQueue.async { [weak self] in
309
331
  guard let self = self, self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
310
332
  if !flag.isCompleted {
311
333
  flag.isCompleted = true
@@ -322,7 +344,7 @@ class NitroSse: HybridNitroSseSpec {
322
344
  dispatchPrecondition(condition: .onQueue(sseQueue))
323
345
  guard self.isRunning, attemptVersion == self.connectionAttemptVersion else { return }
324
346
  print("[NitroSse] Interceptor failed: \(error.localizedDescription)")
325
- self.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Interceptor Error: \(error.localizedDescription)", statusCode: -1, retry: nil))
347
+ self.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Interceptor Error: \(error.localizedDescription)", statusCode: -1, retry: nil))
326
348
  // Reconnect after delay
327
349
  self.scheduleAutomaticReconnect(isError: true, attemptVersion: attemptVersion)
328
350
  }
@@ -451,19 +473,42 @@ class NitroSse: HybridNitroSseSpec {
451
473
  }
452
474
  }
453
475
 
476
+ /// Schedules an automatic reconnection attempt using the configured retry interval, exponential backoff, and jitter.
477
+ ///
478
+ /// If the configured maximum reconnect attempts has been reached, this method emits an error event and stops the connection instead of scheduling a reconnect. Otherwise it increments the reconnect attempt counter, computes a delay (exponential backoff when `isError` is true, with jitter applied and a minimum delay of 1 second), clears the current event source, and schedules `establishConnection(attemptVersion:)` to run after the computed delay only if the client is still running and the provided `attemptVersion` matches the current connection attempt version.
479
+ /// - Parameters:
480
+ /// - isError: Whether the reconnect is being scheduled in response to an error (affects use of exponential backoff).
481
+ /// - attemptVersion: The connection attempt version that must match the current `connectionAttemptVersion` when the scheduled reconnect fires; used to ignore stale or superseded reconnect attempts.
454
482
  private func scheduleAutomaticReconnect(isError: Bool, attemptVersion: Int) {
455
483
  dispatchPrecondition(condition: .onQueue(sseQueue))
456
484
  eventSource?.stop()
457
- var delay: TimeInterval = defaultRetryDelay
485
+
486
+ let jitterFactor = config?.jitterFactor ?? 0.5
487
+ let retryInterval = (config?.retryIntervalMs ?? 1000.0) / 1000.0
488
+ let maxRetryInterval = (config?.maxRetryIntervalMs ?? 30000.0) / 1000.0
489
+
490
+ var delay: TimeInterval = retryInterval
491
+
492
+ let maxAttempts = Int(config?.maxReconnectAttempts ?? -1.0)
493
+ if maxAttempts != -1 && currentReconnectAttempts >= maxAttempts {
494
+ print("[NitroSse] Max reconnection attempts reached (\(maxAttempts)). Stopping.")
495
+ self.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Max reconnection attempts reached (\(maxAttempts)).", statusCode: nil, retry: nil))
496
+ self.stopInternal()
497
+ return
498
+ }
499
+
500
+ currentReconnectAttempts += 1
501
+
458
502
  if isError {
459
503
  let exponent = Double(backoffCounter)
460
- let base = min(baseBackoffDelay * pow(2.0, exponent), maxBackoffDelay)
504
+ let base = min(retryInterval * pow(2.0, exponent), maxRetryInterval)
461
505
  backoffCounter += 1
462
- delay = base * (0.5 + Double.random(in: 0...1))
506
+ delay = base * (1.0 - jitterFactor + Double.random(in: 0...(2 * jitterFactor)))
463
507
  } else {
464
- delay = defaultRetryDelay * (0.8 + Double.random(in: 0...0.4))
508
+ delay = retryInterval * (1.0 - jitterFactor + Double.random(in: 0...(2 * jitterFactor)))
465
509
  }
466
- let safeDelay = max(delay, 2.0)
510
+
511
+ let safeDelay = max(delay, 1.0)
467
512
  eventSource?.stop()
468
513
  eventSource = nil
469
514
  sseQueue.asyncAfter(deadline: .now() + safeDelay) { [weak self] in
@@ -485,18 +530,22 @@ class NitroSse: HybridNitroSseSpec {
485
530
  self.attemptVersion = attemptVersion
486
531
  }
487
532
 
533
+ /// Handle a successful SSE connection open for this handler.
534
+ ///
535
+ /// 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.
488
536
  func onOpened() {
489
- guard let parent = parent, source === parent.eventSource else { return }
537
+ guard let parent = self.parent, source === parent.eventSource else { return }
490
538
  parent.sseQueue.async { [weak parent] in
491
539
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
492
540
  parent.backoffCounter = 0
541
+ parent.currentReconnectAttempts = 0
493
542
  parent.consecutiveAuthErrors = 0
494
- parent.pushEventToBuffer(SseEvent(type: .open, data: nil, id: nil, event: nil, message: nil, statusCode: 200, retry: nil))
543
+ parent.pushEventToBuffer(SseEvent(type: .open, data: nil, parsedData: nil, id: nil, event: nil, message: nil, statusCode: 200, retry: nil))
495
544
  }
496
545
  }
497
546
 
498
547
  func onClosed() {
499
- guard let parent = parent, source === parent.eventSource else { return }
548
+ guard let parent = self.parent, source === parent.eventSource else { return }
500
549
  parent.sseQueue.async { [weak parent] in
501
550
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
502
551
  if let rid = parent.requestId {
@@ -510,7 +559,7 @@ class NitroSse: HybridNitroSseSpec {
510
559
  }
511
560
 
512
561
  func onMessage(eventType: String, messageEvent: MessageEvent) {
513
- guard let parent = parent, source === parent.eventSource else { return }
562
+ guard let parent = self.parent, source === parent.eventSource else { return }
514
563
  parent.sseQueue.async { [weak parent] in
515
564
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
516
565
  let encodedDataSize = Double(messageEvent.data.utf8.count)
@@ -521,21 +570,23 @@ class NitroSse: HybridNitroSseSpec {
521
570
  parent.lastProcessedId = messageEvent.lastEventId
522
571
  }
523
572
 
524
- parent.pushEventToBuffer(SseEvent(type: .message, data: messageEvent.data, id: messageEvent.lastEventId, event: eventType, message: nil, statusCode: 200, retry: nil))
573
+ let parsedData = (parent.config?.autoParseJSON == true) ? parent.parseJsonToAnyMap(messageEvent.data) : nil
574
+
575
+ parent.pushEventToBuffer(SseEvent(type: .message, data: messageEvent.data, parsedData: parsedData, id: messageEvent.lastEventId, event: eventType, message: nil, statusCode: 200, retry: nil))
525
576
  }
526
577
  }
527
578
 
528
579
  func onComment(comment: String) {
529
- guard let parent = parent, source === parent.eventSource else { return }
580
+ guard let parent = self.parent, source === parent.eventSource else { return }
530
581
  parent.sseQueue.async { [weak parent] in
531
582
  guard let parent = parent, self.attemptVersion == parent.connectionAttemptVersion else { return }
532
583
  parent.totalBytesReceived += Double(comment.utf8.count)
533
- parent.pushEventToBuffer(SseEvent(type: .heartbeat, data: nil, id: nil, event: nil, message: comment, statusCode: nil, retry: nil))
584
+ parent.pushEventToBuffer(SseEvent(type: .heartbeat, data: nil, parsedData: nil, id: nil, event: nil, message: comment, statusCode: nil, retry: nil))
534
585
  }
535
586
  }
536
587
 
537
588
  func onError(error: Error) {
538
- guard let parent = parent, source === parent.eventSource else { return }
589
+ guard let parent = self.parent, source === parent.eventSource else { return }
539
590
  parent.sseQueue.async { [weak parent] in
540
591
  guard let parent = parent, parent.isRunning, self.attemptVersion == parent.connectionAttemptVersion else { return }
541
592
  let nsError = error as NSError
@@ -549,33 +600,33 @@ class NitroSse: HybridNitroSseSpec {
549
600
  parent.requestId = nil
550
601
 
551
602
  if statusCode == 204 {
552
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "No Content (204). Stopping.", statusCode: 204, retry: nil))
603
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "No Content (204). Stopping.", statusCode: 204, retry: nil))
553
604
  parent.stopInternal()
554
605
  return
555
606
  }
556
607
 
557
608
  if statusCode == 401 || statusCode == 403 {
558
609
  if parent.config?.onBeforeRequest == nil {
559
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Auth Error (\(statusCode)) - No interceptor provided. Stopping.", statusCode: Double(statusCode), retry: nil))
610
+ 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))
560
611
  parent.stopInternal()
561
612
  return
562
613
  }
563
614
 
564
615
  parent.consecutiveAuthErrors += 1
565
616
  if parent.consecutiveAuthErrors >= parent.maxAuthRetries {
566
- 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))
617
+ 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))
567
618
  parent.stopInternal()
568
619
  return
569
620
  }
570
621
 
571
- 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))
622
+ 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))
572
623
  parent.scheduleAutomaticReconnect(isError: true, attemptVersion: self.attemptVersion)
573
624
  return
574
625
  }
575
626
 
576
627
  let isFatal = (statusCode == 400)
577
628
  if isFatal {
578
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Fatal Error (\(statusCode)). Stopping.", statusCode: Double(statusCode), retry: nil))
629
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Fatal Error (\(statusCode)). Stopping.", statusCode: Double(statusCode), retry: nil))
579
630
  parent.stopInternal()
580
631
  return
581
632
  }
@@ -584,18 +635,18 @@ class NitroSse: HybridNitroSseSpec {
584
635
  if (statusCode == 429 || statusCode == 503), let retryAfter = retryAfterSeconds {
585
636
  let jitter = Double.random(in: 0.5...1.5)
586
637
  let totalDelay = retryAfter + jitter
587
- 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))
638
+ 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))
588
639
  parent.scheduleAutomaticReconnectWithFixedDelay(totalDelay, attemptVersion: self.attemptVersion)
589
640
  return
590
641
  }
591
642
 
592
643
  if statusCode == 429 {
593
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: "Rate Limited (429) without Retry-After. Stopping.", statusCode: 429, retry: nil))
644
+ 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))
594
645
  parent.stopInternal()
595
646
  return
596
647
  }
597
648
 
598
- parent.pushEventToBuffer(SseEvent(type: .error, data: nil, id: nil, event: nil, message: error.localizedDescription, statusCode: Double(statusCode), retry: nil))
649
+ parent.pushEventToBuffer(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: error.localizedDescription, statusCode: Double(statusCode), retry: nil))
599
650
  parent.scheduleAutomaticReconnect(isError: true, attemptVersion: self.attemptVersion)
600
651
  }
601
652
  }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ export class NitroSseClient {
4
+ _listeners = new Map();
5
+ constructor(native) {
6
+ this._native = native;
7
+ }
8
+ setup(config, onEvent) {
9
+ this._legacyCallback = onEvent;
10
+
11
+ // We wrap the native setup to dispatch events to typed listeners
12
+ this._native.setup(config, events => {
13
+ // 1. Call legacy batch callback if provided
14
+ this._legacyCallback?.(events);
15
+
16
+ // 2. Dispatch individual events to registered listeners
17
+ for (const event of events) {
18
+ // Dispatch basic types: 'open', 'message', 'error', 'close', 'heartbeat'
19
+ this._emit(event.type, event);
20
+
21
+ // Dispatch by SSE event name if it's different from the type
22
+ // e.g., if type is 'message' but event name is 'update'
23
+ if (event.event && event.event !== event.type) {
24
+ this._emit(event.event, event);
25
+ }
26
+ }
27
+ });
28
+ }
29
+ addEventListener(type, listener) {
30
+ if (!this._listeners.has(type)) {
31
+ this._listeners.set(type, new Set());
32
+ }
33
+ this._listeners.get(type).add(listener);
34
+ }
35
+ removeEventListener(type, listener) {
36
+ this._listeners.get(type)?.delete(listener);
37
+ }
38
+ _emit(type, event) {
39
+ const listeners = this._listeners.get(type);
40
+ if (listeners) {
41
+ listeners.forEach(listener => {
42
+ try {
43
+ listener(event);
44
+ } catch (e) {
45
+ console.error(`[NitroSse] Error in event listener for "${type}":`, e);
46
+ }
47
+ });
48
+ }
49
+ }
50
+ start() {
51
+ this._native.start();
52
+ }
53
+ stop() {
54
+ this._native.stop();
55
+ }
56
+ restart() {
57
+ this._native.restart();
58
+ }
59
+ flush() {
60
+ this._native.flush();
61
+ }
62
+ isConnected() {
63
+ return this._native.isConnected();
64
+ }
65
+ getStats() {
66
+ return this._native.getStats();
67
+ }
68
+ updateHeaders(headers) {
69
+ this._native.updateHeaders(headers);
70
+ }
71
+ setLastProcessedId(id) {
72
+ this._native.setLastProcessedId(id);
73
+ }
74
+ }
75
+ //# sourceMappingURL=NitroSseClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NitroSseClient","_listeners","Map","constructor","native","_native","setup","config","onEvent","_legacyCallback","events","event","_emit","type","addEventListener","listener","has","set","Set","get","add","removeEventListener","delete","listeners","forEach","e","console","error","start","stop","restart","flush","isConnected","getStats","updateHeaders","headers","setLastProcessedId","id"],"sourceRoot":"../../src","sources":["N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MY,SAAS,GAAG,IAAI,CAACtB,UAAU,CAACkB,GAAG,CAACN,IAAI,CAAC;IAC3C,IAAIU,SAAS,EAAE;MACbA,SAAS,CAACC,OAAO,CAAET,QAAQ,IAAK;QAC9B,IAAI;UACFA,QAAQ,CAACJ,KAAK,CAAC;QACjB,CAAC,CAAC,OAAOc,CAAC,EAAE;UACVC,OAAO,CAACC,KAAK,CAAC,2CAA2Cd,IAAI,IAAI,EAAEY,CAAC,CAAC;QACvE;MACF,CAAC,CAAC;IACJ;EACF;EAEAG,KAAKA,CAAA,EAAS;IACZ,IAAI,CAACvB,OAAO,CAACuB,KAAK,CAAC,CAAC;EACtB;EAEAC,IAAIA,CAAA,EAAS;IACX,IAAI,CAACxB,OAAO,CAACwB,IAAI,CAAC,CAAC;EACrB;EAEAC,OAAOA,CAAA,EAAS;IACd,IAAI,CAACzB,OAAO,CAACyB,OAAO,CAAC,CAAC;EACxB;EAEAC,KAAKA,CAAA,EAAS;IACZ,IAAI,CAAC1B,OAAO,CAAC0B,KAAK,CAAC,CAAC;EACtB;EAEAC,WAAWA,CAAA,EAAY;IACrB,OAAO,IAAI,CAAC3B,OAAO,CAAC2B,WAAW,CAAC,CAAC;EACnC;EAEAC,QAAQA,CAAA,EAAa;IACnB,OAAO,IAAI,CAAC5B,OAAO,CAAC4B,QAAQ,CAAC,CAAC;EAChC;EAEAC,aAAaA,CAACC,OAA+B,EAAQ;IACnD,IAAI,CAAC9B,OAAO,CAAC6B,aAAa,CAACC,OAAO,CAAC;EACrC;EAEAC,kBAAkBA,CAACC,EAAU,EAAQ;IACnC,IAAI,CAAChC,OAAO,CAAC+B,kBAAkB,CAACC,EAAE,CAAC;EACrC;AACF","ignoreList":[]}
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
+
3
+ export {};
2
4
  //# sourceMappingURL=SseInterface.js.map
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  import { NitroModules } from 'react-native-nitro-modules';
4
+ import { NitroSseClient } from "./NitroSseClient.js";
4
5
  export * from "./SseInterface.js";
5
6
  export * from "./NitroSse.nitro.js";
7
+
8
+ /**
9
+ * Creates a high-performance SSE client that supports typed event listeners (`addEventListener`) and legacy batching.
10
+ *
11
+ * @returns An SseClient instance wrapping the native NitroSse implementation.
12
+ * @throws If the native NitroSse module cannot be found. Ensure the library is linked and the app is built for iOS/Android.
13
+ */
6
14
  export function createNitroSse() {
7
15
  let nativeSse;
8
16
  try {
@@ -13,6 +21,6 @@ export function createNitroSse() {
13
21
  if (!nativeSse) {
14
22
  throw new Error('NitroSse: Native module not found. Ensure you have linked the library and built the app for iOS/Android.');
15
23
  }
16
- return nativeSse;
24
+ return new NitroSseClient(nativeSse);
17
25
  }
18
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NitroModules","createNitroSse","nativeSse","createHybridObject","console","debug","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,cAAc,mBAAgB;AAC9B,cAAc,qBAAkB;AAEhC,OAAO,SAASC,cAAcA,CAAA,EAAa;EACzC,IAAIC,SAA+B;EACnC,IAAI;IACFA,SAAS,GAAGF,YAAY,CAACG,kBAAkB,CAAW,UAAU,CAAC;EACnE,CAAC,CAAC,MAAM;IACNC,OAAO,CAACC,KAAK,CACX,qEACF,CAAC;EACH;EAEA,IAAI,CAACH,SAAS,EAAE;IACd,MAAM,IAAII,KAAK,CACb,0GACF,CAAC;EACH;EACA,OAAOJ,SAAS;AAClB","ignoreList":[]}
1
+ {"version":3,"names":["NitroModules","NitroSseClient","createNitroSse","nativeSse","createHybridObject","console","debug","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAEzD,SAASC,cAAc,QAAQ,qBAAkB;AAGjD,cAAc,mBAAgB;AAC9B,cAAc,qBAAkB;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAA,EAAc;EAC1C,IAAIC,SAA+B;EACnC,IAAI;IACFA,SAAS,GAAGH,YAAY,CAACI,kBAAkB,CAAW,UAAU,CAAC;EACnE,CAAC,CAAC,MAAM;IACNC,OAAO,CAACC,KAAK,CACX,qEACF,CAAC;EACH;EAEA,IAAI,CAACH,SAAS,EAAE;IACd,MAAM,IAAII,KAAK,CACb,0GACF,CAAC;EACH;EACA,OAAO,IAAIN,cAAc,CAACE,SAAS,CAAC;AACtC","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import type { NitroSse } from './NitroSse.nitro';
2
+ import type { SseClient, SseConfig, SseEvent, SseListener, SseStats } from './SseInterface';
3
+ export declare class NitroSseClient implements SseClient {
4
+ private _native;
5
+ private _listeners;
6
+ private _legacyCallback?;
7
+ constructor(native: NitroSse);
8
+ setup(config: SseConfig, onEvent?: (events: SseEvent[]) => void): void;
9
+ addEventListener(type: string, listener: SseListener): void;
10
+ removeEventListener(type: string, listener: SseListener): void;
11
+ private _emit;
12
+ start(): void;
13
+ stop(): void;
14
+ restart(): void;
15
+ flush(): void;
16
+ isConnected(): boolean;
17
+ getStats(): SseStats;
18
+ updateHeaders(headers: Record<string, string>): void;
19
+ setLastProcessedId(id: string): void;
20
+ }
21
+ //# sourceMappingURL=NitroSseClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NitroSseClient.d.ts","sourceRoot":"","sources":["../../../src/NitroSseClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAExB,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,UAAU,CAA4C;IAC9D,OAAO,CAAC,eAAe,CAAC,CAA+B;gBAE3C,MAAM,EAAE,QAAQ;IAI5B,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,IAAI,GAAG,IAAI;IAsBtE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI;IAO3D,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI;IAI9D,OAAO,CAAC,KAAK;IAab,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI;IAIZ,OAAO,IAAI,IAAI;IAIf,KAAK,IAAI,IAAI;IAIb,WAAW,IAAI,OAAO;IAItB,QAAQ,IAAI,QAAQ;IAIpB,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAIpD,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAGrC"}
@@ -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
  */
@@ -44,7 +45,7 @@ export interface SseConfig {
44
45
  maxBufferSize?: number;
45
46
  /**
46
47
  * Maximum time (in ms) to wait for the initial server connection and handshake to complete.
47
- * Effectively the "Connect Timeout".
48
+ * Effectively the \"Connect Timeout\".
48
49
  * @default 15000
49
50
  */
50
51
  connectionTimeoutMs?: number;
@@ -55,6 +56,35 @@ export interface SseConfig {
55
56
  * @default 300000
56
57
  */
57
58
  readTimeoutMs?: number;
59
+ /**
60
+ * Initial delay (in ms) for reconnection attempts.
61
+ * Subsequent attempts use exponential backoff.
62
+ * @default 1000
63
+ */
64
+ retryIntervalMs?: number;
65
+ /**
66
+ * Maximum delay (in ms) for reconnection attempts.
67
+ * @default 30000
68
+ */
69
+ maxRetryIntervalMs?: number;
70
+ /**
71
+ * Factor to randomize reconnection attempts (0.0 to 1.0).
72
+ * 0 means no jitter, 1.0 means up to 100% randomization.
73
+ * @default 0.5
74
+ */
75
+ jitterFactor?: number;
76
+ /**
77
+ * Maximum number of reconnection attempts before giving up.
78
+ * Use -1 for infinite (default), 0 to disable auto-reconnection.
79
+ * @default -1
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;
58
88
  /**
59
89
  * Async interceptor called before every connection attempt (including auto-reconnects).
60
90
  * Use this to refresh tokens or calculate dynamic headers.
@@ -68,8 +98,10 @@ export interface SseConfig {
68
98
  export interface SseEvent {
69
99
  /** The type of the event. */
70
100
  type: SseEventType;
71
- /** The data payload of the event. */
101
+ /** The data payload of the event as a raw string. */
72
102
  data?: string;
103
+ /** The parsed JSON data, if autoParseJSON is enabled and parsing succeeds. */
104
+ parsedData?: AnyMap;
73
105
  /** The event ID, if provided. */
74
106
  id?: string;
75
107
  /** The event name, if provided (internal 'event' field in SSE). */
@@ -94,4 +126,44 @@ export interface SseStats {
94
126
  /** Error code of the last error. */
95
127
  lastErrorCode?: string;
96
128
  }
129
+ /**
130
+ * Listener for a specific SSE event.
131
+ */
132
+ export type SseListener = (event: SseEvent) => void;
133
+ /**
134
+ * Public interface for the NitroSse client, supporting typed event listeners.
135
+ */
136
+ export interface SseClient {
137
+ /**
138
+ * Configure SSE and setup event callback.
139
+ * @param config The SSE configuration.
140
+ * @param onEvent Optional legacy batch callback for all events.
141
+ */
142
+ setup(config: SseConfig, onEvent?: (events: SseEvent[]) => void): void;
143
+ /**
144
+ * Register a listener for a specific event type ('message', 'open', etc.)
145
+ * or a custom SSE event name (from the 'event:' field).
146
+ */
147
+ addEventListener(type: string, listener: SseListener): void;
148
+ /**
149
+ * Unregister a listener.
150
+ */
151
+ removeEventListener(type: string, listener: SseListener): void;
152
+ /** Start the connection. */
153
+ start(): void;
154
+ /** Stop the connection. */
155
+ stop(): void;
156
+ /** Restart the connection (stop + start). */
157
+ restart(): void;
158
+ /** Force flush buffered events to JS. */
159
+ flush(): void;
160
+ /** Check if active. */
161
+ isConnected(): boolean;
162
+ /** Get stats. */
163
+ getStats(): SseStats;
164
+ /** Manually update headers. */
165
+ updateHeaders(headers: Record<string, string>): void;
166
+ /** Set last event ID. */
167
+ setLastProcessedId(id: string): void;
168
+ }
97
169
  //# sourceMappingURL=SseInterface.d.ts.map
@@ -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,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACzD;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,6BAA6B;IAC7B,IAAI,EAAE,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AM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAEvE;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5D;;OAEG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;IAE/D,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAAC;IACd,2BAA2B;IAC3B,IAAI,IAAI,IAAI,CAAC;IACb,6CAA6C;IAC7C,OAAO,IAAI,IAAI,CAAC;IAChB,yCAAyC;IACzC,KAAK,IAAI,IAAI,CAAC;IACd,uBAAuB;IACvB,WAAW,IAAI,OAAO,CAAC;IACvB,iBAAiB;IACjB,QAAQ,IAAI,QAAQ,CAAC;IACrB,+BAA+B;IAC/B,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACrD,yBAAyB;IACzB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC"}
@@ -1,5 +1,11 @@
1
- import type { NitroSse } from './NitroSse.nitro';
1
+ import type { SseClient } from './SseInterface';
2
2
  export * from './SseInterface';
3
3
  export * from './NitroSse.nitro';
4
- export declare function createNitroSse(): NitroSse;
4
+ /**
5
+ * Creates a high-performance SSE client that supports typed event listeners (`addEventListener`) and legacy batching.
6
+ *
7
+ * @returns An SseClient instance wrapping the native NitroSse implementation.
8
+ * @throws If the native NitroSse module cannot be found. Ensure the library is linked and the app is built for iOS/Android.
9
+ */
10
+ export declare function createNitroSse(): SseClient;
5
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AAEjC,wBAAgB,cAAc,IAAI,QAAQ,CAgBzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AAEjC;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,SAAS,CAgB1C"}
@@ -19,6 +19,8 @@
19
19
  #include "JSseEventType.hpp"
20
20
  #include <string>
21
21
  #include <optional>
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