---
issue: 166
title: Implement LiveKit Video Streaming for Screenshare Bot
analyzed: 2025-10-21T14:30:00Z
estimated_hours: 8-12
parallelization_factor: 1.5
---

# Parallel Work Analysis: Issue #166

## Overview

Implement video streaming for the Node.js screenshare bot by adding the missing video encoding pipeline. The bot currently captures screenshots at 30fps but doesn't encode/publish them to LiveKit. This task requires research, implementation of video encoding, and testing.

## Parallel Streams

### Stream A: Research & Spike (LiveKit SDK Investigation)
**Scope**: Investigate LiveKit Node SDK capabilities for custom video tracks
**Tasks**:
- Research LiveKit `@livekit/rtc-node` video track API
- Test creating custom video source from image buffers
- Document findings and recommend approach (SDK native vs FFmpeg vs Canvas)
- Create proof-of-concept with single frame publishing
**Files**:
- Research documentation (can be in comments or separate doc)
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` (spike code)
**Agent Type**: backend-specialist (Node.js + video streaming)
**Can Start**: immediately
**Estimated Hours**: 2-3
**Dependencies**: none

### Stream B: Dependency Setup & Infrastructure
**Scope**: Prepare project dependencies and helper utilities
**Tasks**:
- Add required npm packages (sharp for image processing, ffmpeg if needed)
- Create video encoding utility module if needed
- Set up TypeScript types for video frames/encoding
- Update package.json and ensure Railway compatibility
**Files**:
- `apps/bot-spawner/package.json`
- `apps/bot-spawner/src/utils/video-encoder.ts` (if needed)
- `apps/bot-spawner/src/bots/types.ts` (video-related types)
**Agent Type**: backend-specialist
**Can Start**: immediately (parallel with Stream A)
**Estimated Hours**: 1-2
**Dependencies**: none

### Stream C: Core Implementation
**Scope**: Implement video streaming in ScreenshareBot based on research findings
**Tasks**:
- Modify `startCapture()` to publish frames to LiveKit
- Create video track with screenshare source type
- Implement frame encoding pipeline (PNG → video frame)
- Add error handling for encoding failures
- Ensure proper cleanup on shutdown
**Files**:
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` (lines 132-174)
**Agent Type**: backend-specialist
**Can Start**: after Stream A completes (need to know which approach to use)
**Estimated Hours**: 3-5
**Dependencies**: Stream A (research findings)

### Stream D: Testing & Validation
**Scope**: Test video streaming locally and on Railway
**Tasks**:
- Local testing: verify video appears in LiveKit room
- Test slide readability in voice-demo-ui
- Monitor memory usage over 30+ minute sessions
- Test multiple bots simultaneously
- Railway deployment validation
**Files**:
- Test scripts or manual testing procedures
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` (any bug fixes)
**Agent Type**: fullstack (needs to test UI + backend)
**Can Start**: after Stream C completes
**Estimated Hours**: 2-3
**Dependencies**: Stream C (implementation must be complete)

## Coordination Points

### Shared Files
- `apps/bot-spawner/src/bots/ScreenshareBot.ts` - Streams A (spike), C (implementation), D (fixes)
  - **Coordination**: Stream A uses spike/experimental code that will be replaced by Stream C
  - **Risk**: Low - Stream A is just research, code will be rewritten in C

### Sequential Requirements
1. **Stream A must complete first**: Need to know which approach (LiveKit SDK native, FFmpeg, or Canvas) before implementing
2. **Stream B can run parallel with A**: Dependencies can be added based on likely approach
3. **Stream C depends on A**: Implementation approach depends on research findings
4. **Stream D depends on C**: Can't test until implementation is complete

## Conflict Risk Assessment

**Low Risk Overall**:
- Only one main file being modified (`ScreenshareBot.ts`)
- Clear sequential dependencies prevent conflicts
- Stream B works on different files (package.json, utils)
- Research phase (A) is exploratory and won't conflict with implementation (C)

## Parallelization Strategy

**Recommended Approach**: Hybrid (partial parallelization)

**Phase 1 (Parallel)**: Launch Streams A & B simultaneously
- Stream A: Research LiveKit SDK (2-3 hours)
- Stream B: Set up dependencies (1-2 hours)
- **Wall time**: 2-3 hours (max of the two)

**Phase 2 (Sequential)**: Stream C after A completes
- Wait for Stream A findings
- Implement based on research (3-5 hours)
- **Wall time**: 3-5 hours

**Phase 3 (Sequential)**: Stream D after C completes
- Test and validate (2-3 hours)
- **Wall time**: 2-3 hours

## Expected Timeline

**With hybrid execution**:
- **Phase 1**: 2-3 hours (A & B parallel)
- **Phase 2**: 3-5 hours (C sequential)
- **Phase 3**: 2-3 hours (D sequential)
- **Total wall time**: 7-11 hours
- **Total work**: 8-13 hours
- **Efficiency gain**: ~15% (limited parallelization due to dependencies)

**Without parallel execution** (pure sequential):
- **Total wall time**: 8-13 hours (same as total work)

## Notes

### Why Limited Parallelization?

This task has a strong research → implement → test dependency chain. The key bottleneck is **Stream A (research)** - we need to understand the LiveKit SDK capabilities before implementing. This creates a natural sequential flow.

The main benefit of parallelization here is:
1. **Stream B runs during research**: We can set up dependencies while researching, saving 1-2 hours
2. **Reduced cognitive switching**: One person can focus on research while another preps infrastructure

### Key Technical Decisions (Stream A)

Stream A needs to answer:
1. Does `@livekit/rtc-node` support custom video tracks from buffers?
2. If yes, what format does it expect? (RGB, YUV, etc.)
3. If no, do we need FFmpeg or Canvas API?
4. What's the performance impact of each approach?

### Alternative: Single-Stream Sequential

If team size is limited (1 person), just run sequentially:
1. Research (2-3h)
2. Set up dependencies (1-2h)
3. Implement (3-5h)
4. Test (2-3h)

This is actually more efficient for a solo developer due to zero coordination overhead.

### Railway Deployment Considerations

- If using FFmpeg: Need to ensure it's available on Railway (might need custom buildpack)
- If using Canvas: Need node-canvas native dependencies
- LiveKit SDK native approach is cleanest for Railway deployment
