Skip to content

Fix WebSocket keepalive, modernize Riverpod, add connection monitoring UI#157

Draft
Copilot wants to merge 13 commits into
devfrom
copilot/add-voice-channel-features
Draft

Fix WebSocket keepalive, modernize Riverpod, add connection monitoring UI#157
Copilot wants to merge 13 commits into
devfrom
copilot/add-voice-channel-features

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 13, 2026

WebSocket connections were timing out due to missing upgrade headers and lack of keepalive. UI had no visibility into connection state. Server code was a 464-line monolith. Using legacy Riverpod StateNotifier pattern.

Client Changes

Riverpod 3.x Migration

  • StateNotifierNotifier with build() initialization
  • ref.onDispose() for cleanup
  • NotifierProvider throughout

Connection Lifecycle

enum ConnectionStatus { disconnected, connecting, connected, error }

// Ping/pong with latency tracking
void _startPingTimer() {
  _pingTimer = Timer.periodic(const Duration(seconds: 30), (_) {
    final timestamp = DateTime.now().millisecondsSinceEpoch;
    _sendMessage({'type': 'ping', 'timestamp': timestamp});
  });
}

Connection State UI

  • App bar status indicator: 🟢 Connected (42ms) | 🟠 Connecting | 🔴 Error
  • Expandable debug panel: ping latency, reconnect attempts, error details
  • Auto-reconnect with exponential backoff (max 5 attempts)

Server Restructure

pkg/
├── models/types.go      # Config, User, Channel, Message
├── websocket/ping.go    # Keepalive handlers (54s interval)
└── server/
    ├── server.go        # WebSocket upgrade & connection management
    ├── handlers.go      # Message routing
    ├── broadcast.go     # State synchronization
    └── webrtc.go        # SFU implementation

WebSocket Fixes

  • Proper upgrade headers with CORS
  • Ping/pong handlers: 54s server-side (WebSocket), 30s client-side (application)
  • Connection timeouts: 60s read, 10s write
  • Compression enabled

Before/After

  • main.go: 464 lines → 55 lines
  • Clear separation: transport, business logic, media handling

Protocol Additions

// Client → Server
{"type": "ping", "timestamp": 1707826806000}

// Server → Client  
{"type": "pong", "timestamp": 1707826806000}

Latency calculated from round-trip timestamp delta.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 7 commits February 13, 2026 10:06
- Add flutter_webrtc dependency to pubspec.yaml
- Create domain layer entities (VoiceUser, VoiceChannel, ChannelState, UserGroup)
- Create voice chat provider for WebSocket communication
- Create WebRTC provider for audio handling
- Add voice chat page with tree-like channel structure
- Add voice chat drawer item in navigation menu
- Add voice chat route to app routing
- Implement Go WebSocket server for signaling
- Add server config with YAML-based channel and user group management
- Support for Nostr npub-based authentication
- Implement efficient state change broadcasting
- Add speaking indicator and user mute functionality

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
- Add comprehensive VOICE_CHAT.md documentation
- Rename createPeerConnection to initializePeerConnection to avoid naming conflict
- Document architecture, protocol, and usage

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
- Add config.example.yaml with detailed comments and emoji icons
- Add VOICE_CHAT_QUICKSTART.md for easy setup
- Update voice_server README with better instructions
- Include troubleshooting and remote access guide

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
- Fix mute toggle logic in WebRTC provider (track.enabled should be !state.isMuted)
- Add null/empty check for displayName to prevent RangeError
- Use list comprehension syntax for cleaner code
- Add error handling for state update parsing
- Add error logging for WebSocket message writes
- Add TODO comment for CORS restriction in production

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
Use explicit newMutedState variable and add comment explaining
track.enabled relationship to mute state for better code clarity

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
Copilot AI changed the title [WIP] Add voice channel features with user overview Add voice chat with WebSocket signaling and tree-structured channels Feb 13, 2026
Copilot AI requested a review from 1-leo February 13, 2026 10:18
Copilot AI and others added 2 commits February 13, 2026 10:30
- Replace WebSocket with WebRTC data channels for communication
- Use pion/webrtc v4 for pure Go WebRTC implementation
- Add HTTP signaling endpoint at /signaling
- Implement WebRTC peer connection handling
- Update all documentation to reflect WebRTC usage
- Server now uses native WebRTC for better audio/video integration
- Includes STUN server configuration for NAT traversal
- Data channels provide encrypted, reliable messaging

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
Copilot AI changed the title Add voice chat with WebSocket signaling and tree-structured channels Replace gorilla/websocket with pion/webrtc in voice server Feb 13, 2026
- Use WebSocket (gorilla/websocket) for API/signaling
- Use pion/webrtc for SFU (audio forwarding)
- WebSocket handles state changes, channel management, user presence
- WebRTC handles actual audio streams with SFU forwarding
- Add both gorilla/websocket and pion/webrtc to dependencies
- User struct has both WSConn and PeerConnection
- WebRTC offers/answers/ICE sent via WebSocket messages
- SFU forwards audio tracks to users in same channel
- Update all documentation to reflect hybrid architecture
- Server listens on ws://host:port for WebSocket
- Tested: server compiles and runs successfully

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
Copilot AI changed the title Replace gorilla/websocket with pion/webrtc in voice server Implement hybrid WebSocket + WebRTC SFU architecture for voice server Feb 13, 2026
Copilot AI and others added 2 commits February 13, 2026 11:20
…th debug info

- Update voice_chat_provider to use modern Riverpod (Notifier instead of StateNotifier)
- Update webrtc_provider to use modern Riverpod with ref.onDispose cleanup
- Add ConnectionStatus enum (disconnected, connecting, connected, error)
- Add ping/pong support with latency tracking
- Add automatic reconnection with backoff
- Add connection status indicator in app bar with color coding
- Add expandable debug info panel showing ping latency, reconnect attempts, etc
- Reorganize server code into packages (models, websocket, server, handlers)
- Add WebSocket ping/pong mechanism to keep connection alive
- Fix WebSocket upgrade headers and CORS
- Add proper connection timeouts and error handling
- Server now properly handles ping/pong to prevent timeout issues

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
- Add pkg/README.md explaining new server package structure
- Update voice_server/README.md with new build instructions
- Update VOICE_CHAT.md with modern Riverpod info
- Document connection state monitoring features
- Document ping/pong latency tracking
- Document automatic reconnection
- Document new debug info panel
- Update server architecture description

Co-authored-by: 1-leo <58687994+1-leo@users.noreply.github.com>
Copilot AI changed the title Implement hybrid WebSocket + WebRTC SFU architecture for voice server Fix WebSocket keepalive, modernize Riverpod, add connection monitoring UI Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants