wrtc
This is a Rust library wrapper around popular webrtc, that's focused on a developer experience.
Message exchange protocol is compatible with NPM simple-peer library and tries its best to conform to idiomatic Rust structures eg. futures Sink/Stream instead of callbacks.
API coverage
Current state only covers data channels.
Example
#[tokio::main]
async fn main() -> Result<(), Error> {
let options = Options::with_channels(&["test"]);
let p1 = Arc::new(PeerConnection::start(true, options.clone()).await?);
let p2 = Arc::new(PeerConnection::start(false, options).await?);
let _ = exchange(p1.clone(), p2.clone());
let _ = exchange(p2.clone(), p1.clone());
p1.connected().await?;
p2.connected().await?;
{
let mut dc1 = p1.data_channels().next().await.unwrap();
let mut dc2 = p2.data_channels().next().await.unwrap();
dc1.ready().await?;
dc2.ready().await?;
let data: Bytes = "hello".into();
dc1.send(data.clone()).await?;
let msg = dc2.next().await.unwrap()?;
assert_eq!(msg.data, data);
}
p1.close().await?;
p2.close().await?;
Ok(())
}
fn exchange(
from: Arc<PeerConnection>,
to: Arc<PeerConnection>,
) -> JoinHandle<Result<(), Error>> {
tokio::spawn(async move {
while let Some(signal) = from.listen().await {
to.signal(signal).await?;
}
Ok(())
})
}