wasm-peers
This crate provides an easy-to-use wrapper around WebRTC and DataChannels for a peer-to-peer connections.
Overview
As creator of agar.io famously stated WebRTC is hard. This library aims to help, by abstracting away all the setup, and providing a simple way to send and receive messages over the data channel.
It's as easy as providing address to a signaling server instance from accompanying crate and specifying two callbacks. One that specifies what should happen when a connection is established, and one for when a message is received. After that you can send messages back and forth without worrying about the implementation details.
Library contains three network topologies, one-to-one
, which creates an equal connection between two peers,
one-to-many
, which specifies a host and arbitrary number of clients
and many-to-many
that creates connection for each pair of peers and allows sending messages to any of them.
For a "production ready" apps built with this library check out either Live Document or Footballers.
Example
This example shows two peers sending ping
and pong
messages to each other.
use ConnectionType;
use NetworkManager;
use console;
// there must be a signaling server from accompanying crate running on this port
const SIGNALING_SERVER_URL: &str = "ws://0.0.0.0:9001/one-to-one";
For examples of other topologies check out the docs.
Roadmap
- Add tests
- Improve error handling
- Introduce alternative API with futures
- Add possibility to pass video/audio streams over established connection
Version History
- 0.4
- MiniServer callbacks don't accept UserId argument now (it'd always be hosts)
- Fix documentation tests so that they compile
- 0.3
- Initial release to the public
Similar projects
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.
Authors
Tomasz Karwowski LinkedIn
Acknowledgments
These projects helped me grasp WebRTC in Rust:
Also, special thanks to the guys with whom I did my B.Eng. thesis.