#data-channel #web-rtc #async

async-datachannel

Async Wrapper for datachannel

8 unstable releases (3 breaking)

0.4.0 Nov 29, 2022
0.3.0 Mar 9, 2022
0.2.2 Sep 22, 2021
0.1.2 Sep 15, 2021

#438 in Concurrency

Download history 90/week @ 2024-03-12 100/week @ 2024-03-19 88/week @ 2024-03-26 67/week @ 2024-04-02 34/week @ 2024-04-09 44/week @ 2024-04-16 34/week @ 2024-04-23 49/week @ 2024-04-30 74/week @ 2024-05-07 98/week @ 2024-05-14 41/week @ 2024-05-21 61/week @ 2024-05-28 92/week @ 2024-06-04 50/week @ 2024-06-11 1/week @ 2024-06-18 1/week @ 2024-06-25

186 downloads per month
Used in libp2p-webrtc

Apache-2.0 OR MIT

16KB
269 lines

async-datachannel

License Cargo Documentation

Async wrapper for the datachannel crate. For a complete example check the examples directory.

Note that this crate currently is made to work only with the tokio runtime. If you're interested in supporting other runtimes, let me know.

Quickstart

use async_datachannel::{Message, PeerConnection, PeerId, RtcConfig};
use futures::io::{AsyncReadExt, AsyncWriteExt, channel::mpsc};

let ice_servers = vec!["stun:stun.l.google.com:19302"];
let conf = RtcConfig::new(&ice_servers);
let (tx_sig_outbound, mut rx_sig_outbound) = mpsc::channel(32);
let (tx_sig_inbound, rx_sig_inbound) = mpsc::channel(32);
let listener = PeerConnection::new(&conf, (tx_sig_outbound, rx_sig_inbound))?;

// TODO: Wire up `tx_sig_inbound` and `rx_sig_outbound` to a signalling
// mechanism.

let mut dc = listener.dial("Hangout").await?;
dc.write(b"Hello").await?;

let mut buf = vec![0; 32];
let n = dc.read(&mut buf).await?;
assert_eq!(b"World", &buf[..n]);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~11–22MB
~366K SLoC