From 01b70468fc1a6f7275460bfd414cdf595070522f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Aza=C3=B1a?= Date: Sun, 7 Apr 2024 20:24:35 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(Cargo.toml):=20bump=20version=20to?= =?UTF-8?q?=200.1.5=20for=20new=20release=20=E2=9C=A8=20(ls=5Fclient.rs):?= =?UTF-8?q?=20add=20TLCP=5FVERSION=20constant=20for=20protocol=20version?= =?UTF-8?q?=20tracking=20=E2=99=BB=EF=B8=8F=20(ls=5Fclient.rs):=20remove?= =?UTF-8?q?=20commented-out=20code=20and=20unused=20println=20for=20cleane?= =?UTF-8?q?r=20codebase=20=E2=99=BB=EF=B8=8F=20(ls=5Fclient.rs):=20use=20T?= =?UTF-8?q?LCP=5FVERSION=20constant=20instead=20of=20hardcoded=20protocol?= =?UTF-8?q?=20string=20=E2=9C=A8=20(ls=5Fclient.rs):=20handle=20'reqok'=20?= =?UTF-8?q?server=20message=20for=20better=20server=20communication=20?= =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(subscription.rs):=20change=20error=20type?= =?UTF-8?q?=20to=20Box=20for=20more=20generic=20error=20handl?= =?UTF-8?q?ing=20=F0=9F=90=9B=20(subscription.rs):=20fix=20error=20message?= =?UTF-8?q?=20to=20be=20more=20descriptive=20when=20items=20or=20fields=20?= =?UTF-8?q?are=20missing?= 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 {