versatica / JsSIP

JsSIP, the JavaScript SIP library
https://jssip.net
Other
2.4k stars 740 forks source link

_createLocalDescription answer/connect delay greater than 10 seconds #804

Closed palmtown closed 1 year ago

palmtown commented 1 year ago

Hello Community,

I've discovered an issue that is reproducible 100% of the time and it causes the answer/connect to be delayed significantly, greater than 10 seconds to connect the call.

In short, I've tracked the issue to the RTCSession.js file, and the _createLocalDescription function. What happens is that anytime I provide iceServers in the pcConfig variable for RTCSession answer or UA call functions, when answering the call or making the call, there is a long delay before the call is answered or placed.

The logic in _createLocalDescription uses the pc.icegatheringstatechange event determine if the iceGatheringState is complete, and pc.icecandidate event to determine if the event.candidate is null so that it knows when to resolve and execute the ready function and resolve. Unfortunately, in my case, pc.icegatheringstatechange only fires after more than 10 seconds. Also, what I've found is that the icecandidate event is fired immediately with no delay in both cases of setting iceServers and not setting iceServers in pcConfig with the same candidates. Therefore, it doesn't appear to be an issue with getting the ice candidates, rather, knowing when gathering is complete.

Moreover, I've tried several public iceServers such as google and the same result. If any iceServers are set, the connection hangs during answer/call.

Anyone experiencing this issue with setting iceServers?

ibc commented 1 year ago

Please read the JsSIP docs (we provide an event for these cases) and use the mailing list for questions. GitHub is just for bugs.

palmtown commented 1 year ago

Hello Community,

I'm just posting the solution here in case anyone runs into this problem. Bill helped me to resolve at https://groups.google.com/g/jssip/c/dhH78Iwnzik

session.on("icecandidate", function (e) {

        if ( typeof e.candidate === "object" && typeof e.candidate === "object" && typeof e.candidate.type === "string" && ["srflx", "rely"].includes(e.candidate.type))
          e.ready();

});