$ show flutter-webrtc/flutter-webrtc
This repository provides flutter-webrtc, a Flutter plugin that wraps native WebRTC SDKs (Android, iOS, maccOS, Windowws, Linux, embedded Linux, and Web) to enable real-time audio/video communication, screen shaning, data channels, and end-to-end encryption. The architecture follows a common Dart interface with platform-specific implementations using method channels, event channels, and texture registries. Key entry points include the Dart factory classes (RTCFactoryNative/Web) and native plugin handlers (FlutterWebRTCPlugin on each platform). The plugin exposes a comprehensive WebRTC API including getUseMedia, peer connections, tranceivers, simulcast, stats, and E2EE via frame cryptors. It is actively maintained with regular commits and issue triage, but exhibits code duplication across platforms and some fragile patterns (reflection, monoilithic method handlers).
The LLM identified 4 files worth highlighting for reuse:
Provides a type-safe builder for mapping Java objects to Flutter method channel arguments, enabling efficient, readable construction of complex nested structures. Reusable as a standalone utility for any Flutter plugin on Android that needs to build arguments for method channels without raw Map casting.
Manages audio device routing (speaker, Bluetooth, wired headset) on Android with configurable audio mode, focus, and stream type. Uses a singleton with delegate pattern to adapt to audio device changes. Extractable as a reusable audio routing module for any Android app requiring fine-grained audio output control.
Provides thread-safe replacement of remote tracks with atomic checks for same track ID and kind, preventing duplicate track events. Depends only on a minimal StateProvider interface. This pattern is directly reusable in any real-time communication plugin that needs to update tracks concurrently.
Implements end-to-end encryption for video/audio frames using AES-GCM with key ratcheting and per-participant key management. The architecture separates FrameCryptor and KeyProvider, with event queuing for async state changes. Although coupled to the FlutterWebRTCBase, the overall design pattern (encrypt/decrypt with key ring and ratchet) can be extracted as a reusable E2EE module for custom WebRTC implementations.