嘿,我正在使用peerjs创建视频聊天,但是出现了此错误:
我遵循了教程,并根据它并使用Modern API编写了所有内容,但是无论如何,这是我的代码
function openStream(){
const config = {video: true, audio: true};
return navigator.mediaDevices.getUserMedia(config)
}
function playStream(id,stream){
const video = document.getElementById(id);
video.srcObject = stream;
video.play()
}
const peer = new Peer({key: 'lwjd5qra8257b9'})
peer.on('open', (id)=>{
console.log(id)
$('#myid').append(id)
})
$('button').click(() => {
const id = $('#remoteid').val();
openStream()
.then(stream => {
playStream('localVideo', stream);
const call = peer.call(id, stream);
call.on('stream', remoteStream => playStream('remoteVideo',
remoteStream));
});
});
//Callee
peer.on('call', call => {
openStream()
.then(stream => {
call.answer(stream);
playStream('localVideo', stream);
call.on('stream', remoteStream => playStream('remoteVideo',
remoteStream));
});
那怎么了?有帮助吗?谢谢! });