【发布时间】:2019-05-26 07:16:32
【问题描述】:
我的 webrtc 网络应用程序永远不会满足 onicecandidate。 当我查看我的本地(Webrtc 对象)对象时,设置了本地描述和远程描述。 在 Firefox 中,它会触发 onicecandidate 但 event.candidate 为空
我尝试了几个小时来解决这个问题,但我无法解决
谁能解决这个问题?
如何让 onicecandidate 事件被触发?
let local = new RTCPeerConnection();
let remote = new RTCPeerConnection();
try {
local.createOffer().then(function(sdp) {
console.log("Offer Created by Local: " + sdp.sdp);
local.setLocalDescription(sdp);
remote.setRemoteDescription(sdp);
remote.createAnswer().then(function(sdp){
console.log("Answer Created by Remote: " + sdp.sdp);
remote.setLocalDescription(sdp);
local.setRemoteDescription(sdp);
local.onicecandidate = localicecandidate;
remote.onicecandidate = remoteicecandidate;
let channel = local.createDataChannel("channel");
channel.onopen = function(event) {
console.log("Channel opened");
}
channel.onmessgae = function(event) {
console.log(event.data);
}
remote.ondatachannel = function(event) {
let channel = event.channel;
channel.onopen = function(event) {
channel.send("Hi!");
}
}
function localicecandidate (event) {
console.log("Local got new Ice Candidate: " + event.candidate);
remote.addIceCandidate(new RTCIceCandidate(event.candidate));
}
function remoteicecandidate (event) {
console.log("Remote got new Ice Candidate: " + event);
local.addIceCandidate(new RTCIceCandidate(event.candidate));
}
});
})
}
catch (e) {
console.log("Got Error" + e);
}
【问题讨论】:
-
onmessgae -- 你有一个错字。
标签: javascript google-chrome firefox webrtc