InnovateAsterisk / Browser-Phone

A fully featured browser based WebRTC SIP phone for Asterisk
https://www.innovateasterisk.com
GNU Affero General Public License v3.0
508 stars 250 forks source link

how to debug CurrentCalls #94

Open vieridipaola opened 4 years ago

vieridipaola commented 4 years ago

Hi,

I've noticed a problem in a specific browser with Call Waiting disabled. The client did not ave any active calls and even cleared the cache, reloaded the page, etc. However, on call reception, the "answercall" window would pop up and close immediately. In the console, I could see that the CurrentCalls value was 1. The RejectCall function was fired of course. As a side note, the "ringer" sound was not stopped in this case. So the end result was the ringer sound kept playing but there was no way to answer the call. The caller keeps seeing that it's still ringing, so if he/she hangs up then the ringer tone stops playing on the callee.

What I'd like to understand is why the function countSessions returns 1 instead of 0. How can I debug this?

InnovateAsterisk commented 4 years ago

I think with the latest update (#89) the sound will for sure stop, but the call count issue is like this... A while back I found a bug that was incorrectly counting the calls, this was because I had changed to using the UserAgent.sessions array of json objects, that is automatically maintained by the SIPJS code.... saves me the trouble.

However, the latest session is added immediately and without having answered the call, so it will count the unanswered call too. This is important to remember when looking at call waiting and busy detection: the inbound session will already be part of the sessions array before you can do anything, like check to see if you are on the phone.

You can see here:

function countSessions(id){
    var rtn = 0;
    if(userAgent == null) {
        console.warn("userAgent is null");
        return 0;
    }
    $.each(userAgent.sessions, function (i, session) {
        if(id != session.id) rtn ++;
    });
    return rtn;
}

If you parse a session id, it will "not count" that session. This way you can "count all calls except this one".