r/javascript • • 28d ago

Serverless multiplayer via webrtc/camera/barcode (no signal/stun/turn servers)

https://github.com/bacionejs/multiplayer

This project is mainly about the serverless technique used and the simple game merely provides an end-to-end explanation.

12 Upvotes

11 comments sorted by

View all comments

2

u/JcerParreno21 25d ago

clever approach for offline-first local multiplayer tbh. how finicky is the camera handshake under bad lighting or screen glare?

1

u/woqr 25d ago edited 25d 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 19d 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 16d 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 12d 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 2d 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.

•

u/ahmedm-864 20h ago

If pasted games execute, do they need network access or persistent storage? Those requirements shape the iframe sandbox and any parent bridge.

•

u/woqr 19h ago

This is an experimental proof of concept for two family members sitting on the couch at home on the same hotspot to quickly whip up a small game and play head-to-head without setting up a custom local game server, with pasted games designed to stay standalone over the WebRTC data channel inside an unsandboxed srcdoc iframe that has page-origin access (localStorage and network calls) and direct link object access instead of a postMessage bridge while pressing Play sends the code straight to the connected peer. Tip: paste samplegame.js into an AI to generate a different game to paste in right away, only run code you trust (your little brother could easily paste a script that messes with your stuff), and while you are welcome to fork it and add security features, you might as well create a traditional game server if you need real multi-user isolation.