multiplayer-websocket
Manages WebSocket-based real-time multiplayer in Tokyo Sounds. Use when modifying multiplayer sync, useMultiplayer hook, multiplayer-server, message protocol, or adding features that broadcast or receive player state over WebSocket.
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- multiplayer-websocket
- source
- https://github.com/liuchiawei/agent-skills
- license
- MIT
- category
- development
- description
- Manages WebSocket-based real-time multiplayer in Tokyo Sounds. Use when modifying multiplayer sync, useMultiplayer hook, multiplayer-server, message protocol, or adding features that broadcast or receive player state over WebSocket.
- imported_at
- 2026-09-20
- source_path
- skills/3d/multiplayer-websocket/SKILL.md
- source_repository
- liuchiawei/agent-skills
02 资源文件 1
- 参考文档reference.md5.9 KB
03 SKILL.md 正文
Multiplayer WebSocket (Tokyo Sounds)
This project uses a standalone WebSocket server plus a React hook for real-time multiplayer. The server runs separately (e.g. npx tsx multiplayer-server.ts on port 3001). The client connects via useMultiplayer, sends position/rotation updates (throttled), and receives a list of nearby players to render.
Architecture at a Glance
| Layer | Role |
|---|---|
| multiplayer-server.ts | Node.js ws server: join/update/leave, 500m visibility, 50ms broadcast, 10s stale cleanup |
| src/types/multiplayer.ts | Shared ClientMessage / ServerMessage and PlayerState types |
| src/hooks/useMultiplayer.ts | Connect on mount, send join/update/leave, handle welcome/players/playerLeft, throttle updates (50ms), silent reconnect every 5s |
| Pages / MultiplayerManager | Call useMultiplayer, pass nearbyPlayers to OtherPlayers, call sendUpdate from position/rotation callbacks or useFrame |
When to Use This Skill
- Changing WebSocket URL (e.g. env
NEXT_PUBLIC_MULTIPLAYER_URL), port, or ws/wss. - Adding or changing message types (extend
ClientMessage/ServerMessageinsrc/types/multiplayer.tsand both server and hook). - Adjusting throttle/broadcast intervals (
CLIENT_UPDATE_INTERVAL_MS,BROADCAST_INTERVAL_MS,RECONNECT_INTERVAL_MS,STALE_PLAYER_TIMEOUT_MS). - Fixing connection lifecycle, reconnection, or cleanup in
useMultiplayer. - Adding server-side logic (visibility radius, auth, rooms) in
multiplayer-server.ts.
Conventions
- Refs for socket and timers: Hook keeps
WebSocketin a ref; cleanup on unmount clears reconnect timeout and closes socket. - Mounted guard: Use
mountedRef.currentbeforesetStateafter async (onopen/onclose) to avoid updates after unmount. - Throttle on client:
sendUpdateonly sends whenDate.now() - lastUpdateTimeRef >= CLIENT_UPDATE_INTERVAL_MS(50ms). - URL: In browser, use
ws://orwss://to match page protocol; from HTTPS usewss://(mixed content otherwise).
Quick Reference
- Message protocol and example code: see reference.md.
- Server entry:
multiplayer-server.ts; client entry:src/hooks/useMultiplayer.tsandsrc/types/multiplayer.ts.
04 同仓库更多 Skills
dei-assessment
Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.
dei-action-plan
Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.
culture-fit-assessment
Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.
cowork-to-code-bridge
Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.
counter-offer-response
Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.
continuous-feedback-system
Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.