Closed dotnethii closed 3 years ago
Maybe it is coming soon, I am trying to add it
For screen sharing, small help 😉
screenShareButt.addEventListener('click', () => {
screenShareToggle();
});
let screenshareEnabled = false;
function screenShareToggle() {
let screenMediaPromise;
if (!screenshareEnabled) {
if (navigator.getDisplayMedia) {
screenMediaPromise = navigator.getDisplayMedia({ video: true });
} else if (navigator.mediaDevices.getDisplayMedia) {
screenMediaPromise = navigator.mediaDevices.getDisplayMedia({ video: true });
} else {
screenMediaPromise = navigator.mediaDevices.getUserMedia({
video: { mediaSource: "screen" },
});
}
} else {
screenMediaPromise = navigator.mediaDevices.getUserMedia({ video: true });
}
screenMediaPromise
.then((myscreenshare) => {
screenshareEnabled = !screenshareEnabled;
for (let key in connections) {
const sender = connections[key]
.getSenders()
.find((s) => (s.track ? s.track.kind === "video" : false));
sender.replaceTrack(myscreenshare.getVideoTracks()[0]);
}
myscreenshare.getVideoTracks()[0].enabled = true;
const newStream = new MediaStream([
myscreenshare.getVideoTracks()[0],
]);
myvideo.srcObject = newStream;
myvideo.muted = true;
mystream = newStream;
screenShareButt.innerHTML = (screenshareEnabled
? `<i class="fas fa-desktop"></i><span class="tooltiptext">Stop Share Screen</span>`
: `<i class="fas fa-desktop"></i><span class="tooltiptext">Share Screen</span>`
);
myscreenshare.getVideoTracks()[0].onended = function() {
if (screenshareEnabled) screenShareToggle();
};
})
.catch((e) => {
alert("Unable to share screen:" + e.message);
console.error(e);
});
}
Epic @miroslavpejic85
Added, thanks to @miroslavpejic85
U welcome 😉
please add screen share and file share