I recently tried adding screen share functionality to my app, but encountered an issue. The screen share feature only seems to work on my end and not the other user's. Here is the code snippet I used:
try {
navigator.mediaDevices
.getDisplayMedia({
video: true,
audio: true
})
.then((stream) => {
const videoElement = document.createElement("video");
videoElement.controls = true;
addVideoStream(videoElement, stream);
socket.on("user-connected", (userId) => {
const call = peer.call(userId, stream);
stream.getVideoTracks()[0].addEventListener("ended", () => {
videoElement.remove();
});
call.on("close", () => {});
});
stream.getVideoTracks()[0].addEventListener("ended", () => {
videoElement.remove();
});
});
} catch (error) {
console.log("Error: " + error);
}