react-native-nitro-sse 3.0.0 → 3.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/NitroSse.podspec +0 -1
  2. package/README.md +16 -5
  3. package/android/build.gradle +0 -1
  4. package/android/src/main/java/com/margelo/nitro/nitrosse/JsonUtils.kt +33 -10
  5. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +366 -78
  6. package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +417 -94
  7. package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +20 -0
  8. package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +9 -0
  9. package/ios/NitroSse.swift +302 -49
  10. package/ios/SseConnectionHandler.swift +647 -97
  11. package/ios/SseEventBuffer.swift +19 -1
  12. package/ios/SseReconnectStrategy.swift +26 -7
  13. package/lib/module/FetchSseDriver.js +845 -0
  14. package/lib/module/MockSseEngine.js +72 -3
  15. package/lib/module/NitroSseClient.js +43 -18
  16. package/lib/module/SseDriver.js +31 -15
  17. package/lib/module/SseEventParser.js +238 -0
  18. package/lib/module/createNitroSse.js +12 -5
  19. package/lib/module/createNitroSse.native.js +24 -0
  20. package/lib/module/createNitroSse.web.js +13 -0
  21. package/lib/module/index.js +2 -1
  22. package/lib/module/index.native.js +8 -0
  23. package/lib/module/index.web.js +9 -0
  24. package/lib/module/useNitroSse.js +1 -1
  25. package/lib/typescript/src/FetchSseDriver.d.ts +92 -0
  26. package/lib/typescript/src/MockSseEngine.d.ts +16 -0
  27. package/lib/typescript/src/NitroSseClient.d.ts +4 -1
  28. package/lib/typescript/src/SseDriver.d.ts +8 -4
  29. package/lib/typescript/src/SseEventParser.d.ts +42 -0
  30. package/lib/typescript/src/SseInterface.d.ts +46 -3
  31. package/lib/typescript/src/createNitroSse.d.ts +2 -2
  32. package/lib/typescript/src/createNitroSse.native.d.ts +9 -0
  33. package/lib/typescript/src/createNitroSse.web.d.ts +8 -0
  34. package/lib/typescript/src/index.d.ts +1 -0
  35. package/lib/typescript/src/index.native.d.ts +6 -0
  36. package/lib/typescript/src/index.web.d.ts +7 -0
  37. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +4 -0
  38. package/nitrogen/generated/android/c++/JSseDisconnectReason.hpp +67 -0
  39. package/nitrogen/generated/android/c++/JSseStats.hpp +87 -1
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseDisconnectReason.kt +26 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +108 -3
  42. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +18 -0
  43. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +3 -0
  44. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +3 -0
  45. package/nitrogen/generated/ios/swift/SseDisconnectReason.swift +52 -0
  46. package/nitrogen/generated/ios/swift/SseStats.swift +217 -2
  47. package/nitrogen/generated/shared/c++/SseDisconnectReason.hpp +88 -0
  48. package/nitrogen/generated/shared/c++/SseStats.hpp +88 -2
  49. package/package.json +13 -2
@@ -0,0 +1,92 @@
1
+ import type { SseDriver } from './SseDriver';
2
+ import type { SseConfig, SseEvent, SseState, SseStats } from './SseInterface';
3
+ import { type SseEventParserDelegate } from './SseEventParser';
4
+ /**
5
+ * Web SSE Driver executing server-sent events using WHATWG fetch(), ReadableStream, and TextDecoder.
6
+ */
7
+ export declare class FetchSseDriver implements SseDriver, SseEventParserDelegate {
8
+ private _config?;
9
+ private _onBeforeRequest?;
10
+ private _dispatchEvents;
11
+ private _state;
12
+ private _isRunning;
13
+ private _isReconnecting;
14
+ private _lastProcessedId?;
15
+ private _dynamicHeaders;
16
+ private _consecutiveAuthErrors;
17
+ private _connectionAttemptVersion;
18
+ private _abortController?;
19
+ private _activeReader?;
20
+ private _connectionTimer?;
21
+ private _readTimeoutTimer?;
22
+ private _reconnectTimer?;
23
+ private _batchTimer?;
24
+ private _batchBuffer;
25
+ private _wasRunningBeforeNetworkLoss;
26
+ private _reconnectStrategy;
27
+ private _parser?;
28
+ private _rawBytesReceived;
29
+ private _totalBytesReceived;
30
+ private _chunksReceived;
31
+ private _lastStatusCode?;
32
+ private _totalEventsReceived;
33
+ private _commentsReceived;
34
+ private _linesParsed;
35
+ private _parseErrors;
36
+ private _serverRetryDelayMs?;
37
+ private _connectedAt?;
38
+ private _timeToFirstByteMs?;
39
+ private _connectionAttemptStartTime?;
40
+ private _lastEventTime?;
41
+ private _lastHeartbeatTime?;
42
+ private _lastActivityTime;
43
+ private _maxEventGapMs;
44
+ private _peakBufferedEvents;
45
+ private _bufferFlushCount;
46
+ private _bufferOverflowCount;
47
+ private _connectionAttempts;
48
+ private _reconnectCount;
49
+ private _lastReconnectDelayMs?;
50
+ private _disconnectReason?;
51
+ private _lastErrorTime?;
52
+ private _lastErrorCode?;
53
+ private _onlineListener?;
54
+ private _offlineListener?;
55
+ constructor(dispatchEvents?: (events: SseEvent[]) => void);
56
+ setDispatchEvents(dispatchEvents: (events: SseEvent[]) => void): void;
57
+ setup(config: SseConfig, onBeforeRequest?: () => Promise<Record<string, string>>): void;
58
+ start(): void;
59
+ stop(): void;
60
+ restart(): void;
61
+ flush(): void;
62
+ isConnected(): boolean;
63
+ getStats(): SseStats;
64
+ getState(): SseState;
65
+ updateHeaders(headers: Record<string, string>): void;
66
+ setLastProcessedId(id: string): void;
67
+ injectMockEvent(event: Partial<SseEvent>): void;
68
+ dispose(): void;
69
+ private _establishConnection;
70
+ private _scheduleReconnect;
71
+ private _stopInternal;
72
+ private _failAndStop;
73
+ private _cleanupTransport;
74
+ private _cleanupTimers;
75
+ private _resetReadTimeout;
76
+ private _clearReadTimeout;
77
+ private _updateState;
78
+ private _recordError;
79
+ private _parseRetryAfterHeader;
80
+ private _pushEvent;
81
+ private _flushBatch;
82
+ private _cancelBatchTimer;
83
+ onEvent(id: string | undefined, type: string | undefined, data: string): void;
84
+ onComment(comment: string): void;
85
+ onRetry(retryMs: number): void;
86
+ onIdUpdate(id: string | undefined): void;
87
+ onParseError(error: Error): void;
88
+ onLinesParsed(count: number): void;
89
+ private _setupNetworkListeners;
90
+ private _teardownNetworkListeners;
91
+ }
92
+ //# sourceMappingURL=FetchSseDriver.d.ts.map
@@ -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.
@@ -1,6 +1,7 @@
1
1
  import type { AnyMap } from 'react-native-nitro-modules';
2
2
  import type { NitroSse } from './NitroSse.nitro';
3
3
  import type { SseClient, SseClientOptions, SseEvent, SseListener, SseStats, SseState } from './SseInterface';
4
+ import { type SseDriver } from './SseDriver';
4
5
  /**
5
6
  * Sanitizes HTTP headers by stripping carriage returns, newlines, null bytes,
6
7
  * converting non-string values to strings, and pruning null/undefined values.
@@ -21,13 +22,15 @@ export declare function validateConfig(config: SseClientOptions): SseClientOptio
21
22
  */
22
23
  export declare class NitroSseClient implements SseClient {
23
24
  private _native;
25
+ private _baseDriver;
24
26
  private _driver;
25
27
  private _listeners;
26
28
  private _legacyCallback?;
27
29
  private _config?;
28
30
  private _isDisposed;
29
31
  private _pendingHeaders;
30
- constructor(native: NitroSse);
32
+ constructor(nativeOrDriver: NitroSse | SseDriver);
33
+ static fromDriver(driver: SseDriver): NitroSseClient;
31
34
  get isDisposed(): boolean;
32
35
  private _checkDisposed;
33
36
  setup(config: SseClientOptions, onEvent?: (events: SseEvent[]) => void): void;
@@ -1,10 +1,11 @@
1
1
  import type { NitroSse } from './NitroSse.nitro';
2
- import type { SseEvent, SseState, SseStats } from './SseInterface';
2
+ import type { SseConfig, SseEvent, SseState, SseStats } from './SseInterface';
3
3
  import { MockSseEngine } from './MockSseEngine';
4
4
  /**
5
5
  * Internal execution strategy driving the SSE lifecycle.
6
6
  */
7
7
  export interface SseDriver {
8
+ setup(config: SseConfig, onBeforeRequest?: () => Promise<Record<string, string>>): void;
8
9
  start(): void;
9
10
  stop(): void;
10
11
  restart(): void;
@@ -24,6 +25,7 @@ export declare class NativeDriver implements SseDriver {
24
25
  private _native;
25
26
  private _dispatchEvents;
26
27
  constructor(_native: NitroSse, _dispatchEvents: (events: SseEvent[]) => void);
28
+ setup(config: SseConfig, onBeforeRequest?: () => Promise<Record<string, string>>): void;
27
29
  start(): void;
28
30
  stop(): void;
29
31
  restart(): void;
@@ -46,6 +48,7 @@ export declare class MockReplaceDriver implements SseDriver {
46
48
  constructor(_mockEngine: MockSseEngine);
47
49
  get headers(): Record<string, string>;
48
50
  get lastProcessedId(): string | undefined;
51
+ setup(config: SseConfig, _onBeforeRequest?: () => Promise<Record<string, string>>): void;
49
52
  start(): void;
50
53
  stop(): void;
51
54
  restart(): void;
@@ -59,12 +62,13 @@ export declare class MockReplaceDriver implements SseDriver {
59
62
  dispose(): void;
60
63
  }
61
64
  /**
62
- * Driver running native networking in parallel with mock event injection.
65
+ * Driver running underlying network streaming in parallel with mock event injection.
63
66
  */
64
67
  export declare class MockInjectDriver implements SseDriver {
65
- private _native;
68
+ private _realDriver;
66
69
  private _mockEngine;
67
- constructor(_native: NitroSse, _mockEngine: MockSseEngine);
70
+ constructor(_realDriver: SseDriver, _mockEngine: MockSseEngine);
71
+ setup(config: SseConfig, onBeforeRequest?: () => Promise<Record<string, string>>): void;
68
72
  start(): void;
69
73
  stop(): void;
70
74
  restart(): void;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * WHATWG Server-Sent Events (SSE) streaming parser.
3
+ *
4
+ * Implements the W3C/WHATWG SSE parsing algorithm with cross-platform parity
5
+ * matching iOS SseEventParser (Swift) and Android SseEventReader (Kotlin).
6
+ */
7
+ export declare const MAX_SSE_LINE_LENGTH: number;
8
+ export declare const MAX_SSE_EVENT_DATA_SIZE: number;
9
+ export interface SseEventParserDelegate {
10
+ onEvent(id: string | undefined, type: string | undefined, data: string): void;
11
+ onComment(comment: string): void;
12
+ onRetry(retryMs: number): void;
13
+ onIdUpdate(id: string | undefined): void;
14
+ onParseError(error: Error): void;
15
+ onLinesParsed(count: number): void;
16
+ }
17
+ export declare class SseEventParser {
18
+ private _delegate;
19
+ private _buffer;
20
+ private _dataBuffer;
21
+ private _hasData;
22
+ private _eventType?;
23
+ private _lastEventId?;
24
+ private _isAtStreamStart;
25
+ private _skipLeadingLf;
26
+ constructor(delegate: SseEventParserDelegate, initialLastEventId?: string);
27
+ get lastEventId(): string | undefined;
28
+ /**
29
+ * Resets parser state for reconnection.
30
+ */
31
+ reset(initialLastEventId?: string): void;
32
+ /**
33
+ * Signals end of stream (EOF) — flushes pending line and pending event if any.
34
+ */
35
+ endOfStream(): void;
36
+ /**
37
+ * Feeds a decoded UTF-8 text chunk into the streaming parser.
38
+ */
39
+ feed(chunk: string): void;
40
+ private _processLine;
41
+ }
42
+ //# sourceMappingURL=SseEventParser.d.ts.map
@@ -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
- /** Total bytes received so far. */
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 times the connection has been re-established. */
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
  /**
@@ -2,8 +2,8 @@ import type { SseClient } from './SseInterface';
2
2
  /**
3
3
  * Creates a high-performance SSE client that supports typed event listeners (`addEventListener`) and legacy batching.
4
4
  *
5
- * @returns An SseClient instance wrapping the native NitroSse implementation.
6
- * @throws {NitroSseModuleNotFoundError} If the native NitroSse module cannot be found. Ensure the library is linked and the app is built for iOS/Android.
5
+ * @returns An SseClient instance wrapping the native NitroSse implementation, or FetchSseDriver on Web.
6
+ * @throws {NitroSseModuleNotFoundError} If the native NitroSse module cannot be found on iOS/Android.
7
7
  */
8
8
  export declare function createNitroSse(): SseClient;
9
9
  //# sourceMappingURL=createNitroSse.d.ts.map
@@ -0,0 +1,9 @@
1
+ import type { SseClient } from './SseInterface';
2
+ /**
3
+ * Creates an SSE client for iOS and Android using Nitro Modules (JSI).
4
+ *
5
+ * @returns An SseClient instance backed by native NitroSse.
6
+ * @throws {NitroSseModuleNotFoundError} If the native NitroSse module cannot be found.
7
+ */
8
+ export declare function createNitroSse(): SseClient;
9
+ //# sourceMappingURL=createNitroSse.native.d.ts.map
@@ -0,0 +1,8 @@
1
+ import type { SseClient } from './SseInterface';
2
+ /**
3
+ * Creates an SSE client for Web platform using WHATWG fetch() and ReadableStream.
4
+ *
5
+ * @returns An SseClient instance backed by FetchSseDriver.
6
+ */
7
+ export declare function createNitroSse(): SseClient;
8
+ //# sourceMappingURL=createNitroSse.web.d.ts.map
@@ -3,4 +3,5 @@ export * from './useNitroSse';
3
3
  export * from './NitroSseClient';
4
4
  export * from './NitroSseError';
5
5
  export * from './createNitroSse';
6
+ export { FetchSseDriver } from './FetchSseDriver';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ export * from './SseInterface';
2
+ export * from './useNitroSse';
3
+ export * from './NitroSseClient';
4
+ export * from './NitroSseError';
5
+ export * from './createNitroSse.native';
6
+ //# sourceMappingURL=index.native.d.ts.map
@@ -0,0 +1,7 @@
1
+ export * from './SseInterface';
2
+ export * from './useNitroSse';
3
+ export * from './NitroSseClient';
4
+ export * from './NitroSseError';
5
+ export * from './createNitroSse.web';
6
+ export { FetchSseDriver } from './FetchSseDriver';
7
+ //# sourceMappingURL=index.web.d.ts.map
@@ -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
+ }