gschup / ggrs

GGRS is a reimagination of GGPO, enabling P2P rollback networking in Rust. Rollback to the future!
Other
520 stars 25 forks source link

WebRTC Support #10

Closed ValorZard closed 3 years ago

ValorZard commented 3 years ago

Since the UDP bindings are just a single file, it shouldn't be too bad to add webrtc support. The problem with that is only that webrtc itself is a fickle beast, but that just comes with exporting to web.

gschup commented 3 years ago

I'll be honest: I have absolutely no prior knowledge of web-based stuff.

I might take a look in the future, but it is definitely not something I can just add.

gschup commented 3 years ago

PR #18 is a first step to WASM compatability.

johanhelsing commented 3 years ago

I copied the bevy_ggrs box_game_p2p example into the bevy_webgl2 template and got it to build with latest bevy and stop panicking. https://github.com/johanhelsing/bevy_ggrs_box_game_web

I didn't actually start on replacing udp with werbrtc, but thought I'd just share the example as it's a good place to start if someone else wants to try tinkering as well.

You can pass in "command line" args in the query string, so http://127.0.0.1:4000/?players[0]=localhost&players[1]=1.2.3.4:1234 will start the game with one local player and waiting for the other player to join (assuming you comment out udp stuff in ggrs itself).

gschup commented 3 years ago

Since I would love GGRS to stay a 100% rust project without any dependencies from other languages, my current suggestion is to wait for https://github.com/webrtc-rs/webrtc to finish implementing the webRTC protocol and revisit this issue from there.

gschup commented 3 years ago

20 will internally allow to use different kinds of sockets, as long they can send and receive packets. Yet another step towards webRTC!

johanhelsing commented 3 years ago

21 Exposes the socket trait publicly and was enough for me to inject my webrtc nonblocking socket implementation.

We might want further changes in ggrs to make the usage nicer, but that's enough for a minimal implementation :)

johanhelsing commented 3 years ago

I put all my webrtc related code in a separate repo, Matchbox. The matchbox_socket crate implements the ggrs::NonBlockingSocket trait if the ggrs-socket feature is enabled.

I put it there for now, but we could consider moving the ggrs integration code over to ggrs instead... not sure what makes the most sense.

In any case I wrote a blog post about it: https://johanhelsing.studio/posts/introducing-matchbox And the repo is here: https://github.com/johanhelsing/matchbox.

gschup commented 3 years ago

With the matchbox demo showcasing that GGRS works in a WASM environment, I will close this issue for now.