Android SIP 配置不起作用

Android SIP configuration doesn't work

我对 SIP 帐户的配置有点困惑。所以我想在这里,有人根据 SIP stack documentation 澄清问题。

一切正常,但现在我想为工作帐户添加一些配置。请注意,此协议中的所有其他方法都可以正常工作。我想用的,它的配置方法: retryIntervalSec(), delayBeforeRefreshSec() and timeOutSec().

问题,此方法不起作用,下面是设置此配置的一些示例。基于上面的文档,delayBeforeRefreshSec 的值为 5 秒。所以注册在 5 秒后刷新,当我从默认配置中获取这个基值时,它等于默认设置。但!刷新不会在 5 秒后触发!

你准备好施展魔法了吗?

如您所见,方法名称类似于 "delayBeforeRefreshSec",表示用于输入秒数(例如 delayBeforeRefreshSec(5))。但是,当我们将此方法值设置为 long(例如 delayBeforeRefreshSec(100000))时,刷新开始每 5 秒触发一次!请注意,任何超过 500 的值,开始使用周期性 5 秒!

我知道,源代码中可能有一些验证和设置基值,如果它更多一些更高的值。但这到底是什么?为什么这种方法如此有效?请注意,其他方法(如 timeOutSec)不适用于任何值。

最后我的主要问题是,如何让这一切都可配置?

    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);

我在尝试强制 pjsip 库按要求的时间间隔刷新注册时遇到了同样的问题。我发现 pjsua_acc_config Struct Reference 提供了有关可以为注册设置的所有参数的更多详细信息。

不幸的是,并非所有参数都有效,所以我最终使用了 setDelayBeforeRefreshSec 方法,该方法通过设置发送刷新消息的注册到期前的秒数来起作用。例如,如果使用 mAccountConfig.getRegConfig().setDelayBeforeRefreshSec(20),这将导致刷新以 40 秒为间隔发生。所以对于你想要的 5 秒间隔,你必须使用 mAccountConfig.getRegConfig().setDelayBeforeRefreshSec(60-SIP_KEEP_ALIVE_DELAY).

此外,原本用于更改到期时间间隔的方法 setTimeoutSec 不起作用,因此默认使用 60 秒的时间间隔(不知道为什么,因为文档中提到了默认值为 PJSUA_REG_INTERVAL,即 300)。

下面是我的配置,用于在 33 秒时刷新注册,并对每种方法进行注释。

        /*
        * 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);

希望对您或其他人有所帮助。