BXR is a real-time multiplayer 3D application with WebXR (Augmented Reality) support. It combines BabylonJS for 3D rendering, Colyseus for multiplayer state management, and WebRTC for peer-to-peer video/audio communication.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client (Browser) β
β ββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββββ
β β BabylonJS β β Colyseus β β WebRTC Peers ββ
β β 3D Engine β β Client β β (Video/Audio) ββ
β β + WebXR β β β β ββ
β ββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββββ
β β β β β
βββββββββββΌββββββββββββββββΌβββββββββββββββββββββββΌββββββββββββββ
β β β
β WebSocket (State) β
β β P2P Connection
β β β
βββββββββββ΄ββββββββββββββββ΄βββββββββββββββββββββββ΄ββββββββββββββ
β Server (Node.js) β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Colyseus Game Server β β
β β β’ Player State Management β β
β β β’ Position Synchronization β β
β β β’ WebRTC Signaling Relay β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Technology: TypeScript, Colyseus Arena
- Location:
/serverdirectory - Key Components:
MyRoom: Game room managing up to 10 concurrent playersMyRoomState: Synchronized state containing player positions (x, y, z)- WebRTC signaling: Relays offer/answer/ICE candidates between peers
- Technology: TypeScript, BabylonJS, Webpack
- Location:
/clientdirectory - Key Components:
Menu: Room creation/joining interfaceGame: Main game loop and multiplayer logic- 3D Rendering: BabylonJS scene with player spheres
- WebXR Support: Optional AR mode with desktop fallback
- WebRTC: Peer-to-peer video/audio streams displayed above players
- Player Spawning: Random position within 500x500 game area
- Position Updates: Click-to-move system sends coordinates to server
- State Broadcasting: Server broadcasts all player positions to all clients
- Client Interpolation: Smooth movement via
Vector3.Lerp
Client A clicks ground β Send "updatePosition" to server
β
Server updates state
β
State broadcast to all clients
β
All clients interpolate to new positions
- Mesh Topology: Each client connects directly to every other client
- Maximum Peers: 10 clients = 45 peer connections (n*(n-1)/2)
- Signaling: Coordinated via Colyseus server messages
1. Client joins room β Get local media (video/audio)
2. For each remote player:
a. Create RTCPeerConnection
b. Add local media tracks
c. If higher sessionId β Send offer
d. Exchange ICE candidates via server
3. On remote track received β Create video texture above player
- 3D plane mesh with VideoTexture material
- Billboard mode (always faces camera)
- Positioned 50 units above player sphere
- Audio enabled for voice chat
- Check if
immersive-arWebXR session is supported - If supported β Initialize WebXR with BabylonJS
- If not supported β Fallback to ArcRotateCamera (desktop mode)
- AR Mode: No skybox, semi-transparent ground for real-world overlay
- Desktop Mode: Full skybox, standard 3D scene with camera controls
- Node.js LTS (v16+ recommended)
- npm (comes with Node.js)
# Clone the repository
git clone https://github.com/EnchantmentEngine/EE2.git
cd EE2
# Install server dependencies
cd server
npm install
# Install client dependencies
cd ../client
npm installTerminal 1 - Start the Server:
cd server
npm startServer will start on ws://localhost:2567
Monitor interface available at http://localhost:2567/colyseus
Terminal 2 - Start the Client:
cd client
npm startClient will be accessible at http://localhost:8080
Build the Client:
cd client
npm run buildThis creates optimized production files in the dist/ directory.
Run Server Tests:
cd server
npm testTests include:
- β Multiplayer room lifecycle
- β Player state management
- β WebRTC signaling support
- β Message handler validation
- Open
http://localhost:8080in your browser - Choose an option:
- CREATE GAME: Create a new room
- JOIN GAME: Join an existing room
- CREATE OR JOIN: Automatically join or create
- Once in game:
- Click anywhere on the ground to move your player
- See other players as gray spheres (you're orange)
- Video/audio streams appear above players (if media permitted)
- For AR Mode (mobile devices with AR support):
- Grant camera permissions
- Tap the AR button when prompted
- See players overlaid in your real environment
EE2/
βββ client/ # Frontend application
β βββ src/
β β βββ app.ts # Application entry point
β β βββ menu.ts # Room selection UI
β β βββ game.ts # Main game logic, multiplayer, WebRTC
β β βββ utils.ts # Helper functions (skybox)
β βββ public/ # Static assets (images, textures)
β βββ index.html # HTML entry point
β βββ package.json
β βββ webpack.config.js # Build configuration
β
βββ server/ # Backend application
β βββ src/
β β βββ index.ts # Server entry point
β β βββ arena.config.ts # Colyseus configuration
β β βββ rooms/
β β βββ MyRoom.ts # Game room logic
β β βββ schema/
β β βββ MyRoomState.ts # State schema
β βββ test/ # Server tests
β β βββ MyRoom_test.ts
β β βββ WebRTC_signaling_test.ts
β βββ package.json
β βββ tsconfig.json
β
βββ README.md # This file
| Component | Technology | Purpose |
|---|---|---|
| 3D Engine | BabylonJS | Scene rendering, physics, WebXR |
| State Sync | Colyseus | Multiplayer state management |
| P2P Communication | WebRTC | Video/audio streaming |
| Server | Node.js + Express | WebSocket server, signaling |
| Language | TypeScript | Type-safe development |
| Build | Webpack | Client bundling |
| Testing | Mocha + Chai | Server-side testing |
- Port: 2567 (configurable via
PORTenvironment variable) - Max Clients per Room: 10
- Environment Files:
development.env,arena.env
- Server Endpoint:
ws://localhost:2567(seeclient/src/menu.ts) - WebRTC: Uses Google STUN server for NAT traversal
- Ground Size: 500x500 units
- Player Spawn: Random within Β±250 units from center
- WebRTC Signaling Validation: Server validates all signal messages
- Input Sanitization: Position updates clamped to game boundaries
- Session Management: Colyseus handles secure session IDs
Video/Audio Not Working:
- Grant camera/microphone permissions when prompted
- Check browser console for WebRTC errors
- Ensure HTTPS for production (HTTP works for localhost)
AR Mode Not Available:
- AR requires WebXR-compatible device (recent Android/iOS)
- Desktop browsers will automatically use fallback camera
Connection Issues:
- Verify server is running on port 2567
- Check firewall settings
- Ensure client endpoint matches server address
MIT
Based on the BabylonJS + Colyseus tutorial. Enhanced with WebXR support and WebRTC integration.