How kevinshen56714/skyoffice works
Project type and purpose
• SkyOffice is a full-stack, real-time virtual office application.
• Client side: browser game + React UI + Phaser3 + WebRTC for video/screen sharing.
• Server side: Node.js with Colyseus (WebSocket game‐room framework), maintaining in-memory room state.
• No traditional database; room state is managed by Colyseus schemas and commands.
File structure
• Top level:
• client/ → front-end code (Phaser scenes, React components, services, stores).
• server/ → back-end code (Colyseus rooms, state schema, update commands).
• types/ → shared TypeScript interfaces and enums.
• netlify.toml, Procfile → deployment configuration.
• client/src/services/Network.ts: WebSocket/Colyseus client.
• client/src/web/WebRTC.ts & ShareScreenManager.ts: PeerJS signaling and media streams.
• server/rooms/SkyOffice.ts: room logic, uses commands in server/rooms/commands/*.
• server/rooms/schema/OfficeState.ts: shared state model.
Extract architecture insights from README
• Reactive UI built with React/Redux.
• Phaser3 game engine for 2D map, character movement, proximity detection.
• Colyseus for real-time synchronization of map, chat bubbles, items, whiteboards.
• PeerJS for P2P video/screen streams (signaling via Colyseus).
• Whiteboard integration via an embedded iframe (WBO).
Main components
A. Front-End (Browser)
1. UI Layer (React/Redux)
• Components: ChatDialog, RoomSelectionDialog, CreateRoomForm, WhiteboardDialog, etc.
• Redux stores: ChatStore, RoomStore, UserStore, ComputerStore, WhiteboardStore.
2. Game Engine (Phaser3)
• Scenes: Bootstrap → Game → Background
• Characters & Items: MyPlayer, OtherPlayer, Chairs, Computers, VendingMachine, Whiteboard.
• Animations and assets loader.
3. Networking Layer
• Colyseus client connection (Network.ts)
• EventCenter.ts for dispatching received server messages
4. WebRTC Layer (PeerJS)
• PeerJS signaling through Colyseus channels
• Media management: ShareScreenManager, WebRTC.ts
B. Back-End (Node.js + Colyseus)
1. Colyseus Server
• Room handler: SkyOffice (creates/manages player sessions)
• Commands: ChatMessageUpdateCommand, PlayerUpdateCommand, WhiteboardUpdateArrayCommand, etc.
• Schema: OfficeState (users, positions, items, whiteboard data).
2. WebSocket Transport
• Colyseus networking over WS → handles join, leave, patch broadcasts
3. Signaling for WebRTC
• Uses the same Colyseus channel to exchange PeerJS offers/answers
C. External Services
• Whiteboard: iframe embedding WBO (Open-source whiteboard)
• PeerJS cloud or self-hosted signaling server (optional)
Relationships & data flows
• User input (keyboard/mouse) → Phaser3/React → triggers local state changes & updates Network.ts
• Network.ts → sends room commands (join, move, chat, whiteboard) via WebSocket to Colyseus
• Colyseus server receives commands → validates & applies to OfficeState → broadcasts patches to all clients
• Client EventCenter receives patches → updates Redux stores & Phaser scenes
• When two players are in proximity, client WebRTC layer negotiates P2P via PeerJS, using Colyseus for signaling
• WhiteboardDialog uses iframe → communicates with WBO REST/WS endpoints
Architectural patterns & principles
• Real-time event-driven architecture (commands & patches)
• Separation of concerns: UI vs. game engine vs. network vs. media layer
• Single‐page application with client‐side routing (React)
• Command pattern on server side for state mutations
• Shared TypeScript interfaces (in types/) for end-to-end type safety