Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

javascript - Are RTCDataChannels guaranteed to open after the ICE state becomes connected?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...