lightstreamer_rs/client/model.rs
1/******************************************************************************
2 Author: Joaquín Béjar García
3 Email: jb@taunais.com
4 Date: 16/5/25
5******************************************************************************/
6
7/// Represents the current status of the `LightstreamerClient`.
8pub enum ClientStatus {
9 /// The client is attempting to connect to the Lightstreamer Server.
10 Connecting,
11 /// The client has successfully connected to the Lightstreamer Server.
12 /// Contains the type of connection established.
13 Connected(ConnectionType),
14 /// The connection has been temporarily interrupted.
15 /// The client will automatically try to recover the connection.
16 Stalled,
17 /// The client is disconnected from the Lightstreamer Server.
18 /// Contains information about the disconnection type.
19 Disconnected(DisconnectionType),
20}
21
22impl std::fmt::Display for ClientStatus {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 match self {
25 ClientStatus::Connecting => write!(f, "CONNECTING"),
26 ClientStatus::Connected(connection_type) => match connection_type {
27 ConnectionType::HttpPolling => write!(f, "CONNECTED:HTTP-POLLING"),
28 ConnectionType::HttpStreaming => write!(f, "CONNECTED:HTTP-STREAMING"),
29 ConnectionType::StreamSensing => write!(f, "CONNECTED:STREAM-SENSING"),
30 ConnectionType::WsPolling => write!(f, "CONNECTED:WS-POLLING"),
31 ConnectionType::WsStreaming => write!(f, "CONNECTED:WS-STREAMING"),
32 },
33 ClientStatus::Stalled => write!(f, "STALLED"),
34 ClientStatus::Disconnected(disconnection_type) => match disconnection_type {
35 DisconnectionType::WillRetry => write!(f, "DISCONNECTED:WILL-RETRY"),
36 DisconnectionType::TryingRecovery => write!(f, "DISCONNECTED:TRYING-RECOVERY"),
37 },
38 }
39 }
40}
41
42/// Represents the type of connection established with the Lightstreamer Server.
43///
44/// This enum indicates the specific transport protocol and connection mode being used
45/// for communication with the server.
46#[derive(Debug)]
47pub enum ConnectionType {
48 /// Connection established using HTTP polling transport.
49 HttpPolling,
50 /// Connection established using HTTP streaming transport.
51 HttpStreaming,
52 /// Connection in stream-sensing mode, where the client is determining the best
53 /// transport to use.
54 StreamSensing,
55 /// Connection established using WebSocket polling transport.
56 WsPolling,
57 /// Connection established using WebSocket streaming transport.
58 WsStreaming,
59}
60
61/// Represents the type of disconnection that occurred with the Lightstreamer Server.
62///
63/// This enum provides information about the disconnection state and what actions
64/// the client will take following the disconnection.
65#[derive(Debug)]
66pub enum DisconnectionType {
67 /// The client will automatically try to reconnect to the server.
68 WillRetry,
69 /// The client is attempting to recover the previous session.
70 /// This happens when a temporary disconnection is detected and the client
71 /// is trying to restore the previous session without losing subscriptions.
72 TryingRecovery,
73}
74
75/// Represents the type of logging to be used by the LightstreamerClient.
76///
77/// This enum determines how log messages from the client will be handled and output.
78pub enum LogType {
79 /// Use the tracing crate for logging.
80 /// This provides structured, leveled logging with spans and events.
81 TracingLogs,
82 /// Use standard output (stdout/stderr) for logging.
83 /// This provides simpler logging directly to the console.
84 StdLogs,
85}
86
87/// The transport type to be used by the client.
88/// - WS: the Stream-Sense algorithm is enabled as in the `None` case but the client will
89/// only use WebSocket based connections. If a connection over WebSocket is not possible
90/// because of the environment the client will not connect at all.
91/// - HTTP: the Stream-Sense algorithm is enabled as in the `None` case but the client
92/// will only use HTTP based connections. If a connection over HTTP is not possible because
93/// of the environment the client will not connect at all.
94/// - WS-STREAMING: the Stream-Sense algorithm is disabled and the client will only connect
95/// on Streaming over WebSocket. If Streaming over WebSocket is not possible because of
96/// the environment the client will not connect at all.
97/// - HTTP-STREAMING: the Stream-Sense algorithm is disabled and the client will only
98/// connect on Streaming over HTTP. If Streaming over HTTP is not possible because of the
99/// browser/environment the client will not connect at all.
100/// - WS-POLLING: the Stream-Sense algorithm is disabled and the client will only connect
101/// on Polling over WebSocket. If Polling over WebSocket is not possible because of the
102/// environment the client will not connect at all.
103/// - HTTP-POLLING: the Stream-Sense algorithm is disabled and the client will only connect
104/// on Polling over HTTP. If Polling over HTTP is not possible because of the environment
105/// the client will not connect at all.
106#[derive(Debug, PartialEq)]
107pub enum Transport {
108 /// WebSocket transport with Stream-Sense algorithm enabled. The client will only use WebSocket-based connections.
109 Ws,
110 /// HTTP transport with Stream-Sense algorithm enabled. The client will only use HTTP-based connections.
111 Http,
112 /// WebSocket Streaming transport with Stream-Sense algorithm disabled. The client will only connect on Streaming over WebSocket.
113 WsStreaming,
114 /// HTTP Streaming transport with Stream-Sense algorithm disabled. The client will only connect on Streaming over HTTP.
115 HttpStreaming,
116 /// WebSocket Polling transport with Stream-Sense algorithm disabled. The client will only connect on Polling over WebSocket.
117 WsPolling,
118 /// HTTP Polling transport with Stream-Sense algorithm disabled. The client will only connect on Polling over HTTP.
119 HttpPolling,
120}