react-native-nitro-sse 1.4.1 → 1.5.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.
- package/README.md +3 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +148 -20
- package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +2 -2
- package/ios/NitroSse.swift +178 -46
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/SseInterface.d.ts +17 -0
- package/lib/typescript/src/SseInterface.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp +138 -0
- package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +5 -2
- package/nitrogen/generated/android/c++/JSseConfig.hpp +28 -3
- package/nitrogen/generated/android/c++/JSseEvent.hpp +11 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +18 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +9 -3
- package/nitrogen/generated/android/nitrosseOnLoad.cpp +2 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +130 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
- package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +2 -1
- package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.swift +67 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___.swift +66 -0
- package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/SseConfig.swift +84 -1
- package/nitrogen/generated/ios/swift/SseEvent.swift +37 -1
- package/nitrogen/generated/shared/c++/SseConfig.hpp +17 -3
- package/nitrogen/generated/shared/c++/SseEvent.hpp +10 -2
- package/package.json +1 -1
- package/src/SseInterface.ts +17 -0
- package/src/{index.tsx → index.ts} +4 -3
package/README.md
CHANGED
|
@@ -118,6 +118,9 @@ nitroSse.updateHeaders({
|
|
|
118
118
|
| `batchingIntervalMs` | `number` | Time window to buffer events before flushing to JS (Default: 0 - immediate). |
|
|
119
119
|
| `maxBufferSize` | `number` | Native queue limit to prevent memory overflow (Default: 1000). |
|
|
120
120
|
| `backgroundExecution` | `boolean` | (iOS) Attempt to maintain a background task for a short period. |
|
|
121
|
+
| `connectionTimeoutMs`| `number` | Connection timeout in milliseconds (Default: 15000). |
|
|
122
|
+
| `readTimeoutMs` | `number` | Read/Idle timeout in milliseconds (Default: 35000). |
|
|
123
|
+
| `onBeforeRequest` | `function`| Async callback to refresh headers before every request attempt. |
|
|
121
124
|
|
|
122
125
|
---
|
|
123
126
|
|
|
@@ -17,6 +17,7 @@ import androidx.lifecycle.ProcessLifecycleOwner
|
|
|
17
17
|
import java.util.concurrent.TimeUnit
|
|
18
18
|
import java.util.concurrent.atomic.AtomicBoolean
|
|
19
19
|
import java.util.concurrent.atomic.AtomicLong
|
|
20
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
20
21
|
import java.util.UUID
|
|
21
22
|
import kotlin.random.Random
|
|
22
23
|
|
|
@@ -45,6 +46,8 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
45
46
|
|
|
46
47
|
private val isRunning = AtomicBoolean(false)
|
|
47
48
|
private var wasRunningBeforePaused = false
|
|
49
|
+
private val consecutiveAuthErrors = AtomicInteger(0)
|
|
50
|
+
private val maxAuthRetries = 3
|
|
48
51
|
private var sseHandlerThread: android.os.HandlerThread? = null
|
|
49
52
|
private var sseHandler: Handler? = null
|
|
50
53
|
|
|
@@ -55,6 +58,7 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
55
58
|
@Volatile private var lastProcessedId: String? = null
|
|
56
59
|
|
|
57
60
|
private val totalBytesReceived = AtomicLong(0)
|
|
61
|
+
private val connectionAttemptVersion = AtomicInteger(0)
|
|
58
62
|
private var reconnectCount = 0
|
|
59
63
|
private var lastErrorTime: Double? = null
|
|
60
64
|
private var lastErrorCode: String? = null
|
|
@@ -69,14 +73,21 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
69
73
|
private const val TAG = "NitroSse"
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Set up the NitroSse instance with configuration and an event callback.
|
|
78
|
+
* This prepares the OkHttpClient and internal handler threads.
|
|
79
|
+
*
|
|
80
|
+
* @param config The SSE configuration containing URL, headers, and more.
|
|
81
|
+
* @param onEvent Callback function to receive batched SSE events.
|
|
82
|
+
*/
|
|
72
83
|
override fun setup(config: SseConfig, onEvent: (events: Array<SseEvent>) -> Unit) {
|
|
73
84
|
this.config = config
|
|
74
85
|
this.onEventsCallback = onEvent
|
|
75
86
|
|
|
76
87
|
if (this.client == null) {
|
|
77
88
|
this.client = OkHttpClient.Builder()
|
|
78
|
-
.connectTimeout(
|
|
79
|
-
.readTimeout(
|
|
89
|
+
.connectTimeout((config.connectionTimeoutMs ?: 15000.0).toLong(), TimeUnit.MILLISECONDS)
|
|
90
|
+
.readTimeout((config.readTimeoutMs ?: 35000.0).toLong(), TimeUnit.MILLISECONDS)
|
|
80
91
|
.addNetworkInterceptor { chain ->
|
|
81
92
|
val request = chain.request()
|
|
82
93
|
val rid = request.tag(String::class.java)
|
|
@@ -106,7 +117,8 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
106
117
|
for (i in 0 until bytesRead) {
|
|
107
118
|
val b = sink.get(bufferOffset + i)
|
|
108
119
|
if (isAtStartOfLine && b == ':'.code.toByte()) {
|
|
109
|
-
|
|
120
|
+
// This is a comment/heartbeat.
|
|
121
|
+
pushEventToBuffer(SseEvent(SseEventType.HEARTBEAT, null, null, null, "keep-alive", null, null))
|
|
110
122
|
}
|
|
111
123
|
isAtStartOfLine = (b == '\n'.code.toByte() || b == '\r'.code.toByte())
|
|
112
124
|
}
|
|
@@ -139,6 +151,10 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
139
151
|
}
|
|
140
152
|
}
|
|
141
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Called when the app enters the foreground.
|
|
156
|
+
* Automatically resumes the stream if it was hibernated.
|
|
157
|
+
*/
|
|
142
158
|
override fun onStart(owner: LifecycleOwner) {
|
|
143
159
|
if (wasRunningBeforePaused) {
|
|
144
160
|
Log.d(TAG, "App foregrounded. Resuming NitroSse stream.")
|
|
@@ -147,6 +163,10 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
147
163
|
}
|
|
148
164
|
}
|
|
149
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Called when the app enters the background.
|
|
168
|
+
* Hibernates the connection to save battery and resources.
|
|
169
|
+
*/
|
|
150
170
|
override fun onStop(owner: LifecycleOwner) {
|
|
151
171
|
if (isRunning.get()) {
|
|
152
172
|
Log.d(TAG, "App backgrounded. Hibernating NitroSse connection.")
|
|
@@ -189,19 +209,29 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
189
209
|
onEventsCallback?.invoke(eventsToEmit)
|
|
190
210
|
}
|
|
191
211
|
|
|
212
|
+
/**
|
|
213
|
+
* Manually set the last seen event ID.
|
|
214
|
+
* This will be used as the 'Last-Event-ID' header on the next connection attempt.
|
|
215
|
+
*/
|
|
192
216
|
override fun setLastProcessedId(id: String) {
|
|
193
217
|
this.lastProcessedId = id
|
|
194
218
|
}
|
|
195
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Dynamically update the headers for subsequent connection attempts.
|
|
222
|
+
*/
|
|
196
223
|
override fun updateHeaders(headers: Map<String, String>) {
|
|
197
224
|
synchronized(this) {
|
|
198
225
|
this.config?.let {
|
|
199
226
|
this.config = it.copy(headers = headers)
|
|
200
|
-
Log.d(TAG, "Headers updated
|
|
227
|
+
Log.d(TAG, "Headers updated manually")
|
|
201
228
|
}
|
|
202
229
|
}
|
|
203
230
|
}
|
|
204
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Returns runtime statistics about the SSE connection.
|
|
234
|
+
*/
|
|
205
235
|
override fun getStats(): SseStats {
|
|
206
236
|
return SseStats(
|
|
207
237
|
totalBytesReceived.get().toDouble(),
|
|
@@ -211,19 +241,66 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
211
241
|
)
|
|
212
242
|
}
|
|
213
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Start the SSE connection.
|
|
246
|
+
* This triggers the initial request and handles subsequent reconnections.
|
|
247
|
+
*/
|
|
214
248
|
override fun start() {
|
|
215
249
|
if (config == null || isRunning.get()) return
|
|
216
250
|
isRunning.set(true)
|
|
251
|
+
consecutiveAuthErrors.set(0) // Reset auth retry state
|
|
217
252
|
backoffCounter = 0
|
|
218
253
|
requestId = null
|
|
219
|
-
|
|
254
|
+
val version = connectionAttemptVersion.incrementAndGet()
|
|
255
|
+
sseHandler?.post { performConnection(version) }
|
|
220
256
|
}
|
|
221
257
|
|
|
222
|
-
private fun performConnection() {
|
|
258
|
+
private fun performConnection(version: Int) {
|
|
259
|
+
if (!isRunning.get() || version != connectionAttemptVersion.get()) return
|
|
260
|
+
|
|
261
|
+
val currentConfig = synchronized(this) { config } ?: return
|
|
262
|
+
val interceptor = currentConfig.onBeforeRequest
|
|
263
|
+
|
|
264
|
+
if (interceptor != null) {
|
|
265
|
+
interceptor.invoke().then { promise2 ->
|
|
266
|
+
promise2.then { newHeaders ->
|
|
267
|
+
sseHandler?.post {
|
|
268
|
+
if (!isRunning.get() || version != connectionAttemptVersion.get()) return@post
|
|
269
|
+
synchronized(this) {
|
|
270
|
+
val mergedHeaders = (config?.headers ?: emptyMap()).toMutableMap()
|
|
271
|
+
newHeaders.forEach { (k, v) -> mergedHeaders[k] = v }
|
|
272
|
+
config = config?.copy(headers = mergedHeaders)
|
|
273
|
+
}
|
|
274
|
+
executeConnection(version)
|
|
275
|
+
}
|
|
276
|
+
}.catch { error ->
|
|
277
|
+
handleInterceptorError(error, version)
|
|
278
|
+
}
|
|
279
|
+
}.catch { error ->
|
|
280
|
+
handleInterceptorError(error, version)
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
executeConnection(version)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private fun handleInterceptorError(t: Throwable?, version: Int) {
|
|
288
|
+
sseHandler?.post {
|
|
289
|
+
if (!isRunning.get() || version != connectionAttemptVersion.get()) return@post
|
|
290
|
+
Log.e(TAG, "Request Interceptor Error: ${t?.message}")
|
|
291
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Interceptor Error: ${t?.message}", -1.0, null))
|
|
292
|
+
|
|
293
|
+
// Reconnect with delay
|
|
294
|
+
val delay = (defaultRetryDelayMs * (0.8 + Random.nextDouble() * 0.4)).toLong()
|
|
295
|
+
sseHandler?.postDelayed({ if (isRunning.get()) performConnection(version) }, delay)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private fun executeConnection(version: Int) {
|
|
223
300
|
val currentConfig: SseConfig
|
|
224
301
|
val currentLastId: String?
|
|
225
302
|
synchronized(this) {
|
|
226
|
-
if (!isRunning.get() || config == null) return
|
|
303
|
+
if (!isRunning.get() || config == null || version != connectionAttemptVersion.get()) return
|
|
227
304
|
currentConfig = config!!
|
|
228
305
|
currentLastId = lastProcessedId
|
|
229
306
|
}
|
|
@@ -279,8 +356,9 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
279
356
|
private val sseListener = object : EventSourceListener() {
|
|
280
357
|
override fun onOpen(eventSource: EventSource, response: Response) {
|
|
281
358
|
if (eventSource != this@NitroSse.eventSource) return
|
|
359
|
+
consecutiveAuthErrors.set(0) // Successful connection, reset error counter
|
|
282
360
|
backoffCounter = 0
|
|
283
|
-
pushEventToBuffer(SseEvent(SseEventType.OPEN, null, null, null, null))
|
|
361
|
+
pushEventToBuffer(SseEvent(SseEventType.OPEN, null, null, null, null, response.code.toDouble(), null))
|
|
284
362
|
}
|
|
285
363
|
|
|
286
364
|
override fun onEvent(eventSource: EventSource, id: String?, type: String?, data: String) {
|
|
@@ -288,7 +366,7 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
288
366
|
if (!id.isNullOrEmpty()) {
|
|
289
367
|
this@NitroSse.lastProcessedId = id
|
|
290
368
|
}
|
|
291
|
-
pushEventToBuffer(SseEvent(SseEventType.MESSAGE, data, id, type, null))
|
|
369
|
+
pushEventToBuffer(SseEvent(SseEventType.MESSAGE, data, id, type, null, 200.0, null))
|
|
292
370
|
}
|
|
293
371
|
|
|
294
372
|
override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) {
|
|
@@ -303,9 +381,33 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
303
381
|
|
|
304
382
|
requestId?.let { NetworkInspector.reportRequestFailed(it, false) }
|
|
305
383
|
|
|
306
|
-
|
|
384
|
+
// 401/403 are recoverable if we have an interceptor, but with a limit
|
|
385
|
+
if (statusCode == 401 || statusCode == 403) {
|
|
386
|
+
val hasInterceptor = synchronized(this) { config?.onBeforeRequest != null }
|
|
387
|
+
if (!hasInterceptor) {
|
|
388
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Auth Error ($statusCode) - No interceptor provided. Stopping.", statusCode.toDouble(), null))
|
|
389
|
+
stop()
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
val retries = consecutiveAuthErrors.incrementAndGet()
|
|
394
|
+
if (retries >= maxAuthRetries) {
|
|
395
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Auth Error ($statusCode) - Retry limit reached ($maxAuthRetries). Stopping.", statusCode.toDouble(), null))
|
|
396
|
+
stop()
|
|
397
|
+
return
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Auth Error ($statusCode) - Retry $retries/$maxAuthRetries. Refreshing token...", statusCode.toDouble(), null))
|
|
401
|
+
val delay = (defaultRetryDelayMs * (0.8 + Random.nextDouble() * 0.4)).toLong()
|
|
402
|
+
sseHandler?.postDelayed({
|
|
403
|
+
if (isRunning.get() && eventSource == this@NitroSse.eventSource) performConnection(connectionAttemptVersion.get())
|
|
404
|
+
}, delay)
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
val isFatal = (statusCode == 400)
|
|
307
409
|
if (isFatal) {
|
|
308
|
-
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Fatal Error ($statusCode). Stopping."))
|
|
410
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Fatal Error ($statusCode). Stopping.", statusCode.toDouble(), null))
|
|
309
411
|
stop()
|
|
310
412
|
return
|
|
311
413
|
}
|
|
@@ -314,13 +416,15 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
314
416
|
if ((statusCode == 429 || statusCode == 503) && retryAfterMillis != null) {
|
|
315
417
|
val jitter = (500 + Random.nextInt(1500)).toLong()
|
|
316
418
|
val totalDelay = retryAfterMillis + jitter
|
|
317
|
-
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Retry-After received: ${totalDelay/1000}s"))
|
|
318
|
-
sseHandler?.postDelayed({
|
|
419
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Retry-After received: ${totalDelay/1000}s", statusCode.toDouble(), totalDelay.toDouble()))
|
|
420
|
+
sseHandler?.postDelayed({
|
|
421
|
+
if (isRunning.get() && eventSource == this@NitroSse.eventSource) performConnection(connectionAttemptVersion.get())
|
|
422
|
+
}, totalDelay)
|
|
319
423
|
return
|
|
320
424
|
}
|
|
321
425
|
|
|
322
426
|
if (statusCode == 429) {
|
|
323
|
-
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Rate Limited (429) without Retry-After. Stopping."))
|
|
427
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "Rate Limited (429) without Retry-After. Stopping.", 429.0, null))
|
|
324
428
|
stop()
|
|
325
429
|
return
|
|
326
430
|
}
|
|
@@ -335,8 +439,17 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
335
439
|
}
|
|
336
440
|
|
|
337
441
|
val safeReconnectDelay = Math.max(reconnectDelay, 2000L)
|
|
338
|
-
|
|
339
|
-
|
|
442
|
+
|
|
443
|
+
if (statusCode == 204) {
|
|
444
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, "No Content (204). Stopping.", 204.0, null))
|
|
445
|
+
stop()
|
|
446
|
+
return
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
pushEventToBuffer(SseEvent(SseEventType.ERROR, null, null, null, t?.message ?: "Link lost ($statusCode)", if (statusCode != -1) statusCode.toDouble() else null, null))
|
|
450
|
+
sseHandler?.postDelayed({
|
|
451
|
+
if (isRunning.get() && eventSource == this@NitroSse.eventSource) performConnection(connectionAttemptVersion.get())
|
|
452
|
+
}, safeReconnectDelay)
|
|
340
453
|
}
|
|
341
454
|
|
|
342
455
|
override fun onClosed(eventSource: EventSource) {
|
|
@@ -344,25 +457,40 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
344
457
|
if (isRunning.get()) {
|
|
345
458
|
requestId?.let { NetworkInspector.reportResponseEnd(it, totalBytesReceived.get()) }
|
|
346
459
|
val delay = (defaultRetryDelayMs * (0.8 + Random.nextDouble() * 0.4)).toLong()
|
|
347
|
-
sseHandler?.postDelayed({
|
|
460
|
+
sseHandler?.postDelayed({
|
|
461
|
+
if (isRunning.get() && eventSource == this@NitroSse.eventSource) performConnection(connectionAttemptVersion.get())
|
|
462
|
+
}, delay)
|
|
348
463
|
}
|
|
349
464
|
}
|
|
350
465
|
}
|
|
351
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Immediately emit any pending buffered events to the JS bridge.
|
|
469
|
+
*/
|
|
352
470
|
override fun flush() {
|
|
353
471
|
flushBufferToJs()
|
|
354
472
|
}
|
|
355
473
|
|
|
474
|
+
/**
|
|
475
|
+
* Restart the SSE connection by stopping and starting again.
|
|
476
|
+
*/
|
|
356
477
|
override fun restart() {
|
|
357
478
|
stop()
|
|
358
479
|
start()
|
|
359
480
|
}
|
|
360
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Indicates if the SSE connection is currently active or trying to connect.
|
|
484
|
+
*/
|
|
361
485
|
override fun isConnected(): Boolean {
|
|
362
486
|
return isRunning.get()
|
|
363
487
|
}
|
|
364
488
|
|
|
489
|
+
/**
|
|
490
|
+
* Stop the SSE connection and clear any pending reconnect timers.
|
|
491
|
+
*/
|
|
365
492
|
override fun stop() {
|
|
493
|
+
flushBufferToJs()
|
|
366
494
|
isRunning.set(false)
|
|
367
495
|
backoffCounter = 0
|
|
368
496
|
sseHandler?.removeCallbacksAndMessages(null)
|
|
@@ -372,12 +500,12 @@ class NitroSse : HybridNitroSseSpec(), DefaultLifecycleObserver {
|
|
|
372
500
|
NetworkInspector.reportResponseEnd(it, totalBytesReceived.get())
|
|
373
501
|
requestId = null
|
|
374
502
|
}
|
|
375
|
-
synchronized(eventBuffer) {
|
|
376
|
-
eventBuffer.clear()
|
|
377
|
-
}
|
|
378
503
|
isFlushPending.set(false)
|
|
379
504
|
}
|
|
380
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Clean up all resources, including background threads and lifecycle observers.
|
|
508
|
+
*/
|
|
381
509
|
override fun dispose() {
|
|
382
510
|
Log.d(TAG, "Disposing NitroSse instance and cleaning up resources...")
|
|
383
511
|
stop()
|
|
@@ -35,7 +35,7 @@ class NitroSseLogicTest {
|
|
|
35
35
|
batchInterval = 100.0 // Enable batching so we don't flush immediately
|
|
36
36
|
|
|
37
37
|
for (i in 1..10) {
|
|
38
|
-
pushEventToBuffer(SseEvent(SseEventType.MESSAGE, "data $i", "$i", null, null)) {}
|
|
38
|
+
pushEventToBuffer(SseEvent(SseEventType.MESSAGE, "data $i", "$i", null, null, null, null)) {}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
assertEquals(5, eventBuffer.size)
|
|
@@ -48,7 +48,7 @@ class NitroSseLogicTest {
|
|
|
48
48
|
batchInterval = 0.0
|
|
49
49
|
val flushCount = AtomicInteger(0)
|
|
50
50
|
|
|
51
|
-
pushEventToBuffer(SseEvent(SseEventType.OPEN, null, null, null, null)) {
|
|
51
|
+
pushEventToBuffer(SseEvent(SseEventType.OPEN, null, null, null, null, null, null)) {
|
|
52
52
|
flushCount.incrementAndGet()
|
|
53
53
|
}
|
|
54
54
|
|