CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-webrtc-adapter

A shim to insulate apps from WebRTC spec changes and browser prefix differences

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-10/

WebRTC Connection State Monitor

Build a connection state monitoring utility that tracks the overall connection state of WebRTC peer connections and notifies listeners of state changes.

Requirements

Your utility should:

  1. Track the overall connection state of a peer connection
  2. Notify registered listeners when the connection state changes
  3. Support the following connection states: new, connecting, connected, disconnected, failed, closed
  4. Derive the connection state from the ICE connection state when the native connectionState property is not available
  5. Ensure state change notifications are only sent when the state actually changes (no duplicate notifications for the same state)

State Mapping Rules

When deriving connection state from ICE connection state, apply these mappings:

  • ICE state completed → connection state connected
  • ICE state checking → connection state connecting
  • All other ICE states map to the same connection state name

Expected Behavior

  • Monitor the peer connection for state changes
  • Map ICE connection state to connection state according to the rules above
  • Track the last known state to avoid duplicate notifications
  • Dispatch notifications to registered listeners when the state changes

Test Cases

  • When ICE connection state transitions from new to checking, listeners are notified with connection state connecting @test
  • When ICE connection state transitions to completed, listeners are notified with connection state connected @test
  • When ICE connection state transitions to failed, listeners are notified with connection state failed @test
  • When the connection state remains unchanged across multiple ICE state updates, listeners are not notified repeatedly @test

Implementation

@generates

API

/**
 * Creates a connection state monitor for a peer connection.
 *
 * @param {RTCPeerConnection} peerConnection - The peer connection to monitor
 * @param {Function} onStateChange - Callback invoked when connection state changes, receives new state as string
 * @returns {Object} Monitor object with a cleanup method
 */
function createConnectionStateMonitor(peerConnection, onStateChange) {
  // Implementation
}

module.exports = {
  createConnectionStateMonitor
};

Dependencies { .dependencies }

webrtc-adapter { .dependency }

Provides cross-browser compatibility for WebRTC APIs including connection state normalization.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-webrtc-adapter

tile.json