react-native-nitro-sse 3.0.0 → 3.1.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/NitroSse.podspec +0 -1
- package/README.md +1 -1
- package/android/build.gradle +0 -1
- package/android/src/main/java/com/margelo/nitro/nitrosse/JsonUtils.kt +33 -10
- package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +366 -78
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +417 -94
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +20 -0
- package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +9 -0
- package/ios/NitroSse.swift +302 -49
- package/ios/SseConnectionHandler.swift +647 -97
- package/ios/SseEventBuffer.swift +19 -1
- package/ios/SseReconnectStrategy.swift +26 -7
- package/lib/module/MockSseEngine.js +72 -3
- package/lib/module/NitroSseClient.js +24 -1
- package/lib/typescript/src/MockSseEngine.d.ts +16 -0
- package/lib/typescript/src/SseInterface.d.ts +46 -3
- package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +4 -0
- package/nitrogen/generated/android/c++/JSseDisconnectReason.hpp +67 -0
- package/nitrogen/generated/android/c++/JSseStats.hpp +87 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseDisconnectReason.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +108 -3
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +18 -0
- package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +3 -0
- package/nitrogen/generated/ios/swift/SseDisconnectReason.swift +52 -0
- package/nitrogen/generated/ios/swift/SseStats.swift +217 -2
- package/nitrogen/generated/shared/c++/SseDisconnectReason.hpp +88 -0
- package/nitrogen/generated/shared/c++/SseStats.hpp +88 -2
- package/package.json +2 -2
package/ios/SseEventBuffer.swift
CHANGED
|
@@ -12,6 +12,15 @@ class SseEventBuffer {
|
|
|
12
12
|
private var maxBufferSize: Int = 1000
|
|
13
13
|
private weak var dispatcher: SseDispatcher?
|
|
14
14
|
|
|
15
|
+
// MARK: - Buffer Metrics
|
|
16
|
+
private(set) var peakBufferedEvents: Int = 0
|
|
17
|
+
private(set) var bufferFlushCount: Int = 0
|
|
18
|
+
private(set) var bufferOverflowCount: Int = 0
|
|
19
|
+
|
|
20
|
+
var eventsBuffered: Int {
|
|
21
|
+
return eventBuffer.count
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
/// Initializes buffer batching thresholds and dispatch target.
|
|
16
25
|
func configure(
|
|
17
26
|
batchingIntervalMs: Double,
|
|
@@ -34,7 +43,15 @@ class SseEventBuffer {
|
|
|
34
43
|
dispatcher?.assertOnQueue()
|
|
35
44
|
eventBuffer.append(event)
|
|
36
45
|
|
|
37
|
-
if eventBuffer.count
|
|
46
|
+
if eventBuffer.count > peakBufferedEvents {
|
|
47
|
+
peakBufferedEvents = eventBuffer.count
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if eventBuffer.count >= maxBufferSize && batchingIntervalMs > 0 {
|
|
51
|
+
bufferOverflowCount += 1
|
|
52
|
+
cancelPendingTimer()
|
|
53
|
+
flush()
|
|
54
|
+
} else if eventBuffer.count >= maxBufferSize || batchingIntervalMs <= 0 {
|
|
38
55
|
cancelPendingTimer()
|
|
39
56
|
flush()
|
|
40
57
|
} else if pendingTimer == nil, let dispatcher = dispatcher {
|
|
@@ -53,6 +70,7 @@ class SseEventBuffer {
|
|
|
53
70
|
cancelPendingTimer()
|
|
54
71
|
guard !eventBuffer.isEmpty else { return }
|
|
55
72
|
|
|
73
|
+
bufferFlushCount += 1
|
|
56
74
|
let batch = eventBuffer
|
|
57
75
|
eventBuffer.removeAll()
|
|
58
76
|
|
|
@@ -82,23 +82,42 @@ class SseReconnectStrategy {
|
|
|
82
82
|
currentReconnectAttempts = 0
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/// Updates base retry interval when server sends a 'retry: <ms>' directive.
|
|
86
|
+
func updateRetryInterval(_ retryMs: Double) {
|
|
87
|
+
if retryMs.isFinite && retryMs >= 0 {
|
|
88
|
+
self.retryInterval = retryMs / 1000.0
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
/// Parses `Retry-After` HTTP headers per RFC 7231 (integer seconds or RFC 1123 date).
|
|
86
|
-
|
|
93
|
+
static func extractRetryAfterSeconds(from response: HTTPURLResponse) -> TimeInterval? {
|
|
94
|
+
guard let retryAfterHeader = response.value(forHTTPHeaderField: "Retry-After") ?? (response.allHeaderFields["Retry-After"] as? String) else { return nil }
|
|
95
|
+
return parseRetryAfterHeader(retryAfterHeader)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// Parses `Retry-After` HTTP headers per RFC 7231 (integer seconds or RFC 1123 date) from NSError userInfo.
|
|
87
99
|
static func extractRetryAfterSeconds(from error: Error) -> TimeInterval? {
|
|
88
100
|
let nsError = error as NSError
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
if let response = nsError.userInfo["response"] as? HTTPURLResponse {
|
|
102
|
+
return extractRetryAfterSeconds(from: response)
|
|
103
|
+
}
|
|
104
|
+
return nil
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private static func parseRetryAfterHeader(_ retryAfterHeader: String) -> TimeInterval? {
|
|
108
|
+
let trimmed = retryAfterHeader.trimmingCharacters(in: .whitespaces)
|
|
109
|
+
// RFC 7231 Section 7.1.3: delay-seconds is a sequence of 1*DIGIT (ASCII digits only)
|
|
110
|
+
if !trimmed.isEmpty && trimmed.allSatisfy({ $0.isASCII && $0.isNumber }), let seconds = Double(trimmed) {
|
|
93
111
|
return seconds
|
|
94
112
|
}
|
|
95
113
|
|
|
96
114
|
let rfc1123Formatter = DateFormatter()
|
|
97
115
|
rfc1123Formatter.locale = Locale(identifier: "en_US_POSIX")
|
|
116
|
+
rfc1123Formatter.timeZone = TimeZone(secondsFromGMT: 0)
|
|
98
117
|
rfc1123Formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss z"
|
|
99
|
-
if let date = rfc1123Formatter.date(from:
|
|
118
|
+
if let date = rfc1123Formatter.date(from: trimmed) {
|
|
100
119
|
let timeUntilDate = date.timeIntervalSinceNow
|
|
101
|
-
return
|
|
120
|
+
return max(0.0, timeUntilDate)
|
|
102
121
|
}
|
|
103
122
|
return nil
|
|
104
123
|
}
|
|
@@ -7,6 +7,17 @@
|
|
|
7
7
|
export class MockSseEngine {
|
|
8
8
|
_mockIndex = 0;
|
|
9
9
|
_totalBytesReceived = 0;
|
|
10
|
+
_chunksReceived = 0;
|
|
11
|
+
_totalEventsReceived = 0;
|
|
12
|
+
_commentsReceived = 0;
|
|
13
|
+
_linesParsed = 0;
|
|
14
|
+
_parseErrors = 0;
|
|
15
|
+
_lastActivityTime = 0;
|
|
16
|
+
_maxEventGapMs = 0;
|
|
17
|
+
_bufferFlushCount = 0;
|
|
18
|
+
_connectionAttempts = 0;
|
|
19
|
+
_reconnectCount = 0;
|
|
20
|
+
_lastProcessedId = null;
|
|
10
21
|
constructor(config, emitEvents) {
|
|
11
22
|
this._config = config;
|
|
12
23
|
this._emitEvents = emitEvents;
|
|
@@ -58,6 +69,16 @@ export class MockSseEngine {
|
|
|
58
69
|
} = this._config;
|
|
59
70
|
this._mockIndex = 0;
|
|
60
71
|
this._totalBytesReceived = 0;
|
|
72
|
+
this._chunksReceived = 0;
|
|
73
|
+
this._totalEventsReceived = 0;
|
|
74
|
+
this._commentsReceived = 0;
|
|
75
|
+
this._linesParsed = 0;
|
|
76
|
+
this._parseErrors = 0;
|
|
77
|
+
this._maxEventGapMs = 0;
|
|
78
|
+
this._lastActivityTime = 0;
|
|
79
|
+
this._connectionAttempts++;
|
|
80
|
+
this._connectedAt = Date.now();
|
|
81
|
+
this._lastProcessedId = null;
|
|
61
82
|
|
|
62
83
|
// Validate and normalize eventsPerSecond (must be a finite positive number, default to 1)
|
|
63
84
|
let validatedEventsPerSecond = Number(eventsPerSecond);
|
|
@@ -103,6 +124,9 @@ export class MockSseEngine {
|
|
|
103
124
|
message: 'Mock Connection Drop (Simulated Error)',
|
|
104
125
|
statusCode: 500
|
|
105
126
|
};
|
|
127
|
+
this._lastErrorTime = Date.now();
|
|
128
|
+
this._lastErrorCode = 'SIMULATED_MOCK_FAILURE';
|
|
129
|
+
this._reconnectCount++;
|
|
106
130
|
this._emitEvents([errorEvent]);
|
|
107
131
|
|
|
108
132
|
// Retry / reconnect delay simulator (e.g. 2000ms)
|
|
@@ -130,11 +154,32 @@ export class MockSseEngine {
|
|
|
130
154
|
}
|
|
131
155
|
}
|
|
132
156
|
if (batch.length > 0) {
|
|
157
|
+
this._chunksReceived++;
|
|
158
|
+
this._bufferFlushCount++;
|
|
159
|
+
const now = Date.now();
|
|
133
160
|
for (const ev of batch) {
|
|
134
161
|
const dataLen = ev.data ? ev.data.length : 0;
|
|
135
|
-
const evLen = ev.event ? ev.event.length : 0;
|
|
136
|
-
const idLen = ev.id ? ev.id.length : 0;
|
|
162
|
+
const evLen = ev.event && ev.event !== 'message' ? ev.event.length : 0;
|
|
163
|
+
const idLen = ev.id && ev.id !== this._lastProcessedId ? ev.id.length : 0;
|
|
164
|
+
if (ev.id !== undefined) {
|
|
165
|
+
this._lastProcessedId = ev.id === '' ? null : ev.id;
|
|
166
|
+
}
|
|
137
167
|
this._totalBytesReceived += Math.max(1, dataLen + evLen + idLen);
|
|
168
|
+
this._linesParsed += 2;
|
|
169
|
+
if (ev.type === 'message' || ev.event === 'message') {
|
|
170
|
+
this._totalEventsReceived++;
|
|
171
|
+
this._lastEventTime = now;
|
|
172
|
+
} else if (ev.type === 'heartbeat') {
|
|
173
|
+
this._commentsReceived++;
|
|
174
|
+
this._lastHeartbeatTime = now;
|
|
175
|
+
}
|
|
176
|
+
if (this._lastActivityTime > 0) {
|
|
177
|
+
const gap = now - this._lastActivityTime;
|
|
178
|
+
if (gap > this._maxEventGapMs) {
|
|
179
|
+
this._maxEventGapMs = gap;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
this._lastActivityTime = now;
|
|
138
183
|
}
|
|
139
184
|
if (mode === 'replace') {
|
|
140
185
|
this._setMockState('open');
|
|
@@ -170,6 +215,7 @@ export class MockSseEngine {
|
|
|
170
215
|
clearTimeout(this._mockIntervalId);
|
|
171
216
|
this._mockIntervalId = undefined;
|
|
172
217
|
}
|
|
218
|
+
this._connectedAt = undefined;
|
|
173
219
|
if (this._config.mode === 'replace') {
|
|
174
220
|
this._setMockState('closed');
|
|
175
221
|
}
|
|
@@ -183,8 +229,31 @@ export class MockSseEngine {
|
|
|
183
229
|
}
|
|
184
230
|
getStats() {
|
|
185
231
|
return {
|
|
232
|
+
rawBytesReceived: this._totalBytesReceived,
|
|
233
|
+
decompressedBytesReceived: undefined,
|
|
186
234
|
totalBytesReceived: this._totalBytesReceived,
|
|
187
|
-
|
|
235
|
+
chunksReceived: this._chunksReceived,
|
|
236
|
+
lastStatusCode: this._mockState === 'open' ? 200 : undefined,
|
|
237
|
+
totalEventsReceived: this._totalEventsReceived,
|
|
238
|
+
commentsReceived: this._commentsReceived,
|
|
239
|
+
linesParsed: this._linesParsed,
|
|
240
|
+
parseErrors: this._parseErrors,
|
|
241
|
+
serverRetryDelayMs: undefined,
|
|
242
|
+
connectedAt: this._connectedAt,
|
|
243
|
+
timeToFirstByteMs: undefined,
|
|
244
|
+
lastEventTime: this._lastEventTime,
|
|
245
|
+
lastHeartbeatTime: this._lastHeartbeatTime,
|
|
246
|
+
maxEventGapMs: this._maxEventGapMs,
|
|
247
|
+
eventsBuffered: 0,
|
|
248
|
+
peakBufferedEvents: 0,
|
|
249
|
+
bufferFlushCount: this._bufferFlushCount,
|
|
250
|
+
bufferOverflowCount: 0,
|
|
251
|
+
connectionAttempts: this._connectionAttempts,
|
|
252
|
+
reconnectCount: this._reconnectCount,
|
|
253
|
+
lastReconnectDelayMs: undefined,
|
|
254
|
+
disconnectReason: this._mockState === 'closed' ? 'user_stop' : undefined,
|
|
255
|
+
lastErrorTime: this._lastErrorTime,
|
|
256
|
+
lastErrorCode: this._lastErrorCode
|
|
188
257
|
};
|
|
189
258
|
}
|
|
190
259
|
getState() {
|
|
@@ -461,8 +461,31 @@ export class NitroSseClient {
|
|
|
461
461
|
getStats() {
|
|
462
462
|
if (this._isDisposed) {
|
|
463
463
|
return {
|
|
464
|
+
rawBytesReceived: 0,
|
|
465
|
+
decompressedBytesReceived: undefined,
|
|
464
466
|
totalBytesReceived: 0,
|
|
465
|
-
|
|
467
|
+
chunksReceived: 0,
|
|
468
|
+
lastStatusCode: undefined,
|
|
469
|
+
totalEventsReceived: 0,
|
|
470
|
+
commentsReceived: 0,
|
|
471
|
+
linesParsed: 0,
|
|
472
|
+
parseErrors: 0,
|
|
473
|
+
serverRetryDelayMs: undefined,
|
|
474
|
+
connectedAt: undefined,
|
|
475
|
+
timeToFirstByteMs: undefined,
|
|
476
|
+
lastEventTime: undefined,
|
|
477
|
+
lastHeartbeatTime: undefined,
|
|
478
|
+
maxEventGapMs: 0,
|
|
479
|
+
eventsBuffered: 0,
|
|
480
|
+
peakBufferedEvents: 0,
|
|
481
|
+
bufferFlushCount: 0,
|
|
482
|
+
bufferOverflowCount: 0,
|
|
483
|
+
connectionAttempts: 0,
|
|
484
|
+
reconnectCount: 0,
|
|
485
|
+
lastReconnectDelayMs: undefined,
|
|
486
|
+
disconnectReason: 'user_stop',
|
|
487
|
+
lastErrorTime: undefined,
|
|
488
|
+
lastErrorCode: undefined
|
|
466
489
|
};
|
|
467
490
|
}
|
|
468
491
|
return this._driver.getStats();
|
|
@@ -10,6 +10,22 @@ export declare class MockSseEngine {
|
|
|
10
10
|
private _mockIndex;
|
|
11
11
|
private _mockState?;
|
|
12
12
|
private _totalBytesReceived;
|
|
13
|
+
private _chunksReceived;
|
|
14
|
+
private _totalEventsReceived;
|
|
15
|
+
private _commentsReceived;
|
|
16
|
+
private _linesParsed;
|
|
17
|
+
private _parseErrors;
|
|
18
|
+
private _connectedAt?;
|
|
19
|
+
private _lastEventTime?;
|
|
20
|
+
private _lastHeartbeatTime?;
|
|
21
|
+
private _lastActivityTime;
|
|
22
|
+
private _maxEventGapMs;
|
|
23
|
+
private _bufferFlushCount;
|
|
24
|
+
private _connectionAttempts;
|
|
25
|
+
private _reconnectCount;
|
|
26
|
+
private _lastErrorTime?;
|
|
27
|
+
private _lastErrorCode?;
|
|
28
|
+
private _lastProcessedId;
|
|
13
29
|
constructor(config: SseMockConfig, emitEvents: (events: SseEvent[]) => void);
|
|
14
30
|
/**
|
|
15
31
|
* Transforms a raw mock event definition or partial SSE event into a full SseEvent DTO.
|
|
@@ -200,17 +200,60 @@ export interface SseEvent<TData = AnyMap> {
|
|
|
200
200
|
/** The current connection state (only available if type is 'state'). */
|
|
201
201
|
state?: SseState;
|
|
202
202
|
}
|
|
203
|
+
export type SseDisconnectReason = 'user_stop' | 'network_error' | 'server_error' | 'parser_error' | 'timeout';
|
|
203
204
|
/**
|
|
204
205
|
* Statistics about the SSE connection.
|
|
205
206
|
*/
|
|
206
207
|
export interface SseStats {
|
|
207
|
-
/**
|
|
208
|
+
/** Raw bytes received from the network socket before decompression. */
|
|
209
|
+
rawBytesReceived: number;
|
|
210
|
+
/** Decompressed bytes received (if gzip/compression applied). */
|
|
211
|
+
decompressedBytesReceived?: number;
|
|
212
|
+
/** Decoded payload byte length (for backward compatibility). */
|
|
208
213
|
totalBytesReceived: number;
|
|
209
|
-
/** Number of
|
|
214
|
+
/** Number of data chunks/packets read from the network transport. */
|
|
215
|
+
chunksReceived: number;
|
|
216
|
+
/** HTTP response status code of the current or last connection attempt. */
|
|
217
|
+
lastStatusCode?: number;
|
|
218
|
+
/** Total valid SSE message events parsed and emitted. */
|
|
219
|
+
totalEventsReceived: number;
|
|
220
|
+
/** Total SSE comment lines (':') received as heartbeats. */
|
|
221
|
+
commentsReceived: number;
|
|
222
|
+
/** Total raw lines processed by the SSE parser. */
|
|
223
|
+
linesParsed: number;
|
|
224
|
+
/** Number of parsing errors encountered (line length limit exceeded, invalid UTF-8, etc.). */
|
|
225
|
+
parseErrors: number;
|
|
226
|
+
/** Latest retry delay requested by server via 'retry:' directive (ms). */
|
|
227
|
+
serverRetryDelayMs?: number;
|
|
228
|
+
/** Epoch timestamp (ms) when the active connection was established. */
|
|
229
|
+
connectedAt?: number;
|
|
230
|
+
/** Latency in ms from connection start to first body byte received. */
|
|
231
|
+
timeToFirstByteMs?: number;
|
|
232
|
+
/** Epoch timestamp (ms) of the most recently received event. */
|
|
233
|
+
lastEventTime?: number;
|
|
234
|
+
/** Epoch timestamp (ms) of the most recently received heartbeat/comment. */
|
|
235
|
+
lastHeartbeatTime?: number;
|
|
236
|
+
/** Maximum elapsed time (ms) between consecutive events/heartbeats (stall detection). */
|
|
237
|
+
maxEventGapMs: number;
|
|
238
|
+
/** Number of events currently waiting in the dispatch buffer. */
|
|
239
|
+
eventsBuffered: number;
|
|
240
|
+
/** Maximum number of events queued in the buffer at any one time (high-water mark). */
|
|
241
|
+
peakBufferedEvents: number;
|
|
242
|
+
/** Total number of buffer flushes to JavaScript. */
|
|
243
|
+
bufferFlushCount: number;
|
|
244
|
+
/** Total number of early flushes triggered because buffer reached maxBufferSize. */
|
|
245
|
+
bufferOverflowCount: number;
|
|
246
|
+
/** Total connection attempts made (initial and retries). */
|
|
247
|
+
connectionAttempts: number;
|
|
248
|
+
/** Number of successful reconnections. */
|
|
210
249
|
reconnectCount: number;
|
|
250
|
+
/** Delay in ms used for the last reconnect attempt. */
|
|
251
|
+
lastReconnectDelayMs?: number;
|
|
252
|
+
/** Reason for the last disconnection. */
|
|
253
|
+
disconnectReason?: SseDisconnectReason;
|
|
211
254
|
/** Timestamp of the last error event. */
|
|
212
255
|
lastErrorTime?: number;
|
|
213
|
-
/** Error code of the last error. */
|
|
256
|
+
/** Error code or domain of the last error. */
|
|
214
257
|
lastErrorCode?: string;
|
|
215
258
|
}
|
|
216
259
|
/**
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
// Forward declaration of `SseStats` to properly resolve imports.
|
|
11
11
|
namespace margelo::nitro::nitrosse { struct SseStats; }
|
|
12
|
+
// Forward declaration of `SseDisconnectReason` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::nitrosse { enum class SseDisconnectReason; }
|
|
12
14
|
// Forward declaration of `SseState` to properly resolve imports.
|
|
13
15
|
namespace margelo::nitro::nitrosse { enum class SseState; }
|
|
14
16
|
// Forward declaration of `SseConfig` to properly resolve imports.
|
|
@@ -29,6 +31,8 @@ namespace margelo::nitro::nitrosse { struct SseEvent; }
|
|
|
29
31
|
#include "SseStats.hpp"
|
|
30
32
|
#include "JSseStats.hpp"
|
|
31
33
|
#include <optional>
|
|
34
|
+
#include "SseDisconnectReason.hpp"
|
|
35
|
+
#include "JSseDisconnectReason.hpp"
|
|
32
36
|
#include <string>
|
|
33
37
|
#include "SseState.hpp"
|
|
34
38
|
#include "JSseState.hpp"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JSseDisconnectReason.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "SseDisconnectReason.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::nitrosse {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "SseDisconnectReason" and the Kotlin enum "SseDisconnectReason".
|
|
19
|
+
*/
|
|
20
|
+
struct JSseDisconnectReason final: public jni::JavaClass<JSseDisconnectReason> {
|
|
21
|
+
public:
|
|
22
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/SseDisconnectReason;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum SseDisconnectReason.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
SseDisconnectReason toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("value");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<SseDisconnectReason>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JSseDisconnectReason> fromCpp(SseDisconnectReason value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
switch (value) {
|
|
45
|
+
case SseDisconnectReason::USER_STOP:
|
|
46
|
+
static const auto fieldUSER_STOP = clazz->getStaticField<JSseDisconnectReason>("USER_STOP");
|
|
47
|
+
return clazz->getStaticFieldValue(fieldUSER_STOP);
|
|
48
|
+
case SseDisconnectReason::NETWORK_ERROR:
|
|
49
|
+
static const auto fieldNETWORK_ERROR = clazz->getStaticField<JSseDisconnectReason>("NETWORK_ERROR");
|
|
50
|
+
return clazz->getStaticFieldValue(fieldNETWORK_ERROR);
|
|
51
|
+
case SseDisconnectReason::SERVER_ERROR:
|
|
52
|
+
static const auto fieldSERVER_ERROR = clazz->getStaticField<JSseDisconnectReason>("SERVER_ERROR");
|
|
53
|
+
return clazz->getStaticFieldValue(fieldSERVER_ERROR);
|
|
54
|
+
case SseDisconnectReason::PARSER_ERROR:
|
|
55
|
+
static const auto fieldPARSER_ERROR = clazz->getStaticField<JSseDisconnectReason>("PARSER_ERROR");
|
|
56
|
+
return clazz->getStaticFieldValue(fieldPARSER_ERROR);
|
|
57
|
+
case SseDisconnectReason::TIMEOUT:
|
|
58
|
+
static const auto fieldTIMEOUT = clazz->getStaticField<JSseDisconnectReason>("TIMEOUT");
|
|
59
|
+
return clazz->getStaticFieldValue(fieldTIMEOUT);
|
|
60
|
+
default:
|
|
61
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
62
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} // namespace margelo::nitro::nitrosse
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
#include <fbjni/fbjni.h>
|
|
11
11
|
#include "SseStats.hpp"
|
|
12
12
|
|
|
13
|
+
#include "JSseDisconnectReason.hpp"
|
|
14
|
+
#include "SseDisconnectReason.hpp"
|
|
13
15
|
#include <optional>
|
|
14
16
|
#include <string>
|
|
15
17
|
|
|
@@ -32,17 +34,80 @@ namespace margelo::nitro::nitrosse {
|
|
|
32
34
|
[[nodiscard]]
|
|
33
35
|
SseStats toCpp() const {
|
|
34
36
|
static const auto clazz = javaClassStatic();
|
|
37
|
+
static const auto fieldRawBytesReceived = clazz->getField<double>("rawBytesReceived");
|
|
38
|
+
double rawBytesReceived = this->getFieldValue(fieldRawBytesReceived);
|
|
39
|
+
static const auto fieldDecompressedBytesReceived = clazz->getField<jni::JDouble>("decompressedBytesReceived");
|
|
40
|
+
jni::local_ref<jni::JDouble> decompressedBytesReceived = this->getFieldValue(fieldDecompressedBytesReceived);
|
|
35
41
|
static const auto fieldTotalBytesReceived = clazz->getField<double>("totalBytesReceived");
|
|
36
42
|
double totalBytesReceived = this->getFieldValue(fieldTotalBytesReceived);
|
|
43
|
+
static const auto fieldChunksReceived = clazz->getField<double>("chunksReceived");
|
|
44
|
+
double chunksReceived = this->getFieldValue(fieldChunksReceived);
|
|
45
|
+
static const auto fieldLastStatusCode = clazz->getField<jni::JDouble>("lastStatusCode");
|
|
46
|
+
jni::local_ref<jni::JDouble> lastStatusCode = this->getFieldValue(fieldLastStatusCode);
|
|
47
|
+
static const auto fieldTotalEventsReceived = clazz->getField<double>("totalEventsReceived");
|
|
48
|
+
double totalEventsReceived = this->getFieldValue(fieldTotalEventsReceived);
|
|
49
|
+
static const auto fieldCommentsReceived = clazz->getField<double>("commentsReceived");
|
|
50
|
+
double commentsReceived = this->getFieldValue(fieldCommentsReceived);
|
|
51
|
+
static const auto fieldLinesParsed = clazz->getField<double>("linesParsed");
|
|
52
|
+
double linesParsed = this->getFieldValue(fieldLinesParsed);
|
|
53
|
+
static const auto fieldParseErrors = clazz->getField<double>("parseErrors");
|
|
54
|
+
double parseErrors = this->getFieldValue(fieldParseErrors);
|
|
55
|
+
static const auto fieldServerRetryDelayMs = clazz->getField<jni::JDouble>("serverRetryDelayMs");
|
|
56
|
+
jni::local_ref<jni::JDouble> serverRetryDelayMs = this->getFieldValue(fieldServerRetryDelayMs);
|
|
57
|
+
static const auto fieldConnectedAt = clazz->getField<jni::JDouble>("connectedAt");
|
|
58
|
+
jni::local_ref<jni::JDouble> connectedAt = this->getFieldValue(fieldConnectedAt);
|
|
59
|
+
static const auto fieldTimeToFirstByteMs = clazz->getField<jni::JDouble>("timeToFirstByteMs");
|
|
60
|
+
jni::local_ref<jni::JDouble> timeToFirstByteMs = this->getFieldValue(fieldTimeToFirstByteMs);
|
|
61
|
+
static const auto fieldLastEventTime = clazz->getField<jni::JDouble>("lastEventTime");
|
|
62
|
+
jni::local_ref<jni::JDouble> lastEventTime = this->getFieldValue(fieldLastEventTime);
|
|
63
|
+
static const auto fieldLastHeartbeatTime = clazz->getField<jni::JDouble>("lastHeartbeatTime");
|
|
64
|
+
jni::local_ref<jni::JDouble> lastHeartbeatTime = this->getFieldValue(fieldLastHeartbeatTime);
|
|
65
|
+
static const auto fieldMaxEventGapMs = clazz->getField<double>("maxEventGapMs");
|
|
66
|
+
double maxEventGapMs = this->getFieldValue(fieldMaxEventGapMs);
|
|
67
|
+
static const auto fieldEventsBuffered = clazz->getField<double>("eventsBuffered");
|
|
68
|
+
double eventsBuffered = this->getFieldValue(fieldEventsBuffered);
|
|
69
|
+
static const auto fieldPeakBufferedEvents = clazz->getField<double>("peakBufferedEvents");
|
|
70
|
+
double peakBufferedEvents = this->getFieldValue(fieldPeakBufferedEvents);
|
|
71
|
+
static const auto fieldBufferFlushCount = clazz->getField<double>("bufferFlushCount");
|
|
72
|
+
double bufferFlushCount = this->getFieldValue(fieldBufferFlushCount);
|
|
73
|
+
static const auto fieldBufferOverflowCount = clazz->getField<double>("bufferOverflowCount");
|
|
74
|
+
double bufferOverflowCount = this->getFieldValue(fieldBufferOverflowCount);
|
|
75
|
+
static const auto fieldConnectionAttempts = clazz->getField<double>("connectionAttempts");
|
|
76
|
+
double connectionAttempts = this->getFieldValue(fieldConnectionAttempts);
|
|
37
77
|
static const auto fieldReconnectCount = clazz->getField<double>("reconnectCount");
|
|
38
78
|
double reconnectCount = this->getFieldValue(fieldReconnectCount);
|
|
79
|
+
static const auto fieldLastReconnectDelayMs = clazz->getField<jni::JDouble>("lastReconnectDelayMs");
|
|
80
|
+
jni::local_ref<jni::JDouble> lastReconnectDelayMs = this->getFieldValue(fieldLastReconnectDelayMs);
|
|
81
|
+
static const auto fieldDisconnectReason = clazz->getField<JSseDisconnectReason>("disconnectReason");
|
|
82
|
+
jni::local_ref<JSseDisconnectReason> disconnectReason = this->getFieldValue(fieldDisconnectReason);
|
|
39
83
|
static const auto fieldLastErrorTime = clazz->getField<jni::JDouble>("lastErrorTime");
|
|
40
84
|
jni::local_ref<jni::JDouble> lastErrorTime = this->getFieldValue(fieldLastErrorTime);
|
|
41
85
|
static const auto fieldLastErrorCode = clazz->getField<jni::JString>("lastErrorCode");
|
|
42
86
|
jni::local_ref<jni::JString> lastErrorCode = this->getFieldValue(fieldLastErrorCode);
|
|
43
87
|
return SseStats(
|
|
88
|
+
rawBytesReceived,
|
|
89
|
+
decompressedBytesReceived != nullptr ? std::make_optional(decompressedBytesReceived->value()) : std::nullopt,
|
|
44
90
|
totalBytesReceived,
|
|
91
|
+
chunksReceived,
|
|
92
|
+
lastStatusCode != nullptr ? std::make_optional(lastStatusCode->value()) : std::nullopt,
|
|
93
|
+
totalEventsReceived,
|
|
94
|
+
commentsReceived,
|
|
95
|
+
linesParsed,
|
|
96
|
+
parseErrors,
|
|
97
|
+
serverRetryDelayMs != nullptr ? std::make_optional(serverRetryDelayMs->value()) : std::nullopt,
|
|
98
|
+
connectedAt != nullptr ? std::make_optional(connectedAt->value()) : std::nullopt,
|
|
99
|
+
timeToFirstByteMs != nullptr ? std::make_optional(timeToFirstByteMs->value()) : std::nullopt,
|
|
100
|
+
lastEventTime != nullptr ? std::make_optional(lastEventTime->value()) : std::nullopt,
|
|
101
|
+
lastHeartbeatTime != nullptr ? std::make_optional(lastHeartbeatTime->value()) : std::nullopt,
|
|
102
|
+
maxEventGapMs,
|
|
103
|
+
eventsBuffered,
|
|
104
|
+
peakBufferedEvents,
|
|
105
|
+
bufferFlushCount,
|
|
106
|
+
bufferOverflowCount,
|
|
107
|
+
connectionAttempts,
|
|
45
108
|
reconnectCount,
|
|
109
|
+
lastReconnectDelayMs != nullptr ? std::make_optional(lastReconnectDelayMs->value()) : std::nullopt,
|
|
110
|
+
disconnectReason != nullptr ? std::make_optional(disconnectReason->toCpp()) : std::nullopt,
|
|
46
111
|
lastErrorTime != nullptr ? std::make_optional(lastErrorTime->value()) : std::nullopt,
|
|
47
112
|
lastErrorCode != nullptr ? std::make_optional(lastErrorCode->toStdString()) : std::nullopt
|
|
48
113
|
);
|
|
@@ -54,13 +119,34 @@ namespace margelo::nitro::nitrosse {
|
|
|
54
119
|
*/
|
|
55
120
|
[[maybe_unused]]
|
|
56
121
|
static jni::local_ref<JSseStats::javaobject> fromCpp(const SseStats& value) {
|
|
57
|
-
using JSignature = JSseStats(double, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
|
|
122
|
+
using JSignature = JSseStats(double, jni::alias_ref<jni::JDouble>, double, double, jni::alias_ref<jni::JDouble>, double, double, double, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, double, double, double, double, double, double, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<JSseDisconnectReason>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
|
|
58
123
|
static const auto clazz = javaClassStatic();
|
|
59
124
|
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
60
125
|
return create(
|
|
61
126
|
clazz,
|
|
127
|
+
value.rawBytesReceived,
|
|
128
|
+
value.decompressedBytesReceived.has_value() ? jni::JDouble::valueOf(value.decompressedBytesReceived.value()) : nullptr,
|
|
62
129
|
value.totalBytesReceived,
|
|
130
|
+
value.chunksReceived,
|
|
131
|
+
value.lastStatusCode.has_value() ? jni::JDouble::valueOf(value.lastStatusCode.value()) : nullptr,
|
|
132
|
+
value.totalEventsReceived,
|
|
133
|
+
value.commentsReceived,
|
|
134
|
+
value.linesParsed,
|
|
135
|
+
value.parseErrors,
|
|
136
|
+
value.serverRetryDelayMs.has_value() ? jni::JDouble::valueOf(value.serverRetryDelayMs.value()) : nullptr,
|
|
137
|
+
value.connectedAt.has_value() ? jni::JDouble::valueOf(value.connectedAt.value()) : nullptr,
|
|
138
|
+
value.timeToFirstByteMs.has_value() ? jni::JDouble::valueOf(value.timeToFirstByteMs.value()) : nullptr,
|
|
139
|
+
value.lastEventTime.has_value() ? jni::JDouble::valueOf(value.lastEventTime.value()) : nullptr,
|
|
140
|
+
value.lastHeartbeatTime.has_value() ? jni::JDouble::valueOf(value.lastHeartbeatTime.value()) : nullptr,
|
|
141
|
+
value.maxEventGapMs,
|
|
142
|
+
value.eventsBuffered,
|
|
143
|
+
value.peakBufferedEvents,
|
|
144
|
+
value.bufferFlushCount,
|
|
145
|
+
value.bufferOverflowCount,
|
|
146
|
+
value.connectionAttempts,
|
|
63
147
|
value.reconnectCount,
|
|
148
|
+
value.lastReconnectDelayMs.has_value() ? jni::JDouble::valueOf(value.lastReconnectDelayMs.value()) : nullptr,
|
|
149
|
+
value.disconnectReason.has_value() ? JSseDisconnectReason::fromCpp(value.disconnectReason.value()) : nullptr,
|
|
64
150
|
value.lastErrorTime.has_value() ? jni::JDouble::valueOf(value.lastErrorTime.value()) : nullptr,
|
|
65
151
|
value.lastErrorCode.has_value() ? jni::make_jstring(value.lastErrorCode.value()) : nullptr
|
|
66
152
|
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SseDisconnectReason.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.nitrosse
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents the JavaScript enum/union "SseDisconnectReason".
|
|
15
|
+
*/
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
@Keep
|
|
18
|
+
enum class SseDisconnectReason(@DoNotStrip @Keep val value: Int) {
|
|
19
|
+
USER_STOP(0),
|
|
20
|
+
NETWORK_ERROR(1),
|
|
21
|
+
SERVER_ERROR(2),
|
|
22
|
+
PARSER_ERROR(3),
|
|
23
|
+
TIMEOUT(4);
|
|
24
|
+
|
|
25
|
+
companion object
|
|
26
|
+
}
|