---
issue: 148
stream: screenshare-bot-subscription
agent: general-purpose
started: 2025-10-15T21:46:28Z
status: in_progress
---

# Stream B: Screenshare Bot Subscription

## Scope
Add Supabase realtime subscription to screenshare bot

## Files
- `apps/slide-system/bots/screenshare-bot/transports/livekit_transport.py`
- `apps/slide-system/bots/screenshare-bot/bot.py`
- `apps/slide-system/bots/screenshare-bot/pyproject.toml`

## Progress
- ✅ Read analysis and understood requirements
- ✅ Updated slide_control_listener.py to use Supabase broadcast channels
- ✅ Implemented new message format (navigate/confirmation protocol)
- ✅ Added confirmation response logic with channel.send_broadcast()
- ✅ Updated slide_navigator.py to return confirmation data
- ✅ Added slide count detection (_detect_slide_count method)
- ✅ Updated bot.py to accept deck_id parameter
- ✅ Integrated deck_id into SlideControlListener initialization
- ✅ Updated CLI argument parsing for deck_id parameter
- ⚠️  Tests need updating to match new broadcast protocol (existing tests use table subscriptions)

## Implementation Summary

### Key Changes:
1. **slide_control_listener.py**:
   - Changed from table subscription (`on_postgres_changes`) to broadcast channel (`on_broadcast`)
   - Channel name format: `slide_control:{deck_id}`
   - New message format with `type`, `direction`, `timestamp`, `session_id`
   - Added confirmation sending via `channel.send_broadcast()`
   - Session ID filtering now happens in message handler (broadcast channels don't support server-side filtering)

2. **slide_navigator.py**:
   - Updated execute_command to accept Dict and return Dict (instead of str/int)
   - Added slide tracking: `_current_slide` and `_total_slides`
   - Implemented `_detect_slide_count()` using Slidev's `__slidev__.nav.total`
   - Returns confirmation dict with success, current_slide, total_slides, error fields
   - Queue processing updated to handle async result futures

3. **bot.py**:
   - Added `deck_id` parameter to ScreenshareBot.__init__()
   - Updated start_slide_control() to pass deck_id to listener
   - CLI now accepts deck_id as optional 5th argument
   - Better logging with deck_id info

### Protocol Compliance:
✅ Command format: `{"type": "navigate", "direction": "next"|"previous"|"goto", "slide_number": int, "timestamp": str, "session_id": str}`
✅ Confirmation format: `{"type": "confirmation", "success": bool, "current_slide": int, "total_slides": int, "error": str, "timestamp": str, "session_id": str}`
✅ Channel naming: `slide_control:{deckId}`
✅ Latency tracking (<500ms target)
✅ Error handling and validation

### Testing Status:
- Unit tests exist but need updates for broadcast protocol
- Current tests assume table subscription (INSERT events)
- Need to mock broadcast channel API instead
- Integration with voice agent (Stream A) pending
