This implementation provides browser-compatible mock clients and servers for testing the P2P networking and token management framework.
The browser implementation consists of:
- UniQuakeTokenService - Browser-compatible token management service
- BrowserMockClient - Client implementation for browser environment
- BrowserMockServer - Server implementation for browser environment
- BrowserMockGame - Mock game implementation for testing
- GameIntegration - Connects the game with the token service and networking
- P2PConnection - WebRTC/WebSocket connection wrapper
The easiest way to run the browser mock implementation is using the provided npm scripts:
- Install dependencies if you haven't already:
npm install
- Start both the master server and web server in one command:
npm run start-browser-mocks
- Open the client in your browser:
http://localhost:8080/client
- Open the server in your browser (in a different window or tab):
http://localhost:8080/server
If you prefer to run the servers separately:
- Start the master server:
npm run master
or
node bin/webrtc-master.js
- Start the web server:
npm run browser-mock
or
node bin/web.js --config ./bin/web.json
- Open the client and server in your browser as described above.
The mock client provides:
- Server list retrieval and connection
- Chat messaging
- Game state visualization
- Token management (minting, sending, verifying)
- WebRTC P2P connections with WebSocket fallback
The mock server provides:
- Registration with master server
- Client connection management
- Game state broadcasting
- Token collection and distribution
- Game state token verification
The implementation includes two transport adapters:
- WebRTC Adapter - Uses WebRTC data channels for P2P connections
- WebSocket Fallback - Uses WebSocket proxy via master server for browsers without WebRTC support
The system automatically detects WebRTC support and chooses the appropriate transport.
The same components can be used to integrate with the actual Quake game in the browser by:
- Connecting the token service to the game's state management
- Using the P2P connection for game data transport
- Implementing the necessary hooks in the game code to support token functionality
The mock implementation provides a complete testing environment for the P2P networking and token management framework without requiring the full Quake game.
The system follows a modular architecture:
+--------------------+ +------------------+ +----------------+
| BrowserMockClient |<-->| P2P Connection |<-->| Master Server |
+--------------------+ +------------------+ +----------------+
^ ^
| |
v v
+--------------------+ +------------------+ +----------------+
| Token Service |<-->| Game Integration |<-->| BrowserMockServer |
+--------------------+ +------------------+ +----------------+
^ ^
| |
v v
+--------------------+ +------------------+
| Token Management |<-->| BrowserMockGame |
+--------------------+ +------------------+
This architecture allows for flexible transport options and clean separation of concerns between networking, token management, and game logic.