Search code examples
androidsiptelephonypjsip

Android SIP configuration doesn't work


I a little confused with configuration of SIP Account. So I think here, somebody clarify issues, based on SIP stack documentation.

All works fine, but now I want to add some configuration to working Account. Note, that all other methods from this protocol works fine. What I want to use, its configure methods: retryIntervalSec(), delayBeforeRefreshSec() and timeOutSec().

Problem, that this methods doesn't work, below some example of setting this config. Based on doc above delayBeforeRefreshSec has value of 5 sec. So registration refreshing after 5 sec, and when i getting this base value from default config, it's equal to default setting. But! refreshing doesn't firing after 5 sec!

Do you ready for magic?

As you can see, methods name like "delayBeforeRefreshSec", which means to use for input seconds (for ex. delayBeforeRefreshSec(5)). But, when we setting to this methods value from long (for ex. delayBeforeRefreshSec(100000)), refreshing start firing every 5 sec! Note, that any value above 500, start working with periodic 5 sec!

I know, that maybe there some verification and setting base value in source, if it's more some higher value. But what is that all? Why this methods, work so? Note, that other methods, like timeOutSec, doesn't work with any value.

And finally my main question, it's how make this all configurable?

    mAccountConfig = new AccountConfig();
            mAccountConfig.setIdUri(myAccountName);
            mAccountConfig.getRegConfig().setRetryIntervalSec(SIP_RECONNECT_DELAY);
            mAccountConfig.getRegConfig().setDelayBeforeRefreshSec(SIP_KEEP_ALIVE_DELAY);
            mAccountConfig.getNatConfig().setUdpKaIntervalSec(SIP_KEEP_ALIVE_DELAY);

//....

mAccount = new Account;
mAccount.create(mAccountConfig);

Solution

  • I've had the same problems when tried to force pjsip library to refresh the registration at required interval. I found pjsua_acc_config Struct Reference to provide more details regarding all parameters that can be set for the registration.

    Unfortunately not all the parameters will work so I ended up with using setDelayBeforeRefreshSec method that will act by setting the number of seconds before registration expires in which the refresh message is sent. As an example, if mAccountConfig.getRegConfig().setDelayBeforeRefreshSec(20) is used, this will cause the refresh to occur at 40 seconds interval. So for you desired 5 seconds interval you have to use mAccountConfig.getRegConfig().setDelayBeforeRefreshSec(60-SIP_KEEP_ALIVE_DELAY).

    Also, the method that was intended to change the expiring interval setTimeoutSec doesn't work, so an interval of 60 seconds is used as default (don't know why exactly because in the documentation is mentioned that the default is PJSUA_REG_INTERVAL, which is 300).

    Bellow is my configuration used to refresh the registration at 33 seconds with comments for each method.

            /*
            * Specify interval of auto registration retry upon registration failure (including
            * caused by transport problem), in second. Set to 0 to disable auto re-registration.
            * Note that if the registration retry occurs because of transport failure, the first
            * retry will be done after reg_first_retry_interval seconds instead. Also note that
            * the interval will be randomized slightly by some seconds (specified in reg_retry_
            * random_interval) to avoid all clients re-registering at the same time.
            * */
            sipAccountConfig.getRegConfig().setFirstRetryIntervalSec(3);
            sipAccountConfig.getRegConfig().setRetryIntervalSec(10);
    
            /*
            * This specifies maximum randomized value to be added/subtracted to/from the
            * registration retry interval specified in reg_retry_interval and
            * reg_first_retry_interval, in second. This is useful to avoid all clients
            * re-registering at the same time. For example, if the registration retry interval
            * is set to 100 seconds and this is set to 10 seconds, the actual registration retry
            * interval will be in the range of 90 to 110 seconds.
            */
            sipAccountConfig.getRegConfig().setRandomRetryIntervalSec(7);
    
            /*
            * Optional interval for registration, in seconds. If the value is zero, default
            * interval will be used (PJSUA_REG_INTERVAL, 300 seconds).
            */
            sipAccountConfig.getRegConfig().setTimeoutSec(60);
    
            /*
             * Specify the number of seconds to refresh the client registration before the
             * registration expires.
             * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
             */
            sipAccountConfig.getRegConfig().setDelayBeforeRefreshSec(27);
    

    Hope it will help you or someone.