maybe this fixes the poor audio idk loool

This commit is contained in:
2026-02-23 04:11:46 +01:00
parent 56e59a5e2b
commit 831d76c10e

View File

@@ -23,12 +23,12 @@ socket.on('offer', (id, description) => {
overlay.classList.add('hidden');
};
// Auto-unmute when the user interacts with the document to bypass browser// Auto-unmute when the user interacts with the document to bypass browser
document.addEventListener('click', () => {
// Auto-unmute when the user interacts with the document to bypass browser autoplay restrictions
document.addEventListener('click', () => {
remoteVideo.muted = false;
// Set sink to max possible volume explicitly avoiding browser gain staging
remoteVideo.volume = 1.0;
}, {once: true});
}, {once: true});
peerConnection.onicecandidate = event => {
if (event.candidate) {
@@ -39,7 +39,30 @@ document.addEventListener('click', () => {
peerConnection
.setRemoteDescription(description)
.then(() => peerConnection.createAnswer())
.then(sdp => peerConnection.setLocalDescription(sdp))
.then(sdp => {
let sdpLines = sdp.sdp.split('\r\n');
let opusPayloadType = null;
for (let i = 0; i < sdpLines.length; i++) {
if (sdpLines[i].includes('a=rtpmap:') && sdpLines[i].includes('opus/48000/2')) {
const match = sdpLines[i].match(/a=rtpmap:(\d+) /);
if (match) opusPayloadType = match[1];
}
}
if (opusPayloadType) {
let fmtpFound = false;
for (let i = 0; i < sdpLines.length; i++) {
if (sdpLines[i].startsWith(`a=fmtp:${opusPayloadType}`)) {
sdpLines[i] = `a=fmtp:${opusPayloadType} minptime=10;useinbandfec=1;maxplaybackrate=48000;stereo=1;sprop-stereo=1;maxaveragebitrate=510000;cbr=1`;
fmtpFound = true;
}
}
if (!fmtpFound) {
sdpLines.push(`a=fmtp:${opusPayloadType} minptime=10;useinbandfec=1;maxplaybackrate=48000;stereo=1;sprop-stereo=1;maxaveragebitrate=510000;cbr=1`);
}
}
sdp.sdp = sdpLines.join('\r\n');
return peerConnection.setLocalDescription(sdp);
})
.then(() => {
socket.emit('answer', id, peerConnection.localDescription);
});