From 84e9b49f566ad988dc1e589db7f3b9b0e6cba804 Mon Sep 17 00:00:00 2001 From: Hamza Jadid Date: Sun, 14 Jan 2024 00:54:11 +0200 Subject: [PATCH] refactor: remove transport type from jaconfig --- jarust/examples/raw_echotest.rs | 8 +++----- jarust/src/jaconfig.rs | 9 +-------- jarust/src/lib.rs | 6 +++--- jarust/tests/integration.rs | 8 +------- jarust_plugins/examples/echotest.rs | 8 +++----- 5 files changed, 11 insertions(+), 28 deletions(-) diff --git a/jarust/examples/raw_echotest.rs b/jarust/examples/raw_echotest.rs index 973a17e..43bf99c 100644 --- a/jarust/examples/raw_echotest.rs +++ b/jarust/examples/raw_echotest.rs @@ -10,12 +10,10 @@ use simple_logger::SimpleLogger; async fn main() -> anyhow::Result<()> { init_logger()?; - let mut connection = jarust::connect(JaConfig::new( - "wss://janus.conf.meetecho.com/ws", - None, + let mut connection = jarust::connect( + JaConfig::new("wss://janus.conf.meetecho.com/ws", None, "janus"), TransportType::Wss, - "janus", - )) + ) .await?; let session = connection.create(10).await?; let (handle, mut event_receiver) = session.attach("janus.plugin.echotest").await?; diff --git a/jarust/src/jaconfig.rs b/jarust/src/jaconfig.rs index 7bfda4b..a585276 100644 --- a/jarust/src/jaconfig.rs +++ b/jarust/src/jaconfig.rs @@ -4,7 +4,6 @@ pub const CHANNEL_BUFFER_SIZE: usize = 32; pub struct JaConfig { pub(crate) uri: String, pub(crate) apisecret: Option, - pub(crate) transport_type: TransportType, pub(crate) root_namespace: String, } @@ -14,16 +13,10 @@ pub enum TransportType { } impl JaConfig { - pub fn new( - uri: &str, - apisecret: Option, - transport_type: TransportType, - root_namespace: &str, - ) -> Self { + pub fn new(uri: &str, apisecret: Option, root_namespace: &str) -> Self { Self { uri: uri.into(), apisecret, - transport_type, root_namespace: root_namespace.into(), } } diff --git a/jarust/src/lib.rs b/jarust/src/lib.rs index 01d6f47..f49faa2 100644 --- a/jarust/src/lib.rs +++ b/jarust/src/lib.rs @@ -1,5 +1,5 @@ use crate::transport::trans::Transport; -use jaconfig::JaConfig; +use jaconfig::{JaConfig, TransportType}; use jaconnection::JaConnection; use prelude::JaResult; @@ -18,8 +18,8 @@ mod tmanager; mod utils; /// Creates a new connection with janus server from the provided configs -pub async fn connect(jaconfig: JaConfig) -> JaResult { - let transport = match jaconfig.transport_type { +pub async fn connect(jaconfig: JaConfig, transport_type: TransportType) -> JaResult { + let transport = match transport_type { jaconfig::TransportType::Wss => transport::wss::WebsocketTransport::new(), }; connect_with_transport(jaconfig, transport).await diff --git a/jarust/tests/integration.rs b/jarust/tests/integration.rs index 3432619..9004acc 100644 --- a/jarust/tests/integration.rs +++ b/jarust/tests/integration.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use jarust::jaconfig::JaConfig; -use jarust::jaconfig::TransportType; use jarust::prelude::*; use jarust::transport::trans::Transport; use tokio::sync::mpsc; @@ -31,12 +30,7 @@ impl Transport for MockTransport { #[tokio::test] async fn test_connection() { - let config = JaConfig::new( - "wss://janus.conf.meetecho.com/ws", - None, - TransportType::Wss, - "janus", - ); + let config = JaConfig::new("wss://janus.conf.meetecho.com/ws", None, "janus"); let transport = MockTransport::new(); jarust::connect_with_transport(config, transport) .await diff --git a/jarust_plugins/examples/echotest.rs b/jarust_plugins/examples/echotest.rs index 440fe59..cf24849 100644 --- a/jarust_plugins/examples/echotest.rs +++ b/jarust_plugins/examples/echotest.rs @@ -11,12 +11,10 @@ use simple_logger::SimpleLogger; async fn main() -> anyhow::Result<()> { init_logger()?; - let mut connection = jarust::connect(JaConfig::new( - "wss://janus.conf.meetecho.com/ws", - None, + let mut connection = jarust::connect( + JaConfig::new("wss://janus.conf.meetecho.com/ws", None, "janus"), TransportType::Wss, - "janus", - )) + ) .await?; let session = connection.create(10).await?; let (handle, mut event_receiver) = session.attach_echo_test().await?;