Cyberdeck
A library for easily creating WebRTC data channel connections in Rust.
let mut cd = Cyberdeck::new(|c, msg| {
if let Some(m) = msg {
println!("Recieved a message from channel {}!", c.name());
let msg_str = String::from_utf8(m.data.to_vec()).unwrap();
println!("Message from DataChannel '{}': {}", c.name(), msg_str);
} else if c.state() == RTCDataChannelState::Open {
println!("DataChannel '{}' opened", c.name());
c.send_text("Connected to client!").unwrap();
} else if c.state() == RTCDataChannelState::Closed {
println!("DataChannel '{}' closed", c.name());
}
})
.await?;
let answer = cd.set_offer(offer).await?;
You can try out this code by going to https://jsfiddle.net/ndgvLuyc/
- Copy the code from "Browser base64 Session Description"
- Open up a terminal and type in
echo
| cargo run --example simple
- Copy the response code in the terminal, and past it into "Rust base64 Session Description"
- Hit connect and send messages