gpt4 book ai didi

javascript - Webrtc 如何让 onicecandidate 在我的代码上工作

转载 作者:行者123 更新时间:2023-12-03 00:04:23 25 4
gpt4 key购买 nike

大家好,我对这个 webrtc 和 javascript 很陌生,我尝试完成视频流,但在我的代码中,onicecandidate 从未被调用,有人可以帮助我解决我犯错误的地方

 $('body #call').on('click', function () {
let receiverid = $(this).attr('data-ids');
const peerConnection = new RTCPeerConnection(configuration);
navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
localStream = stream;
localStream.getTracks().forEach((track) => {
peerConnection.addTrack(track, localStream);
localVideo.srcObject = localStream;
});

}).catch(err => console.log(err));
peerConnection.createOffer()
.then(sdp => peerConnection.setLocalDescription(sdp))
.then(function () {
console.log('is emitedd offer');
socket.emit('onOffer', { callerid: userid, receiverid, offer: peerConnection.localDescription });
});
peerConnection.ontrack = event => handleRemoteStreamAdded(event.streams[0], userid);

peerConnection.onicecandidate = function(event) {
if (event.candidate) {
console.log('emit candidate');
socket.emit('candidate', id, event.candidate);
}
};
});
});

非常感谢

最佳答案

好吧,我看到了更好的例子,我的错误是我从视频对象异地调用 peerConnection.createOffer() navigator.mediaDevices.getUserMedia({ video: true }).then( Stream => {//在此处创建报价 }); 他们我的候选人开始发出

关于javascript - Webrtc 如何让 onicecandidate 在我的代码上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55032033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com