我想通过调用在我的主选项卡中启动屏幕共享getDisplayMedia
,然后将其克隆到我从我的应用程序(使用window.open
)打开的另一个弹出窗口,有效地同时显示两次屏幕截图。
async function startCapture() {
return await navigator.mediaDevices.getDisplayMedia();
}
function openPopup() {
startCapture().then((stream) => {
let video = document.getElementById("source");
video.srcObject = stream;
let popUpWindow = window.open("", "_blank", "x=y");
let videoElem = document.createElement("video");
videoElem.autoplay = true;
let remoteVideo = popUpWindow.document.body.appendChild(videoElem);
remoteVideo.srcObject = stream;
});
}
我错过了什么?