This is the easiest way to test the P2P connection flow:
-
Start the dev server:
npm run dev
-
Open two browser tabs:
- Tab 1 (Host): Navigate to
http://localhost:5173 - Tab 2 (Guest): Navigate to
http://localhost:5173
- Tab 1 (Host): Navigate to
-
Set up the connection:
- In Tab 1 (Host):
- Click "Host Game"
- Note the peer ID displayed (e.g.,
royal-a1b2) - Keep this tab open
- In Tab 2 (Guest):
- Click "Join Game"
- Since camera won't work in browser, click "Enter code manually"
- Type the peer ID from Tab 1
- Click "Connect"
- In Tab 1 (Host):
-
Verify connection:
- Tab 1 should show "Guest Player" in the players list
- Tab 2 should show "Connected successfully!"
- Both tabs should show green connection indicator in top-right
For testing with QR code scanning:
-
Start dev server with network access:
npm run dev -- --host
Note the Network URL (e.g.,
http://192.168.1.100:5173) -
On Host Device (e.g., laptop):
- Navigate to the Network URL
- Click "Host Game"
- QR code will be displayed
-
On Guest Device (e.g., phone):
- Navigate to the same Network URL
- Click "Join Game"
- Grant camera permission
- Scan the QR code from host device
- Connection should establish automatically
-
Build the project:
npm run build
-
Preview the production build:
npm run preview -- --host
-
Follow the same steps as Option 1 or 2
- Host creates game with unique peer ID
- Guest can scan QR code (on mobile)
- Guest can manually enter peer ID
- Connection status indicator updates correctly
- "Back" buttons properly disconnect and return to lobby
- Invalid peer ID shows appropriate error
- Camera permission denied shows manual input
- Connection timeout handled gracefully
- Disconnection shows reconnection UI
- QR code displays clearly
- Peer ID is readable and copyable
- Connection status indicator shows correct state
- "Start Game" button enables when guest joins
If you see a blank screen when navigating to http://localhost:5173:
-
Clear browser cache and hard reload:
- Chrome/Edge:
Ctrl+Shift+R(Windows/Linux) orCmd+Shift+R(Mac) - Firefox:
Ctrl+F5(Windows/Linux) orCmd+Shift+R(Mac)
- Chrome/Edge:
-
Ensure dependencies are installed:
rm -rf node_modules package-lock.json npm install npm run dev
-
Check browser console for errors:
- Open DevTools (F12)
- Look for red errors in Console tab
- Common issues: module import errors, missing dependencies
-
Try a different browser:
- Requires modern browser with WebRTC support
- Recommended: Chrome, Firefox, Edge (latest versions)
- Ensure both devices are on the same network
- Check firewall isn't blocking WebRTC connections
- Try using the manual peer ID input instead of QR
- Ensure HTTPS or localhost (required for camera access)
- Grant camera permissions when prompted
- Use manual peer ID input as fallback
- The free PeerJS cloud server may have rate limits
- Consider setting up your own PeerJS server for production use
- Camera access: Only works over HTTPS or localhost
- NAT traversal: Some network configurations may prevent direct P2P connections
- Browser compatibility: Requires modern browser with WebRTC support