A shim to insulate apps from WebRTC spec changes and browser prefix differences
Overall
score
98%
Build a utility library that helps implement the "perfect negotiation" pattern for WebRTC peer connections in a cross-browser compatible way. Perfect negotiation is a design pattern that allows two peers to negotiate connection details symmetrically, without explicitly designating one peer as "caller" and the other as "callee".
In WebRTC, the negotiationneeded event fires when the peer connection needs to renegotiate (e.g., when adding/removing tracks). However, certain browser implementations have timing issues where spurious negotiationneeded events can fire during the middle of an ongoing offer/answer exchange, which can cause negotiation to fail or enter an unstable state.
A robust implementation should only act on negotiationneeded events when the connection is in a stable state and ready for negotiation.
Your library should provide a utility function that wraps a RTCPeerConnection instance to ensure reliable negotiation event handling. Specifically:
RTCPeerConnection instance as inputnegotiationneeded events that fire during ongoing offer/answer exchanges are properly handled or suppressed@generates
/**
* Sets up reliable negotiation handling for a peer connection.
* Ensures negotiation only proceeds when the connection is in a stable state.
*
* @param {RTCPeerConnection} pc - The peer connection to wrap
* @param {Function} onNegotiationNeeded - Callback to invoke when negotiation is safe
* @returns {void}
*/
function setupReliableNegotiation(pc, onNegotiationNeeded) {
// IMPLEMENTATION HERE
}
module.exports = {
setupReliableNegotiation
};Provides cross-browser compatibility for WebRTC APIs
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