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-7/

WebRTC Session Description Handler

Build a helper module that simplifies WebRTC session description management during the offer-answer exchange process.

Requirements

Your implementation should provide a function that:

  1. Creates a WebRTC offer from a peer connection and sets it as the local description
  2. Returns the offer SDP string to send to the remote peer
  3. Accepts an answer from the remote peer as a plain object with type and sdp properties
  4. Sets the received answer as the remote description

The function should leverage modern WebRTC APIs to simplify session description handling.

Implementation

@generates

API

/**
 * Creates an offer and handles the answer for a WebRTC peer connection.
 *
 * @param {RTCPeerConnection} pc - The peer connection to negotiate
 * @param {Object} answerData - The answer from remote peer as plain object with type and sdp
 * @returns {Promise<string>} The offer SDP string to send to remote peer
 */
async function createAndExchangeOffer(pc, answerData) {
  // IMPLEMENTATION HERE
}

module.exports = { createAndExchangeOffer };

Test Cases

  • Given a peer connection in stable state, creates an offer and returns the SDP string @test
  • Given a peer connection and answer data as plain object {type: 'answer', sdp: '...'}, successfully sets both local and remote descriptions @test
  • The function completes the full offer-answer exchange without requiring manual RTCSessionDescription construction @test

Dependencies { .dependencies }

webrtc-adapter { .dependency }

Provides cross-browser WebRTC compatibility and session description handling.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-webrtc-adapter

tile.json