During high CPU load, in Firefox, an RTCDataChannel's onopen
event fires before the RTCPeerConnection's oniceconnectionstatechange
. I'm wondering if there is anything in the spec regarding the order in which the two events fire, and how to ensure that oniceconnectionstatechange
fires first.
| Chrome 88 | Firefox 85
--------------+-----------------------------------+------------------------------------
Low CPU load | oniceconnectionstatechange first | oniceconnectionstatechange first
| onopen second | onopen second
--------------+-----------------------------------+------------------------------------
High CPU load | oniceconnectionstatechange first | onopen first?
| onopen second | oniceconnectionstatechange second
This is the code I'm using to test:
(async function()
{
var p1 = new RTCPeerConnection();
var p2 = new RTCPeerConnection();
p1.channel = p1.createDataChannel("channel", { negotiated: true, id: 88 });
p2.channel = p2.createDataChannel("channel", { negotiated: true, id: 88 });
p1.onicecandidate = function(e)
{
if(e.candidate)
p2.addIceCandidate(e.candidate);
};
p2.onicecandidate = function(e)
{
if(e.candidate)
p1.addIceCandidate(e.candidate);
};
p1.oniceconnectionstatechange = function()
{
if(p1.iceConnectionState === "connected")
console.log("P1 PeerConnection connected");
};
p2.oniceconnectionstatechange = function()
{
if(p2.iceConnectionState === "connected")
console.log("P2 PeerConnection connected");
};
p1.channel.onopen = function()
{
console.log("P1 DataChannel opened");
};
p2.channel.onopen = function()
{
console.log("P2 DataChannel opened");
};
var offer = await p1.createOffer();
await p1.setLocalDescription(offer);
await p2.setRemoteDescription(offer);
var answer = await p2.createAnswer();
await p2.setLocalDescription(answer);
await p1.setRemoteDescription(answer);
})();
//create some load
requestAnimationFrame(renderingLoopTest); //comment this line for no load
function renderingLoopTest()
{
var lag = Date.now();
while(Date.now() - lag < 60);
requestAnimationFrame(renderingLoopTest);
}
question from:
https://stackoverflow.com/questions/66067571/are-rtcdatachannels-guaranteed-to-open-after-the-ice-state-becomes-connected 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…