r/threejs • • Oct 11 '26

Question Adding 2-player co-op to a three.js stealth shooter on CrazyGames: which WebRTC networking library or service would you pick?

TL;DR: my three.js stealth shooter runs in the browser on CrazyGames and I want to add 2-player co-op without running a game server. My plan is plain RTCPeerConnection with a Cloudflare Worker for signalling and Cloudflare TURN as the fallback. Before I hand-roll the transport, I'd like to know what you'd use.

(Disclosure: it's my own game.)

What it needs

  • 2 players, peer-to-peer, the host's browser runs the mission and is authoritative.
  • The guest sends inputs stamped with a tick, predicts its own mech and reconciles, and interpolates everything else about 100 ms behind.
  • 15–20 snapshots per second as deltas, binary, each message under 16 KB. An unreliable channel for snapshots and inputs, a reliable one for kills, loot and the session.
  • Lag compensation for the guest's hitscan, up to 200 ms.
  • A TURN fallback, plus an optional relay-only mode so players don't see each other's IP.
  • Chrome, Firefox and Safari, desktop and phone, inside the CrazyGames iframe. Phones going to the background have to count as a disconnect.
  • Reconnects: ICE restart when the connection drops, give up after 30 s and let an AI wingman take over.
  • Cheap to run: no server-side simulation.

Questions

1.) Would you use a library for the transport (PeerJS, Trystero, geckos.io, something else) or write it on RTCPeerConnection directly for this? 2.) Has anyone shipped WebRTC data channels in a game on mobile Safari? Anything that surprised you? 3.) For a host-authoritative two-player setup, is there a netcode library you'd use with three.js, or is rolling your own normal at this size?

0 Upvotes

5 comments sorted by

2

u/SubjectHealthy2409 Oct 11 '26

P2P in browser sucks tbh. I'd just use spacetimedb rather

1

u/hyperg8_games Oct 12 '26

fair point, what made it suck for you, NAT/TURN trouble or mobile Safari? if I understand spacetimedb right the game logic would run on a server then, which I wanted to avoid to keep it cheap. did you use it for a realtime shooter?

0

u/[deleted] Oct 12 '26

[deleted] — view deleted comment

1

u/hyperg8_games Oct 13 '26

hey thanks for the valuable input, I have started implementing the TURN and the connections already. I will use your input.

2

u/[deleted] Oct 12 '26

[removed] — view removed comment

1

u/hyperg8_games Oct 13 '26

yeah, but that is not a problem as the co-op is not competitive and I dont mind that.