johanhelsing/matchbox
소개
Rust wasm과 네이티브 환경에서 간편하게 사용할 수 있는 WebRTC P2P 네트워킹입니다.
웹 및 앱측정된 스타 증가
- in 24h
- -1
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalPainless peer-to-peer WebRTC networking for rust's native and wasm applications.
The goal of the Matchbox project is to enable udp-like, unordered, unreliable p2p connections in web browsers or native to facilitate low-latency multiplayer games.
Matchbox supports both unreliable and reliable data channels, with configurable ordering guarantees and variable packet retransmits.
The Matchbox project contains:
matchbox_socket: A socket abstraction for Wasm or Native, with:
ggrs: A feature providing a ggrs compatible socket.tls12(default): TLS 1.2 for nativewss://signaling, for servers or proxies without TLS 1.3. Disable withdefault-features = false.
matchbox_signaling: A signaling server library, with ready to use examples
matchbox_server: A ready to use full-mesh signalling server
bevy_matchbox: A
matchbox_socketintegration for the Bevy game enginebevy bevy_matchbox 0.19 0.15, main 0.18 0.14 0.17 0.13 0.16 0.12 0.15 0.11 0.14 0.10 0.13 0.9 0.12 0.8 0.11 0.7 0.10 0.6 < 0.9 Unsupported
Examples
- simple: A simple communication loop using matchbox_socket
- bevy_ggrs: An example browser game, using
bevyandbevy_ggrs- Live 2-player demo: https://johanhelsing.github.io/matchbox/
- Live 4-player demo: https://johanhelsing.github.io/matchbox/?players=4
How it works
WebRTC allows direct connections between peers, but in order to establish those connections, some kind of signaling service is needed. matchbox_server is such a service. Once the connections are established, however, data will flow directly between peers, and no traffic will go through the signaling server.
The signaling service needs to run somewhere all clients can reach it over http or https connections. In production, this usually means the public internet.
When a client wants to join a p2p (mesh) network, it connects to the signaling service. The signaling server then notifies the peers that have already connected about the new peer (sends a NewPeer event).
Peers then negotiate a connection through the signaling server. The initiator sends an "offer" and the recipient responds with an "answer." Once peers have enough information relayed, a RTCPeerConnection is established for each peer, which comes with one or more data channels.
All of this, however, is hidden from rust application code. All you will need to do on the client side, is:
- Create a new socket, and give it a signaling server url
.awaitthe message loop future that processes new messages.
You can hook into the lifecycle of your socket through the socket's API, such as connection state changes. Similarly, you can send packets to peers using the socket through a simple, non-blocking method.
To check whether a connected peer is reached through a TURN relay (yours or theirs), ask the socket after update_peers(). The answer is None until known:
if socket.is_relayed(peer) == Some(true) {
info!("{peer} is connected through the relay");
}
Showcase
Projects using Matchbox:
- NES Bundler - Transform your NES game into a single executable targeting your favorite OS!
- Cargo Space (in development) - A coop 2D space game about building and flying a ship together
- Extreme Bevy - Simple 2-player arcade shooter
- Matchbox demo
- A Janitors Nightmare - 2-player jam game
- Lavagna - collaborative blackboard for online meetings
Contributing
PRs welcome!
If you have questions or suggestions, feel free to make an issue. There's also a Discord channel if you want to get in touch.
Thanks
- A huge thanks to Ernest Wong for his Dango Tribute experiment!
matchbox_socketis heavily inspired its wasm-bindgen server_socket and Matchbox would probably not exist without it.
License
All code in this repository dual-licensed under either:
- MIT License or http://opensource.org/licenses/MIT
- Apache License, Version 2.0 or http://www.apache.org/licenses/LICENSE-2.0
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.
관련 프로젝트 살펴보기
불러오는 중…
