Skip to content

Commit

Permalink
chore: wss -> ws, and example uses local dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghamza-Jd committed Feb 8, 2024
1 parent 141b679 commit e7028eb
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 12 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ The library wraps the Janus core API and some of the most popular plugins APIs.

## Examples

- [jarust examples](./jarust/examples/), example usage of jarust.
To run the examples first you have to lunch the janus server.

```sh
docker compose up -d
```

Then you can run any of the these examples:

- [jarust examples](./jarust/examples/), example usage of core jarust.
- [plugins examples](./jarust_plugins/examples/), example usage of jarust's predefined plugins.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '2.1'
version: '3.8'

services:
janus-gateway:
name: janus-server
container_name: janus-dev-server
image: 'canyan/janus-gateway:latest'
command: ["/usr/local/bin/janus", "-F", "/usr/local/etc/janus"]
ports:
Expand Down
4 changes: 2 additions & 2 deletions jarust/examples/raw_echotest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ async fn main() -> anyhow::Result<()> {
init_logger()?;

let mut connection = jarust::connect(
JaConfig::new("wss://janus.conf.meetecho.com/ws", None, "janus"),
TransportType::Wss,
JaConfig::new("ws://localhost:8188/ws", None, "janus"),
TransportType::Ws,
)
.await?;
let session = connection.create(10).await?;
Expand Down
44 changes: 44 additions & 0 deletions jarust/examples/secure_ws.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use jarust::jaconfig::JaConfig;
use jarust::jaconfig::TransportType;
use jarust::japlugin::Attach;
use log::LevelFilter;
use log::SetLoggerError;
use serde_json::json;
use simple_logger::SimpleLogger;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
init_logger()?;

let mut connection = jarust::connect(
JaConfig::new("wss://janus.conf.meetecho.com/ws", None, "janus"),
TransportType::Ws,
)
.await?;
let session = connection.create(10).await?;
let (handle, mut event_receiver) = session.attach("janus.plugin.echotest").await?;

handle
.message(json!({
"video": true,
"audio": true,
}))
.await?;

while let Some(event) = event_receiver.recv().await {
log::info!("response: {event:?}");
}

Ok(())
}

fn init_logger() -> Result<(), SetLoggerError> {
SimpleLogger::new()
.with_level(LevelFilter::Trace)
.with_colors(true)
.with_module_level("tokio_tungstenite", LevelFilter::Off)
.with_module_level("tungstenite", LevelFilter::Off)
.with_module_level("want", LevelFilter::Off)
.with_module_level("rustls", LevelFilter::Off)
.init()
}
2 changes: 1 addition & 1 deletion jarust/src/jaconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct JaConfig {

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TransportType {
Wss,
Ws,
}

impl JaConfig {
Expand Down
4 changes: 2 additions & 2 deletions jarust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use prelude::JaResult;
/// Creates a new connection with janus server from the provided configs
pub async fn connect(jaconfig: JaConfig, transport_type: TransportType) -> JaResult<JaConnection> {
let transport = match transport_type {
jaconfig::TransportType::Wss => transport::wss::WebsocketTransport::new(),
jaconfig::TransportType::Ws => transport::web_socket::WebsocketTransport::new(),
};
connect_with_transport(jaconfig, transport).await
}

#[cfg(target_family = "wasm")]
/// Creates a new connection with janus server from the provided configs
pub async fn connect(jaconfig: JaConfig, transport_type: TransportType) -> JaResult<JaConnection> {
let transport = transport::wasm_wss::WasmWsTransport;
let transport = transport::wasm_web_socket::WasmWsTransport;
connect_with_transport(jaconfig, transport).await
}

Expand Down
4 changes: 2 additions & 2 deletions jarust/src/transport/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod trans;
#[cfg(target_family = "wasm")]
pub mod wasm_wss;
pub mod wasm_web_socket;
#[cfg(not(target_family = "wasm"))]
pub mod wss;
pub mod web_socket;
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions jarust_plugins/examples/echotest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ async fn main() -> anyhow::Result<()> {
init_logger()?;

let mut connection = jarust::connect(
JaConfig::new("wss://janus.conf.meetecho.com/ws", None, "janus"),
TransportType::Wss,
JaConfig::new("ws://localhost:8188/ws", None, "janus"),
TransportType::Ws,
)
.await?;
let session = connection.create(10).await?;
Expand Down

0 comments on commit e7028eb

Please sign in to comment.