pub struct SignalingService(/* private fields */);Expand description
Signaling service is used by y-webrtc protocol in order to exchange WebRTC offerings between clients subscribing to particular rooms.
§Example
use std::net::SocketAddr;
use std::str::FromStr;
use axum::{
Router,
routing::get,
extract::ws::{WebSocket, WebSocketUpgrade},
extract::State,
response::IntoResponse,
};
use yrs_axum::signaling::{SignalingService, signaling_conn};
#[tokio::main]
async fn main() {
let addr = SocketAddr::from_str("0.0.0.0:8000").unwrap();
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
let signaling = SignalingService::new();
let app = Router::new()
.route("/signaling", get(ws_handler))
.with_state(signaling);
let (tx, rx) = tokio::sync::oneshot::channel::<bool>();
tokio::spawn(async move {
axum::serve(listener, app.into_make_service())
.with_graceful_shutdown(async move {
rx.await.unwrap();
})
.await
.unwrap();
});
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
tx.send(true);
}
async fn ws_handler(
ws: WebSocketUpgrade,
State(svc): State<SignalingService>,
) -> impl IntoResponse {
ws.on_upgrade(move |socket| peer(socket, svc))
}
async fn peer(ws: WebSocket, svc: SignalingService) {
match signaling_conn(ws, svc).await {
Ok(_) => println!("signaling connection stopped"),
Err(e) => eprintln!("signaling connection failed: {}", e),
}
}Implementations§
Trait Implementations§
Source§impl Clone for SignalingService
impl Clone for SignalingService
Source§fn clone(&self) -> SignalingService
fn clone(&self) -> SignalingService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SignalingService
impl Debug for SignalingService
Auto Trait Implementations§
impl Freeze for SignalingService
impl !RefUnwindSafe for SignalingService
impl Send for SignalingService
impl Sync for SignalingService
impl Unpin for SignalingService
impl !UnwindSafe for SignalingService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more