Handling the process of handling ICE candidates when using a PeerConnection?

后端 未结 2 675
借酒劲吻你
借酒劲吻你 2021-02-06 06:50

I have exhausted all possibilities to get a stable WebRTC implementation working and am looking to get some advice.

All possible solutions to handling a working connecti

2条回答
  •  醉话见心
    2021-02-06 07:19

    I found this function useful in your situation :)

    function waitForAllICE(pc) {
      return new Promise((fufill, reject) => {
        pc.onicecandidate = (iceEvent) => {
          if (iceEvent.candidate === null) fufill()
        }
          setTimeout(() => reject("Waited a long time for ice candidates..."), 10000)
      }) 
    } 
    

    You can then do, for something along the lines of

    pc.createOffer()
      .then(offer => pc.setLocalDescription(offer))
      .then(  ()  => waitForAllICE(pc))
      .then(  ()  => signallingWire.send(pc.localDescription))
      .catch(  e  => smartErrorHandling(e))
    

提交回复
热议问题