admin管理员组文章数量:1320670
I have a basic webRTC application that supports video/audio munication and file sharing between two peers, The app runs as intended when I open it on Mozilla Firefox but when I run it on Google Chrome the onicecandidate returns null
My RTCPeerConnection
myConnection = new RTCPeerConnection();
Setting up the peer connection
myConnection.createOffer().then(offer => {
currentoffer = offer
myConnection.setLocalDescription(offer);
})
.then(function () {
myConnection.onicecandidate = function (event) {
console.log(event.candidate);
if (event.candidate) {
send({
type: "candidate",
candidate: event.candidate
});
}
};
send({
type: "offer",
offer: currentoffer
});
})
.catch(function (reason) {
alert("Problem with creating offer. " + reason);
});
On Mozilla Firefox you can see in the console log all the ICE candidates that are collected on each "onicecandidate" event
On Chrome the output is null
I have a basic webRTC application that supports video/audio munication and file sharing between two peers, The app runs as intended when I open it on Mozilla Firefox but when I run it on Google Chrome the onicecandidate returns null
My RTCPeerConnection
myConnection = new RTCPeerConnection();
Setting up the peer connection
myConnection.createOffer().then(offer => {
currentoffer = offer
myConnection.setLocalDescription(offer);
})
.then(function () {
myConnection.onicecandidate = function (event) {
console.log(event.candidate);
if (event.candidate) {
send({
type: "candidate",
candidate: event.candidate
});
}
};
send({
type: "offer",
offer: currentoffer
});
})
.catch(function (reason) {
alert("Problem with creating offer. " + reason);
});
On Mozilla Firefox you can see in the console log all the ICE candidates that are collected on each "onicecandidate" event
On Chrome the output is null
Share Improve this question asked Apr 8, 2019 at 11:44 FlubberFlubsFlubberFlubs 931 silver badge4 bronze badges 1- I ran into the same issue, did you find a solution? – alexward1230 Commented Oct 24, 2021 at 4:42
2 Answers
Reset to default 8You should pass options object when calling createOffer()
method, e.g.:
myConnection = new RTCPeerConnection();
var mediaConstraints = {
'offerToReceiveAudio': true,
'offerToReceiveVideo': true
};
myConnection.createOffer(mediaConstraints).then(offer => {
currentoffer = offer
myConnection.setLocalDescription(offer);
})
...// the rest of you code goes here
Alternatively, you can specify RTCRtpTransceiver
before creating an offer:
myConnection = new RTCPeerConnection();
myConnection.addTransceiver("audio");
myConnection.addTransceiver("video");
myConnection.createOffer().then(offer => {
currentoffer = offer
myConnection.setLocalDescription(offer);
})
...// the rest of you code goes here
Sources:
WebRTC 1.0
MDN RTCPeerConnection.createOffer()
MDN RTCPeerConnection.addTransceiver()
Example -- GitHub
You have to pass STUN/TURN servers when create a peer connection.
Otherwise you will only local candidates and hence will be able to connect locally only
var STUN = {
'url': 'stun:stun.l.google.:19302',
};
var iceServers =
{
iceServers: [STUN]
};
var pc = new RTCPeerConnection(iceServers);
本文标签:
版权声明:本文标题:javascript - No ICE candidates generated when I run my local webRTC application on google chrome browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742063544a2418696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论