react-native-nitro-sse 2.4.2 → 3.0.0-beta.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/README.md +209 -95
- package/android/build.gradle +4 -1
- package/android/src/main/java/com/margelo/nitro/nitrosse/AndroidSseDispatcher.kt +5 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/JsonUtils.kt +11 -18
- package/android/src/main/java/com/margelo/nitro/nitrosse/NetworkInspector.kt +79 -36
- package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +164 -88
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +40 -15
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseDispatcher.kt +1 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +34 -25
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseLifecycleManager.kt +8 -1
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseNetworkMonitor.kt +7 -4
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +2 -4
- package/ios/NitroSse.swift +229 -191
- package/ios/SseConfig+CopyWith.swift +2 -1
- package/ios/SseConnectionHandler.swift +40 -29
- package/ios/SseDispatchQueueDispatcher.swift +15 -2
- package/ios/SseDispatcher.swift +7 -1
- package/ios/SseEventBuffer.swift +23 -7
- package/ios/SseLifecycleManager.swift +10 -1
- package/ios/SseNetworkMonitor.swift +5 -0
- package/ios/SseReconnectStrategy.swift +4 -3
- package/lib/module/MockSseEngine.js +12 -21
- package/lib/module/NitroSseClient.js +385 -12
- package/lib/module/NitroSseError.js +61 -0
- package/lib/module/SseDriver.js +33 -2
- package/lib/module/index.js +6 -3
- package/lib/module/useNitroSse.js +359 -0
- package/lib/typescript/src/MockSseEngine.d.ts +1 -1
- package/lib/typescript/src/NitroSse.nitro.d.ts +25 -2
- package/lib/typescript/src/NitroSseClient.d.ts +20 -2
- package/lib/typescript/src/NitroSseError.d.ts +38 -0
- package/lib/typescript/src/SseDriver.d.ts +10 -2
- package/lib/typescript/src/SseInterface.d.ts +23 -7
- package/lib/typescript/src/index.d.ts +4 -2
- package/lib/typescript/src/useNitroSse.d.ts +69 -0
- package/nitrogen/generated/android/c++/JSseConfig.hpp +5 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +9 -4
- package/nitrogen/generated/ios/swift/SseConfig.swift +19 -1
- package/nitrogen/generated/shared/c++/SseConfig.hpp +5 -1
- package/package.json +8 -7
- package/android/jacoco.gradle +0 -33
- package/lib/module/MockSseEngine.js.map +0 -1
- package/lib/module/NitroSse.nitro.js.map +0 -1
- package/lib/module/NitroSseClient.js.map +0 -1
- package/lib/module/SseDriver.js.map +0 -1
- package/lib/module/SseInterface.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/typescript/src/MockSseEngine.d.ts.map +0 -1
- package/lib/typescript/src/NitroSse.nitro.d.ts.map +0 -1
- package/lib/typescript/src/NitroSseClient.d.ts.map +0 -1
- package/lib/typescript/src/SseDriver.d.ts.map +0 -1
- package/lib/typescript/src/SseInterface.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/src/MockSseEngine.ts +0 -254
- package/src/NitroSse.nitro.ts +0 -58
- package/src/NitroSseClient.ts +0 -154
- package/src/SseDriver.ts +0 -161
- package/src/SseInterface.ts +0 -274
- package/src/index.ts +0 -31
|
@@ -31,18 +31,26 @@ enum SseConnectionHandler {
|
|
|
31
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
|
+
// Prevent LDSwiftEventSource's default 300s idle timeout override.
|
|
35
|
+
esConfig.idleTimeout = readTimeout
|
|
36
|
+
// Disable LDSwift internal reconnect; reconnection is coordinated externally by NitroSse.
|
|
34
37
|
esConfig.connectionErrorHandler = { [weak handler] error in
|
|
35
38
|
handler?.onError(error: error)
|
|
36
39
|
return .shutdown
|
|
37
40
|
}
|
|
38
41
|
esConfig.urlSessionConfiguration = sessionConfig
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
// Prevent initial config headers from overriding the dynamic Last-Event-ID on reconnection.
|
|
43
|
+
var initialHeaders = config.headers ?? [:]
|
|
44
|
+
initialHeaders = initialHeaders.filter { $0.key.caseInsensitiveCompare("Last-Event-Id") != .orderedSame }
|
|
45
|
+
esConfig.headers = initialHeaders
|
|
46
|
+
esConfig.lastEventId = lastProcessedId ?? ""
|
|
41
47
|
if let lastId = lastProcessedId, !lastId.isEmpty {
|
|
42
|
-
esConfig.
|
|
48
|
+
esConfig.headerTransform = { headers in
|
|
49
|
+
var transformed = headers
|
|
50
|
+
transformed["Last-Event-Id"] = lastId
|
|
51
|
+
return transformed
|
|
52
|
+
}
|
|
43
53
|
}
|
|
44
|
-
|
|
45
|
-
esConfig.lastEventId = lastProcessedId ?? ""
|
|
46
54
|
esConfig.method = config.method?.stringValue.uppercased() ?? "GET"
|
|
47
55
|
esConfig.body = config.body?.data(using: .utf8)
|
|
48
56
|
|
|
@@ -64,6 +72,7 @@ private class SseHandler: EventHandler {
|
|
|
64
72
|
let attemptVersion: Int
|
|
65
73
|
let dispatcher: SseDispatcher
|
|
66
74
|
private var isConnectedOrFinished: Bool = false
|
|
75
|
+
private var isTerminalDispatched: Bool = false
|
|
67
76
|
|
|
68
77
|
init(delegate: SseConnectionDelegate, attemptVersion: Int, dispatcher: SseDispatcher) {
|
|
69
78
|
self.delegate = delegate
|
|
@@ -71,11 +80,25 @@ private class SseHandler: EventHandler {
|
|
|
71
80
|
self.dispatcher = dispatcher
|
|
72
81
|
}
|
|
73
82
|
|
|
83
|
+
private func dispatchToDelegate(isTerminal: Bool = false, _ action: @escaping (SseConnectionDelegate) -> Void) {
|
|
84
|
+
dispatcher.async { [weak self] in
|
|
85
|
+
guard let self = self, self.source != nil else { return }
|
|
86
|
+
if isTerminal {
|
|
87
|
+
guard !self.isTerminalDispatched else { return }
|
|
88
|
+
self.isTerminalDispatched = true
|
|
89
|
+
}
|
|
90
|
+
self.isConnectedOrFinished = true
|
|
91
|
+
guard let delegate = self.delegate else { return }
|
|
92
|
+
action(delegate)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
74
96
|
func startConnectionTimer(timeout: TimeInterval) {
|
|
75
97
|
guard timeout > 0 else { return }
|
|
76
98
|
dispatcher.asyncAfter(delay: timeout) { [weak self] in
|
|
77
99
|
guard let self = self, !self.isConnectedOrFinished, self.source != nil else { return }
|
|
78
100
|
self.isConnectedOrFinished = true
|
|
101
|
+
self.isTerminalDispatched = true
|
|
79
102
|
self.source?.stop()
|
|
80
103
|
self.source = nil
|
|
81
104
|
self.delegate?.connectionDidFail(
|
|
@@ -86,28 +109,20 @@ private class SseHandler: EventHandler {
|
|
|
86
109
|
}
|
|
87
110
|
|
|
88
111
|
func onOpened() {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
dispatcher.async { [weak self] in
|
|
92
|
-
guard let self = self else { return }
|
|
93
|
-
self.delegate?.connectionDidOpen(attemptVersion: self.attemptVersion)
|
|
112
|
+
dispatchToDelegate { delegate in
|
|
113
|
+
delegate.connectionDidOpen(attemptVersion: self.attemptVersion)
|
|
94
114
|
}
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
func onClosed() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
dispatcher.async { [weak self] in
|
|
101
|
-
guard let self = self else { return }
|
|
102
|
-
self.delegate?.connectionDidClose(attemptVersion: self.attemptVersion)
|
|
118
|
+
dispatchToDelegate(isTerminal: true) { delegate in
|
|
119
|
+
delegate.connectionDidClose(attemptVersion: self.attemptVersion)
|
|
103
120
|
}
|
|
104
121
|
}
|
|
105
122
|
|
|
106
123
|
func onMessage(eventType: String, messageEvent: MessageEvent) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
guard let self = self else { return }
|
|
110
|
-
self.delegate?.connectionDidReceiveMessage(
|
|
124
|
+
dispatchToDelegate { delegate in
|
|
125
|
+
delegate.connectionDidReceiveMessage(
|
|
111
126
|
eventType: eventType,
|
|
112
127
|
data: messageEvent.data,
|
|
113
128
|
lastEventId: messageEvent.lastEventId,
|
|
@@ -117,21 +132,17 @@ private class SseHandler: EventHandler {
|
|
|
117
132
|
}
|
|
118
133
|
|
|
119
134
|
/// Maps native SSE comments (lines starting with ':') to heartbeat events.
|
|
120
|
-
///
|
|
135
|
+
/// Normalizes comment by removing single leading space per WHATWG SSE specification for cross-platform parity.
|
|
121
136
|
func onComment(comment: String) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
self.delegate?.connectionDidReceiveComment(comment, attemptVersion: self.attemptVersion)
|
|
137
|
+
let normalized = comment.hasPrefix(" ") ? String(comment.dropFirst()) : comment
|
|
138
|
+
dispatchToDelegate { delegate in
|
|
139
|
+
delegate.connectionDidReceiveComment(normalized, attemptVersion: self.attemptVersion)
|
|
126
140
|
}
|
|
127
141
|
}
|
|
128
142
|
|
|
129
143
|
func onError(error: Error) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
dispatcher.async { [weak self] in
|
|
133
|
-
guard let self = self else { return }
|
|
134
|
-
self.delegate?.connectionDidFail(error: error, attemptVersion: self.attemptVersion)
|
|
144
|
+
dispatchToDelegate(isTerminal: true) { delegate in
|
|
145
|
+
delegate.connectionDidFail(error: error, attemptVersion: self.attemptVersion)
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
148
|
}
|
|
@@ -15,8 +15,21 @@ class SseDispatchQueueDispatcher: SseDispatcher {
|
|
|
15
15
|
queue.async(execute: block)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
private class WorkItemCancellable: SseCancellable {
|
|
19
|
+
private let item: DispatchWorkItem
|
|
20
|
+
init(item: DispatchWorkItem) {
|
|
21
|
+
self.item = item
|
|
22
|
+
}
|
|
23
|
+
func cancel() {
|
|
24
|
+
item.cancel()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@discardableResult
|
|
29
|
+
func asyncAfter(delay: TimeInterval, _ block: @escaping () -> Void) -> SseCancellable? {
|
|
30
|
+
let workItem = DispatchWorkItem(block: block)
|
|
31
|
+
queue.asyncAfter(deadline: .now() + delay, execute: workItem)
|
|
32
|
+
return WorkItemCancellable(item: workItem)
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
/// Executes block inline if already running on queue to avoid re-entrant deadlocks.
|
package/ios/SseDispatcher.swift
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
|
+
/// Token representing a scheduled asynchronous delayed work item that can be cancelled.
|
|
4
|
+
protocol SseCancellable: AnyObject {
|
|
5
|
+
func cancel()
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
/// Abstraction layer for serializing operations and scheduling timers across production and test environments.
|
|
4
9
|
/// Enables deterministic synchronous control in unit tests (`MockSseDispatcher`) without real-time wait delays.
|
|
5
10
|
protocol SseDispatcher: AnyObject {
|
|
6
11
|
func async(_ block: @escaping () -> Void)
|
|
7
|
-
|
|
12
|
+
@discardableResult
|
|
13
|
+
func asyncAfter(delay: TimeInterval, _ block: @escaping () -> Void) -> SseCancellable?
|
|
8
14
|
func sync<T>(_ block: () throws -> T) rethrows -> T
|
|
9
15
|
|
|
10
16
|
/// Checks whether the caller is running on the dispatcher's execution context to avoid re-entrant deadlocks on `sync`.
|
package/ios/SseEventBuffer.swift
CHANGED
|
@@ -5,7 +5,7 @@ import NitroModules
|
|
|
5
5
|
/// All mutating operations must be synchronized on the associated `SseDispatcher`.
|
|
6
6
|
class SseEventBuffer {
|
|
7
7
|
private var eventBuffer: [SseEvent] = []
|
|
8
|
-
private var
|
|
8
|
+
private var pendingTimer: SseCancellable?
|
|
9
9
|
private var onFlush: ((_ events: [SseEvent]) -> Void)?
|
|
10
10
|
|
|
11
11
|
private var batchingIntervalMs: Double = 0
|
|
@@ -35,11 +35,14 @@ class SseEventBuffer {
|
|
|
35
35
|
eventBuffer.append(event)
|
|
36
36
|
|
|
37
37
|
if eventBuffer.count >= maxBufferSize || batchingIntervalMs <= 0 {
|
|
38
|
+
cancelPendingTimer()
|
|
38
39
|
flush()
|
|
39
|
-
} else if
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
self?.
|
|
40
|
+
} else if pendingTimer == nil, let dispatcher = dispatcher {
|
|
41
|
+
pendingTimer = dispatcher.asyncAfter(delay: batchingIntervalMs / 1000.0) { [weak self] in
|
|
42
|
+
guard let self = self else { return }
|
|
43
|
+
self.dispatcher?.assertOnQueue()
|
|
44
|
+
self.pendingTimer = nil
|
|
45
|
+
self.flush()
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -47,20 +50,33 @@ class SseEventBuffer {
|
|
|
47
50
|
/// Flushes all pending buffered events to JavaScript.
|
|
48
51
|
func flush() {
|
|
49
52
|
dispatcher?.assertOnQueue()
|
|
53
|
+
cancelPendingTimer()
|
|
50
54
|
guard !eventBuffer.isEmpty else { return }
|
|
51
55
|
|
|
52
56
|
let batch = eventBuffer
|
|
53
57
|
eventBuffer.removeAll()
|
|
54
|
-
isFlushPending = false
|
|
55
58
|
|
|
56
59
|
onFlush?(batch)
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
private func cancelPendingTimer() {
|
|
63
|
+
dispatcher?.assertOnQueue()
|
|
64
|
+
pendingTimer?.cancel()
|
|
65
|
+
pendingTimer = nil
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// Nullifies the flush callback to prevent invoking a destroyed JS runtime during teardown.
|
|
69
|
+
func clearCallback() {
|
|
70
|
+
dispatcher?.assertOnQueue()
|
|
71
|
+
self.onFlush = nil
|
|
72
|
+
}
|
|
73
|
+
|
|
59
74
|
/// Clears buffered events without invoking the flush callback.
|
|
60
75
|
/// Used during teardown to avoid executing JS callbacks after the bridge runtime is destroyed.
|
|
61
76
|
func clear() {
|
|
77
|
+
dispatcher?.assertOnQueue()
|
|
78
|
+
cancelPendingTimer()
|
|
62
79
|
eventBuffer.removeAll()
|
|
63
|
-
isFlushPending = false
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
/// Converts a raw JSON payload string into a Nitro `AnyMap`.
|
|
@@ -27,10 +27,17 @@ class SseLifecycleManager {
|
|
|
27
27
|
self.onForeground = onForeground
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/// Ensures notification observers are unregistered and active background tasks are ended on deallocation.
|
|
31
|
+
deinit {
|
|
32
|
+
stopObserving()
|
|
33
|
+
cleanupBackgroundTask()
|
|
34
|
+
}
|
|
35
|
+
|
|
30
36
|
/// Registers observer for iOS application state transitions via `NotificationCenter`.
|
|
37
|
+
/// Calls `removeObserver(self)` first to guarantee idempotency without mutable state.
|
|
31
38
|
func startObserving() {
|
|
32
|
-
NotificationCenter.default.removeObserver(self)
|
|
33
39
|
#if os(iOS)
|
|
40
|
+
NotificationCenter.default.removeObserver(self)
|
|
34
41
|
NotificationCenter.default.addObserver(
|
|
35
42
|
self,
|
|
36
43
|
selector: #selector(handleAppDidEnterBackground),
|
|
@@ -48,7 +55,9 @@ class SseLifecycleManager {
|
|
|
48
55
|
|
|
49
56
|
/// Unregisters all lifecycle notification observers.
|
|
50
57
|
func stopObserving() {
|
|
58
|
+
#if os(iOS)
|
|
51
59
|
NotificationCenter.default.removeObserver(self)
|
|
60
|
+
#endif
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
/// Begins a `UIBackgroundTask` to request background execution time from iOS.
|
|
@@ -24,6 +24,11 @@ class SseNetworkMonitor {
|
|
|
24
24
|
self.onChange = onChange
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/// Synchronously queries whether the active network path is currently satisfied (online).
|
|
28
|
+
var isPathSatisfied: Bool {
|
|
29
|
+
return pathMonitor?.currentPath.status == .satisfied
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
/// Starts observing system network changes. Idempotent call.
|
|
28
33
|
func start() {
|
|
29
34
|
guard pathMonitor == nil else { return }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
|
-
/// Calculates backoff delays using randomized full jitter exponential backoff
|
|
4
|
-
///
|
|
3
|
+
/// Calculates backoff delays using randomized full jitter exponential backoff.
|
|
4
|
+
/// Custom implementation guarantees cross-platform parity with Android and enforces maxReconnectAttempts.
|
|
5
5
|
class SseReconnectStrategy {
|
|
6
6
|
private var backoffCounter: Int = 0
|
|
7
7
|
private var currentReconnectAttempts: Int = 0
|
|
@@ -82,7 +82,8 @@ class SseReconnectStrategy {
|
|
|
82
82
|
currentReconnectAttempts = 0
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
/// Parses `Retry-After` HTTP headers per RFC 7231
|
|
85
|
+
/// Parses `Retry-After` HTTP headers per RFC 7231 (integer seconds or RFC 1123 date).
|
|
86
|
+
/// Fallback to full jitter backoff when response metadata is omitted by underlying client.
|
|
86
87
|
static func extractRetryAfterSeconds(from error: Error) -> TimeInterval? {
|
|
87
88
|
let nsError = error as NSError
|
|
88
89
|
guard let response = nsError.userInfo["response"] as? HTTPURLResponse else { return nil }
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export class MockSseEngine {
|
|
8
8
|
_mockIndex = 0;
|
|
9
|
+
_totalBytesReceived = 0;
|
|
9
10
|
constructor(config, emitEvents) {
|
|
10
11
|
this._config = config;
|
|
11
12
|
this._emitEvents = emitEvents;
|
|
@@ -56,6 +57,7 @@ export class MockSseEngine {
|
|
|
56
57
|
errorRate = 0
|
|
57
58
|
} = this._config;
|
|
58
59
|
this._mockIndex = 0;
|
|
60
|
+
this._totalBytesReceived = 0;
|
|
59
61
|
|
|
60
62
|
// Validate and normalize eventsPerSecond (must be a finite positive number, default to 1)
|
|
61
63
|
let validatedEventsPerSecond = Number(eventsPerSecond);
|
|
@@ -133,24 +135,20 @@ export class MockSseEngine {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
if (batch.length > 0) {
|
|
138
|
+
for (const ev of batch) {
|
|
139
|
+
const dataLen = ev.data ? ev.data.length : 0;
|
|
140
|
+
const evLen = ev.event ? ev.event.length : 0;
|
|
141
|
+
const idLen = ev.id ? ev.id.length : 0;
|
|
142
|
+
this._totalBytesReceived += Math.max(1, dataLen + evLen + idLen);
|
|
143
|
+
}
|
|
136
144
|
if (mode === 'replace') {
|
|
137
145
|
this._setMockState('open');
|
|
138
146
|
}
|
|
139
147
|
this._emitEvents(batch);
|
|
140
148
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
}
|
|
149
|
+
const nextItem = this._mockIndex < data.length ? data[this._mockIndex] : data[0];
|
|
150
|
+
const nextDelay = this._mockIndex >= data.length && !loop ? 0 : typeof nextItem?.delayMs === 'number' ? nextItem.delayMs : intervalMs;
|
|
151
|
+
this._mockIntervalId = setTimeout(scheduleNext, nextDelay);
|
|
154
152
|
};
|
|
155
153
|
const firstItem = data[0];
|
|
156
154
|
const firstDelay = firstItem && typeof firstItem.delayMs === 'number' ? firstItem.delayMs : intervalMs;
|
|
@@ -190,20 +188,13 @@ export class MockSseEngine {
|
|
|
190
188
|
}
|
|
191
189
|
getStats() {
|
|
192
190
|
return {
|
|
193
|
-
totalBytesReceived: this.
|
|
191
|
+
totalBytesReceived: this._totalBytesReceived,
|
|
194
192
|
reconnectCount: 0
|
|
195
193
|
};
|
|
196
194
|
}
|
|
197
195
|
getState() {
|
|
198
196
|
return this._mockState ?? 'idle';
|
|
199
197
|
}
|
|
200
|
-
resetState() {
|
|
201
|
-
this._mockState = undefined;
|
|
202
|
-
if (this._mockIntervalId) {
|
|
203
|
-
clearTimeout(this._mockIntervalId);
|
|
204
|
-
this._mockIntervalId = undefined;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
198
|
injectEvent(event) {
|
|
208
199
|
const sseEvent = MockSseEngine.createSseEvent(event);
|
|
209
200
|
this._emitEvents([sseEvent]);
|