Skip to content

Commit

Permalink
refactor: moved all examples to jarust crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghamza-Jd committed Nov 3, 2024
1 parent d4e3bd8 commit c38563e
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 192 deletions.
11 changes: 10 additions & 1 deletion jarust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "jarust"
version.workspace = true
authors.workspace = true
description.workspace = true
readme.workspace = true
readme = "./README.md"
license.workspace = true
keywords.workspace = true
categories.workspace = true
Expand All @@ -28,3 +28,12 @@ __plugin_expiremental = ["jarust_plugins/__experimental"]
# Interface
use-native-tls = ["jarust_interface/use-native-tls"]
use-rustls = ["jarust_interface/use-rustls"]

[dev-dependencies]
anyhow = "1.0.89"
serde_json.workspace = true
serde.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing.workspace = true
jarust_plugins = { version = "0.7.0", path = "../jarust_plugins" }
48 changes: 48 additions & 0 deletions jarust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Jarust

Jarust is a memory safe and high-performance Rust adapter for [Janus WebRTC server](https://github.com/meetecho/janus-gateway).

Inspired by [Janode](https://github.com/meetecho/janode), jarust offers similar functionalities but it's designed
to be customizable, for exmaple, you could use the built-in WebSocket transport or provide your own RabbitMQ transport implementation.

The crate wraps the Janus core API and some of the most popular plugins APIs.

## Example Usage

```rust
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::core::prelude::Attach;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use std::time::Duration;

#[tokio::main]
async fn main() {
let config = JaConfig {
url: "ws://localhost:8188/ws".to_string(),
apisecret: None,
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust::core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator)
.await
.unwrap();

let info = connection
.server_info(Duration::from_secs(5))
.await
.unwrap();
println!("{:#?}", info);

let session = connection
.create_session(10, Duration::from_secs(5))
.await
.unwrap();

let (handle, _) = session
.attach("janus.plugin.echotest".to_string(), Duration::from_secs(5))
.await
.unwrap();
}
```
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust_plugins::audio_bridge::jahandle_ext::AudioBridge;
use jarust_plugins::audio_bridge::params::AudioBridgeJoinParams;
use jarust_plugins::audio_bridge::params::AudioBridgeJoinParamsOptional;
use jarust_plugins::audio_bridge::params::AudioBridgeListParticipantsParams;
use jarust_plugins::audio_bridge::params::AudioBridgeMuteParams;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::audio_bridge::jahandle_ext::AudioBridge;
use jarust::plugins::audio_bridge::params::AudioBridgeJoinParams;
use jarust::plugins::audio_bridge::params::AudioBridgeJoinParamsOptional;
use jarust::plugins::audio_bridge::params::AudioBridgeListParticipantsParams;
use jarust::plugins::audio_bridge::params::AudioBridgeMuteParams;
use std::path::Path;
use std::time::Duration;
use tracing_subscriber::EnvFilter;
Expand All @@ -28,8 +29,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let session = connection
.create_session(10, Duration::from_secs(10))
.await?;
Expand All @@ -40,7 +40,7 @@ async fn main() -> anyhow::Result<()> {
let error_room = handle
.create_room(Some(create_room_rsp.room.clone()), timeout)
.await;
if let Err(jarust_interface::Error::PluginResponseError { .. }) = error_room {
if let Err(jarust::interface::Error::PluginResponseError { .. }) = error_room {
tracing::info!("Already created");
};

Expand Down Expand Up @@ -72,8 +72,8 @@ async fn main() -> anyhow::Result<()> {
list_participants_rsp.participants
);

use jarust_plugins::audio_bridge::events::AudioBridgeEvent as ABE;
use jarust_plugins::audio_bridge::events::PluginEvent as PE;
use jarust::plugins::audio_bridge::events::AudioBridgeEvent as ABE;
use jarust::plugins::audio_bridge::events::PluginEvent as PE;
if let Some(PE::AudioBridgeEvent(ABE::RoomJoined { id, room, .. })) = events.recv().await {
handle
.mute(AudioBridgeMuteParams {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust_plugins::echo_test::events::EchoTestEvent;
use jarust_plugins::echo_test::events::PluginEvent;
use jarust_plugins::echo_test::jahandle_ext::EchoTest;
use jarust_plugins::echo_test::params::EchoTestStartParams;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::echo_test::events::EchoTestEvent;
use jarust::plugins::echo_test::events::PluginEvent;
use jarust::plugins::echo_test::jahandle_ext::EchoTest;
use jarust::plugins::echo_test::params::EchoTestStartParams;
use std::path::Path;
use std::time::Duration;
use tracing_subscriber::EnvFilter;
Expand All @@ -26,8 +27,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let timeout = Duration::from_secs(10);
let session = connection
.create_session(10, Duration::from_secs(10))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_interface::japrotocol::EstProto;
use jarust_interface::japrotocol::Jsep;
use jarust_interface::japrotocol::JsepType;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust_plugins::echo_test::events::EchoTestEvent;
use jarust_plugins::echo_test::events::PluginEvent;
use jarust_plugins::echo_test::jahandle_ext::EchoTest;
use jarust_plugins::echo_test::params::EchoTestStartParams;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::interface::japrotocol::EstProto;
use jarust::interface::japrotocol::Jsep;
use jarust::interface::japrotocol::JsepType;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::echo_test::events::EchoTestEvent;
use jarust::plugins::echo_test::events::PluginEvent;
use jarust::plugins::echo_test::jahandle_ext::EchoTest;
use jarust::plugins::echo_test::params::EchoTestStartParams;
use std::path::Path;
use std::time::Duration;
use tracing_subscriber::EnvFilter;
Expand All @@ -29,8 +30,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let timeout = Duration::from_secs(10);
let session = connection
.create_session(10, Duration::from_secs(10))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_core::prelude::Attach;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::core::prelude::Attach;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use serde_json::json;
use std::time::Duration;
use tracing_subscriber::EnvFilter;
Expand All @@ -17,8 +18,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let timeout = Duration::from_secs(10);
let session = connection
.create_session(10, Duration::from_secs(10))
Expand Down
18 changes: 9 additions & 9 deletions jarust_core/examples/restful.rs → jarust/examples/restful.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_core::japlugin::Attach;
use jarust_interface::japrotocol::EstProto;
use jarust_interface::japrotocol::Jsep;
use jarust_interface::japrotocol::JsepType;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::core::japlugin::Attach;
use jarust::interface::japrotocol::EstProto;
use jarust::interface::japrotocol::Jsep;
use jarust::interface::japrotocol::JsepType;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use serde_json::json;
use std::path::Path;
use std::time::Duration;
Expand All @@ -25,8 +26,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::Restful, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::Restful, RandomTransactionGenerator).await?;
let timeout = Duration::from_secs(10);

let session = connection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_core::japlugin::Attach;
use jarust_interface::japrotocol::EstProto;
use jarust_interface::japrotocol::Jsep;
use jarust_interface::japrotocol::JsepType;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::core::japlugin::Attach;
use jarust::interface::japrotocol::EstProto;
use jarust::interface::japrotocol::Jsep;
use jarust::interface::japrotocol::JsepType;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use serde_json::json;
use std::path::Path;
use std::time::Duration;
Expand All @@ -25,8 +26,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let timeout = Duration::from_secs(10);

let session = connection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust_plugins::streaming::jahandle_ext::Streaming;
use jarust_plugins::streaming::params::*;
use jarust_plugins::JanusId;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::streaming::jahandle_ext::Streaming;
use jarust::plugins::streaming::params::*;
use jarust::plugins::JanusId;
use std::path::Path;
use std::time::Duration;
use tracing_subscriber::EnvFilter;
Expand All @@ -26,8 +27,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let session = connection
.create_session(10, Duration::from_secs(10))
.await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::JanusAPI;
use jarust_interface::japrotocol::EstProto;
use jarust_interface::japrotocol::Jsep;
use jarust_interface::japrotocol::JsepType;
use jarust_interface::tgenerator::RandomTransactionGenerator;
use jarust_plugins::video_room::jahandle_ext::VideoRoom;
use jarust_plugins::video_room::params::*;
use jarust_plugins::JanusId;
use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::interface::japrotocol::EstProto;
use jarust::interface::japrotocol::Jsep;
use jarust::interface::japrotocol::JsepType;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::video_room::jahandle_ext::VideoRoom;
use jarust::plugins::video_room::params::*;
use jarust::plugins::JanusId;
use std::path::Path;
use std::time::Duration;
use tracing_subscriber::EnvFilter;
Expand All @@ -29,8 +30,7 @@ async fn main() -> anyhow::Result<()> {
server_root: "janus".to_string(),
capacity: 32,
};
let mut connection =
jarust_core::connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let mut connection = connect(config, JanusAPI::WebSocket, RandomTransactionGenerator).await?;
let session = connection
.create_session(10, Duration::from_secs(10))
.await?;
Expand Down
40 changes: 1 addition & 39 deletions jarust_core/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
# Jarust
# Jarust Core

The core of jarust.

It under the hood it uses [jarust_interface](https://crates.io/crates/jarust_interface) to provide an abstract api
for connecting, creating a session, attaching to a plugin, and then communicate with the plugin handle.

It's also the building block for the plugin crate [jarust_plugins](https://crates.io/crates/jarust_plugins)

## Example usage

```rust
use jarust_core::jaconfig::JaConfig;
use jarust_core::jaconfig::TransportType;
use jarust_core::japlugin::Attach;
use serde_json::json;
use tracing_subscriber::EnvFilter;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env().add_directive("jarust_core=trace".parse()?))
.init();

let mut connection = jarust_core::connect(
JaConfig::new("ws://localhost:8188/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 {
tracing::info!("response: {event:#?}");
}

Ok(())
}
```
Loading

0 comments on commit c38563e

Please sign in to comment.