如何使用PeerJS添加屏幕共享功能



目前,我正在进行一个webRTC项目,您可以在该项目中拨打电话和接听电话。我还想为其添加屏幕共享功能。

有人能给我一个好的文档链接吗?我目前正在关注peerJS的官方文档。我可以进行音频-视频通话,但一直停留在屏幕共享部分。帮帮我!

您需要像使用getUserMedia一样获取流,然后将该流提供给PeerJS。

应该是这样的:

var displayMediaOptions = {
video: {
cursor: "always"
},
audio: false
};
navigator.mediaDevices.getDisplayMedia(displayMediaOptions)
.then(function (stream) {
// add this stream to your peer 
});

我正在与WebRTC合作并了解它。根据我所读到的内容,我认为这里的解决方案可能取决于getDisplayMedia。这也是React、Node和peerJS教程的建议(尽管我自己还没有尝试过(。

let screenShare = document.getElementById('shareScreen');
screenShare.addEventListener('click', async () => {
captureStream = await navigator.mediaDevices.getDisplayMedia({
audio: true,
video: { mediaSource: "screen" }
});
//Instead of adminId, pass peerId who will taking captureStream in call
myPeer.call(adminId, captureStream);
})

最新更新