Crates.io | async-datachannel-wasm |
lib.rs | async-datachannel-wasm |
version | 0.2.1 |
source | src |
created_at | 2021-09-21 07:33:43.38498 |
updated_at | 2022-11-29 08:07:49.983514 |
description | Async Wrapper for WebRTC datachannel in the browser environment |
homepage | https://github.com/wngr/async-datachannel |
repository | https://github.com/wngr/async-datachannel |
max_upload_size | |
id | 454286 |
size | 24,774 |
Async wrapper API for browser provided WebRTC API.
use async_datachannel_wasm::{Message, PeerConnection, 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(ice_servers, (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]);
Licensed under either of
at your option.
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.