react-native-webrtc 124.0.6 → 124.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/.eslintignore +1 -0
- package/CLAUDE.md +714 -0
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +5 -3
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +74 -8
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +24 -3
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +4 -4
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +8 -0
- package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +8 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +112 -26
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +56 -28
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +19 -0
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +22 -23
- package/ios/RCTWebRTC/SerializeUtils.m +6 -0
- package/ios/RCTWebRTC/VideoCaptureController.m +40 -1
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +23 -9
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +2 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +95 -0
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +1 -0
- package/lib/commonjs/MediaDevices.js +12 -10
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStream.js +14 -9
- package/lib/commonjs/MediaStream.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +28 -12
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/MediaStreamTrackEvent.js +2 -2
- package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -1
- package/lib/commonjs/MessageEvent.js +2 -2
- package/lib/commonjs/MessageEvent.js.map +1 -1
- package/lib/commonjs/Permissions.js +3 -3
- package/lib/commonjs/Permissions.js.map +1 -1
- package/lib/commonjs/RTCCertificate.js +25 -0
- package/lib/commonjs/RTCCertificate.js.map +1 -0
- package/lib/commonjs/RTCDataChannel.js +38 -13
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCDataChannelEvent.js +2 -2
- package/lib/commonjs/RTCDataChannelEvent.js.map +1 -1
- package/lib/commonjs/RTCErrorEvent.js +2 -2
- package/lib/commonjs/RTCErrorEvent.js.map +1 -1
- package/lib/commonjs/RTCIceCandidateEvent.js +2 -2
- package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +109 -27
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpEncodingParameters.js +17 -1
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/commonjs/RTCTrackEvent.js +2 -2
- package/lib/commonjs/RTCTrackEvent.js.map +1 -1
- package/lib/commonjs/RTCUtil.js +1 -1
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/getDisplayMedia.js +2 -1
- package/lib/commonjs/getDisplayMedia.js.map +1 -1
- package/lib/commonjs/index.js +22 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/vendor/event-target-shim/LICENSE +22 -0
- package/lib/commonjs/vendor/event-target-shim/index.d.js +6 -0
- package/lib/commonjs/vendor/event-target-shim/index.d.js.map +1 -0
- package/lib/commonjs/vendor/event-target-shim/index.js +1221 -0
- package/lib/commonjs/vendor/event-target-shim/index.js.map +1 -0
- package/lib/module/MediaDevices.js +11 -9
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStream.js +13 -8
- package/lib/module/MediaStream.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +25 -9
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/MediaStreamTrackEvent.js +1 -1
- package/lib/module/MediaStreamTrackEvent.js.map +1 -1
- package/lib/module/MessageEvent.js +1 -1
- package/lib/module/MessageEvent.js.map +1 -1
- package/lib/module/Permissions.js +3 -3
- package/lib/module/Permissions.js.map +1 -1
- package/lib/module/RTCCertificate.js +18 -0
- package/lib/module/RTCCertificate.js.map +1 -0
- package/lib/module/RTCDataChannel.js +37 -12
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCDataChannelEvent.js +1 -1
- package/lib/module/RTCDataChannelEvent.js.map +1 -1
- package/lib/module/RTCErrorEvent.js +1 -1
- package/lib/module/RTCErrorEvent.js.map +1 -1
- package/lib/module/RTCIceCandidateEvent.js +1 -1
- package/lib/module/RTCIceCandidateEvent.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +103 -21
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpEncodingParameters.js +17 -1
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/module/RTCTrackEvent.js +1 -1
- package/lib/module/RTCTrackEvent.js.map +1 -1
- package/lib/module/RTCUtil.js +1 -1
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/getDisplayMedia.js +2 -1
- package/lib/module/getDisplayMedia.js.map +1 -1
- package/lib/module/index.js +5 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/vendor/event-target-shim/LICENSE +22 -0
- package/lib/module/vendor/event-target-shim/index.d.js +52 -0
- package/lib/module/vendor/event-target-shim/index.d.js.map +1 -0
- package/lib/module/vendor/event-target-shim/index.js +1221 -0
- package/lib/module/vendor/event-target-shim/index.js.map +1 -0
- package/lib/typescript/MediaDevices.d.ts +8 -4
- package/lib/typescript/MediaStream.d.ts +5 -1
- package/lib/typescript/MediaStreamTrack.d.ts +7 -1
- package/lib/typescript/MediaStreamTrackEvent.d.ts +1 -1
- package/lib/typescript/MessageEvent.d.ts +1 -1
- package/lib/typescript/Permissions.d.ts +1 -1
- package/lib/typescript/RTCCertificate.d.ts +16 -0
- package/lib/typescript/RTCDataChannel.d.ts +13 -1
- package/lib/typescript/RTCDataChannelEvent.d.ts +1 -1
- package/lib/typescript/RTCErrorEvent.d.ts +1 -1
- package/lib/typescript/RTCIceCandidateEvent.d.ts +1 -1
- package/lib/typescript/RTCPeerConnection.d.ts +30 -1
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +4 -0
- package/lib/typescript/RTCTrackEvent.d.ts +1 -1
- package/lib/typescript/getDisplayMedia.d.ts +7 -1
- package/lib/typescript/index.d.ts +4 -1
- package/package.json +2 -3
- package/src/MediaDevices.ts +15 -14
- package/src/MediaStream.ts +17 -9
- package/src/MediaStreamTrack.ts +30 -10
- package/src/MediaStreamTrackEvent.ts +2 -2
- package/src/MessageEvent.ts +1 -1
- package/src/Permissions.ts +3 -3
- package/src/RTCCertificate.ts +24 -0
- package/src/RTCDataChannel.ts +49 -14
- package/src/RTCDataChannelEvent.ts +2 -2
- package/src/RTCErrorEvent.ts +1 -1
- package/src/RTCIceCandidateEvent.ts +2 -2
- package/src/RTCPeerConnection.ts +138 -24
- package/src/RTCRtpEncodingParameters.ts +20 -0
- package/src/RTCTrackEvent.ts +1 -1
- package/src/RTCUtil.ts +1 -1
- package/src/getDisplayMedia.ts +9 -2
- package/src/index.ts +9 -2
- package/src/vendor/event-target-shim/LICENSE +22 -0
- package/src/vendor/event-target-shim/index.d.ts +411 -0
- package/src/vendor/event-target-shim/index.js +1186 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
**react-native-webrtc** is a React Native module that provides WebRTC functionality for real-time communication applications on mobile and desktop platforms. It bridges the native WebRTC libraries on Android and iOS to JavaScript/TypeScript, enabling developers to build peer-to-peer audio/video communication applications and data channel functionality.
|
|
8
|
+
|
|
9
|
+
- **Version**: 124.0.7
|
|
10
|
+
- **Supported Platforms**: Android (armeabi-v7a, arm64-v8a, x86, x86_64), iOS (arm64, x86_64), tvOS (arm64)
|
|
11
|
+
- **WebRTC Revision**: M124 (Jitsi-maintained fork)
|
|
12
|
+
|
|
13
|
+
## Common Development Commands
|
|
14
|
+
|
|
15
|
+
### Building and Linting
|
|
16
|
+
```bash
|
|
17
|
+
# Lint TypeScript code and run type checking
|
|
18
|
+
npm run lint
|
|
19
|
+
|
|
20
|
+
# Lint and auto-fix issues
|
|
21
|
+
npm run lintfix
|
|
22
|
+
|
|
23
|
+
# Format code using Prettier
|
|
24
|
+
npm run format
|
|
25
|
+
# Or directly: tools/format.sh
|
|
26
|
+
|
|
27
|
+
# Build the TypeScript module (generates lib/ directory)
|
|
28
|
+
npm run prepare
|
|
29
|
+
# This runs: husky install && bob build
|
|
30
|
+
# Output: lib/commonjs/, lib/module/, lib/typescript/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Package Build
|
|
34
|
+
The package uses `react-native-builder-bob` to generate multiple build targets:
|
|
35
|
+
- CommonJS (`lib/commonjs/`)
|
|
36
|
+
- ES Modules (`lib/module/`)
|
|
37
|
+
- TypeScript definitions (`lib/typescript/`)
|
|
38
|
+
|
|
39
|
+
### Testing with Example Apps
|
|
40
|
+
```bash
|
|
41
|
+
# Navigate to example directory
|
|
42
|
+
cd examples/GumTestApp
|
|
43
|
+
|
|
44
|
+
# iOS
|
|
45
|
+
npm install
|
|
46
|
+
cd ios && pod install && cd ..
|
|
47
|
+
npx react-native run-ios
|
|
48
|
+
|
|
49
|
+
# Android
|
|
50
|
+
npm install
|
|
51
|
+
npx react-native run-android
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Native Development
|
|
55
|
+
|
|
56
|
+
**Android:**
|
|
57
|
+
- Open `android/` in Android Studio
|
|
58
|
+
- Uses Gradle build system
|
|
59
|
+
- WebRTC dependency: `org.jitsi:webrtc:124.+`
|
|
60
|
+
- Minimum SDK: 24
|
|
61
|
+
|
|
62
|
+
**iOS:**
|
|
63
|
+
- Open `ios/RCTWebRTC.xcworkspace` in Xcode
|
|
64
|
+
- Uses CocoaPods: `pod install` in ios/ directory
|
|
65
|
+
- WebRTC dependency: `JitsiWebRTC ~> 124.0.0`
|
|
66
|
+
- Minimum iOS: 12.0
|
|
67
|
+
|
|
68
|
+
### Important Notes
|
|
69
|
+
- The native WebRTC library is maintained by Jitsi at https://github.com/jitsi/webrtc
|
|
70
|
+
- This module does NOT include the WebRTC source; it depends on pre-built binaries from Jitsi
|
|
71
|
+
- To customize WebRTC builds, refer to the Jitsi WebRTC repository
|
|
72
|
+
|
|
73
|
+
## Directory Structure
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
react-native-webrtc/
|
|
77
|
+
├── src/ # TypeScript/JavaScript bridge layer (~3,143 lines)
|
|
78
|
+
│ ├── index.ts # Main entry point, exports all public API
|
|
79
|
+
│ ├── EventEmitter.ts # Native event bridging system
|
|
80
|
+
│ ├── RTCPeerConnection.ts # Peer connection wrapper (primary API)
|
|
81
|
+
│ ├── RTCDataChannel.ts # Data channel communication
|
|
82
|
+
│ ├── MediaStream.ts # Media stream container
|
|
83
|
+
│ ├── MediaStreamTrack.ts # Audio/video track abstraction
|
|
84
|
+
│ ├── getUserMedia.ts # Camera/microphone acquisition
|
|
85
|
+
│ ├── getDisplayMedia.ts # Screen capture
|
|
86
|
+
│ ├── Permissions.ts # Permission handling (cross-platform)
|
|
87
|
+
│ ├── RTCView.ts # Video rendering component wrapper
|
|
88
|
+
│ ├── RTCPIPView.tsx # Picture-in-Picture iOS support
|
|
89
|
+
│ ├── RTCRtpSender.ts # RTP sender control
|
|
90
|
+
│ ├── RTCRtpReceiver.ts # RTP receiver control
|
|
91
|
+
│ ├── RTCRtpTransceiver.ts # Transceiver management
|
|
92
|
+
│ ├── RTCIceCandidate.ts # ICE candidate wrapper
|
|
93
|
+
│ ├── RTCSessionDescription.ts # Session description wrapper
|
|
94
|
+
│ └── [other support files]
|
|
95
|
+
│
|
|
96
|
+
├── android/ # Android native implementation
|
|
97
|
+
│ ├── build.gradle # Android module build configuration
|
|
98
|
+
│ └── src/main/java/com/oney/WebRTCModule/
|
|
99
|
+
│ ├── WebRTCModule.java # Main native module (ReactContextBaseJavaModule)
|
|
100
|
+
│ ├── WebRTCModulePackage.java # React package registration
|
|
101
|
+
│ ├── GetUserMediaImpl.java # getUserMedia implementation
|
|
102
|
+
│ ├── PeerConnectionObserver.java # PeerConnection event observer
|
|
103
|
+
│ ├── DataChannelWrapper.java # DataChannel wrapper
|
|
104
|
+
│ ├── RTCVideoViewManager.java # Video view manager
|
|
105
|
+
│ ├── WebRTCView.java # Native video rendering view
|
|
106
|
+
│ ├── CameraCaptureController.java # Camera control
|
|
107
|
+
│ ├── DisplayUtils.java # Display utilities
|
|
108
|
+
│ └── [video capture, effects, utilities]
|
|
109
|
+
│
|
|
110
|
+
├── ios/ # iOS native implementation
|
|
111
|
+
│ ├── RCTWebRTC/ # Main iOS module
|
|
112
|
+
│ │ ├── WebRTCModule.h/m # Main module header/implementation
|
|
113
|
+
│ │ ├── WebRTCModule+RTCPeerConnection.m
|
|
114
|
+
│ │ ├── WebRTCModule+RTCMediaStream.m
|
|
115
|
+
│ │ ├── WebRTCModule+RTCDataChannel.m
|
|
116
|
+
│ │ ├── WebRTCModule+Permissions.m
|
|
117
|
+
│ │ ├── WebRTCModule+RTCAudioSession.m
|
|
118
|
+
│ │ ├── WebRTCModule+Transceivers.m
|
|
119
|
+
│ │ ├── WebRTCModule+VideoTrackAdapter.m
|
|
120
|
+
│ │ ├── RTCVideoViewManager.h/m # Video view manager
|
|
121
|
+
│ │ ├── PIPController.h/m # Picture-in-Picture
|
|
122
|
+
│ │ ├── ScreenCaptureController.h/m # Screen capture
|
|
123
|
+
│ │ ├── WebRTCModuleOptions.h/m # Module options
|
|
124
|
+
│ │ ├── RCTConvert+WebRTC.h/m # Type conversion utilities
|
|
125
|
+
│ │ └── [other support files]
|
|
126
|
+
│ ├── RCTWebRTC.xcodeproj/
|
|
127
|
+
│ └── RCTWebRTC.xcworkspace/
|
|
128
|
+
│
|
|
129
|
+
├── lib/ # Build output (generated)
|
|
130
|
+
│ ├── commonjs/ # CommonJS build
|
|
131
|
+
│ ├── module/ # ES module build
|
|
132
|
+
│ └── typescript/ # TypeScript definitions
|
|
133
|
+
│
|
|
134
|
+
├── Documentation/ # User guides
|
|
135
|
+
│ ├── BasicUsage.md
|
|
136
|
+
│ ├── CallGuide.md
|
|
137
|
+
│ ├── AndroidInstallation.md
|
|
138
|
+
│ ├── iOSInstallation.md
|
|
139
|
+
│ └── [other guides]
|
|
140
|
+
│
|
|
141
|
+
├── examples/ # Test applications
|
|
142
|
+
│ ├── GumTestApp/ # iOS/Android example
|
|
143
|
+
│ └── GumTestApp_macOS/ # macOS example
|
|
144
|
+
│
|
|
145
|
+
├── package.json # NPM configuration
|
|
146
|
+
├── react-native-webrtc.podspec # CocoaPods specification
|
|
147
|
+
├── react-native.config.js # React Native linking config
|
|
148
|
+
└── tsconfig.json # TypeScript configuration
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Architecture Overview
|
|
152
|
+
|
|
153
|
+
### High-Level Data Flow
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
JavaScript/TypeScript Layer
|
|
157
|
+
↓
|
|
158
|
+
React Native Bridge
|
|
159
|
+
↓
|
|
160
|
+
NativeModule (WebRTCModule)
|
|
161
|
+
↓
|
|
162
|
+
Native WebRTC Library (org.jitsi.webrtc)
|
|
163
|
+
↓
|
|
164
|
+
OS-level APIs (MediaCodec, AVFoundation, etc.)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Key Architectural Components
|
|
168
|
+
|
|
169
|
+
### 1. JavaScript/TypeScript Bridge Layer (`src/`)
|
|
170
|
+
|
|
171
|
+
The TypeScript layer provides a W3C-compliant WebRTC API surface that JavaScript developers use. All native functionality is exposed through the `NativeModules.WebRTCModule` API.
|
|
172
|
+
|
|
173
|
+
**Key files and their roles:**
|
|
174
|
+
|
|
175
|
+
#### Main Entry Point
|
|
176
|
+
- **`index.ts`**:
|
|
177
|
+
- Imports `WebRTCModule` from React Native's `NativeModules`
|
|
178
|
+
- Throws error if native module not found
|
|
179
|
+
- Calls `setupNativeEvents()` to initialize event listeners
|
|
180
|
+
- Exports all public classes and functions (RTCPeerConnection, MediaStream, etc.)
|
|
181
|
+
- Provides `registerGlobals()` to set up W3C-standard `navigator.mediaDevices` and global WebRTC objects
|
|
182
|
+
|
|
183
|
+
#### Event System
|
|
184
|
+
- **`EventEmitter.ts`**:
|
|
185
|
+
- Manages bidirectional communication of WebRTC events from native to JS
|
|
186
|
+
- Creates a `NativeEventEmitter` subscribed to the native `WebRTCModule`
|
|
187
|
+
- Defines 13 core native event types: `peerConnectionSignalingStateChanged`, `peerConnectionStateChanged`, `peerConnectionIceConnectionChanged`, `dataChannelStateChanged`, `dataChannelReceiveMessage`, `mediaStreamTrackMuteChanged`, etc.
|
|
188
|
+
- Implements a JS-only `EventEmitter` that re-emits native events for application code
|
|
189
|
+
- Tracks subscriptions per listener to allow cleanup
|
|
190
|
+
|
|
191
|
+
#### Core WebRTC Classes
|
|
192
|
+
|
|
193
|
+
**RTCPeerConnection** (`RTCPeerConnection.ts`):
|
|
194
|
+
- Main class for managing peer-to-peer connections
|
|
195
|
+
- Each instance has a numeric ID (`_pcId`) tracked by the native module
|
|
196
|
+
- Key methods:
|
|
197
|
+
- `createOffer()` / `createAnswer()` - generate session descriptions via native bridge
|
|
198
|
+
- `setLocalDescription()` / `setRemoteDescription()` - manage connection state
|
|
199
|
+
- `addTrack()` / `removeTrack()` - manage media tracks
|
|
200
|
+
- `addIceCandidate()` - process ICE candidates
|
|
201
|
+
- `createDataChannel()` - create data channels
|
|
202
|
+
- `getStats()` - retrieve connection statistics
|
|
203
|
+
- Uses EventTarget pattern for event handling
|
|
204
|
+
- Maintains internal state: `signalingState`, `iceConnectionState`, `connectionState`, `iceGatheringState`
|
|
205
|
+
- Tracks transceivers, remote streams, and pending track events
|
|
206
|
+
|
|
207
|
+
**MediaStream** (`MediaStream.ts`):
|
|
208
|
+
- Container for audio/video tracks
|
|
209
|
+
- Each stream has a unique `_id` and `_reactTag`
|
|
210
|
+
- Methods:
|
|
211
|
+
- `addTrack()` / `removeTrack()` - manage contained tracks
|
|
212
|
+
- `getTracks()` / `getAudioTracks()` / `getVideoTracks()` - query tracks
|
|
213
|
+
- `release()` - cleanup stream
|
|
214
|
+
- Maintains internal `_tracks` array
|
|
215
|
+
|
|
216
|
+
**MediaStreamTrack** (`MediaStreamTrack.ts`):
|
|
217
|
+
- Represents individual audio or video tracks
|
|
218
|
+
- Properties: `id`, `kind` (audio/video), `enabled`, `readyState`, `settings`
|
|
219
|
+
- Distinguishes between local and remote tracks via `remote` flag
|
|
220
|
+
- Methods:
|
|
221
|
+
- `setConstraints()` - apply media constraints
|
|
222
|
+
- `stop()` - stop track capture
|
|
223
|
+
- `getSettings()` / `getCapabilities()` - query capabilities
|
|
224
|
+
- Emits events: `ended`, `mute`, `unmute`
|
|
225
|
+
|
|
226
|
+
**RTCDataChannel** (`RTCDataChannel.ts`):
|
|
227
|
+
- For non-media data transmission
|
|
228
|
+
- States: connecting, open, closing, closed
|
|
229
|
+
- Methods: `send()`, `close()`
|
|
230
|
+
- Supports both text and binary (ArrayBuffer) message types
|
|
231
|
+
- Tracks: `label`, `id`, `ordered`, `maxPacketLifeTime`, `maxRetransmits`, `protocol`
|
|
232
|
+
|
|
233
|
+
**Media Device Access**:
|
|
234
|
+
- `getUserMedia.ts`: Requests camera/microphone access with constraints
|
|
235
|
+
- Checks permissions first
|
|
236
|
+
- Normalizes constraints
|
|
237
|
+
- Returns `Promise<MediaStream>`
|
|
238
|
+
- `getDisplayMedia.ts`: Requests screen capture
|
|
239
|
+
- `Permissions.ts`: Cross-platform permission management
|
|
240
|
+
- Android: Uses `PermissionsAndroid` API
|
|
241
|
+
- iOS: Delegates to native `WebRTCModule` methods
|
|
242
|
+
|
|
243
|
+
**Video Rendering**:
|
|
244
|
+
- `RTCView.ts`: Exports `requireNativeComponent('RTCVideoView')`
|
|
245
|
+
- Props: `streamURL`, `mirror`, `objectFit`, `zOrder`, `onDimensionsChange`
|
|
246
|
+
- iOS-specific: `iosPIP` for Picture-in-Picture support
|
|
247
|
+
- `RTCPIPView.tsx`: Picture-in-Picture controller (iOS only)
|
|
248
|
+
- Methods: `startIOSPIP()`, `stopIOSPIP()`
|
|
249
|
+
|
|
250
|
+
**RTP Control**:
|
|
251
|
+
- `RTCRtpSender.ts`: RTP sender control and statistics
|
|
252
|
+
- `RTCRtpReceiver.ts`: RTP receiver control
|
|
253
|
+
- `RTCRtpTransceiver.ts`: Bidirectional transceiver management
|
|
254
|
+
- `RTCRtpEncodingParameters.ts`: Encoding configuration for simulcast/SVC
|
|
255
|
+
|
|
256
|
+
### 2. Android Native Implementation (`android/`)
|
|
257
|
+
|
|
258
|
+
#### WebRTCModule (Main Bridge)
|
|
259
|
+
**`WebRTCModule.java`** (extends `ReactContextBaseJavaModule`):
|
|
260
|
+
- Central module implementing all native methods
|
|
261
|
+
- Initialization:
|
|
262
|
+
- Creates `PeerConnectionFactory` using Jitsi's WebRTC library
|
|
263
|
+
- Initializes video encoder/decoder factories with H.264 hardware acceleration
|
|
264
|
+
- Sets up audio device module
|
|
265
|
+
- Configures EGL context for hardware acceleration
|
|
266
|
+
- Maintains:
|
|
267
|
+
- `mPeerConnectionObservers`: SparseArray mapping peer connection IDs to observer objects
|
|
268
|
+
- `localStreams`: HashMap of local media streams
|
|
269
|
+
- `getUserMediaImpl`: Separate handler for getUserMedia
|
|
270
|
+
|
|
271
|
+
**Key Exported Methods** (called from JS via NativeModules):
|
|
272
|
+
- `peerConnectionInit(config, id)` - Create new peer connection
|
|
273
|
+
- `peerConnectionCreateOffer(id, options)` - Generate offer SDP
|
|
274
|
+
- `peerConnectionCreateAnswer(id, options)` - Generate answer SDP
|
|
275
|
+
- `peerConnectionSetLocalDescription(id, sdp)` - Set local SDP
|
|
276
|
+
- `peerConnectionSetRemoteDescription(id, sdp)` - Set remote SDP
|
|
277
|
+
- `peerConnectionAddIceCandidate(id, candidate)` - Add ICE candidate
|
|
278
|
+
- `mediaStreamCreate(streamId)` - Create media stream
|
|
279
|
+
- `mediaStreamAddTrack(streamTag, pcId, trackId)` - Add track to stream
|
|
280
|
+
- `getUserMedia(constraints, success, failure)` - Acquire camera/mic
|
|
281
|
+
- `getDisplayMedia(success, failure)` - Screen capture
|
|
282
|
+
- `dataChannelSend(pcId, dataChannelId, data)` - Send data channel message
|
|
283
|
+
|
|
284
|
+
**Event Emission**:
|
|
285
|
+
```java
|
|
286
|
+
void sendEvent(String eventName, @Nullable ReadableMap params) {
|
|
287
|
+
getReactApplicationContext()
|
|
288
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
289
|
+
.emit(eventName, params);
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
Emits native events that are received by the JS `NativeEventEmitter`
|
|
293
|
+
|
|
294
|
+
#### GetUserMediaImpl
|
|
295
|
+
**`GetUserMediaImpl.java`**:
|
|
296
|
+
- Handles camera/microphone and screen capture acquisition
|
|
297
|
+
- Features:
|
|
298
|
+
- Uses `CameraEnumerator` to discover available cameras
|
|
299
|
+
- Applies media constraints (resolution, frame rate, facing mode)
|
|
300
|
+
- Manages permissions via `ActivityEventListener`
|
|
301
|
+
- Handles screen capture permission via `MediaProjectionManager`
|
|
302
|
+
- Creates `AudioTrack` and `VideoTrack` objects
|
|
303
|
+
- Returns track info via callbacks to JS layer
|
|
304
|
+
|
|
305
|
+
#### PeerConnectionObserver
|
|
306
|
+
**`PeerConnectionObserver.java`**:
|
|
307
|
+
- Implements `PeerConnection.Observer` interface
|
|
308
|
+
- Listens to native WebRTC events and translates them to React Native events
|
|
309
|
+
- Manages:
|
|
310
|
+
- Data channels (`DataChannelWrapper` instances)
|
|
311
|
+
- Remote streams and tracks
|
|
312
|
+
- Video track adapters for rendering
|
|
313
|
+
- Callbacks translate native events → `sendEvent()` calls
|
|
314
|
+
|
|
315
|
+
#### WebRTCView (Video Rendering)
|
|
316
|
+
**`WebRTCView.java`**:
|
|
317
|
+
- Custom Android View for video rendering
|
|
318
|
+
- Uses `SurfaceViewRenderer` from WebRTC library
|
|
319
|
+
- Properties: `mirror`, `objectFit`, `zOrder`, `streamURL`
|
|
320
|
+
- Automatically connects to media stream when `streamURL` is set
|
|
321
|
+
|
|
322
|
+
**`RTCVideoViewManager.java`** (extends `SimpleViewManager<WebRTCView>`):
|
|
323
|
+
- React ViewManager that creates and manages WebRTCView instances
|
|
324
|
+
- Handles prop updates (mirror, objectFit, streamURL, zOrder)
|
|
325
|
+
|
|
326
|
+
#### Helper Classes
|
|
327
|
+
- **`DataChannelWrapper.java`**: Wraps RTCDataChannel with state tracking
|
|
328
|
+
- **`CameraCaptureController.java`** / **`AbstractVideoCaptureController.java`**: Camera capture management
|
|
329
|
+
- **`ReactBridgeUtil.java`**: Conversion utilities between React Bridge types and WebRTC types
|
|
330
|
+
- **`VideoTrackAdapter.java`**: Adapts video frames for rendering
|
|
331
|
+
|
|
332
|
+
### 3. iOS Native Implementation (`ios/RCTWebRTC/`)
|
|
333
|
+
|
|
334
|
+
#### WebRTCModule (Main Bridge)
|
|
335
|
+
**`WebRTCModule.h/m`** (implements `RCTBridgeModule`, `RCTEventEmitter`):
|
|
336
|
+
- Central iOS module managing all WebRTC functionality
|
|
337
|
+
- Key properties:
|
|
338
|
+
- `RTCPeerConnectionFactory *peerConnectionFactory`: Factory for creating connections
|
|
339
|
+
- `NSMutableDictionary<NSNumber *, RTCPeerConnection *> *peerConnections`: Active peer connections
|
|
340
|
+
- `NSMutableDictionary<NSString *, RTCMediaStream *> *localStreams`: Local media streams
|
|
341
|
+
- `NSMutableDictionary<NSString *, RTCMediaStreamTrack *> *localTracks`: Local tracks
|
|
342
|
+
- `dispatch_queue_t workerQueue`: Background execution queue
|
|
343
|
+
|
|
344
|
+
**Initialization** (`init`):
|
|
345
|
+
- Sets up video encoder/decoder factories
|
|
346
|
+
- Initializes `RTCPeerConnectionFactory`
|
|
347
|
+
- Creates dispatch queue for background work
|
|
348
|
+
- Applies field trials for WebRTC optimization
|
|
349
|
+
|
|
350
|
+
**Modular Architecture** (using Objective-C categories):
|
|
351
|
+
- `WebRTCModule+RTCPeerConnection.m`: Peer connection methods
|
|
352
|
+
- `WebRTCModule+RTCMediaStream.m`: Media stream methods
|
|
353
|
+
- `WebRTCModule+RTCDataChannel.m`: Data channel methods
|
|
354
|
+
- `WebRTCModule+RTCAudioSession.m`: Audio configuration
|
|
355
|
+
- `WebRTCModule+Permissions.m`: Permission handling
|
|
356
|
+
- `WebRTCModule+Transceivers.m`: RTP transceiver management
|
|
357
|
+
- `WebRTCModule+VideoTrackAdapter.m`: Video frame adaptation
|
|
358
|
+
|
|
359
|
+
**Event Emission**:
|
|
360
|
+
- Extends `RCTEventEmitter`
|
|
361
|
+
- Supports array of events: `supportedEvents`
|
|
362
|
+
- Emits events via `[self sendEventWithName:body:]`
|
|
363
|
+
|
|
364
|
+
#### Key Supporting Classes
|
|
365
|
+
|
|
366
|
+
**`RTCVideoViewManager.h/m`**:
|
|
367
|
+
- ViewManager for RTCView component
|
|
368
|
+
- Creates and manages `RTCVideoView` native instances
|
|
369
|
+
- Handles prop updates
|
|
370
|
+
|
|
371
|
+
**`ScreenCaptureController.h/m`**:
|
|
372
|
+
- Manages screen recording via `RPScreenRecorder`
|
|
373
|
+
- Handles permission flow
|
|
374
|
+
- Creates screen capture media stream
|
|
375
|
+
|
|
376
|
+
**`PIPController.h/m`**:
|
|
377
|
+
- Picture-in-Picture controller for iOS 15+
|
|
378
|
+
- Manages `AVPictureInPictureController`
|
|
379
|
+
- Handles PIP lifecycle (start, stop, pause, resume)
|
|
380
|
+
|
|
381
|
+
**`WebRTCModuleOptions.h/m`**:
|
|
382
|
+
- Singleton for configurable module options
|
|
383
|
+
- Custom encoder/decoder factories
|
|
384
|
+
- Custom audio device
|
|
385
|
+
- Field trials configuration
|
|
386
|
+
- Logging severity
|
|
387
|
+
|
|
388
|
+
**`RCTConvert+WebRTC.h/m`**:
|
|
389
|
+
- Type conversion utilities
|
|
390
|
+
- Converts between React Bridge types and WebRTC native types
|
|
391
|
+
|
|
392
|
+
**Helper Classes**:
|
|
393
|
+
- `DataChannelWrapper.h`: Wraps RTCDataChannel
|
|
394
|
+
- `CapturerEventsDelegate.h`: Camera capture event delegate
|
|
395
|
+
- `VideoCaptureController.h`: Camera control
|
|
396
|
+
- `I420Converter.h`: Video frame format conversion
|
|
397
|
+
- `SerializeUtils.h/m`: Serialization utilities for cross-layer communication
|
|
398
|
+
|
|
399
|
+
## Native Dependency Management
|
|
400
|
+
|
|
401
|
+
### Android
|
|
402
|
+
**`android/build.gradle`**:
|
|
403
|
+
```gradle
|
|
404
|
+
dependencies {
|
|
405
|
+
implementation "com.facebook.react:react-android:+"
|
|
406
|
+
api 'org.jitsi:webrtc:124.+' // WebRTC library
|
|
407
|
+
implementation "androidx.core:core:1.7.0"
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
- Uses Jitsi-maintained WebRTC build
|
|
411
|
+
- Requires Java 8 for WebRTC compatibility
|
|
412
|
+
- Hardware acceleration via EGL
|
|
413
|
+
|
|
414
|
+
### iOS
|
|
415
|
+
**`react-native-webrtc.podspec`**:
|
|
416
|
+
```ruby
|
|
417
|
+
s.dependency 'React-Core'
|
|
418
|
+
s.dependency 'JitsiWebRTC', '~> 124.0.0' # Jitsi WebRTC pod
|
|
419
|
+
s.framework = 'AudioToolbox', 'AVFoundation', 'CoreAudio',
|
|
420
|
+
'CoreGraphics', 'CoreVideo', 'GLKit', 'VideoToolbox'
|
|
421
|
+
```
|
|
422
|
+
- Minimum iOS 12.0, macOS 10.13, tvOS 16.0
|
|
423
|
+
- Links required audio/video frameworks
|
|
424
|
+
- Uses Jitsi's pre-built WebRTC pod
|
|
425
|
+
|
|
426
|
+
## Build System
|
|
427
|
+
|
|
428
|
+
### JavaScript/TypeScript Build
|
|
429
|
+
**`package.json`**:
|
|
430
|
+
```json
|
|
431
|
+
{
|
|
432
|
+
"react-native": "src/index.ts",
|
|
433
|
+
"main": "lib/commonjs/index.js",
|
|
434
|
+
"module": "lib/module/index.js",
|
|
435
|
+
"types": "lib/typescript/index.d.ts"
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
- Uses `react-native-builder-bob` for multi-target output
|
|
439
|
+
- Generates: CommonJS, ES Modules, TypeScript definitions
|
|
440
|
+
- Targets: `["commonjs", "module", "typescript"]`
|
|
441
|
+
|
|
442
|
+
### Native Module Registration
|
|
443
|
+
**`react-native.config.js`**:
|
|
444
|
+
```javascript
|
|
445
|
+
module.exports = {
|
|
446
|
+
reactNativePath: '...',
|
|
447
|
+
project: {
|
|
448
|
+
ios: {},
|
|
449
|
+
android: {}
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
```
|
|
453
|
+
- Auto-linking configuration for React Native
|
|
454
|
+
|
|
455
|
+
**Android (`WebRTCModulePackage.java`)**:
|
|
456
|
+
```java
|
|
457
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
458
|
+
return Arrays.asList(new WebRTCModule(reactContext));
|
|
459
|
+
}
|
|
460
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
461
|
+
return Arrays.asList(new RTCVideoViewManager());
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
**iOS** (via CocoaPods):
|
|
466
|
+
- Automatically linked through `.podspec`
|
|
467
|
+
- React sees `WebRTCModule` via RN_EXPORT macros
|
|
468
|
+
|
|
469
|
+
## Bridge Communication Patterns
|
|
470
|
+
|
|
471
|
+
### 1. One-Way Native Calls (JS → Native)
|
|
472
|
+
JavaScript calls native methods synchronously or asynchronously:
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
// JS
|
|
476
|
+
const config = { iceServers: [...] };
|
|
477
|
+
const success = WebRTCModule.peerConnectionInit(config, pcId);
|
|
478
|
+
|
|
479
|
+
// Android/iOS
|
|
480
|
+
@ReactMethod
|
|
481
|
+
public void peerConnectionInit(ReadableMap config, int id, Promise promise) {
|
|
482
|
+
// Process config, create native resources
|
|
483
|
+
promise.resolve(success);
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### 2. Event Emission (Native → JS)
|
|
488
|
+
Native code emits events that JS layer receives:
|
|
489
|
+
|
|
490
|
+
```java
|
|
491
|
+
// Android
|
|
492
|
+
WritableMap params = Arguments.createMap();
|
|
493
|
+
params.putInt("id", pcId);
|
|
494
|
+
params.putString("state", "connected");
|
|
495
|
+
sendEvent("peerConnectionStateChanged", params);
|
|
496
|
+
|
|
497
|
+
// JS - EventEmitter intercepts
|
|
498
|
+
nativeEmitter.addListener("peerConnectionStateChanged", (params) => {
|
|
499
|
+
eventEmitter.emit("peerConnectionStateChanged", params);
|
|
500
|
+
});
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### 3. Asynchronous Operations (Callbacks)
|
|
504
|
+
For complex operations like getUserMedia:
|
|
505
|
+
|
|
506
|
+
```java
|
|
507
|
+
// Android
|
|
508
|
+
WebRTCModule.getUserMedia(constraints, success, failure);
|
|
509
|
+
|
|
510
|
+
// Implementation
|
|
511
|
+
private void getUserMedia(ReadableMap constraints, Callback success, Callback failure) {
|
|
512
|
+
// ... acquire camera/mic ...
|
|
513
|
+
success.invoke(streamId, tracksArray); // or failure.invoke(error)
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// JS
|
|
517
|
+
WebRTCModule.getUserMedia(constraints, (streamId, tracks) => {
|
|
518
|
+
resolve(new MediaStream({streamId, streamReactTag: streamId, tracks}));
|
|
519
|
+
}, (error) => {
|
|
520
|
+
reject(error);
|
|
521
|
+
});
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
## Key Design Patterns
|
|
525
|
+
|
|
526
|
+
### 1. Wrapper Pattern
|
|
527
|
+
Each native WebRTC object has a JS wrapper that maintains state and bridges calls:
|
|
528
|
+
- Native `RTCPeerConnection` → JS `RTCPeerConnection` class
|
|
529
|
+
- Native `MediaStream` → JS `MediaStream` class
|
|
530
|
+
- Each wrapper tracks a unique ID for native reference
|
|
531
|
+
|
|
532
|
+
### 2. Event-Driven Architecture
|
|
533
|
+
- Native observer/delegate patterns capture WebRTC events
|
|
534
|
+
- Events are serialized and sent to JS
|
|
535
|
+
- JS EventEmitter re-broadcasts to application listeners
|
|
536
|
+
|
|
537
|
+
### 3. Dual Initialization
|
|
538
|
+
Each major class initializes in both JS and native:
|
|
539
|
+
|
|
540
|
+
```typescript
|
|
541
|
+
constructor(config) {
|
|
542
|
+
this._pcId = nextId++;
|
|
543
|
+
WebRTCModule.peerConnectionInit(config, this._pcId); // Native init
|
|
544
|
+
this._registerEvents(); // JS event setup
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### 4. Lazy Stream Resolution
|
|
549
|
+
Remote media streams are created on-demand when track events arrive:
|
|
550
|
+
```typescript
|
|
551
|
+
// onRemoteTrack event
|
|
552
|
+
const remoteStream = this._remoteStreams.get(streamId)
|
|
553
|
+
|| new MediaStream({ streamId, streamReactTag, tracks });
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### 5. Object Pooling
|
|
557
|
+
- PeerConnection and DataChannel objects are pooled by ID
|
|
558
|
+
- Android: `SparseArray<PeerConnectionObserver>`
|
|
559
|
+
- iOS: `NSMutableDictionary<NSNumber *, RTCPeerConnection *>`
|
|
560
|
+
|
|
561
|
+
## Data Flow Examples
|
|
562
|
+
|
|
563
|
+
### Example 1: Peer Connection Creation
|
|
564
|
+
```
|
|
565
|
+
JS: new RTCPeerConnection(config)
|
|
566
|
+
↓
|
|
567
|
+
JS: WebRTCModule.peerConnectionInit(config, pcId)
|
|
568
|
+
↓
|
|
569
|
+
Native: Create RTCPeerConnection object, store in observers map
|
|
570
|
+
↓
|
|
571
|
+
Native: Return success flag
|
|
572
|
+
↓
|
|
573
|
+
JS: Register event listeners for this peer connection
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
### Example 2: Media Track Reception
|
|
577
|
+
```
|
|
578
|
+
Native: WebRTC detects remote track
|
|
579
|
+
↓
|
|
580
|
+
Native: PeerConnectionObserver.onAddTrack() fires
|
|
581
|
+
↓
|
|
582
|
+
Native: Create MediaStreamTrack wrapper, send event with track info
|
|
583
|
+
↓
|
|
584
|
+
Native: sendEvent("peerConnectionOnTrack", {pcId, streamId, trackInfo})
|
|
585
|
+
↓
|
|
586
|
+
JS: EventEmitter receives event
|
|
587
|
+
↓
|
|
588
|
+
JS: RTCPeerConnection instance finds event via pcId
|
|
589
|
+
↓
|
|
590
|
+
JS: Emits RTCTrackEvent with new MediaStream and MediaStreamTrack
|
|
591
|
+
↓
|
|
592
|
+
App: Receives 'track' event on RTCPeerConnection
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Example 3: Video Rendering
|
|
596
|
+
```
|
|
597
|
+
JS: <RTCView streamURL={stream.id} />
|
|
598
|
+
↓
|
|
599
|
+
React Native: Maps to native RTCVideoView component
|
|
600
|
+
↓
|
|
601
|
+
Native: Looks up stream by ID in stream registry
|
|
602
|
+
↓
|
|
603
|
+
Native: Connects video track to SurfaceViewRenderer (Android)
|
|
604
|
+
or RTCMTLVideoView (iOS)
|
|
605
|
+
↓
|
|
606
|
+
Native: Renders video frames in real-time
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## Platform-Specific Considerations
|
|
610
|
+
|
|
611
|
+
### Android
|
|
612
|
+
- Uses hardware video codec when available (H.264)
|
|
613
|
+
- Fallback to software encoding/decoding
|
|
614
|
+
- Requires API 24+ (min SDK)
|
|
615
|
+
- Audio routing controlled via RTCModule
|
|
616
|
+
- Screen capture requires API 21+ for MediaProjection
|
|
617
|
+
|
|
618
|
+
### iOS
|
|
619
|
+
- Uses VideoToolbox for hardware acceleration
|
|
620
|
+
- Metal rendering for RTCView
|
|
621
|
+
- Picture-in-Picture support iOS 15+
|
|
622
|
+
- Audio categories: PlayAndRecord, Speakerphone
|
|
623
|
+
- Background audio requires entitlements
|
|
624
|
+
|
|
625
|
+
### Permissions
|
|
626
|
+
- **Android**: Handled via `PermissionsAndroid` API (queued due to one-at-a-time limit)
|
|
627
|
+
- **iOS**: Handled via native `AVCaptureDevice` requests (show native permission dialogs)
|
|
628
|
+
|
|
629
|
+
## Extension Points
|
|
630
|
+
|
|
631
|
+
### Customization
|
|
632
|
+
1. **Video Codec**: Pass custom encoder/decoder factories to `WebRTCModuleOptions`
|
|
633
|
+
2. **Audio Device**: Provide custom audio device implementation
|
|
634
|
+
3. **Field Trials**: Configure WebRTC experimental features
|
|
635
|
+
4. **Video Capture**: Extend `CameraCaptureController` (Android) or `VideoCaptureController` (iOS)
|
|
636
|
+
5. **Event Handling**: Listen to emitted events via EventTarget API
|
|
637
|
+
|
|
638
|
+
### Common Tasks
|
|
639
|
+
|
|
640
|
+
**Enable Custom Video Processing**:
|
|
641
|
+
- Android: Provide `VideoFrameProcessor` implementation
|
|
642
|
+
- iOS: Override video frame callbacks in capture controller
|
|
643
|
+
|
|
644
|
+
**Add Statistics Tracking**:
|
|
645
|
+
```typescript
|
|
646
|
+
const stats = await peerConnection.getStats();
|
|
647
|
+
for (const report of stats) {
|
|
648
|
+
if (report.type === 'inbound-rtp') {
|
|
649
|
+
// Process video/audio stats
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
**Control Audio Session** (iOS):
|
|
655
|
+
```typescript
|
|
656
|
+
RTCAudioSession.configureAudioSession();
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
## Testing & Debugging
|
|
660
|
+
|
|
661
|
+
### Debug Logging
|
|
662
|
+
TypeScript layer uses debug module:
|
|
663
|
+
```typescript
|
|
664
|
+
Logger.enable(`${Logger.ROOT_PREFIX}:*`);
|
|
665
|
+
```
|
|
666
|
+
Prefix: `react-native-webrtc:*`
|
|
667
|
+
|
|
668
|
+
### Native Logging
|
|
669
|
+
- Android: Logcat output with `WebRTCModule` tag
|
|
670
|
+
- iOS: Console output, or via Xcode debugger
|
|
671
|
+
|
|
672
|
+
### Example App
|
|
673
|
+
`GumTestApp` in examples directory demonstrates:
|
|
674
|
+
- getUserMedia (camera/mic access)
|
|
675
|
+
- Basic video rendering
|
|
676
|
+
- Permission handling
|
|
677
|
+
|
|
678
|
+
## File Organization Philosophy
|
|
679
|
+
|
|
680
|
+
1. **Clear Separation**: JS/TS layer is completely separate from native implementations
|
|
681
|
+
2. **Modular Native Code**: iOS uses categories to split functionality by concern
|
|
682
|
+
3. **Single Responsibility**: Each class has one primary purpose
|
|
683
|
+
4. **Bridge Indirection**: No direct native API exposure; all bridging through WebRTCModule
|
|
684
|
+
5. **W3C Compliance**: JS API closely follows W3C WebRTC specification
|
|
685
|
+
|
|
686
|
+
## Dependencies
|
|
687
|
+
|
|
688
|
+
### Core
|
|
689
|
+
- `react-native` >= 0.60.0 (peer dependency)
|
|
690
|
+
- `base64-js` 1.5.1 (data encoding)
|
|
691
|
+
- `event-target-shim` 6.0.2 (W3C event model)
|
|
692
|
+
- `debug` 4.3.4 (logging utility)
|
|
693
|
+
|
|
694
|
+
### Build-Time
|
|
695
|
+
- `typescript` 4.6.2
|
|
696
|
+
- `react-native-builder-bob` 0.18.2 (multi-target build)
|
|
697
|
+
- `eslint` + TypeScript eslint
|
|
698
|
+
- `prettier` (code formatting)
|
|
699
|
+
- `husky` 7.0.2 (git hooks)
|
|
700
|
+
|
|
701
|
+
### Runtime Native
|
|
702
|
+
- Android: `org.jitsi:webrtc:124.+`
|
|
703
|
+
- iOS: `JitsiWebRTC ~> 124.0.0`
|
|
704
|
+
|
|
705
|
+
## Conclusion
|
|
706
|
+
|
|
707
|
+
React Native WebRTC follows a clean layered architecture:
|
|
708
|
+
|
|
709
|
+
1. **Presentation**: TypeScript/JavaScript W3C-compliant API
|
|
710
|
+
2. **Bridge Layer**: React Native NativeModules, EventEmitter, and conversion utilities
|
|
711
|
+
3. **Native Implementation**: Android (Java) and iOS (Objective-C) modules using platform WebRTC SDKs
|
|
712
|
+
4. **Platform SDKs**: Android WebRTC, iOS AVFoundation/WebRTC
|
|
713
|
+
|
|
714
|
+
The modular design allows for platform-specific optimizations while maintaining a unified API surface for developers. Event-driven architecture ensures responsive real-time communication, while the wrapper pattern provides clean abstraction boundaries.
|