aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-04-07 20:24:35 +0200
committerLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-04-07 20:24:35 +0200
commit01b70468fc1a6f7275460bfd414cdf595070522f (patch)
tree051ec102222fd1f1e3c625961364fd8aa29d4c86
parent2883c5e0503e1494ddbbba2d1bc871ee36acb38d (diff)
✨ (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<dyn Error> for more generic error handling 🐛 (subscription.rs): fix error message to be more descriptive when items or fields are missing
-rw-r--r--Cargo.toml2
-rw-r--r--src/ls_client.rs11
-rw-r--r--src/subscription.rs5
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 <daniloaz@gmail.com>"]
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(&params)?;
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<Vec<String>>,
fields: Option<Vec<String>>,
- ) -> Result<Subscription, String> {
+ ) -> Result<Subscription, Box<dyn Error>> {
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 {