How testpress/react-native-tpstreams works
Project type and purpose
• This is an open-source React Native native-module library (“react-native-tpstreams”) that exposes TPStreams video-playback and download functionality to a React Native app.
• It contains:
• A JavaScript/TypeScript layer (in src/) that defines the public API (player component, download functions).
• Native modules for Android (Kotlin/Java under android/src/main/java/com/tpstreams/*) and iOS (Swift/Obj-C under ios/).
• An example/ React Native application demonstrating integration.
• CI/CD and packaging config (.github/, package.json, TPStreamsRNPlayerView.podspec, Gradle files).
File structure
• Top-level directories:
• src/ – JS/TS implementation of the React Native bridge API and UI component.
• android/ – Android native module and view manager implementations.
• ios/ – iOS native module and view manager implementations.
• example/ – Demo React Native app to test the library on both platforms.
• Config files and build scripts:
• babel.config.js, tsconfig.json, package.json – define build targets and dependencies.
• TPStreamsRNPlayerView.podspec – iOS CocoaPods spec.
• .github/workflows/*.yml – CI for lint/test and npm publishing.
README for additional insights
• Describes initialization (TPStreams.initialize(orgId)), UI component (<TPStreamsPlayerView>), player & download methods, events, and a complete example of real-time download progress.
• Reveals two primary subsystems: video playback and download management, each with JS methods calling into native.
Main components of the system (
a. React Native JavaScript layer
• TPStreams.initialize(...)
• TPStreamsPlayerView component (JS wrapper)
• Download API functions (pauseDownload, resumeDownload, etc.)
b. React Native Bridge Layer
• EventEmitter channels
• Method invoker
c. Android native module
• TPStreamsRNModule (initialization, playback commands)
• TPStreamsRNPlayerViewManager (native view for video)
• TPStreamsDownloadModule (download commands & progress)
• Underlying ExoPlayer or TPStreams Android SDK
d. iOS native module
• TPStreamsModule (init & playback commands)
• TPStreamsRNPlayerViewManager (native view using AVPlayer)
• TPStreamsDownloadModule (download commands & events)
• Underlying TPStreams iOS SDK
e. External TPStreams backend service
• Video streaming CDN/API
• Token refresh endpoint
f. Device subsystems
• Media playback engine (ExoPlayer/AVPlayer)
• Local file storage / SQLite or file system for offline downloads
g. Example App (consumer)
• Embeds JS layer + native modules via react-native-tpstreams dependency
Relationships and interactions
• JS calls (init, play/pause, download control) → React Native Bridge → invokes native module methods.
• Native module → interacts with TPStreams SDK (network calls, media engine) → returns results/events via EventEmitter over the bridge → JS listeners.
• Download progress: native download manager reports real-time progress events → JS state updates in onDownloadProgressChanged.
• Token renewal: native fires onAccessTokenExpired event → JS callback fetches new token → supplies it back to native.
Architectural patterns and design principles
• Bridge Pattern: clear separation between JS and native modules.
• Modularization: separate modules for playback vs. downloads vs. view management.
• Event-driven communication: using React Native’s EventEmitter for real-time updates.
• Single-responsibility modules: each native component handles one domain.