fix screensharing chrome

This commit is contained in:
murdle 2025-12-14 00:47:59 +02:00
parent 6e727e26d7
commit 81291213bf

View File

@ -64,4 +64,51 @@ function addFingerprintToSdp(sdp) {
}
return result.join("\n");
}
if (window.location.pathname.startsWith("/channel")) {
const observer = new MutationObserver(() => {
const screenshareButton = document.querySelector('[aria-label="Share your screen"]');
if (screenshareButton) {
screenshareButton.addEventListener("click", async () => {
try {
const displayStream = await navigator.mediaDevices.getDisplayMedia({
video: {
width: { ideal: 1920 },
height: { ideal: 1080 },
frameRate: { ideal: 30 }
},
audio: false
});
const audioStream = await navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: { ideal: true },
autoGainControl: { ideal: true },
noiseSuppression: { ideal: true }
}
});
const combinedStream = new MediaStream();
displayStream.getVideoTracks().forEach(track => {
combinedStream.addTrack(track);
});
audioStream.getAudioTracks().forEach(track => {
combinedStream.addTrack(track);
});
displayStream.getVideoTracks()[0].onended = () => {
audioStream.getTracks().forEach(track => track.stop());
};
} catch (error) {
console.error("Screenshare failed:", error);
}
}, { once: true });
observer.disconnect();
}
});
observer.observe(document.body, { childList: true, subtree: true });
}