因此,我正在使用webrtc、socketio和peerjs创建一个基于web的视频聊天应用程序。但是当一个用户离开时,其余的用户仍然可以看到断开连接的用户的冻结视频元素。我怀疑这是因为peer.on(“close”,())没有被解雇。
const connectToNewUser = (userId, stream) => {
const call = peer.call(userId, stream) //calls new user and sends them our stream
const video = document.createElement('video') //creates new video element for new user
call.on('stream', userVideoStream => {
addVideoStream(video, userVideoStream) //sends new user our stream
})
call.on('close', function(){
console.log('check')
video.remove();
delete videoGrid[userId];
})
peers[userId] = call;
}
const addVideoStream = (video, stream) => {
video.srcObject = stream
video.addEventListener('loadedmetadata', () => {
video.play();
})
videoGrid.append(video);
}
我还怀疑这可能是因为我必须从视频网格中删除视频元素?但是我不知道如果我的同龄人没有被炒鱿鱼,我怎么能做到这一点。
socket.on("user-disconnected", (userId) => {
//message in chat saying x user disconnected
console.log("New User Disconnected");
if (peers[userId]) peers[userId].close();
});
另外,我在某个地方看到,我应该尝试从“用户断开连接”部分删除视频元素,但既然它不理解视频元素是什么,那该如何工作呢?
暂无答案!
目前还没有任何答案,快来回答吧!