fix screensharing chrome
This commit is contained in:
parent
6e727e26d7
commit
81291213bf
@ -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 });
|
||||
}
|
||||
Reference in New Issue
Block a user