Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Easy-to-use wrapper for WebRTC DataChannels peer-to-peer connections written in Rust and compiling to WASM.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

wasm-peers/wasm-peers

Repository files navigation

wasm-peers logo

crates.iodocs.rscrates.ioMIT/Apache 2.0 licensedCIcoverage statuspre-commit

This crate provides an easy-to-use wrapper around WebRTC and DataChannels for a peer-to-peer connections.

Overview

As creator ofagar.io famously statedWebRTC is hard.This library aims to help, by abstracting away all the setup, and providing a simple way to sendand receive messages over the data channel.

It's as easy as providing address to a signaling server instance fromaccompanying 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 clientsandmany-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 thislibrary check out eitherLive Document orFootballers.

Example

This example shows two peers sendingping andpong messages to each other.

use wasm_peers::ConnectionType;use wasm_peers::one_to_one::NetworkManager;use web_sys::console;// there must be a signaling server from accompanying crate running on this portconstSIGNALING_SERVER_URL:&str ="ws://0.0.0.0:9001/one-to-one";fnmain(){// there must be some mechanism for exchanging session ids between peerslet session_id =SessionId::new("some-session-id".to_string());letmut peer1 =NetworkManager::new(SIGNALING_SERVER_URL,        session_id.clone(),&ConnectionType::Stun,).unwrap();let peer1_clone = peer1.clone();let peer1_on_open =move || peer1_clone.send_message("ping!").unwrap();let peer1_on_message ={move |message|{            console::log_1(&format!("peer1 received message: {}", message).into());}};    peer1.start(peer1_on_open, peer1_on_message).unwrap();letmut peer2 =NetworkManager::new(SIGNALING_SERVER_URL,        session_id,&ConnectionType::Stun,).unwrap();let peer2_on_open = ||{/* do nothing */};let peer2_clone = peer2.clone();let peer2_on_message ={let peer2_received_message = peer2_received_message.clone();move |message|{            console::log_1(&format!("peer2 received message: {}", message).into());            peer2_clone.send_message("pong!").unwrap();}};    peer2.start(peer2_on_open, peer2_on_message).unwrap();}

For examples of other topologies check out thedocs.

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

Contribution

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

Authors

Tom KarwowskiLinkedIn

Acknowledgments

These projects helped me grasp WebRTC in Rust:

Also, special thanks to the guys with whom I did my B.Eng. thesis.

About

Easy-to-use wrapper for WebRTC DataChannels peer-to-peer connections written in Rust and compiling to WASM.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

[8]ページ先頭

©2009-2025 Movatter.jp