Skip to content

Commit

Permalink
refactor: remove transport type from jaconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghamza-Jd committed Jan 13, 2024
1 parent 710ef79 commit 84e9b49
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
8 changes: 3 additions & 5 deletions jarust/examples/raw_echotest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
9 changes: 1 addition & 8 deletions jarust/src/jaconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub const CHANNEL_BUFFER_SIZE: usize = 32;
pub struct JaConfig {
pub(crate) uri: String,
pub(crate) apisecret: Option<String>,
pub(crate) transport_type: TransportType,
pub(crate) root_namespace: String,
}

Expand All @@ -14,16 +13,10 @@ pub enum TransportType {
}

impl JaConfig {
pub fn new(
uri: &str,
apisecret: Option<String>,
transport_type: TransportType,
root_namespace: &str,
) -> Self {
pub fn new(uri: &str, apisecret: Option<String>, root_namespace: &str) -> Self {
Self {
uri: uri.into(),
apisecret,
transport_type,
root_namespace: root_namespace.into(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions jarust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::transport::trans::Transport;
use jaconfig::JaConfig;
use jaconfig::{JaConfig, TransportType};
use jaconnection::JaConnection;
use prelude::JaResult;

Expand All @@ -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<JaConnection> {
let transport = match jaconfig.transport_type {
pub async fn connect(jaconfig: JaConfig, transport_type: TransportType) -> JaResult<JaConnection> {
let transport = match transport_type {
jaconfig::TransportType::Wss => transport::wss::WebsocketTransport::new(),
};
connect_with_transport(jaconfig, transport).await
Expand Down
8 changes: 1 addition & 7 deletions jarust/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions jarust_plugins/examples/echotest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down

0 comments on commit 84e9b49

Please sign in to comment.