From 01b70468fc1a6f7275460bfd414cdf595070522f Mon Sep 17 00:00:00 2001 From: Daniel López Azaña Date: Sun, 7 Apr 2024 20:24:35 +0200 Subject: ✨ (Cargo.toml): bump version to 0.1.5 for new release ✨ (ls_client.rs): add TLCP_VERSION constant for protocol version tracking ♻️ (ls_client.rs): remove commented-out code and unused println for cleaner codebase ♻️ (ls_client.rs): use TLCP_VERSION constant instead of hardcoded protocol string ✨ (ls_client.rs): handle 'reqok' server message for better server communication ♻️ (subscription.rs): change error type to Box for more generic error handling 🐛 (subscription.rs): fix error message to be more descriptive when items or fields are missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- src/ls_client.rs | 11 +++++++---- src/subscription.rs | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e78524a..8e076aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lightstreamer-client" -version = "0.1.4" +version = "0.1.5" edition = "2021" authors = ["Daniel López Azaña "] description = "A Rust client for Lightstreamer, designed to facilitate real-time communication with Lightstreamer servers." diff --git a/src/ls_client.rs b/src/ls_client.rs index 4d46dfb..95cdfba 100644 --- a/src/ls_client.rs +++ b/src/ls_client.rs @@ -123,6 +123,9 @@ impl LightstreamerClient { /// A constant string representing the version of the library. pub const LIB_VERSION: &'static str = "0.1.0"; + /// A constant string representing the version of the TLCP protocol used by the library. + pub const TLCP_VERSION: &'static str = "TLCP-2.4.0"; + /// Static method that can be used to share cookies between connections to the Server (performed by /// this library) and connections to other sites that are performed by the application. With this /// method, cookies received by the application can be added (or replaced if already present) to @@ -440,14 +443,12 @@ impl LightstreamerClient { // Prepare the subscription request. // let mut params: Vec<(&str, &str)> = vec![ - //("LS_session", session_id), ("LS_reqId", &ls_req_id), ("LS_op", "add"), ("LS_subId", &ls_sub_id), ("LS_mode", &ls_mode), ("LS_group", &ls_group), ("LS_schema", &ls_schema), - ("LS_data_adapter", &ls_data_adapter), ("LS_ack", "false"), ]; if ls_snapshot != "" { @@ -476,6 +477,9 @@ impl LightstreamerClient { "probe" => { println!("Received probe message from server: '{}'", clean_text); }, + "reqok" => { + println!("Received reqok message from server: '{}'", clean_text); + }, // // Subscription confirmation from server. // @@ -506,12 +510,10 @@ impl LightstreamerClient { }, }; let ls_send_sync = self.connection_options.get_send_sync().to_string(); - println!("self.connection_options.get_send_sync(): {:?}", self.connection_options.get_send_sync()); let mut params: Vec<(&str, &str)> = vec![ ("LS_adapter_set", &ls_adapter_set), ("LS_cid", "mgQkwtwdysogQz2BJ4Ji kOj2Bg"), ("LS_send_sync", &ls_send_sync), - ("LS_protocol", "TLCP-2.4.0"), ]; if let Some(user) = &self.connection_details.get_user() { params.push(("LS_user", user)); @@ -519,6 +521,7 @@ impl LightstreamerClient { if let Some(password) = &self.connection_details.get_password() { params.push(("LS_password", password)); } + params.push(("LS_protocol", Self::TLCP_VERSION)); let encoded_params = serde_urlencoded::to_string(¶ms)?; write_stream .send(Message::Text(format!("create_session\r\n{}\n", encoded_params))) diff --git a/src/subscription.rs b/src/subscription.rs index e008804..07c580c 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -1,5 +1,6 @@ use crate::subscription_listener::SubscriptionListener; use std::collections::HashMap; +use std::error::Error; use std::fmt::{self, Debug, Formatter}; /// Enum representing the snapshot delivery preferences to be requested to Lightstreamer Server for the items in the Subscription. @@ -116,9 +117,9 @@ impl Subscription { mode: SubscriptionMode, items: Option>, fields: Option>, - ) -> Result { + ) -> Result> { if items.is_none() || fields.is_none() { - return Err("Items and fields must be provided".to_string()); + return Err("Items and fields must be provided".to_string().into()); } Ok(Subscription { -- cgit v1.2.3