The persistent backend for SyncStream, powered by Hapi.js and WebSockets. It handles real-time state synchronization, user session management, and proxying for video streams.
- WebSocket Hub: Manages all client connections for real-time chat, video state (time/pause), and control commands.
- State Arbitration: Maintains the "source of truth" for video playback to ensure late-joiners sync instantly.
- Stream Proxy: Built-in proxy service to bypass CORS restrictions for video URLs.
- Admin Authentication: Secure handling of admin login and privileged command broadcasting.
- Runtime: Node.js
- Framework: Hapi.js
- WebSocket:
wslibrary - Language: TypeScript
-
Install Dependencies
npm install
-
Environment Configuration Copy the sample env file:
cp .env.sample .env
-
Google API Setup
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to APIs & Services > Credentials.
- Create OAuth 2.0 Client ID credentials.
- Add your authorized origins (e.g.,
http://localhost:5173,https://your-domain.com). - Copy the Client ID.
- You will need to add this Client ID to your UI environment (
VITE_GOOGLE_CLIENT_ID).
-
Cloudflare Tunnel Setup To expose your local server to the internet securely:
- Install
cloudflared. - Authenticate:
cloudflared tunnel login. - Create a tunnel:
cloudflared tunnel create syncplayer. - Configure the tunnel to point to your local server port (default 8000):
# config.yml tunnel: <Tunnel-UUID> credentials-file: /path/to/creds.json ingress: - hostname: your-domain.com service: http://localhost:8000 - service: http_status:404
- Run the tunnel:
cloudflared tunnel run syncplayer
- Install
-
Start Development Server
npm run dev
Runs on
http://localhost:8000(default) with hot-reload vianodemon. -
Production Build
npm run build npm start
server.ts: Entry point setting up Hapi and WebSocket servers.state.service.ts: Manages the global application state (current video, paused status, active users).websocket.service.ts: Handles incoming socket messages and broadcasts updates.