23 releases (7 breaking)

0.8.1 Nov 12, 2024
0.7.0 Oct 1, 2024
0.4.0 Jun 26, 2024
0.2.4 Feb 28, 2024

#1287 in Asynchronous

Download history 2/week @ 2024-08-30 195/week @ 2024-09-13 230/week @ 2024-09-20 184/week @ 2024-09-27 38/week @ 2024-10-04 13/week @ 2024-10-11 5/week @ 2024-10-18 86/week @ 2024-11-01 150/week @ 2024-11-08 24/week @ 2024-11-15 4/week @ 2024-11-22

264 downloads per month

Apache-2.0

270KB
5.5K SLoC

Jarust

Jarust is a memory safe and high-performance Rust adapter for Janus WebRTC server.

Inspired by 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

use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::core::japlugin::Attach;
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;
use tokio::time;
use tracing_subscriber::EnvFilter;

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
    let filename = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
    let env_filter = EnvFilter::from_default_env()
        .add_directive("jarust_core=debug".parse()?)
        .add_directive(format!("{filename}=info").parse()?);
    tracing_subscriber::fmt().with_env_filter(env_filter).init();

    let config = JaConfig {
        url: "wss://janus.conf.meetecho.com/ws".to_string(),
        apisecret: None,
        server_root: "janus".to_string(),
        capacity: 32,
    };
    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))
        .await?;
    let (handle, mut event_receiver) = session
        .attach("janus.plugin.echotest".to_string(), timeout)
        .await?;

    tokio::spawn(async move {
        let mut interval = time::interval(time::Duration::from_secs(2));

        loop {
            handle
                .fire_and_forget(json!({
                    "video": true,
                    "audio": true,
                }))
                .await
                .unwrap();

            handle
                .send_waiton_ack(
                    json!({
                        "video": true,
                        "audio": true,
                    }),
                    Duration::from_secs(10),
                )
                .await
                .unwrap();

            handle
                .fire_and_forget_with_jsep(
                    json!({
                        "video": true,
                        "audio": true,
                    }),
                    Jsep {
                        sdp: "".to_string(),
                        trickle: Some(false),
                        jsep_type: JsepType::Offer,
                    },
                )
                .await
                .unwrap();

            interval.tick().await;
        }
    });

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

    Ok(())
}

Dependencies

~8–22MB
~339K SLoC