A shim to insulate apps from WebRTC spec changes and browser prefix differences
Overall
score
98%
Firefox-specific shims handle compatibility issues and behavioral differences in Firefox browsers to ensure consistent WebRTC behavior across all supported platforms.
Provides consistent ontrack event handling for RTCPeerConnection in Firefox.
/**
* Shims ontrack event for Firefox browsers
* Ensures proper track event handling and timing
* @param window - Browser window object
*/
function shimOnTrack(window: Window): void;What it fixes:
Main Firefox RTCPeerConnection compatibility shim.
/**
* Main Firefox RTCPeerConnection shim
* Applies comprehensive Firefox-specific fixes
* @param window - Browser window object
* @param browserDetails - Browser detection information
*/
function shimPeerConnection(window: Window, browserDetails: IBrowserDetails): void;What it fixes:
Normalizes RTCRtpSender.getStats() method for Firefox.
/**
* Shims RTCRtpSender getStats method for Firefox
* Provides consistent sender statistics API
* @param window - Browser window object
*/
function shimSenderGetStats(window: Window): void;What it fixes:
Usage Examples:
import adapter from 'webrtc-adapter';
const pc = new RTCPeerConnection();
// Get sender statistics (automatically shimmed)
pc.getSenders().forEach(async (sender) => {
if (sender.track) {
const stats = await sender.getStats();
stats.forEach((report) => {
if (report.type === 'outbound-rtp') {
console.log('Bytes sent:', report.bytesSent);
console.log('Packets sent:', report.packetsSent);
console.log('Bandwidth:', report.bytesReceived);
}
});
}
});Normalizes RTCRtpReceiver.getStats() method for Firefox.
/**
* Shims RTCRtpReceiver getStats method for Firefox
* Provides consistent receiver statistics API
* @param window - Browser window object
*/
function shimReceiverGetStats(window: Window): void;What it fixes:
Usage Examples:
import adapter from 'webrtc-adapter';
const pc = new RTCPeerConnection();
// Get receiver statistics (automatically shimmed)
pc.getReceivers().forEach(async (receiver) => {
if (receiver.track) {
const stats = await receiver.getStats();
stats.forEach((report) => {
if (report.type === 'inbound-rtp') {
console.log('Bytes received:', report.bytesReceived);
console.log('Packets received:', report.packetsReceived);
console.log('Jitter:', report.jitter);
}
});
}
});Provides removeStream() method compatibility for Firefox.
/**
* Shims removeStream method for Firefox
* Provides legacy stream removal API compatibility
* @param window - Browser window object
*/
function shimRemoveStream(window: Window): void;What it fixes:
Usage Examples:
import adapter from 'webrtc-adapter';
const pc = new RTCPeerConnection();
// Legacy stream removal (automatically shimmed)
function removeLocalStream(stream) {
if (pc.removeStream) {
pc.removeStream(stream);
} else {
// Fallback to modern track removal
stream.getTracks().forEach(track => {
const sender = pc.getSenders().find(s => s.track === track);
if (sender) {
pc.removeTrack(sender);
}
});
}
}Provides RTCDataChannel compatibility fixes for Firefox.
/**
* Shims RTCDataChannel API for Firefox
* Ensures consistent data channel behavior
* @param window - Browser window object
*/
function shimRTCDataChannel(window: Window): void;What it fixes:
Provides addTransceiver() method compatibility for Firefox.
/**
* Shims addTransceiver method for Firefox
* Provides consistent transceiver creation API
* @param window - Browser window object
*/
function shimAddTransceiver(window: Window): void;What it fixes:
Usage Examples:
import adapter from 'webrtc-adapter';
const pc = new RTCPeerConnection();
// Add transceiver (automatically shimmed)
const transceiver = pc.addTransceiver('video', {
direction: 'sendrecv',
streams: [localStream]
});
console.log('Created transceiver:', transceiver.mid);
console.log('Direction:', transceiver.direction);Shims getParameters() method for RTCRtpSender in Firefox.
/**
* Shims getParameters method for Firefox
* Provides consistent sender parameter access
* @param window - Browser window object
*/
function shimGetParameters(window: Window): void;What it fixes:
Normalizes createOffer() method behavior for Firefox.
/**
* Shims createOffer method for Firefox
* Ensures consistent offer creation behavior
* @param window - Browser window object
*/
function shimCreateOffer(window: Window): void;What it fixes:
Normalizes createAnswer() method behavior for Firefox.
/**
* Shims createAnswer method for Firefox
* Ensures consistent answer creation behavior
* @param window - Browser window object
*/
function shimCreateAnswer(window: Window): void;What it fixes:
Usage Examples:
import adapter from 'webrtc-adapter';
const pc = new RTCPeerConnection();
// Create offer/answer (automatically shimmed)
async function createOfferAnswer() {
try {
const offer = await pc.createOffer({
offerToReceiveAudio: true,
offerToReceiveVideo: true
});
await pc.setLocalDescription(offer);
// Send offer to remote peer, then create answer
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
} catch (error) {
console.error('Offer/Answer creation failed:', error);
}
}Firefox-specific getUserMedia compatibility shim.
/**
* Shims getUserMedia for Firefox browsers
* Provides consistent media access API
* @param window - Browser window object
* @param browserDetails - Browser detection information
*/
function shimGetUserMedia(window: Window, browserDetails: IBrowserDetails): void;What it fixes:
Firefox-specific getDisplayMedia compatibility shim.
/**
* Shims getDisplayMedia for Firefox browsers
* Provides screen sharing compatibility
* @param window - Browser window object
* @param preferredMediaSource - Preferred screen capture source
*/
function shimGetDisplayMedia(window: Window, preferredMediaSource: string): void;What it fixes:
Usage Examples:
import adapter from 'webrtc-adapter';
// Screen sharing (automatically shimmed)
async function shareScreen() {
try {
const stream = await navigator.mediaDevices.getDisplayMedia({
video: true,
audio: true
});
console.log('Screen sharing started');
return stream;
} catch (error) {
console.error('Screen sharing failed:', error);
}
}All Firefox-specific shims are available through the browser shim interface:
interface IFirefoxShim {
shimOnTrack: (window: Window) => void;
shimPeerConnection: (window: Window, browserDetails: IBrowserDetails) => void;
shimSenderGetStats: (window: Window) => void;
shimReceiverGetStats: (window: Window) => void;
shimRemoveStream: (window: Window) => void;
shimRTCDataChannel: (window: Window) => void;
shimAddTransceiver: (window: Window) => void;
shimGetParameters: (window: Window) => void;
shimCreateOffer: (window: Window) => void;
shimCreateAnswer: (window: Window) => void;
shimGetUserMedia: (window: Window, browserDetails: IBrowserDetails) => void;
shimGetDisplayMedia: (window: Window, preferredMediaSource: string) => void;
}These shims are automatically applied when Firefox is detected and can be accessed via adapter.browserShim when the current browser is Firefox.
Install with Tessl CLI
npx tessl i tessl/npm-webrtc-adapterdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10