react-native-nitro-sse 2.4.0 → 2.4.2
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/android/src/main/java/com/margelo/nitro/nitrosse/NetworkInspector.kt +0 -2
- package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +41 -23
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +2 -2
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +0 -3
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +4 -0
- package/ios/NitroSse.swift +39 -23
- package/ios/SseConnectionHandler.swift +26 -3
- package/ios/SseNetworkMonitor.swift +3 -2
- package/ios/SseReconnectStrategy.swift +5 -0
- package/lib/module/MockSseEngine.js +212 -0
- package/lib/module/MockSseEngine.js.map +1 -0
- package/lib/module/NitroSseClient.js +40 -216
- package/lib/module/NitroSseClient.js.map +1 -1
- package/lib/module/SseDriver.js +125 -0
- package/lib/module/SseDriver.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/MockSseEngine.d.ts +31 -0
- package/lib/typescript/src/MockSseEngine.d.ts.map +1 -0
- package/lib/typescript/src/NitroSseClient.d.ts +5 -5
- package/lib/typescript/src/NitroSseClient.d.ts.map +1 -1
- package/lib/typescript/src/SseDriver.d.ts +72 -0
- package/lib/typescript/src/SseDriver.d.ts.map +1 -0
- package/lib/typescript/src/SseInterface.d.ts +2 -0
- package/lib/typescript/src/SseInterface.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JSseConfig.hpp +2 -0
- package/nitrogen/generated/android/c++/JSseMockConfig.hpp +2 -0
- package/nitrogen/generated/android/c++/JSseMockEvent.hpp +9 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +9 -4
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +15 -15
- package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +3 -3
- package/nitrogen/generated/ios/swift/SseMockEvent.swift +12 -1
- package/nitrogen/generated/shared/c++/SseMockEvent.hpp +9 -2
- package/package.json +5 -7
- package/src/MockSseEngine.ts +254 -0
- package/src/NitroSseClient.ts +54 -237
- package/src/SseDriver.ts +161 -0
- package/src/SseInterface.ts +2 -0
- package/src/index.ts +1 -1
|
@@ -3,7 +3,6 @@ package com.margelo.nitro.nitrosse
|
|
|
3
3
|
import android.util.Log
|
|
4
4
|
import okhttp3.Request
|
|
5
5
|
import okhttp3.Response
|
|
6
|
-
import java.util.UUID
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Reports SSE connection events to the React Native DevTools Network inspector.
|
|
@@ -15,7 +14,6 @@ import java.util.UUID
|
|
|
15
14
|
object NetworkInspector {
|
|
16
15
|
private const val TAG = "NitroSseNetworkInspector"
|
|
17
16
|
private var reporterClass: Class<*>? = null
|
|
18
|
-
private var isEnabledCached: Boolean = false
|
|
19
17
|
|
|
20
18
|
init {
|
|
21
19
|
try {
|
|
@@ -94,8 +94,12 @@ class NitroSse @DoNotStrip constructor() : HybridNitroSseSpec(), SseConnectionDe
|
|
|
94
94
|
val builder = OkHttpClient.Builder()
|
|
95
95
|
.connectTimeout((config.connectionTimeoutMs ?: 15000.0).toLong(), TimeUnit.MILLISECONDS)
|
|
96
96
|
.readTimeout((config.readTimeoutMs ?: 300000.0).toLong(), TimeUnit.MILLISECONDS)
|
|
97
|
-
.addNetworkInterceptor(HeartbeatNetworkInterceptor(totalBytesReceived) {
|
|
98
|
-
|
|
97
|
+
.addNetworkInterceptor(HeartbeatNetworkInterceptor(totalBytesReceived) { heartbeatRid ->
|
|
98
|
+
// Guard keep-alive signals by active request ID to ignore residual bytes from closed/closing sockets
|
|
99
|
+
val currentRid = synchronized(this@NitroSse) { requestId }
|
|
100
|
+
if (heartbeatRid == null || heartbeatRid == currentRid) {
|
|
101
|
+
eventBuffer.push(SseEvent(SseEventType.HEARTBEAT, null, null, null, null, "keep-alive", null, null, null))
|
|
102
|
+
}
|
|
99
103
|
})
|
|
100
104
|
this.client = builder.build()
|
|
101
105
|
} else {
|
|
@@ -347,6 +351,11 @@ class NitroSse @DoNotStrip constructor() : HybridNitroSseSpec(), SseConnectionDe
|
|
|
347
351
|
|
|
348
352
|
currentConfig.headers?.forEach { (k, v) -> requestBuilder.header(k, v) }
|
|
349
353
|
|
|
354
|
+
// Explicitly set identity encoding after custom headers to prevent OkHttp from requesting gzip.
|
|
355
|
+
// If gzipped, HeartbeatNetworkInterceptor intercepts raw compressed bytes before decompression,
|
|
356
|
+
// corrupting byte-level comment scanning for keep-alive events (':').
|
|
357
|
+
requestBuilder.header("Accept-Encoding", "identity")
|
|
358
|
+
|
|
350
359
|
if (currentConfig.method == HttpMethod.POST) {
|
|
351
360
|
val body = currentConfig.body?.toRequestBody("application/json".toMediaType()) ?: "".toRequestBody()
|
|
352
361
|
requestBuilder.post(body)
|
|
@@ -406,16 +415,12 @@ class NitroSse @DoNotStrip constructor() : HybridNitroSseSpec(), SseConnectionDe
|
|
|
406
415
|
if (statusCode == 401 || statusCode == 403) {
|
|
407
416
|
val currentConfig = synchronized(this@NitroSse) { config }
|
|
408
417
|
if (currentConfig?.onBeforeRequest == null) {
|
|
409
|
-
|
|
410
|
-
updateState(SseState.FAILED)
|
|
411
|
-
stopInternal()
|
|
418
|
+
failAndStop("Auth Error ($statusCode) - No interceptor provided. Stopping.", statusCode.toDouble())
|
|
412
419
|
return@post
|
|
413
420
|
}
|
|
414
421
|
val retries = consecutiveAuthErrors.incrementAndGet()
|
|
415
422
|
if (retries >= maxAuthRetries) {
|
|
416
|
-
|
|
417
|
-
updateState(SseState.FAILED)
|
|
418
|
-
stopInternal()
|
|
423
|
+
failAndStop("Auth Error ($statusCode) - Retry limit reached ($maxAuthRetries). Stopping.", statusCode.toDouble())
|
|
419
424
|
return@post
|
|
420
425
|
}
|
|
421
426
|
eventBuffer.push(SseEvent(SseEventType.ERROR, null, null, null, null, "Auth Error ($statusCode) - Retry $retries/$maxAuthRetries. Refreshing token...", statusCode.toDouble(), null, null))
|
|
@@ -424,34 +429,35 @@ class NitroSse @DoNotStrip constructor() : HybridNitroSseSpec(), SseConnectionDe
|
|
|
424
429
|
}
|
|
425
430
|
|
|
426
431
|
if (statusCode == 400) {
|
|
427
|
-
|
|
428
|
-
updateState(SseState.FAILED)
|
|
429
|
-
stopInternal()
|
|
432
|
+
failAndStop("Fatal Error ($statusCode). Stopping.", statusCode.toDouble())
|
|
430
433
|
return@post
|
|
431
434
|
}
|
|
432
435
|
|
|
433
436
|
val retryAfterMillis = SseReconnectStrategy.extractRetryAfterMillis(response)
|
|
434
437
|
if ((statusCode == 429 || statusCode == 503) && retryAfterMillis != null) {
|
|
438
|
+
if (reconnectStrategy.hasReachedMaxAttempts()) {
|
|
439
|
+
val maxAttempts = reconnectStrategy.currentReconnectAttempts
|
|
440
|
+
Log.d(TAG, "Max reconnection attempts reached ($maxAttempts). Stopping.")
|
|
441
|
+
failAndStop("Max reconnection attempts reached ($maxAttempts).")
|
|
442
|
+
return@post
|
|
443
|
+
}
|
|
444
|
+
reconnectStrategy.recordAttempt()
|
|
435
445
|
val jitter = (500 + Random.nextInt(1001)).toLong()
|
|
436
446
|
val totalDelay = retryAfterMillis + jitter
|
|
437
447
|
eventBuffer.push(SseEvent(SseEventType.ERROR, null, null, null, null, "Retry-After received: ${totalDelay/1000}s", statusCode.toDouble(), totalDelay.toDouble(), null))
|
|
438
|
-
val
|
|
448
|
+
val newAttemptVersion = connectionAttemptVersion.incrementAndGet()
|
|
439
449
|
updateState(SseState.RECONNECTING)
|
|
440
|
-
sseDispatcher?.postDelayed({ if (isRunning.get()) performConnection(
|
|
450
|
+
sseDispatcher?.postDelayed({ if (isRunning.get() && newAttemptVersion == connectionAttemptVersion.get()) performConnection(newAttemptVersion) }, totalDelay)
|
|
441
451
|
return@post
|
|
442
452
|
}
|
|
443
453
|
|
|
444
454
|
if (statusCode == 429) {
|
|
445
|
-
|
|
446
|
-
updateState(SseState.FAILED)
|
|
447
|
-
stopInternal()
|
|
455
|
+
failAndStop("Rate Limited (429) without Retry-After. Stopping.", 429.0)
|
|
448
456
|
return@post
|
|
449
457
|
}
|
|
450
458
|
|
|
451
459
|
if (statusCode == 204) {
|
|
452
|
-
|
|
453
|
-
updateState(SseState.FAILED)
|
|
454
|
-
stopInternal()
|
|
460
|
+
failAndStop("No Content (204). Stopping.", 204.0)
|
|
455
461
|
return@post
|
|
456
462
|
}
|
|
457
463
|
|
|
@@ -478,18 +484,30 @@ class NitroSse @DoNotStrip constructor() : HybridNitroSseSpec(), SseConnectionDe
|
|
|
478
484
|
}
|
|
479
485
|
}
|
|
480
486
|
|
|
487
|
+
private fun failAndStop(message: String, statusCode: Double? = null) {
|
|
488
|
+
eventBuffer.push(SseEvent(SseEventType.ERROR, null, null, null, null, message, statusCode, null, null))
|
|
489
|
+
updateState(SseState.FAILED)
|
|
490
|
+
stopInternal()
|
|
491
|
+
}
|
|
492
|
+
|
|
481
493
|
private fun scheduleReconnect(isError: Boolean, attemptVersion: Int) {
|
|
494
|
+
if (!isRunning.get() || attemptVersion != connectionAttemptVersion.get()) return
|
|
482
495
|
if (reconnectStrategy.hasReachedMaxAttempts()) {
|
|
483
496
|
val maxAttempts = reconnectStrategy.currentReconnectAttempts
|
|
484
497
|
Log.d(TAG, "Max reconnection attempts reached ($maxAttempts). Stopping.")
|
|
485
|
-
|
|
486
|
-
updateState(SseState.FAILED)
|
|
487
|
-
stopInternal()
|
|
498
|
+
failAndStop("Max reconnection attempts reached ($maxAttempts).")
|
|
488
499
|
return
|
|
489
500
|
}
|
|
501
|
+
// Increment attempt version before scheduling to invalidate pending tasks from previous cycles
|
|
502
|
+
val newAttemptVersion = connectionAttemptVersion.incrementAndGet()
|
|
490
503
|
val safeReconnectDelay = reconnectStrategy.nextDelay(isError)
|
|
491
504
|
updateState(SseState.RECONNECTING)
|
|
492
|
-
sseDispatcher?.postDelayed({
|
|
505
|
+
sseDispatcher?.postDelayed({
|
|
506
|
+
// Double check version and running state at trigger time to discard stale delayed callbacks
|
|
507
|
+
if (isRunning.get() && newAttemptVersion == connectionAttemptVersion.get()) {
|
|
508
|
+
performConnection(newAttemptVersion)
|
|
509
|
+
}
|
|
510
|
+
}, safeReconnectDelay)
|
|
493
511
|
}
|
|
494
512
|
|
|
495
513
|
private fun stopInternal() {
|
|
@@ -59,7 +59,7 @@ class SseConnectionHandler(private val delegate: SseConnectionDelegate) {
|
|
|
59
59
|
*/
|
|
60
60
|
internal class HeartbeatNetworkInterceptor(
|
|
61
61
|
private val totalBytesReceived: AtomicLong,
|
|
62
|
-
private val onHeartbeat: () -> Unit
|
|
62
|
+
private val onHeartbeat: (requestId: String?) -> Unit
|
|
63
63
|
) : Interceptor {
|
|
64
64
|
override fun intercept(chain: Interceptor.Chain): Response {
|
|
65
65
|
val request = chain.request()
|
|
@@ -91,7 +91,7 @@ internal class HeartbeatNetworkInterceptor(
|
|
|
91
91
|
val bytes = scratch.snapshot().toByteArray()
|
|
92
92
|
for (b in bytes) {
|
|
93
93
|
if (isAtStartOfLine && b == ':'.code.toByte()) {
|
|
94
|
-
onHeartbeat()
|
|
94
|
+
onHeartbeat(rid)
|
|
95
95
|
}
|
|
96
96
|
isAtStartOfLine = (b == '\n'.code.toByte() || b == '\r'.code.toByte())
|
|
97
97
|
}
|
|
@@ -59,6 +59,10 @@ class SseReconnectStrategy {
|
|
|
59
59
|
return _currentReconnectAttempts.get() >= maxReconnectAttempts
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
fun recordAttempt(): Int {
|
|
63
|
+
return _currentReconnectAttempts.incrementAndGet()
|
|
64
|
+
}
|
|
65
|
+
|
|
62
66
|
fun reset() {
|
|
63
67
|
backoffCounter = 0
|
|
64
68
|
_currentReconnectAttempts.set(0)
|
package/ios/NitroSse.swift
CHANGED
|
@@ -443,37 +443,60 @@ class NitroSse: HybridNitroSseSpec {
|
|
|
443
443
|
self.lifecycleManager?.cleanupBackgroundTask()
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
+
private func failAndStop(message: String, statusCode: Double? = nil) {
|
|
447
|
+
dispatcher.assertOnQueue()
|
|
448
|
+
self.connectionAttemptVersion += 1
|
|
449
|
+
self.eventBuffer.push(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: message, statusCode: statusCode, retry: nil, state: nil))
|
|
450
|
+
self.updateState(.failed)
|
|
451
|
+
self.stopInternal()
|
|
452
|
+
}
|
|
453
|
+
|
|
446
454
|
private func scheduleAutomaticReconnect(isError: Bool, attemptVersion: Int) {
|
|
447
455
|
dispatcher.assertOnQueue()
|
|
448
|
-
|
|
456
|
+
guard isRunning, attemptVersion == self.connectionAttemptVersion else { return }
|
|
449
457
|
|
|
450
458
|
if reconnectStrategy.hasReachedMaxAttempts() {
|
|
451
459
|
let maxAttempts = Int(config?.maxReconnectAttempts ?? -1.0)
|
|
452
460
|
print("[NitroSse] Max reconnection attempts reached (\(maxAttempts)). Stopping.")
|
|
453
|
-
|
|
454
|
-
self.updateState(.failed)
|
|
455
|
-
self.stopInternal()
|
|
461
|
+
failAndStop(message: "Max reconnection attempts reached (\(maxAttempts)).")
|
|
456
462
|
return
|
|
457
463
|
}
|
|
458
464
|
|
|
465
|
+
// Increment connectionAttemptVersion before stopping eventSource to invalidate any in-flight
|
|
466
|
+
// or asynchronous onError/onClosed callbacks triggered during shutdown/teardown.
|
|
467
|
+
self.connectionAttemptVersion += 1
|
|
468
|
+
let newVersion = self.connectionAttemptVersion
|
|
459
469
|
let safeDelay = reconnectStrategy.nextDelay(isError: isError)
|
|
460
470
|
self.updateState(.reconnecting)
|
|
461
471
|
eventSource?.stop()
|
|
462
472
|
eventSource = nil
|
|
463
473
|
dispatcher.asyncAfter(delay: safeDelay) { [weak self] in
|
|
464
|
-
guard let self = self, self.isRunning,
|
|
465
|
-
self.establishConnection(attemptVersion:
|
|
474
|
+
guard let self = self, self.isRunning, newVersion == self.connectionAttemptVersion else { return }
|
|
475
|
+
self.establishConnection(attemptVersion: newVersion)
|
|
466
476
|
}
|
|
467
477
|
}
|
|
468
478
|
|
|
469
479
|
private func scheduleAutomaticReconnectWithFixedDelay(_ delay: TimeInterval, attemptVersion: Int) {
|
|
470
480
|
dispatcher.assertOnQueue()
|
|
481
|
+
guard isRunning, attemptVersion == self.connectionAttemptVersion else { return }
|
|
482
|
+
|
|
483
|
+
if reconnectStrategy.hasReachedMaxAttempts() {
|
|
484
|
+
let maxAttempts = Int(config?.maxReconnectAttempts ?? -1.0)
|
|
485
|
+
print("[NitroSse] Max reconnection attempts reached (\(maxAttempts)). Stopping.")
|
|
486
|
+
failAndStop(message: "Max reconnection attempts reached (\(maxAttempts)).")
|
|
487
|
+
return
|
|
488
|
+
}
|
|
489
|
+
reconnectStrategy.recordAttempt()
|
|
490
|
+
|
|
491
|
+
// Increment connectionAttemptVersion to discard stale callbacks from previous cycle
|
|
492
|
+
self.connectionAttemptVersion += 1
|
|
493
|
+
let newVersion = self.connectionAttemptVersion
|
|
471
494
|
eventSource?.stop()
|
|
472
495
|
eventSource = nil
|
|
473
496
|
self.updateState(.reconnecting)
|
|
474
497
|
dispatcher.asyncAfter(delay: delay) { [weak self] in
|
|
475
|
-
guard let self = self, self.isRunning,
|
|
476
|
-
self.establishConnection(attemptVersion:
|
|
498
|
+
guard let self = self, self.isRunning, newVersion == self.connectionAttemptVersion else { return }
|
|
499
|
+
self.establishConnection(attemptVersion: newVersion)
|
|
477
500
|
}
|
|
478
501
|
}
|
|
479
502
|
}
|
|
@@ -566,26 +589,20 @@ extension NitroSse: SseConnectionDelegate {
|
|
|
566
589
|
|
|
567
590
|
// HTTP 204 No Content indicates the server closed the stream intentionally without error.
|
|
568
591
|
if statusCode == 204 {
|
|
569
|
-
self.
|
|
570
|
-
self.updateState(.failed)
|
|
571
|
-
self.stopInternal()
|
|
592
|
+
self.failAndStop(message: "No Content (204). Stopping.", statusCode: 204)
|
|
572
593
|
return
|
|
573
594
|
}
|
|
574
595
|
|
|
575
596
|
// HTTP 401/403 Auth errors trigger token refresh via onBeforeRequest interceptor up to maxAuthRetries.
|
|
576
597
|
if statusCode == 401 || statusCode == 403 {
|
|
577
598
|
if self.config?.onBeforeRequest == nil {
|
|
578
|
-
self.
|
|
579
|
-
self.updateState(.failed)
|
|
580
|
-
self.stopInternal()
|
|
599
|
+
self.failAndStop(message: "Auth Error (\(statusCode)) - No interceptor provided. Stopping.", statusCode: Double(statusCode))
|
|
581
600
|
return
|
|
582
601
|
}
|
|
583
602
|
|
|
584
603
|
self.consecutiveAuthErrors += 1
|
|
585
604
|
if self.consecutiveAuthErrors >= self.maxAuthRetries {
|
|
586
|
-
self.
|
|
587
|
-
self.updateState(.failed)
|
|
588
|
-
self.stopInternal()
|
|
605
|
+
self.failAndStop(message: "Auth Error (\(statusCode)) - Retry limit reached (\(self.maxAuthRetries)). Stopping.", statusCode: Double(statusCode))
|
|
589
606
|
return
|
|
590
607
|
}
|
|
591
608
|
|
|
@@ -596,9 +613,7 @@ extension NitroSse: SseConnectionDelegate {
|
|
|
596
613
|
|
|
597
614
|
let isFatal = (statusCode == 400)
|
|
598
615
|
if isFatal {
|
|
599
|
-
self.
|
|
600
|
-
self.updateState(.failed)
|
|
601
|
-
self.stopInternal()
|
|
616
|
+
self.failAndStop(message: "Fatal Error (\(statusCode)). Stopping.", statusCode: Double(statusCode))
|
|
602
617
|
return
|
|
603
618
|
}
|
|
604
619
|
|
|
@@ -612,10 +627,11 @@ extension NitroSse: SseConnectionDelegate {
|
|
|
612
627
|
return
|
|
613
628
|
}
|
|
614
629
|
|
|
630
|
+
// HTTP 429 without Retry-After: Fallback to exponential backoff rather than stopping permanently,
|
|
631
|
+
// as rate limits are transient and recoverable.
|
|
615
632
|
if statusCode == 429 {
|
|
616
|
-
self.eventBuffer.push(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Rate Limited (429)
|
|
617
|
-
self.
|
|
618
|
-
self.stopInternal()
|
|
633
|
+
self.eventBuffer.push(SseEvent(type: .error, data: nil, parsedData: nil, id: nil, event: nil, message: "Rate Limited (429). Retrying with backoff...", statusCode: 429, retry: nil, state: nil))
|
|
634
|
+
self.scheduleAutomaticReconnect(isError: true, attemptVersion: attemptVersion)
|
|
619
635
|
return
|
|
620
636
|
}
|
|
621
637
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import LDSwiftEventSource
|
|
3
|
-
import NitroModules
|
|
4
3
|
|
|
5
4
|
/// Delegate protocol for receiving lifecycle and stream events from `SseConnectionHandler`.
|
|
6
5
|
protocol SseConnectionDelegate: AnyObject {
|
|
@@ -25,12 +24,17 @@ enum SseConnectionHandler {
|
|
|
25
24
|
) -> EventSource {
|
|
26
25
|
let sessionConfig = URLSessionConfiguration.default
|
|
27
26
|
let readTimeout = (config.readTimeoutMs ?? 300000.0) / 1000.0
|
|
28
|
-
|
|
27
|
+
// Use timeoutIntervalForRequest (resets on incoming chunks) rather than timeoutIntervalForResource.
|
|
28
|
+
// Setting timeoutIntervalForResource would hard-cap the total lifetime of persistent SSE streams.
|
|
29
29
|
sessionConfig.timeoutIntervalForRequest = readTimeout
|
|
30
|
-
sessionConfig.timeoutIntervalForResource = connectionTimeout
|
|
31
30
|
|
|
31
|
+
let connectionTimeout = (config.connectionTimeoutMs ?? 15000.0) / 1000.0
|
|
32
32
|
let handler = SseHandler(delegate: delegate, attemptVersion: attemptVersion, dispatcher: dispatcher)
|
|
33
33
|
var esConfig = EventSource.Config(handler: handler, url: url)
|
|
34
|
+
esConfig.connectionErrorHandler = { [weak handler] error in
|
|
35
|
+
handler?.onError(error: error)
|
|
36
|
+
return .shutdown
|
|
37
|
+
}
|
|
34
38
|
esConfig.urlSessionConfiguration = sessionConfig
|
|
35
39
|
esConfig.headers = config.headers ?? [:]
|
|
36
40
|
|
|
@@ -44,6 +48,7 @@ enum SseConnectionHandler {
|
|
|
44
48
|
|
|
45
49
|
let es = EventSource(config: esConfig)
|
|
46
50
|
handler.source = es
|
|
51
|
+
handler.startConnectionTimer(timeout: connectionTimeout)
|
|
47
52
|
es.start()
|
|
48
53
|
return es
|
|
49
54
|
}
|
|
@@ -58,6 +63,7 @@ private class SseHandler: EventHandler {
|
|
|
58
63
|
weak var source: EventSource?
|
|
59
64
|
let attemptVersion: Int
|
|
60
65
|
let dispatcher: SseDispatcher
|
|
66
|
+
private var isConnectedOrFinished: Bool = false
|
|
61
67
|
|
|
62
68
|
init(delegate: SseConnectionDelegate, attemptVersion: Int, dispatcher: SseDispatcher) {
|
|
63
69
|
self.delegate = delegate
|
|
@@ -65,8 +71,23 @@ private class SseHandler: EventHandler {
|
|
|
65
71
|
self.dispatcher = dispatcher
|
|
66
72
|
}
|
|
67
73
|
|
|
74
|
+
func startConnectionTimer(timeout: TimeInterval) {
|
|
75
|
+
guard timeout > 0 else { return }
|
|
76
|
+
dispatcher.asyncAfter(delay: timeout) { [weak self] in
|
|
77
|
+
guard let self = self, !self.isConnectedOrFinished, self.source != nil else { return }
|
|
78
|
+
self.isConnectedOrFinished = true
|
|
79
|
+
self.source?.stop()
|
|
80
|
+
self.source = nil
|
|
81
|
+
self.delegate?.connectionDidFail(
|
|
82
|
+
error: NSError(domain: NSURLErrorDomain, code: NSURLErrorTimedOut, userInfo: [NSLocalizedDescriptionKey: "Connection timed out"]),
|
|
83
|
+
attemptVersion: self.attemptVersion
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
68
88
|
func onOpened() {
|
|
69
89
|
guard source != nil else { return }
|
|
90
|
+
isConnectedOrFinished = true
|
|
70
91
|
dispatcher.async { [weak self] in
|
|
71
92
|
guard let self = self else { return }
|
|
72
93
|
self.delegate?.connectionDidOpen(attemptVersion: self.attemptVersion)
|
|
@@ -75,6 +96,7 @@ private class SseHandler: EventHandler {
|
|
|
75
96
|
|
|
76
97
|
func onClosed() {
|
|
77
98
|
guard source != nil else { return }
|
|
99
|
+
isConnectedOrFinished = true
|
|
78
100
|
dispatcher.async { [weak self] in
|
|
79
101
|
guard let self = self else { return }
|
|
80
102
|
self.delegate?.connectionDidClose(attemptVersion: self.attemptVersion)
|
|
@@ -106,6 +128,7 @@ private class SseHandler: EventHandler {
|
|
|
106
128
|
|
|
107
129
|
func onError(error: Error) {
|
|
108
130
|
guard source != nil else { return }
|
|
131
|
+
isConnectedOrFinished = true
|
|
109
132
|
dispatcher.async { [weak self] in
|
|
110
133
|
guard let self = self else { return }
|
|
111
134
|
self.delegate?.connectionDidFail(error: error, attemptVersion: self.attemptVersion)
|
|
@@ -65,12 +65,13 @@ class SseNetworkMonitor {
|
|
|
65
65
|
|
|
66
66
|
print("[NitroSse] Network path changed: status=\(path.status), interface=\(String(describing: interfaceType))")
|
|
67
67
|
|
|
68
|
+
// Only trigger an interface change if both the previous and current interfaces are known and differ.
|
|
69
|
+
// Initial detection (lastPathInterface == nil) must NOT be flagged as an interface change to avoid
|
|
70
|
+
// falsely triggering an immediate stream restart right after connection startup.
|
|
68
71
|
let interfaceChanged: Bool
|
|
69
72
|
if isSatisfied {
|
|
70
73
|
if let lastInterface = lastPathInterface, let currentInterface = interfaceType {
|
|
71
74
|
interfaceChanged = lastInterface != currentInterface
|
|
72
|
-
} else if lastPathInterface == nil && interfaceType != nil {
|
|
73
|
-
interfaceChanged = true
|
|
74
75
|
} else {
|
|
75
76
|
interfaceChanged = false
|
|
76
77
|
}
|
|
@@ -52,6 +52,11 @@ class SseReconnectStrategy {
|
|
|
52
52
|
guard maxReconnectAttempts != -1 else { return false }
|
|
53
53
|
return currentReconnectAttempts >= maxReconnectAttempts
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
/// Records an explicit reconnection attempt without altering the backoff exponent.
|
|
57
|
+
func recordAttempt() {
|
|
58
|
+
currentReconnectAttempts += 1
|
|
59
|
+
}
|
|
55
60
|
|
|
56
61
|
/// Calculates the next reconnection delay in seconds (enforcing a minimum 1.0s floor).
|
|
57
62
|
/// Exponential backoff is applied for errors (`isError == true`), while normal disconnects use the base interval with jitter.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Encapsulates mock streaming logic for testing and offline simulation.
|
|
5
|
+
* Handles timer intervals, looping, custom delays, simulated error rates, and mock state tracking.
|
|
6
|
+
*/
|
|
7
|
+
export class MockSseEngine {
|
|
8
|
+
_mockIndex = 0;
|
|
9
|
+
constructor(config, emitEvents) {
|
|
10
|
+
this._config = config;
|
|
11
|
+
this._emitEvents = emitEvents;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Transforms a raw mock event definition or partial SSE event into a full SseEvent DTO.
|
|
16
|
+
*/
|
|
17
|
+
static createSseEvent(rawMock) {
|
|
18
|
+
return {
|
|
19
|
+
type: rawMock.type ?? 'message',
|
|
20
|
+
data: rawMock.data,
|
|
21
|
+
parsedData: rawMock.parsedData,
|
|
22
|
+
id: rawMock.id,
|
|
23
|
+
event: rawMock.event,
|
|
24
|
+
message: rawMock.message,
|
|
25
|
+
statusCode: rawMock.statusCode ?? 200,
|
|
26
|
+
retry: rawMock.retry,
|
|
27
|
+
state: rawMock.state
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
_setMockState(state) {
|
|
31
|
+
if (this._mockState !== state) {
|
|
32
|
+
this._mockState = state;
|
|
33
|
+
const stateEvent = {
|
|
34
|
+
type: 'state',
|
|
35
|
+
state,
|
|
36
|
+
statusCode: 200
|
|
37
|
+
};
|
|
38
|
+
this._emitEvents([stateEvent]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Starts mock stream scheduling.
|
|
44
|
+
* @returns true if native stream should be skipped (replace mode), false otherwise (inject mode).
|
|
45
|
+
*/
|
|
46
|
+
start() {
|
|
47
|
+
if (this._mockIntervalId) {
|
|
48
|
+
clearTimeout(this._mockIntervalId);
|
|
49
|
+
this._mockIntervalId = undefined;
|
|
50
|
+
}
|
|
51
|
+
const {
|
|
52
|
+
mode,
|
|
53
|
+
data,
|
|
54
|
+
eventsPerSecond = 1,
|
|
55
|
+
loop = false,
|
|
56
|
+
errorRate = 0
|
|
57
|
+
} = this._config;
|
|
58
|
+
this._mockIndex = 0;
|
|
59
|
+
|
|
60
|
+
// Validate and normalize eventsPerSecond (must be a finite positive number, default to 1)
|
|
61
|
+
let validatedEventsPerSecond = Number(eventsPerSecond);
|
|
62
|
+
if (Number.isNaN(validatedEventsPerSecond) || !Number.isFinite(validatedEventsPerSecond) || validatedEventsPerSecond <= 0) {
|
|
63
|
+
validatedEventsPerSecond = 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Validate and normalize errorRate (must be a finite number within [0,1], default to 0)
|
|
67
|
+
let validatedErrorRate = Number(errorRate);
|
|
68
|
+
if (Number.isNaN(validatedErrorRate) || !Number.isFinite(validatedErrorRate)) {
|
|
69
|
+
validatedErrorRate = 0;
|
|
70
|
+
} else {
|
|
71
|
+
validatedErrorRate = Math.max(0, Math.min(1, validatedErrorRate));
|
|
72
|
+
}
|
|
73
|
+
const delayMs = 1000 / validatedEventsPerSecond;
|
|
74
|
+
// Safeguard: if eventsPerSecond is huge (e.g. 1000), setInterval/setTimeout is too slow.
|
|
75
|
+
// We batch events together in chunks if the calculated interval is under 10ms.
|
|
76
|
+
const batchSize = Math.max(1, Math.round(validatedEventsPerSecond / 100)); // chunk size for 10ms intervals
|
|
77
|
+
const intervalMs = Math.max(10, delayMs * batchSize);
|
|
78
|
+
const scheduleNext = () => {
|
|
79
|
+
if (this._mockIndex >= data.length) {
|
|
80
|
+
if (loop && data.length > 0) {
|
|
81
|
+
this._mockIndex = 0;
|
|
82
|
+
} else {
|
|
83
|
+
if (this._mockIntervalId) {
|
|
84
|
+
clearTimeout(this._mockIntervalId);
|
|
85
|
+
this._mockIntervalId = undefined;
|
|
86
|
+
}
|
|
87
|
+
if (mode === 'replace') {
|
|
88
|
+
this._setMockState('closed');
|
|
89
|
+
const closeEvent = {
|
|
90
|
+
type: 'close',
|
|
91
|
+
statusCode: 200
|
|
92
|
+
};
|
|
93
|
+
this._emitEvents([closeEvent]);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Simulate connection drops
|
|
100
|
+
if (validatedErrorRate && Math.random() < validatedErrorRate) {
|
|
101
|
+
if (mode === 'replace') {
|
|
102
|
+
this._setMockState('reconnecting');
|
|
103
|
+
}
|
|
104
|
+
const errorEvent = {
|
|
105
|
+
type: 'error',
|
|
106
|
+
message: 'Mock Connection Drop (Simulated Error)',
|
|
107
|
+
statusCode: 500
|
|
108
|
+
};
|
|
109
|
+
this._emitEvents([errorEvent]);
|
|
110
|
+
|
|
111
|
+
// Retry / reconnect delay simulator (e.g. 2000ms)
|
|
112
|
+
this._mockIntervalId = setTimeout(scheduleNext, 2000);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const currentItem = data[this._mockIndex];
|
|
116
|
+
const hasCustomDelay = currentItem && typeof currentItem.delayMs === 'number';
|
|
117
|
+
const batch = [];
|
|
118
|
+
if (hasCustomDelay) {
|
|
119
|
+
const rawMock = data[this._mockIndex++];
|
|
120
|
+
if (rawMock) {
|
|
121
|
+
batch.push(MockSseEngine.createSseEvent(rawMock));
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
for (let i = 0; i < batchSize && this._mockIndex < data.length; i++) {
|
|
125
|
+
const nextItem = data[this._mockIndex];
|
|
126
|
+
if (nextItem && typeof nextItem.delayMs === 'number') {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
const rawMock = data[this._mockIndex++];
|
|
130
|
+
if (rawMock) {
|
|
131
|
+
batch.push(MockSseEngine.createSseEvent(rawMock));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (batch.length > 0) {
|
|
136
|
+
if (mode === 'replace') {
|
|
137
|
+
this._setMockState('open');
|
|
138
|
+
}
|
|
139
|
+
this._emitEvents(batch);
|
|
140
|
+
}
|
|
141
|
+
if (this._mockIndex >= data.length) {
|
|
142
|
+
if (loop && data.length > 0) {
|
|
143
|
+
const nextItem = data[0];
|
|
144
|
+
const nextDelay = nextItem && typeof nextItem.delayMs === 'number' ? nextItem.delayMs : intervalMs;
|
|
145
|
+
this._mockIntervalId = setTimeout(scheduleNext, nextDelay);
|
|
146
|
+
} else {
|
|
147
|
+
this._mockIntervalId = setTimeout(scheduleNext, 0);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
const nextItem = data[this._mockIndex];
|
|
151
|
+
const nextDelay = nextItem && typeof nextItem.delayMs === 'number' ? nextItem.delayMs : intervalMs;
|
|
152
|
+
this._mockIntervalId = setTimeout(scheduleNext, nextDelay);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const firstItem = data[0];
|
|
156
|
+
const firstDelay = firstItem && typeof firstItem.delayMs === 'number' ? firstItem.delayMs : intervalMs;
|
|
157
|
+
if (mode === 'replace') {
|
|
158
|
+
this._setMockState('connecting');
|
|
159
|
+
this._setMockState('open');
|
|
160
|
+
|
|
161
|
+
// Emit simulated open event
|
|
162
|
+
const openEvent = {
|
|
163
|
+
type: 'open',
|
|
164
|
+
statusCode: 200
|
|
165
|
+
};
|
|
166
|
+
this._emitEvents([openEvent]);
|
|
167
|
+
this._mockIntervalId = setTimeout(scheduleNext, firstDelay);
|
|
168
|
+
return true; // Indicates replace mode (skip native start)
|
|
169
|
+
} else if (mode === 'inject') {
|
|
170
|
+
this._mockIntervalId = setTimeout(scheduleNext, firstDelay);
|
|
171
|
+
return false; // Indicates inject mode (continue native start)
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
stop() {
|
|
176
|
+
if (this._mockIntervalId) {
|
|
177
|
+
clearTimeout(this._mockIntervalId);
|
|
178
|
+
this._mockIntervalId = undefined;
|
|
179
|
+
}
|
|
180
|
+
if (this._config.mode === 'replace') {
|
|
181
|
+
this._setMockState('closed');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
restart() {
|
|
185
|
+
this.stop();
|
|
186
|
+
this.start();
|
|
187
|
+
}
|
|
188
|
+
isConnected() {
|
|
189
|
+
return this._mockState === 'open' || this._mockState === 'connecting' || this._mockState === 'reconnecting';
|
|
190
|
+
}
|
|
191
|
+
getStats() {
|
|
192
|
+
return {
|
|
193
|
+
totalBytesReceived: this._mockIndex * 150,
|
|
194
|
+
reconnectCount: 0
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
getState() {
|
|
198
|
+
return this._mockState ?? 'idle';
|
|
199
|
+
}
|
|
200
|
+
resetState() {
|
|
201
|
+
this._mockState = undefined;
|
|
202
|
+
if (this._mockIntervalId) {
|
|
203
|
+
clearTimeout(this._mockIntervalId);
|
|
204
|
+
this._mockIntervalId = undefined;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
injectEvent(event) {
|
|
208
|
+
const sseEvent = MockSseEngine.createSseEvent(event);
|
|
209
|
+
this._emitEvents([sseEvent]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=MockSseEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MockSseEngine","_mockIndex","constructor","config","emitEvents","_config","_emitEvents","createSseEvent","rawMock","type","data","parsedData","id","event","message","statusCode","retry","state","_setMockState","_mockState","stateEvent","start","_mockIntervalId","clearTimeout","undefined","mode","eventsPerSecond","loop","errorRate","validatedEventsPerSecond","Number","isNaN","isFinite","validatedErrorRate","Math","max","min","delayMs","batchSize","round","intervalMs","scheduleNext","length","closeEvent","random","errorEvent","setTimeout","currentItem","hasCustomDelay","batch","push","i","nextItem","nextDelay","firstItem","firstDelay","openEvent","stop","restart","isConnected","getStats","totalBytesReceived","reconnectCount","getState","resetState","injectEvent","sseEvent"],"sourceRoot":"../../src","sources":["MockSseEngine.ts"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