Crates.io | rheomesh |
lib.rs | rheomesh |
version | |
source | src |
created_at | 2024-11-18 15:34:27.040458 |
updated_at | 2024-12-08 16:17:55.0036 |
description | WebRTC SFU server-side library for Rust. |
homepage | https://github.com/h3poteto/rheomesh |
repository | https://github.com/h3poteto/rheomesh |
max_upload_size | |
id | 1452288 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Rheomesh is a WebRTC SFU library that provides a simple API for building real-time communication applications. This provides an SDK to help you build a WebRTC SFU server. Here is an example SFU server for video streaming.
Add your Cargo.toml
like this:
[dependencies]
rheomesh = { version = "0" }
First of all, please create a router. Router accommodates multiple transports and they can communicate with each other. That means transports belonging to the same Router can send/receive their media. Router is like a meeting room.
use rheomesh::config::MediaConfig;
use rheomesh::router::Router;
//...
async fn new() {
let config = MediaConfig::default();
let router = Router::new(config);
}
Next, please create publish and subscribe transports.
use rheomesh::config::WebRTCTransportConfig
async fn new() {
//...
let mut config = WebRTCTransportConfig::default();
config.configuration.ice_servers = vec![RTCIceServer {
urls: vec!["stun:stun.l.google.com:19302".to_owned()],
..Default::default()
}];
let publish_transport = router.create_publish_transport(config.clone()).await;
let subscribe_transport = router.create_subscribe_transport(config.clone()).await;
}
on_ice_candidate
callbackpublish_transport
.on_ice_candidate(Box::new(move |candidate| {
let init = candidate.to_json().expect("failed to parse candidate");
// Send `init` message to client. The client have to call `addIceCandidate` method with this parameter.
}))
.await;
Please send init
to client. The corresponding client-side handler is here.
RTCIceCandidateInit
On the other hand, you will receive RTCIceCandidateInit
message from client, here.
let _ = publish_transport
.add_ice_candidate(candidate)
.await
.expect("failed to add ICE candidate");
offer
messageThen, server will receive offer
from client, the corresponding client-side handler is here.
let answer = publish_transport
.get_answer(offer)
.await
.expect("failed to connect publish_transport");
// Send `answer` message to client. The client have to call `setAnswer` method.
Please send answer
to client. The corresponding client-side handler is here.
Finally, please handle publish event with track_id
.
let publisher = publish_transport.publish(track_id).await;
on_ice_candidate
and on_negotiation_needed
callbacksubscribe_transport
.on_ice_candidate(Box::new(move |candidate| {
let init = candidate.to_json().expect("failed to parse candidate");
// Send `init` message to client. The client have to call `addIceCandidate` method with this parameter.
}))
.await;
subscribe_transport
.on_negotiation_needed(Box::new(move |offer| {
// Send `offer` message to client. The client have to call `setOffer` method.
}))
Please send init
to client. The corresponding client-side handler is here.
RTCIceCandidateInit
On the other hand, you will receive RTCIceCandidateInit
message from client, here.
let _ = subscribe_transport
.add_ice_candidate(candidate)
.await
.expect("failed to add ICE candidate");
Then, please call subscribe
method.
let (subscriber, offer) = subscribe_transport
.subscribe(track_id)
.await
.expect("failed to connect subscribe_transport");
// Send `offer` message to client. The client have to call `setOffer` method.
Please send offer
message to client. The corresponding client-side handler is here.
answer
messageFinally, server will receive answer
from client, the corresponding client-side handler is here.
let _ = subscribe_transport
.set_answer(answer)
.await
.expect("failed to set answer");