Skip to content

nivekithan/fireside-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

50 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Fireside Events

A real-time video broadcasting application built with WebRTC, Cloudflare Workers, and XState state machines. Experience multi-participant video calls with seamless screen sharing capabilities.

🌐 Live Demo: https://calls.nivekithan.com/

πŸ“Š State Machine Visualization: View XState Machine

Features

  • Real-time Video Broadcasting: Share your webcam feed with multiple participants in real-time
  • Screen Sharing: Broadcast your screen to all participants with a single click
  • Adaptive Video States: Pause/resume video broadcasting with automatic peer notification
  • Room Synchronization: Automatic syncing of participants joining and leaving
  • Featured Stream View: Click any participant to view them in full-screen mode
  • Permission Management: Intelligent camera permission handling with user-friendly UI
  • State Machine Architecture: Complex state management powered by XState v5
  • Real-time Signaling: WebSocket-based signaling using Cloudflare Durable Objects

Architecture

Tech Stack

Frontend (web/)

  • React Router v7: Full-stack React framework with SSR
  • XState v5: Type-safe state machines for complex UI flows
  • WebRTC: Browser-native peer-to-peer video/audio streaming
  • Tailwind CSS + shadcn/ui: Modern UI components and styling
  • Neverthrow: Functional error handling
  • OpenTelemetry: Distributed tracing with Honeycomb integration

Backend (backend/)

  • Cloudflare Workers: Edge compute platform
  • Durable Objects: Stateful serverless coordination
  • Drizzle ORM: Type-safe SQL with SQLite
  • Hono: Lightweight web framework
  • PartyServer: WebSocket abstraction layer
  • Cloudflare Calls API: WebRTC infrastructure

Shared (packages/signaling-messages/)

  • Zod: Runtime type validation for WebSocket messages
  • Type-safe message schemas shared between client and server

Key Components

State Machine (web/app/lib/features/broadcast/state.ts)

The application uses a complex XState state machine to manage:

  • Permission states (granted, denied, pending)
  • Broadcasting states (camera, screen share, remote tracks)
  • Room synchronization with version-based conflict resolution
  • WebRTC connection lifecycle

Main states:

determiningPermission β†’ permissionGranted/Denied/Pending
  β†’ joiningRoom
  β†’ broadcasting (parallel states):
      - localTracks: broadcastVideo ⟷ pauseVideo
      - screenShareTracks: noScreenShare ⟷ screenShare
      - remoteTracks: syncWithRoom ⟷ roomInSync

Room Manager (backend/src/features/broadcast/roomManager/roomManager.ts)

Durable Object that manages:

  • Track registration (video/screen share)
  • Participant lifecycle
  • Room state versioning
  • Real-time signaling between peers

WebRTC Integration

Uses Cloudflare Calls API for:

  • Session management
  • SDP offer/answer negotiation
  • Track publishing and subscription
  • ICE candidate handling

Getting Started

Prerequisites

  • Node.js 20+
  • pnpm 9.1.1+
  • Cloudflare account (for deployment)

Installation

# Clone the repository
git clone <repository-url>
cd fireside-events

# Install dependencies
pnpm install

Development

# Start all services (recommended)
pnpm dev
# or with Turbo TUI
turbo dev --ui tui

# Start frontend only
cd web
pnpm dev

# Start backend only
cd backend
pnpm dev

Environment Variables

Backend (.env in backend/)

JWT_SECRET=<your-jwt-secret>
CALLS_APP_SECRET=<cloudflare-calls-app-secret>

Type Checking

cd web
pnpm typecheck

Testing

cd backend
pnpm test

# Run specific test
pnpm test -- -t "test name"

Project Structure

fireside-events/
β”œβ”€β”€ backend/                # Cloudflare Workers backend
β”‚   β”œβ”€β”€ migrations/         # Drizzle ORM migrations
β”‚   β”‚   └── roomManager/   # Room state migrations
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ features/
β”‚   β”‚   β”‚   └── broadcast/ # Broadcasting logic
β”‚   β”‚   β”‚       β”œβ”€β”€ roomManager/  # Durable Object for room state
β”‚   β”‚   β”‚       β”œβ”€β”€ callsProxy.ts # Cloudflare Calls API client
β”‚   β”‚   β”‚       └── signaling.ts  # WebSocket signaling (deprecated)
β”‚   β”‚   β”œβ”€β”€ index.ts       # Worker entry point
β”‚   β”‚   └── server.ts      # Hono HTTP routes
β”‚   └── wrangler.toml      # Cloudflare configuration
β”‚
β”œβ”€β”€ web/                   # React Router frontend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ components/ui/ # shadcn/ui components
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   └── features/
β”‚   β”‚   β”‚       └── broadcast/
β”‚   β”‚   β”‚           β”œβ”€β”€ state.ts      # XState machine
β”‚   β”‚   β”‚           β”œβ”€β”€ signaling.ts  # WebSocket client
β”‚   β”‚   β”‚           β”œβ”€β”€ calls.ts      # Calls API integration
β”‚   β”‚   β”‚           └── rtc.ts        # WebRTC utilities
β”‚   β”‚   └── routes/
β”‚   β”‚       └── home.tsx   # Main broadcasting UI
β”‚   └── wrangler.toml      # Frontend deployment config
β”‚
└── packages/
    └── signaling-messages/ # Shared WebSocket message types
        └── message.ts      # Zod schemas

Deployment

Backend

cd backend
pnpm deploy

Frontend

cd web
pnpm deploy

How It Works

1. Permission & Setup

  • User lands on the page
  • App checks camera permissions
  • If granted, requests media stream
  • If pending, shows permission prompt

2. Joining a Room

  • Creates a new Cloudflare Calls session
  • Establishes RTCPeerConnection
  • Publishes local video track via SDP negotiation
  • Connects to Room Manager Durable Object via WebSocket

3. Room Synchronization

  • Room Manager tracks all participants and their video/screen tracks
  • Each state change increments a version number
  • Clients poll for version changes
  • On version mismatch:
    • Fetches latest tracks from other peers
    • Negotiates new SDP offers/answers
    • Subscribes to new remote tracks

4. Broadcasting

  • Local video displayed in grid
  • Remote tracks appear as they're published
  • Click any stream for full-screen view
  • Toggle video on/off (sends pause/resume signals)
  • Start screen share (adds additional track)

5. Signaling

  • WebSocket messages notify peers of:
    • Video pause/resume states
    • Room version changes (poke)
    • New participants joining

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors