Skip to main content

Signaling Server

The CloudGaming signaling server is a Node.js application that facilitates WebRTC peer connection establishment between hosts and clients.

Architecture Overview

The signaling server provides:
  • WebSocket Signaling: SDP offer/answer exchange and ICE candidate relay
  • Redis Pub/Sub: Multi-node horizontal scaling
  • Room Management: Isolated signaling channels per game session
  • Health Checks: Railway-compatible health/readiness endpoints
  • Rate Limiting: Redis-backed rate limiting for abuse prevention

Implementation

Server Initialization

WebSocket Signaling Protocol

Connection Flow

  1. Client connects with room ID:
  2. Server validates and joins room:
  3. Exchange signaling messages:

Message Types

Offer: Initial connection proposal from client
Answer: Host response to client offer
Candidate: Network connectivity information
Peer Disconnected: Notification when peer leaves
Schema Error: Validation failure notification

Schema Validation

Ensures all messages conform to expected structure before forwarding.

Configuration

Environment Variables

Authentication (Optional)

Key Source Files

ScalableSignalingServer.js

Main signaling server implementation with WebSocket and Redis integration.

config.js

Configuration loader with environment variable parsing and defaults.

validation.js

Message schema validation using Zod for type safety.

rateLimiter.js

Redis-backed token bucket rate limiter implementation.
Deployment Tips:
  • Use Redis Cluster for high availability
  • Deploy multiple server instances behind a load balancer
  • Monitor /metrics endpoint with Prometheus
  • Set REQUIRE_WSS=true in production