r/javascript • u/woqr • 27d ago
Serverless multiplayer via webrtc/camera/barcode (no signal/stun/turn servers)
https://github.com/bacionejs/multiplayerThis project is mainly about the serverless technique used and the simple game merely provides an end-to-end explanation.
2
u/JcerParreno21 24d ago
clever approach for offline-first local multiplayer tbh. how finicky is the camera handshake under bad lighting or screen glare?
1
u/woqr 23d ago edited 23d ago
The optical handshake barcode scan can be finicky with very low-cost cameras, but smartphones above $100 typically feature PDAF or autofocusing optics, making the scanning process fast and reliable. While lighting/glare can occasionally cause issues, tests using a native barcode scanner on printed paper confirm that the core limitation on budget devices is contrast autofocus hunting.
1
u/woqr 18d ago
I made a change by adding a textarea so people can paste in their own game so that they don't have to host it.
1
u/gianluca_caruso-6 15d ago
Does the textarea sandbox pasted games? The no-hosting flow is handy, but trust boundaries matter if pasted code runs.
1
u/p-reyes-6823 11d ago
If pasted JS executes, a textarea only collects input; a sandboxed iframe with allow-scripts but no allow-same-origin adds origin isolation.
1
u/jjohnson-13233 1d ago
If the game needs a parent bridge, keep it narrow: treat every message from pasted code as untrusted and expose only the actions gameplay needs.
2
u/Dry_Recognition_3070 25d ago
Nice approach for the offer/answer exchange. One practical limit with QR/barcode signaling is payload size: a raw SDP with a handful of ICE candidates easily runs past a thousand characters, so it helps to wait for ICE gathering to complete, strip unneeded lines and compress before encoding, or split it across multiple frames. Also keep in mind that with no STUN, you only get host candidates, so it works on the same LAN but typically not across different NATs. And since browsers now hide local IPs behind mDNS .local names, some networks that block multicast DNS will fail to connect even on the same Wi-Fi, which is worth documenting for anyone trying it.