Skip to main content

WebRTC Internals

lib-jitsi-meet provides enhanced WebRTC functionality through TraceablePeerConnection and RTCUtils, offering debugging capabilities, browser compatibility, and SDP manipulation.

TraceablePeerConnection

The TraceablePeerConnection 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
Media Management
  • Local and remote track lifecycle management
  • SSRC mapping and tracking
  • Simulcast and SVC support
  • Codec preference handling

Creating a Peer Connection

Source: modules/RTC/TraceablePeerConnection.ts:233-241

Configuration Options

Source: modules/RTC/TraceablePeerConnection.ts:85-95

Track Management

Local Tracks
  • Stored in localTracks Map indexed by rtcId
  • SSRC info maintained in localSSRCs Map
  • Transceiver mapping via localTrackTransceiverMids
Remote Tracks
  • Indexed by SSRC in remoteTracksBySsrc Map
  • Organized by endpoint and media type in remoteTracks Map
  • Source name mapping in remoteSources Map
Source: modules/RTC/TraceablePeerConnection.ts:314-364

SDP Handling

lib-jitsi-meet performs extensive SDP manipulation for simulcast, codec preferences, and browser compatibility. SDP Munging
Source: modules/RTC/TraceablePeerConnection.ts:877-892 Simulcast SDP Munging For browsers using SDP-based simulcast (Chrome, Safari):
Source: modules/RTC/TraceablePeerConnection.ts:1075-1080 RTX SSRC Modification
Source: modules/RTC/TraceablePeerConnection.ts:1082-1088

Encoding Parameters

lib-jitsi-meet configures RTCRtpEncodingParameters for simulcast and quality control. Configure Sender Encodings
Source: modules/RTC/TraceablePeerConnection.ts:669-685 Video Sender Configuration Dynamically adjust resolution, bitrate, and codec per encoding:
Source: modules/RTC/TraceablePeerConnection.ts:923-1036
Chrome resets the transaction ID after setParameters(). Chain video sender updates to avoid conflicts:
Source: modules/RTC/TraceablePeerConnection.ts:905-912

Codec Preferences

Using setCodecPreferences API For browsers that support RTCRtpTransceiver.setCodecPreferences() (Chrome, Edge):
Source: modules/RTC/TraceablePeerConnection.ts:1116-1144 Codec Selection API (Chrome 126+) Set codec per encoding without renegotiation:
Source: modules/RTC/TraceablePeerConnection.ts:1007-1023

RTCUtils

The RTCUtils singleton handles browser compatibility, device enumeration, and media stream acquisition.

Initialization

Source: modules/RTC/RTCUtils.js:274-294

Media Constraints

Default Constraints
Source: modules/RTC/RTCUtils.js:28-45 Constraint Building
Source: modules/RTC/RTCUtils.js:95-183

Device Management

Device Enumeration
Source: modules/RTC/RTCUtils.js:372-383 Device Change Detection
  • Modern browsers: devicechange event listener
  • Legacy browsers: 3-second polling interval
Source: modules/RTC/RTCUtils.js:318-328

getUserMedia Wrapper

Source: modules/RTC/RTCUtils.js:394-433

Audio Output Selection

Source: modules/RTC/RTCUtils.js:836-852

Browser Compatibility

lib-jitsi-meet uses webrtc-adapter for cross-browser compatibility:
Source: modules/RTC/RTCUtils.js:3
Safari WebKit Bug WorkaroundOn macOS versions before Big Sur, Safari fails to start the camera if min/max constraints are specified. lib-jitsi-meet removes these constraints on WebKit-based browsers:
See: https://bugs.webkit.org/show_bug.cgi?id=210932Source: modules/RTC/RTCUtils.js:120-131

Statistics Collection

TraceablePeerConnection maintains stats history for debugging. Stats Interval
Source: modules/RTC/TraceablePeerConnection.ts:587-605 Stat Processing
Source: modules/RTC/TraceablePeerConnection.ts:1223-1243

Next Steps