我正在开发一个屏幕共享应用程序,下面的代码捕获了displayMediaStream并尝试与其他浏览器中的其他同伴共享它。
下面是我的代码:
async function startCapture(displayMediaOptions) {
let captureStream = null;
try {
captureStream = await navigator.mediaDevices.getDisplayMedia({audio: false, video: true });
} catch (err) {
console.error("Error: " + err);
}
return captureStream;
}
function shareScreen() {
startCapture().then((stream) => {
if (stream) {
stream.oninactive = () => { // Click on browser UI stop sharing button
shareVideoRef.current.srcObject = null;
};
socketRef.current.emit("screen share send", stream);
}
});
}
//Inside my server.js
...
socket.on("screen share send", payload => {
io.emit('screen share listen', payload);
});
...
//内部client.js ....
socketRef.current.on("screen share listen", (stream) => {
//Here im getting the stream as blannk
});
...
我的应用程序正在使用 simple-peer , socket.io , express