I have created an app with a live conversation module in javascript. I am using WebRTC to set up the Peer connection. Signaling and candidates all seem to work correctly. The peers are not on the same network.
At some point, the audio starts to add clicks to the stream. The quality starts to fail quite fast.
I have tried to reduce bitrates but to no avail. The code to reduce bitrate looks like this:
function setMediaBitrates(sdp, videoRate = 250, audioRate = 50) {
let f = navigator.userAgent.search("Firefox");
let modifier = 'AS';
// if (f > -1) {
// videoRate = (videoRate >>> 0) * 1000;
// audioRate = (audioRate >>> 0) * 1000;
// modifier = 'TIAS';
// }
//find the correct m lines (video and audio)
var lines = sdp.sdp.split("\n");
let i = 0;
while (i < lines.length) {
//if we find an m-line
if (lines[i].indexOf("m=") === 0) {
let video = lines[i].indexOf("m=video") === 0;
let audio = lines[i].indexOf("m=audio") === 0;
if (video || audio) {
while(i < lines.length && (lines[i].indexOf("i=") === 0 || lines[i].indexOf("c=") === 0)) {
i++;
}
// If we're on a b line, replace it
if (i < lines.length && lines[i].indexOf("b") === 0) {
lines[i] = `b=${modifier}:${video ? videoRate : audioRate}`;
} else if (i == lines.length) {
lines.push(`b=${modifier}:${video ? videoRate : audioRate}`);
i++;
} else {
i++;
lines.splice(i, 0, `b=${modifier}:${video ? videoRate : audioRate}`);
}
}
}
i++;
}
let s = lines.join("\n");
return { type : sdp.type, sdp : s };
}
With rate limiting, I have about 15 minutes of good audio, and after that static starts to appear.
I am starting the peer connection using the following ReactJS code:
pc
.createOffer({ offerToReceiveVideo : useVideo ? 1 : 0 })
.then(sdp => {
pc.setLocalDescription(sdp);
let newSdp = setMediaBitrates(sdp);
dispatch(sendWebRTCSdp(activeConversationId, newSdp));
})
.catch(e => {});