$ show pcccccc/AngelLive
AngelLive is a cross-platform (iOS, macOS, tvOS) live streaming viewer that aggregates content from multiple Chinese streaming platforms (Bilibili, etc.) via a dynamic plugin system. The application is built entirely in Swift, using SwiftUI for the UI layer with UIKit bridging where needed. Its core architecture revolves around a shared library, AngelLiveCore, which provides a plugin runtime for loading JavaScript-based platform adapters, a custom danmaku (bullet-chat) rendering engine, unified playback recovery with a state machine, and iCloud-based favorite and credential synchronization. The macOS and tvOS targets share the same core but have platform-specific UI components and input handling (e.g., tvOS focus-driven navigation, macOS menu bar and window management). The system is characterized by a high degree of modularity and concurrency: plugins are isolated sandboxed JavaScript runtimes, the danmaku engine uses asynchronous layer rendering and a dedicated shoot scheduler to handle burst traffic, and the playback recovery coordinator implements a tunable ladder of fallback actions (reload, switch CDN, refresh play args) to handle stream stalls. The favorite syncing engine uses `CKSyncEngine` with actor-based concurrency and circuit breakers to avoid retry storms. The codebase also includes a comprehensive test suite covering plugin operation, playback recovery, danmaku connection reconnection, and favorite refresh policies. Key entry points for the iOS app are `AngelLiveApp.swift` and `ContentView.swift`, which manage navigation and deep link handling. The macOS app uses `TabView` with sidebar navigation, and the tvOS app uses a SwiftUI-based sidebar and focusable grid. The developer console (`PluginConsoleView`) provides real-time logging and filtering of plugin calls, which is useful for debugging and extending the platform support. The app supports DLNA casting via SSDP discovery and a local HTTP proxy, and it integrates with AirPlay and Picture-in-Picture. Overall, AngelLive is a well-engineered, production-quality application with a clear separation of concerns, strong test coverage, and a plugin architecture that allows it to adapt to new platforms without modifying the core app. Its design patternsβsuch as the actor-based credential manager, the state machine for playback recovery, and the modular danmaku engineβare candidates for extraction into other projects.
The LLM identified 5 files worth highlighting for reuse:
Implements a state machine for automatic stream recovery during live playback. Defines a ladder of recovery actions (reload, switch CDN, refresh play args) with configurable timeouts and budgets. Used by all platforms via the shared core. The state machine is fully testable through injected `RecoveryActions` and `RecoveryConfig`, and the test suite covers startup timeout, stall detection, budget per session, and sustained health reset. This pattern can be reused for any network-dependent operation that requires a fallback chain.
The core danmaku (bullet-chat) view that renders scrolling, top, and bottom comments using a custom asynchronous layer rendering system. Supports mixed text and image cells, GIF animations, track management with collision detection, and a shoot scheduler that limits burst rates. The entire framework is self-contained within `AngelLiveCore` and can be extracted into a separate library for any app needing bullet-chat overlays. The architecture includes a queue pool, cell reuse, and a platform abstraction layer (`DanmakuPlatform`) that makes it compatible with both UIKit and AppKit.
Manages the lifecycle of JavaScript plugins: installation, activation, deactivation, and rollback. Uses a three-phase installation process (confirm, download, activate) with smoke tests and semver-based version comparison. The manager is a singleton that coordinates with `PluginAvailabilityService` and `SandboxPluginCatalog` to dynamically load plugins from a remote index. This pattern is reusable for any app that needs to load and manage third-party code at runtime with safety guarantees.
An actor-based batch refresh engine for live status of favorites. It manages per-plugin concurrency limits, global concurrency, foreground budget, and circuit-breaking to avoid hammering servers after failures. The refresh produces a stream of events (progress, partial results, errors) that drives UI updates. The test suite (`FavoriteRefreshSessionTests`) thoroughly validates timeout, cancellation, and off-path behavior. This component can be extracted as a generic batch fetch utility with rate limiting and resilience.
An actor-based service that manages user login sessions for streaming platforms. It provides methods for cookie-based login, credential validation, session persistence (metadata in UserDefaults, secrets in Keychain), and logout. It uses a serialization pattern (`acquireCredentialOperation`/`releaseCredentialOperation`) to ensure per-plugin credential operations are non-overlapping, with a waiter queue and timeout. This pattern is reusable for any app that needs to manage multiple third-party authentication flows with retry and cancellation safety.