Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to retrieve connection info #10

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
ntest = "0.9.0"
13 changes: 13 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> {
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<V: DeserializeOwned>(&self, key: &str) -> Option<V> {
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<String> {
self.call_uuid.clone()
Expand Down
Loading