after reading jav-ivar Perfect negotiation in WebRTC have some question to ask

59 views
Skip to first unread message

adam rama

unread,
Dec 8, 2022, 2:25:24 AM12/8/22
to discuss-webrtc
i have to figure out if
CONNECTION..state === "failed")



and if

oniceconnectionstatechange = (e) => {
 switch (yourConn2.connectionState) {
 case "failed":
            yourConn2.restartIce();
         
            break;
}

}



<Renegotiation>

   
how i can split apllication to know if i need to rollback connection or i just wanted to restartice

logic for handlerestartice i maybe use

async function handleIceRestart(peerCOnnection , state) {
    if (state == "ICErollback") {
      try {
        var pc;
      var pc2;
      if (peerCOnnection = "yourConn") {
        pc = yourConn
        pc2 = yourConn2
      } else {
        pc = yourConn2
        pc2 = yourConn
      }
   
 
    const offer = await pc.createOffer({iceRestart: true});
    await pc.setLocalDescription(offer);
    await pc2.setRemoteDescription(offer);
   
    const answer = await pc2.createAnswer();
    await pc2.setLocalDescription(answer);
    await pc.setRemoteDescription(answer);
  } catch(e){console.log(e)}  
    }
  }

    should i split the logic of restarice and rollback connection or After calling restartIce()
    negotiate will occur with create offer has a set of restartice : true
    with no need to explicitly trigger ICE restart and rollback insted then restart ice

note that my logic for renegotation is what spec recommended and with modification  of jan-ivar from his blog thanks to him

yourConn.onnegotiationneeded = async () => {
    console.warn("yourConn.onnegotiationneeded");
    try {
      makingOffer = true;
      if (yourConn.signalingState != "stable") return;
      await yourConn.setLocalDescription(offer);
      wbsc.emit("SEND_EVENT_EMIT_CALL_AUDIO", {
    data: { type: "negotiation", description: yourConn.localDescription, id: connectedUser },
  })
}
catch (e) {console.log("renegotiationneded fail is ",e) }
finally { makingOffer = false }

}


logic forhanddlenegotation is after signilaing message is come

let handleRenegotiation = async (description) => {
 
    try {
      if (description) {

        const offerCollision = description.type == "offer" &&
          (makingOffer || yourConn.signalingState != "stable");
       
          ignoreOffer = !polite && offerCollision;

          if (ignoreOffer) {
            return;
          }

        if (offerCollision) {
          await Promise.all([
            //polite peer rollback it's local offer .
            yourConn.setLocalDescription({type: "rollback"}),
            yourConn.setRemoteDescription(description)
           
          ]);
       
        } else {
          await yourConn2.setRemoteDescription(description);
        }
       
        if (description.type == "offer") {
          await yourConn.setLocalDescription(await yourConn2.createAnswer());
          wbsc.emit("SEND_EVENT_EMIT_CALL_AUDIO", {
            data: { type: "negotiation", description: yourConn.localDescription, id: connectedUser },
          })
        }
      }else if (candidate) {
        try {
          await pc.addIceCandidate(candidate);
        } catch (e) {
          if (!ignoreOffer) console.log(e);
        }
      }
 
    }catch (e) {
      console.log(e);
    }
   
  }

     is createOffer({iceRestart: true});

    should i do it explicity in negotiationneeded and make handlerestartice fire
 or leave it to rollback and retcpeerconection will do it automatically since it will remember that i called restartIce before rollback

    i'm now in a loop where i can't understand what the difference between trigger icerestart
    explicitly or just rollback and automatically will restartice happend automatically with
     need to restartice : true .
    since "the RTCPeerConnection will remember that you requested ICE restart. The next time the connection's signalingState changes to stable, the connection will fire the negotiationneeded event. This process continues until an ICE restart has been successfully completed."

    i'm aware of glare and race of handlerestartice and i will fix it as soon as i know if should use it
Reply all
Reply to author
Forward
0 new messages