(The following was adapted from a talk I gave at DWeb Weekend 2025 at the Internet Archive in San Francisco on August 17, 2025)
Simplifying WebRTC Datachannels for Games
First of all, to get some stuff out of the way, instead of using the “super complicated” WebRTC datachannels, why don’t we use something simpler?
Why Not Use Websockets?
- Too slow: Most games use UDP with a reliability layer on top.
- Suitable for turn-based games: Fine for games that are turn-based/slow-paced, like Runescape.
- For more details, see:
The Case for Web Transport
- Replacement for Websockets, uses QUIC instead of TCP.
- However, it has been in development for a long time, and I want to get started on making games now.
- Current issues:
- Caniuse WebTransport
- Official demos on GitHub do not work on Firefox on Windows.
- GitHub Issue
- Firefox Bugzilla
- Potential: Will probably solve most problems once finished and would be the best choice for making a multiplayer game on the web.
Datachannels: A Hidden Gem of WebRTC
- Feature: Lets us send unreliable packets over the web using SCTP.
- Advantage: We don’t need WebTransport; we can use this today.
- They were created in part for exactly this use case
Benefits and Drawbacks of WebRTC
Benefits
- Host flexibility: Do not need to host servers - players can make their own.
- No more need for port forwarding or Hamachi!
- Minimal server requirements: Only need one server for signaling.
- Community-supported specification: There are many options for making your own WebRTC-based app.
Drawbacks
- Complex setup: Setting up WebRTC is challenging.
- Server dependence: You need to host or use two different servers (Signaling + STUN/TURN).
- Can use Google’s STUN, but combining signaling and STUN into one server would be nice.
WebRTC Implementations
- libwebrtc - (a fork of) the original WebRTC implementation.
- libdatachannel - C/C++.
- Pion WebRTC - Go.
- webrtc-rs - Rust (using Tokio Runtime).
- str0m - Rust (sans-io).
- sipsorcery - C#
- GameNetworkingSockets
- Uses ICE and STUN/TURN for Peer to Peer.
- Created by Valve and made for Steam, which means if you’ve ever played a game like Counter Strike or Deadlock, you’ve already seen this library in action!
Existing Game Networking Libraries Using WebRTC
- Geckos.io
- A client-server abstraction for WebRTC Datachannels written in Node.js.
- Past experience: Really nice but a bit inefficient. See GitHub Issue.
- Netlib - Peer-to-peer WebRTC datachannel library for TypeScript.
- Matchbox - WebRTC datachannel library for Rust, compiles to both native and WASM.
- PeerJS - Great for browser-only apps/games, not specifically for game networking.
- Netplayjs - Untested but seems to work well.
- Godot Engine’s WebRTC Native - Official Godot bindings to libdatachannel for Godot’s multiplayer API.
Real-World Uses
- WebXash3D: Reimplementation of Half-Life 1 + Counter-Strike 1.6 using WebRTC.
- Hypersomnia - Open source 2D shooter made with C++ and libdatachannel
- Has cross platform capabilities between both
- The native Steam port
- And in the browser (On CrazyGames and the official website)
- Github Link
- Has cross platform capabilities between both
Why Go for Development?
- Efficient: It just gets the job done.
- Pion: Has a pure-Go implementation of WebRTC.
- Minimal dependencies: No need for external dependencies like OpenSSL.
Why Not Rust?
- Preference: I like Rust, but Go has a more active scene/easier help for WebRTC.
- Speed of development: It’s faster to code in Go compared to Rust.
Why Ebitengine for Game Development?
- Website Link
- Versatile: 2D game engine that works across various platforms.
- The creator, Hajime Hoshi, has ported the engine (and the Go language!) to the Nintendo Switch and other game consoles
- Battle Tested: Has been used for actual games like
- From Madness with Love
- Coral & The Abyss
- Rakuen
- And more on the Ebitengine Showcase Page
- Potential Crossplay: You could make a cross platform multiplayer game in pure Go that works between the Nintendo Switch, PC, and the browser!
Official Pion Example
- We now have an official example using Ebitengine in the Pion example-webrtc-applications repository
- This includes an bundled in signaling server so you can host your own lobby, and connect with another player.
- Github Link to Game
- PR where it was merged in: Example WebRTC Applications
- Limitations
- Right now, this can only support two players on the same computer
- Could probably work between two different computers, but we would need to figure out how to setup CORS properly for the signaling server
- The machinery is there to support more than two players in a lobby, but as of writing this article it is currently hardcoded to just two
- Right now, this can only support two players on the same computer
Other Games That Use WebRTC
Possibilities with WebRTC
- Hosting a Minecraft-style game without dedicated servers or port forwarding.
- Players host everything themselves: no need for VPN/Hamachi.
Community Acknowledgements
- A big thanks to:
- And many more who made this journey possible. I stand on the shoulders of giants.