• Stars
    star
    877
  • Rank 52,062 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Painless peer-to-peer WebRTC networking for rust wasm (and native!)

Matchbox

crates.io MIT/Apache 2.0 crates.io docs.rs

Painless 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.
  • 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_socket integration for the Bevy game engine
    bevy bevy_matchbox
    0.11 0.7, main
    0.10 0.6
    < 0.9 Unsupported

Examples

How it works

Connection

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
  • .await the message loop future that processes new messages.
    • If you are using Bevy, this is done automatically by bevy_matchbox (see the bevy_ggrs example).
    • Otherwise, if you are using WASM, wasm-bindgen-futures can help (see the simple example).
    • Alternatively, the future can be polled manually, i.e. once per frame.

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.

Showcase

Projects using Matchbox:

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_socket is 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:

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.

More Repositories

1

bevy_smud

Sdf 2d shape renderer for Bevy
Rust
97
star
2

qt-csd-demo

Demo for custom client side window decorations using Qt
QML
86
star
3

bevy_pancam

A bevy plugin for panning orthographic cameras
Rust
61
star
4

extreme_bevy

A low-latency multiplayer action game, showcasing how to implement p2p connections and rollback networking in a web browser.
Rust
52
star
5

bevy_pkv

Cross-platform (including wasm) persistent key value store plugin for rust games/apps
Rust
45
star
6

bevy_web_asset

Bevy asset loader that transparently supports loading over http(s)
Rust
35
star
7

noisy_bevy

Simple stupid noise primitives for WGSL and Rust (glam/bevy types)
Rust
23
star
8

bevy_snap

Saving and loading entity and resource state for bevy
Rust
15
star
9

qtws17-compositor

Qt Wayland Compositor presentation for Qt World Summit 2017
QML
10
star
10

bevy_gaff

a networked (p2p), cross-platform physics simulation example using rollback netcode
Rust
9
star
11

bevy_sparse_grid_2d

An opinionated 2D sparse grid made for use with Bevy. For storing and querying entities
Rust
8
star
12

docker-qt-tests

Docker container for headless GUI testing of Qt (might diverge from https://git.qt.io/qtwaylandtests/docker-qt-tests)
Shell
7
star
13

StealWithAttribution

Unity tool for downloading, importing and storing assets with attribution metadata from free online asset repositories like HDRI haven and Sketchfab.
C#
6
star
14

bevy_crossbeam_event

Trigger Bevy events from crossbeam channels
Rust
6
star
15

bevy_lospec

Asset loader plugin for Bevy that adds support for lospec color palette formats
Rust
5
star
16

kitchen-compositor

Wayland compositor for manual testing. Let's you easily inspect and send events to clients.
QML
5
star
17

UniSdf

Signed distance shader library for Unity (including shader graph)
ShaderLab
4
star
18

wayland-log-reader

App for navigating and making sense of WAYLAND_DEBUG log output
JavaScript
4
star
19

OneOf-Unity

Sum types for Unity C#
C#
2
star
20

bevy_trauma_shake

A Bevy plugin for shaking 2d cameras
Rust
1
star
21

unity-physics-joints

UPM package of the joints components from the official EntityComponentSystemSamples repo
C#
1
star
22

ultra_crustaceous

Tools for making Ultra Zeus compatible roms in rust. And a sample emulator in js
Rust
1
star
23

cowry-ld44

A game about change
C#
1
star
24

krita_bevy_anim

WIP 1-click krita animation to bevy export + hot reload
Rust
1
star
25

bevy_stutter

Make your Bevy app stutter
Rust
1
star
26

logz_plz

Rust
1
star
27

webgltemplate

A template for easy webgl development with THREE.js and webpack.
JavaScript
1
star
28

qtwayland-backports

EXPERIMENTAL qtwayland backports for old versions of Qt (Might be stale, or I might force push or delete branches)
C++
1
star
29

johanhelsing.github.io

Johan Helsings github page
HTML
1
star
30

UniRxObservableReference

Inspectable and serializable references to UniRx IObservable properties
C#
1
star
31

bevy_roll

Rollback-safe implementations and utilities for Bevy Engine
Rust
1
star