From 4f4a84a9834469533da10375230eb3703ca674fd Mon Sep 17 00:00:00 2001 From: Brian May Date: Sun, 22 Oct 2023 18:53:36 +1100 Subject: [PATCH] Add get_info_string() function Fixes: #8 --- Cargo.toml | 3 ++- src/connection.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index be5426f..e24ffd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,10 @@ futures = "0.3" serde_json = "1.0" uuid = { version = "1.4", features = ["v4"] } thiserror = "1.0" +serde = "1.0.158" [dev-dependencies] tokio = { version = "1", features = ["rt-multi-thread", "macros"] } anyhow = "*" regex ="*" -ntest = "0.9.0" \ No newline at end of file +ntest = "0.9.0" diff --git a/src/connection.rs b/src/connection.rs index 49bc8f1..630abf4 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -4,6 +4,7 @@ use crate::esl::EslConnectionType; use crate::event::Event; use crate::io::EslCodec; use futures::SinkExt; +use serde::de::DeserializeOwned; use serde_json::Value; use std::collections::{HashMap, VecDeque}; use std::sync::atomic::Ordering; @@ -30,6 +31,18 @@ pub struct EslConnection { } impl EslConnection { + /// Returns one of the session parameters as a string + pub fn get_info_string(&self, key: &str) -> Option { + let value = self.connection_info.as_ref()?.get(key)?.clone(); + serde_json::from_value(value).ok()? + } + + /// Returns one of the session parameters as any deserializable type + pub fn get_info(&self, key: &str) -> Option { + let value = self.connection_info.as_ref()?.get(key)?.clone(); + serde_json::from_value(value).ok()? + } + /// returns call uuid in outbound mode pub async fn call_uuid(&self) -> Option { self.call_uuid.clone()