Overview
Minecraft Web Client supports peer-to-peer (P2P) multiplayer powered by PeerJS, allowing you to share your singleplayer world with friends over the internet without setting up a dedicated server. Open your world to WAN and send a join link to anyone!From the README: “Play with friends over internet! (P2P is powered by Peer.js discovery servers)“
How P2P Works
- Host opens their singleplayer world to WAN
- PeerJS discovery server coordinates the connection
- WebRTC establishes direct peer-to-peer connection
- Players communicate directly without a proxy
Opening Your World to WAN
Load a Singleplayer World
Start or load any singleplayer world. You must have an active local server running.
Share the Join Link
The join link is automatically copied to your clipboard. Share it with friends:Your friends can click this link to join your world directly!
Join Link Format
Fromsrc/localServerMultiplayer.ts:25-38:
connectPeer: Unique peer IDpeerVersion: Minecraft versionserver: PeerJS server (optional)
Connecting to a Friend’s World
Click the Link
Simply click the join link. The game will:
- Connect to the PeerJS server
- Establish WebRTC connection
- Join the world automatically
PeerJS Configuration
The client uses PeerJS with automatic fallback servers. Fromsrc/localServerMultiplayer.ts:59-64:
Custom PeerJS Server
You can specify a custom PeerJS server:Connection Lifecycle
Fromsrc/localServerMultiplayer.ts:66-97:
Closing WAN
To stop accepting connections:src/localServerMultiplayer.ts:171-176:
Troubleshooting
Connection Timeout
If connection times out (6 seconds), the client automatically tries the fallback server:Common Issues
Failed to open to WAN
Failed to open to WAN
Causes:
- PeerJS server is down
- Network firewall blocking WebRTC
- Browser doesn’t support WebRTC
- Wait for automatic fallback server (6 seconds)
- Check browser console for errors
- Try different browser (Chrome/Firefox recommended)
- Disable VPN or restrictive firewall
Connection drops immediately
Connection drops immediately
Causes:
- ICE connection failed
- NAT traversal issues
- Network instability
- Both players should have stable internet
- Try connecting again
- Check if router supports WebRTC
- Consider using a TURN server
Join link not copying
Join link not copying
Causes:
- Browser clipboard permissions denied
- Running in non-secure context (HTTP)
- Allow clipboard access in browser settings
- Use HTTPS version of the site
- Manually copy from prompt dialog
Version mismatch error
Version mismatch error
Cause: Host and joining player have different Minecraft versionsSolution: Both players must use the same version (specified in join link)
Advanced Features
State Tracking
Manual Connection
Connect to a peer directly:src/localServerMultiplayer.ts:182-229.
Custom Duplex Stream
P2P uses a custom duplex stream to bridge WebRTC and Minecraft protocol:- Outgoing: Minecraft packets →
writeAction→ WebRTC data channel - Incoming: WebRTC data channel →
push()→ Minecraft client
Performance Considerations
Latency
P2P connections are typically faster than proxy connections:- Direct peer-to-peer reduces hops
- No server-side packet processing
- WebRTC optimizes for real-time data
- Same region: 10-40ms
- Different regions: 100-200ms
- Intercontinental: 200-400ms
Bandwidth
The host’s upload bandwidth limits how many players can join:- 1 player: ~100 KB/s
- 2-3 players: ~300 KB/s
- 4+ players: 500+ KB/s
Security Notes
- Direct connection: Players connect directly to your browser, not your IP
- No port forwarding: WebRTC handles NAT traversal automatically
- Encrypted: WebRTC uses DTLS encryption
- Peer ID: Temporary and changes each session
Limitations
- Host must stay online: If the host closes the game, all players disconnect
- No persistence: World state is not synchronized; only host has the world
- Browser-based: Both host and players must use the web client
- NAT traversal: May not work on extremely restrictive networks
Query Parameters
Hosting
No special parameters needed - use/publish in-game.
Joining
?connectPeer=<peer-id>- Peer to connect to?peerVersion=<version>- Minecraft version?server=<server>- Custom PeerJS server
See Also
- Multiplayer - Connecting to regular servers
- Singleplayer - Creating local worlds
- Servers & Proxy - Setting up proxy servers
