RTCPeerConnection Shim for ORTC
raw JSON → 1.2.15 verified Sat Apr 25 auth: no javascript maintenance
The rtcpeerconnection-shim package (v1.2.15) is a JavaScript library that provides a polyfill/shim implementing the W3C RTCPeerConnection API on top of the ORTC (Object RTC) API, which is used by Microsoft Edge (pre-Chromium). It allows developers to use the standard WebRTC RTCPeerConnection interface in environments that only support ORTC. The project is in maintenance mode, with its last release in 2018. It offers a compatibility layer, but it is limited compared to native WebRTC support. Key differentiator: it enables RTCPeerConnection in legacy Edge; however, it is no longer needed in modern browsers and has subtle API differences.
Common errors
error TypeError: Cannot read property 'createOffer' of null ↓
cause RTCPeerConnection not properly initialized or underlying ORTC not available.
fix
Ensure the shim is loaded before creating any connections: import the module at the entry point of your app.
error Failed to set local offer sdp: Called in wrong state: kStable ↓
cause Attempting to call setLocalDescription multiple times without proper signaling state management.
fix
Check the signaling state (pc.signalingState) before setting descriptions. Typical flow: createOffer -> setLocalDescription -> wait for answer.
error ReferenceError: RTCPeerConnection is not defined ↓
cause The shim was not imported or loaded before use, or environment doesn't support the shim.
fix
Import 'rtcpeerconnection-shim' at the top of your script. For Node.js, ensure it's bundled correctly.
Warnings
breaking The peerconnection may behave differently than native WebRTC, e.g., no support for unified plan or some SDP attributes. ↓
fix Test extensively on target browsers; consider using adapter.js for cross-browser support.
deprecated This shim is no longer needed for Edge Chromium (2020+). Modern Edge uses Chromium with native WebRTC. ↓
fix Remove this dependency if targeting only modern browsers; use standard WebRTC API directly.
gotcha The RTCIceCandidate constructor may not accept strings like in standard WebRTC; use object format. ↓
fix Use `new RTCIceCandidate({ candidate: 'candidate string' })` instead of passing a string directly.
Install
npm install rtcpeerconnection-shim yarn add rtcpeerconnection-shim pnpm add rtcpeerconnection-shim Imports
- RTCPeerConnection wrong
const RTCPeerConnection = require('rtcpeerconnection-shim')correctimport { RTCPeerConnection } from 'rtcpeerconnection-shim' - RTCSessionDescription wrong
import RTCSessionDescription from 'rtcpeerconnection-shim'correctimport { RTCSessionDescription } from 'rtcpeerconnection-shim' - RTCIceCandidate
import { RTCIceCandidate } from 'rtcpeerconnection-shim'
Quickstart
import { RTCPeerConnection, RTCSessionDescription, RTCIceCandidate } from 'rtcpeerconnection-shim';
const pc = new RTCPeerConnection({
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
});
pc.onicecandidate = (e) => {
if (e.candidate) {
console.log('ICE candidate:', e.candidate.candidate);
}
};
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then((stream) => {
stream.getTracks().forEach((track) => pc.addTrack(track, stream));
return pc.createOffer();
})
.then((offer) => pc.setLocalDescription(offer))
.catch((err) => console.error(err));