首页 > 解决方案 > 注册失败后如何更改默认时间延迟300秒(Pjsua 2 Android)重试注册?

问题描述

注册失败后如何更改默认的 pjsua2 重新注册。目前它已设置为 300 秒。我希望设置在注册失败后重试注册到 60 秒左右。

我浏览了文档...但是有些我无法在示例 android pjsua2 应用程序上实现它们。

unsigned timeoutSec 可选的注册间隔,以秒为单位。

如果该值为零,将使用默认间隔(PJSUA_REG_INTERVAL,300 秒)。

unsigned retryIntervalSec 指定注册失败(包括传输问题)时自动注册重试的时间间隔,以秒为单位。

设置为 0 以禁用自动重新注册。请注意,如果由于传输失败而发生注册重试,则第一次重试将在 firstRetryIntervalSec 秒后完成。另请注意,间隔将稍微随机几秒(在 reg_retry_random_interval 中指定)以避免所有客户端同时重新注册。

另请参阅 firstRetryIntervalSec 和 randomRetryIntervalSec 设置。

默认值:PJSUA_REG_RETRY_INTERVAL

链接:https ://www.pjsip.org/docs/book-latest/html/reference.html

标签: androidpjsippjsua2

解决方案


您可以使用下面的代码,并根据您的需要阅读注释和设置值。

             accCfg = new AccountConfig();

             /*
             * 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.
             * */
             accCfg.getRegConfig().setFirstRetryIntervalSec(3);
             accCfg.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.
             */
            accCfg.getRegConfig().setRandomRetryIntervalSec(7);
            /*
             * Optional interval for registration, in seconds. If the value is zero, 
            default
             * interval will be used (PJSUA_REG_INTERVAL, 300 seconds).
             */
            accCfg.getRegConfig().setTimeoutSec(65);

            /*
             * Specify the number of seconds to refresh the client registration before 
             the
             * registration expires.
             * Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
             */
            accCfg.getRegConfig().setDelayBeforeRefreshSec(10);

推荐阅读