5 releases (3 breaking)

0.3.1 May 27, 2024
0.3.0 Apr 22, 2024
0.2.0 Mar 25, 2024
0.1.0 Mar 19, 2024
0.0.0 Feb 8, 2023

#50 in WebSocket

Download history 677/week @ 2024-06-15 790/week @ 2024-06-22 619/week @ 2024-06-29 615/week @ 2024-07-06 680/week @ 2024-07-13 816/week @ 2024-07-20 608/week @ 2024-07-27 516/week @ 2024-08-03 354/week @ 2024-08-10 288/week @ 2024-08-17 1191/week @ 2024-08-24 1300/week @ 2024-08-31 1483/week @ 2024-09-07 834/week @ 2024-09-14 780/week @ 2024-09-21 963/week @ 2024-09-28

4,299 downloads per month

EUPL-1.2

160KB
4K SLoC

This crate wraps the Janus WebSocket asynchronous API to provide a more or less idiomatic Rust API.

For this the client internally resolves futures based on the incoming responses and their respective transaction identifier. This is hidden to provide an API where you can simply call a function and .await the response. Thus this creates needs to be run in a async/.await runtime. Currently we only support the tokio runtime.

Examples

 # use opentalk_janus_client::types::outgoing;
 # use opentalk_janus_client::{JanusPlugin, Client, RabbitMqConfig, ClientId};
 # use tokio::sync::{broadcast,mpsc};
 # use std::sync::Arc;
 # tokio_test::block_on(async {
 let (sink, _) = mpsc::channel(1);
 let connection = lapin::Connection::connect("amqp://janus-backend:5672", lapin::ConnectionProperties::default()).await.unwrap();
 let channel = connection.create_channel().await.unwrap();
 let config = RabbitMqConfig::new_from_channel(channel, "janus-gateway".into(), "to-janus".into(), "from-janus".into(), "opentalk-signaling".into());
 let client = Client::new(config, ClientId("".into()), sink).await.unwrap();
 let session = client.create_session().await.unwrap();
 let echo_handle = session
     .attach_to_plugin(JanusPlugin::Echotest, None)
     .await
     .unwrap();

 let echo = echo_handle
     .send(outgoing::EchoPluginUnnamed {
             audio: Some(true),
             ..Default::default()
     })
     .await.unwrap();
 println!("Echo {:?}, JSEP: {:?}", &echo.0, &echo.1);
 # });

Furtermore you can wrap the API and build upon that similar to spreed

pub struct SubscriberClient(Handle);
impl SubscriberClient {
    /// Joins a Room
    pub async fn join_room(&self, candidate: String ) {
        let room_id: RoomId = 2.into();
        let feed_id: FeedId = 1.into();
        let request = VideoRoomPluginJoinSubscriber::new(room_id, feed_id);
        self.0.send(request).await;
    }
}

pub struct PublisherClient(Handle);
impl PublisherClient {
    /// Sends the candidate SDP string to Janus
    pub async fn send_candidates(&self, candidate: String ) {
        self.0.trickle(TrickleMessage::Candidate(TrickleCandidate{
            candidate: "candidate:..".to_owned(),
            sdp_m_line_index: 1
        })).await;
    }
}
tokio_test::block_on(async {
let (sink, _) = mpsc::channel(1);
let connection = lapin::Connection::connect("amqp://janus-backend:5672", lapin::ConnectionProperties::default()).await.unwrap();
let channel = connection.create_channel().await.unwrap();
let config = RabbitMqConfig::new_from_channel(channel, "janus-gateway".into(), "to-janus".into(), "from-janus".into(), "opentalk-signaling".into());
let client = opentalk_janus_client::Client::new(config, ClientId("".into()), sink).await.unwrap();
let session = client.create_session().await.unwrap();

let echo_handle = session
    .attach_to_plugin(JanusPlugin::VideoRoom, None)
    .await
    .unwrap();
let publisher = PublisherClient(echo_handle);

let echo_handle = session
    .attach_to_plugin(JanusPlugin::VideoRoom, None)
    .await
    .unwrap();
let subscriber = SubscriberClient(echo_handle);
});
}

Features

Specific plugins are hidden behind feature flags. Supported Janus plugins can be enabled with the following cargo features

  • echotest for the EchoTest Janus plugin
  • videoroom for the VideoRoom Janus plugin

By default echotest and videoroom are enabled.

Dependencies

~11–23MB
~364K SLoC