| 1 |
# WebRTC DataChannel Example |
| 2 |
|
| 3 |
[View full source code][code] or [view the compiled example online][online] |
| 4 |
|
| 5 |
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/webrtc_datachannel/ |
| 6 |
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/webrtc_datachannel/ |
| 7 |
|
| 8 |
This example creates 2 peer connections and 2 data channels in single browser tab. |
| 9 |
Send ping/pong between `peer1.dc` and `peer2.dc`. |
| 10 |
|
| 11 |
## `Cargo.toml` |
| 12 |
|
| 13 |
The `Cargo.toml` enables features necessary to use WebRTC DataChannel and its negotiation. |
| 14 |
|
| 15 |
```toml |
| 16 |
{{#include ../../../examples/webrtc_datachannel/Cargo.toml}} |
| 17 |
``` |
| 18 |
|
| 19 |
## `src/lib.rs` |
| 20 |
|
| 21 |
The Rust code connects WebRTC data channel. |
| 22 |
|
| 23 |
```rust |
| 24 |
{{#include ../../../examples/webrtc_datachannel/src/lib.rs}} |
| 25 |
``` |