WebRTC Internals
lib-jitsi-meet provides enhanced WebRTC functionality through TraceablePeerConnection and RTCUtils, offering debugging capabilities, browser compatibility, and SDP manipulation.TraceablePeerConnection
TheTraceablePeerConnection class extends the standard RTCPeerConnection with enhanced debugging, logging, and state management.
Core Features
Enhanced Debugging- Detailed trace logging for all peer connection events
- SDP dumping with
TraceablePeerConnection.dumpSDP() - Stats collection and history tracking
- Update log for all state changes
- Local and remote track lifecycle management
- SSRC mapping and tracking
- Simulcast and SVC support
- Codec preference handling
Creating a Peer Connection
modules/RTC/TraceablePeerConnection.ts:233-241
Configuration Options
modules/RTC/TraceablePeerConnection.ts:85-95
Track Management
Local Tracks- Stored in
localTracksMap indexed byrtcId - SSRC info maintained in
localSSRCsMap - Transceiver mapping via
localTrackTransceiverMids
- Indexed by SSRC in
remoteTracksBySsrcMap - Organized by endpoint and media type in
remoteTracksMap - Source name mapping in
remoteSourcesMap
modules/RTC/TraceablePeerConnection.ts:314-364
SDP Handling
lib-jitsi-meet performs extensive SDP manipulation for simulcast, codec preferences, and browser compatibility. SDP Mungingmodules/RTC/TraceablePeerConnection.ts:877-892
Simulcast SDP Munging
For browsers using SDP-based simulcast (Chrome, Safari):
modules/RTC/TraceablePeerConnection.ts:1075-1080
RTX SSRC Modification
modules/RTC/TraceablePeerConnection.ts:1082-1088
Encoding Parameters
lib-jitsi-meet configures RTCRtpEncodingParameters for simulcast and quality control. Configure Sender Encodingsmodules/RTC/TraceablePeerConnection.ts:669-685
Video Sender Configuration
Dynamically adjust resolution, bitrate, and codec per encoding:
modules/RTC/TraceablePeerConnection.ts:923-1036
Codec Preferences
Using setCodecPreferences API For browsers that supportRTCRtpTransceiver.setCodecPreferences() (Chrome, Edge):
modules/RTC/TraceablePeerConnection.ts:1116-1144
Codec Selection API (Chrome 126+)
Set codec per encoding without renegotiation:
modules/RTC/TraceablePeerConnection.ts:1007-1023
RTCUtils
The RTCUtils singleton handles browser compatibility, device enumeration, and media stream acquisition.Initialization
modules/RTC/RTCUtils.js:274-294
Media Constraints
Default Constraintsmodules/RTC/RTCUtils.js:28-45
Constraint Building
modules/RTC/RTCUtils.js:95-183
Device Management
Device Enumerationmodules/RTC/RTCUtils.js:372-383
Device Change Detection
- Modern browsers:
devicechangeevent listener - Legacy browsers: 3-second polling interval
modules/RTC/RTCUtils.js:318-328
getUserMedia Wrapper
modules/RTC/RTCUtils.js:394-433
Audio Output Selection
modules/RTC/RTCUtils.js:836-852
Browser Compatibility
lib-jitsi-meet uses webrtc-adapter for cross-browser compatibility:modules/RTC/RTCUtils.js:3
Statistics Collection
TraceablePeerConnection maintains stats history for debugging. Stats Intervalmodules/RTC/TraceablePeerConnection.ts:587-605
Stat Processing
modules/RTC/TraceablePeerConnection.ts:1223-1243
Next Steps
- XMPP Signaling - Jingle protocol implementation
- Codec Selection - Codec preferences and quality
- Network Optimization - ICE and connectivity