当我试图强制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)。
Bellow是我用来在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);
希望它能帮助你或某人。