Skip to content

Commit

Permalink
webrtc: detect stereo tracks published with the web page (#2902)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Apr 17, 2024
1 parent 9e718f9 commit 203f79b
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions internal/servers/webrtc/publish_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,13 @@
}

const lines3 = [];
let firstLine = true;

for (const line of lines2) {
if (line.startsWith('a=fmtp:')) {
if (firstLine) {
firstLine = false;
lines3.push(line.split(' ').slice(0, 3).concat(payloadFormats).join(' '));
} else if (line.startsWith('a=fmtp:')) {
if (payloadFormats.includes(line.slice('a=fmtp:'.length).split(' ')[0])) {
lines3.push(line);
}
Expand Down Expand Up @@ -368,15 +372,28 @@
return lines.join('\r\n');
};

const editAnswer = (sdp, videoCodec, audioCodec, videoBitrate, audioBitrate, audioVoice) => {
const editOffer = (sdp) => {
const sections = sdp.split('m=');

for (let i = 0; i < sections.length; i++) {
const section = sections[i];
if (section.startsWith('video')) {
sections[i] = setVideoBitrate(setCodec(section, videoCodec), videoBitrate);
sections[i] = setCodec(section, videoForm.codec.value);
} else if (section.startsWith('audio')) {
sections[i] = setAudioBitrate(setCodec(section, audioCodec), audioBitrate, audioVoice);
sections[i] = setAudioBitrate(setCodec(section, audioForm.codec.value), audioForm.bitrate.value, audioForm.voice.checked);
}
}

return sections.join('m=');
};

const editAnswer = (sdp) => {
const sections = sdp.split('m=');

for (let i = 0; i < sections.length; i++) {
const section = sections[i];
if (section.startsWith('video')) {
sections[i] = setVideoBitrate(section, videoForm.bitrate.value);
}
}

Expand Down Expand Up @@ -421,14 +438,7 @@
return;
}

sdp = editAnswer(
sdp,
videoForm.codec.value,
audioForm.codec.value,
videoForm.bitrate.value,
audioForm.bitrate.value,
audioForm.voice.checked,
);
sdp = editAnswer(sdp);

pc.setRemoteDescription(new RTCSessionDescription({
type: 'answer',
Expand All @@ -442,12 +452,14 @@
};

const sendOffer = (offer) => {
offer = editOffer(offer);

fetch(new URL('whip', window.location.href) + window.location.search, {
method: 'POST',
headers: {
'Content-Type': 'application/sdp',
},
body: offer.sdp,
body: offer,
})
.then((res) => {
if (res.status !== 201) {
Expand All @@ -456,7 +468,7 @@
sessionUrl = new URL(res.headers.get('location'), window.location.href).toString();
return res.text();
})
.then((sdp) => onRemoteAnswer(sdp))
.then((answer) => onRemoteAnswer(answer))
.catch((err) => {
onError(err.toString(), true);
});
Expand All @@ -467,7 +479,7 @@
.then((offer) => {
offerData = parseOffer(offer.sdp);
pc.setLocalDescription(offer);
sendOffer(offer);
sendOffer(offer.sdp);
});
};

Expand Down

0 comments on commit 203f79b

Please sign in to comment.