0
# Firefox Shims
1
2
Firefox-specific shims handle compatibility issues and behavioral differences in Firefox browsers to ensure consistent WebRTC behavior across all supported platforms.
3
4
## Capabilities
5
6
### OnTrack Event Shimming
7
8
Provides consistent ontrack event handling for RTCPeerConnection in Firefox.
9
10
```javascript { .api }
11
/**
12
* Shims ontrack event for Firefox browsers
13
* Ensures proper track event handling and timing
14
* @param window - Browser window object
15
*/
16
function shimOnTrack(window: Window): void;
17
```
18
19
**What it fixes:**
20
- Standardizes track event structure and properties
21
- Ensures proper event timing during remote stream addition
22
- Provides consistent transceiver and receiver information
23
24
### Peer Connection Shimming
25
26
Main Firefox RTCPeerConnection compatibility shim.
27
28
```javascript { .api }
29
/**
30
* Main Firefox RTCPeerConnection shim
31
* Applies comprehensive Firefox-specific fixes
32
* @param window - Browser window object
33
* @param browserDetails - Browser detection information
34
*/
35
function shimPeerConnection(window: Window, browserDetails: IBrowserDetails): void;
36
```
37
38
**What it fixes:**
39
- Standardizes RTCPeerConnection constructor behavior
40
- Normalizes offer/answer creation and handling
41
- Ensures consistent ICE candidate processing
42
- Provides uniform configuration option handling
43
44
### Sender GetStats Shimming
45
46
Normalizes RTCRtpSender.getStats() method for Firefox.
47
48
```javascript { .api }
49
/**
50
* Shims RTCRtpSender getStats method for Firefox
51
* Provides consistent sender statistics API
52
* @param window - Browser window object
53
*/
54
function shimSenderGetStats(window: Window): void;
55
```
56
57
**What it fixes:**
58
- Standardizes sender statistics format and structure
59
- Ensures consistent outbound RTP statistics
60
- Provides uniform track-based statistics filtering
61
62
**Usage Examples:**
63
64
```javascript
65
import adapter from 'webrtc-adapter';
66
67
const pc = new RTCPeerConnection();
68
69
// Get sender statistics (automatically shimmed)
70
pc.getSenders().forEach(async (sender) => {
71
if (sender.track) {
72
const stats = await sender.getStats();
73
stats.forEach((report) => {
74
if (report.type === 'outbound-rtp') {
75
console.log('Bytes sent:', report.bytesSent);
76
console.log('Packets sent:', report.packetsSent);
77
console.log('Bandwidth:', report.bytesReceived);
78
}
79
});
80
}
81
});
82
```
83
84
### Receiver GetStats Shimming
85
86
Normalizes RTCRtpReceiver.getStats() method for Firefox.
87
88
```javascript { .api }
89
/**
90
* Shims RTCRtpReceiver getStats method for Firefox
91
* Provides consistent receiver statistics API
92
* @param window - Browser window object
93
*/
94
function shimReceiverGetStats(window: Window): void;
95
```
96
97
**What it fixes:**
98
- Standardizes receiver statistics format and structure
99
- Ensures consistent inbound RTP statistics
100
- Provides uniform remote track statistics
101
102
**Usage Examples:**
103
104
```javascript
105
import adapter from 'webrtc-adapter';
106
107
const pc = new RTCPeerConnection();
108
109
// Get receiver statistics (automatically shimmed)
110
pc.getReceivers().forEach(async (receiver) => {
111
if (receiver.track) {
112
const stats = await receiver.getStats();
113
stats.forEach((report) => {
114
if (report.type === 'inbound-rtp') {
115
console.log('Bytes received:', report.bytesReceived);
116
console.log('Packets received:', report.packetsReceived);
117
console.log('Jitter:', report.jitter);
118
}
119
});
120
}
121
});
122
```
123
124
### Remove Stream Shimming
125
126
Provides removeStream() method compatibility for Firefox.
127
128
```javascript { .api }
129
/**
130
* Shims removeStream method for Firefox
131
* Provides legacy stream removal API compatibility
132
* @param window - Browser window object
133
*/
134
function shimRemoveStream(window: Window): void;
135
```
136
137
**What it fixes:**
138
- Adds legacy removeStream() method support
139
- Handles stream removal with proper cleanup
140
- Maintains compatibility with older WebRTC code
141
142
**Usage Examples:**
143
144
```javascript
145
import adapter from 'webrtc-adapter';
146
147
const pc = new RTCPeerConnection();
148
149
// Legacy stream removal (automatically shimmed)
150
function removeLocalStream(stream) {
151
if (pc.removeStream) {
152
pc.removeStream(stream);
153
} else {
154
// Fallback to modern track removal
155
stream.getTracks().forEach(track => {
156
const sender = pc.getSenders().find(s => s.track === track);
157
if (sender) {
158
pc.removeTrack(sender);
159
}
160
});
161
}
162
}
163
```
164
165
### RTCDataChannel Shimming
166
167
Provides RTCDataChannel compatibility fixes for Firefox.
168
169
```javascript { .api }
170
/**
171
* Shims RTCDataChannel API for Firefox
172
* Ensures consistent data channel behavior
173
* @param window - Browser window object
174
*/
175
function shimRTCDataChannel(window: Window): void;
176
```
177
178
**What it fixes:**
179
- Standardizes data channel creation and configuration
180
- Normalizes data channel state transitions
181
- Ensures consistent message handling
182
183
### Add Transceiver Shimming
184
185
Provides addTransceiver() method compatibility for Firefox.
186
187
```javascript { .api }
188
/**
189
* Shims addTransceiver method for Firefox
190
* Provides consistent transceiver creation API
191
* @param window - Browser window object
192
*/
193
function shimAddTransceiver(window: Window): void;
194
```
195
196
**What it fixes:**
197
- Adds missing addTransceiver() method support
198
- Handles transceiver creation with proper configuration
199
- Provides unified send/receive control
200
201
**Usage Examples:**
202
203
```javascript
204
import adapter from 'webrtc-adapter';
205
206
const pc = new RTCPeerConnection();
207
208
// Add transceiver (automatically shimmed)
209
const transceiver = pc.addTransceiver('video', {
210
direction: 'sendrecv',
211
streams: [localStream]
212
});
213
214
console.log('Created transceiver:', transceiver.mid);
215
console.log('Direction:', transceiver.direction);
216
```
217
218
### Get Parameters Shimming
219
220
Shims getParameters() method for RTCRtpSender in Firefox.
221
222
```javascript { .api }
223
/**
224
* Shims getParameters method for Firefox
225
* Provides consistent sender parameter access
226
* @param window - Browser window object
227
*/
228
function shimGetParameters(window: Window): void;
229
```
230
231
**What it fixes:**
232
- Adds missing getParameters() method functionality
233
- Provides encoding parameter access
234
- Ensures consistent parameter structure
235
236
### Create Offer Shimming
237
238
Normalizes createOffer() method behavior for Firefox.
239
240
```javascript { .api }
241
/**
242
* Shims createOffer method for Firefox
243
* Ensures consistent offer creation behavior
244
* @param window - Browser window object
245
*/
246
function shimCreateOffer(window: Window): void;
247
```
248
249
**What it fixes:**
250
- Standardizes offer creation options handling
251
- Normalizes SDP generation behavior
252
- Ensures consistent codec preferences
253
254
### Create Answer Shimming
255
256
Normalizes createAnswer() method behavior for Firefox.
257
258
```javascript { .api }
259
/**
260
* Shims createAnswer method for Firefox
261
* Ensures consistent answer creation behavior
262
* @param window - Browser window object
263
*/
264
function shimCreateAnswer(window: Window): void;
265
```
266
267
**What it fixes:**
268
- Standardizes answer creation options handling
269
- Normalizes answer SDP generation
270
- Ensures proper codec negotiation
271
272
**Usage Examples:**
273
274
```javascript
275
import adapter from 'webrtc-adapter';
276
277
const pc = new RTCPeerConnection();
278
279
// Create offer/answer (automatically shimmed)
280
async function createOfferAnswer() {
281
try {
282
const offer = await pc.createOffer({
283
offerToReceiveAudio: true,
284
offerToReceiveVideo: true
285
});
286
287
await pc.setLocalDescription(offer);
288
289
// Send offer to remote peer, then create answer
290
const answer = await pc.createAnswer();
291
await pc.setLocalDescription(answer);
292
293
} catch (error) {
294
console.error('Offer/Answer creation failed:', error);
295
}
296
}
297
```
298
299
### GetUserMedia Shimming
300
301
Firefox-specific getUserMedia compatibility shim.
302
303
```javascript { .api }
304
/**
305
* Shims getUserMedia for Firefox browsers
306
* Provides consistent media access API
307
* @param window - Browser window object
308
* @param browserDetails - Browser detection information
309
*/
310
function shimGetUserMedia(window: Window, browserDetails: IBrowserDetails): void;
311
```
312
313
**What it fixes:**
314
- Standardizes getUserMedia constraints handling
315
- Normalizes device selection and permissions
316
- Provides consistent error handling patterns
317
318
### GetDisplayMedia Shimming
319
320
Firefox-specific getDisplayMedia compatibility shim.
321
322
```javascript { .api }
323
/**
324
* Shims getDisplayMedia for Firefox browsers
325
* Provides screen sharing compatibility
326
* @param window - Browser window object
327
* @param preferredMediaSource - Preferred screen capture source
328
*/
329
function shimGetDisplayMedia(window: Window, preferredMediaSource: string): void;
330
```
331
332
**What it fixes:**
333
- Adds missing getDisplayMedia() functionality
334
- Provides screen sharing capability
335
- Handles display source selection
336
337
**Usage Examples:**
338
339
```javascript
340
import adapter from 'webrtc-adapter';
341
342
// Screen sharing (automatically shimmed)
343
async function shareScreen() {
344
try {
345
const stream = await navigator.mediaDevices.getDisplayMedia({
346
video: true,
347
audio: true
348
});
349
350
console.log('Screen sharing started');
351
return stream;
352
353
} catch (error) {
354
console.error('Screen sharing failed:', error);
355
}
356
}
357
```
358
359
## Firefox Shim Interface
360
361
All Firefox-specific shims are available through the browser shim interface:
362
363
```javascript { .api }
364
interface IFirefoxShim {
365
shimOnTrack: (window: Window) => void;
366
shimPeerConnection: (window: Window, browserDetails: IBrowserDetails) => void;
367
shimSenderGetStats: (window: Window) => void;
368
shimReceiverGetStats: (window: Window) => void;
369
shimRemoveStream: (window: Window) => void;
370
shimRTCDataChannel: (window: Window) => void;
371
shimAddTransceiver: (window: Window) => void;
372
shimGetParameters: (window: Window) => void;
373
shimCreateOffer: (window: Window) => void;
374
shimCreateAnswer: (window: Window) => void;
375
shimGetUserMedia: (window: Window, browserDetails: IBrowserDetails) => void;
376
shimGetDisplayMedia: (window: Window, preferredMediaSource: string) => void;
377
}
378
```
379
380
These shims are automatically applied when Firefox is detected and can be accessed via `adapter.browserShim` when the current browser is Firefox.