shinyoshiaki / werift-webrtc

WebRTC Implementation for TypeScript (Node.js), includes ICE/DTLS/SCTP/RTP/SRTP/WEBM/MP4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Probable Bug with SDP building in RTCPeerConnection createAnswer()

benharp opened this issue · comments

Hello, and thank you for this great WebRTC implementation! It has been very useful, and great for learning.

I'm building a werift server that communicates media to and from a Chrome browser, and getting the following error in Chrome:

DOMException: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: A BUNDLE group in answer contains a MID='2av' that was not in the offered group.

This seems to only happen when werift has an "inactive" transceiver in its list and receives an offer from the Chrome side. (I have inactive transceivers after adding and later removing tracks on the werift side, and Chrome sends an offer when I add a track from the Chrome side.)

Looking closer at the offer and answer SDP provided, Chrome includes only active transceivers in the bundle group for its offer, but werift's answer includes all transceivers, active or inactive, and Chrome throws a fit.

Chrome's offer: a=group:BUNDLE 0av 0
werift's answer: a=group:BUNDLE 0av 0 2av

I'm assuming this is unintended, as looking at the code, peerConnection's createOffer() does correctly filter inactive transceivers out of the SDP offer, but peerConnection's createAnswer() doesn't.

Working correctly:

const mids = description.media
.map((m) => (m.direction !== "inactive" ? m.rtp.muxId : undefined))
.filter((v) => v) as string[];
if (mids.length) {
const bundle = new GroupDescription("BUNDLE", mids);
description.group.push(bundle);

vs working incorrectly:
bundle.items.push(media.rtp.muxId!);

If this should be fixed, I'm happy to try my hand at a pull request, but I figured I'd ask first as I'm still new to werift, WebRTC, and Open Source in general.
If this is intended, or shouldn't be happening in the first place, I'd be grateful for any other advice on why this might be happening. Thank you.

I will investigate later.

I'm happy to try my hand at a pull request, but I figured I'd ask first as I'm still new to werift, WebRTC, and Open Source in general.

If you have code that reproduces the problem and patches to fix it, you can send a PullRequest directly.