使用pjsua2文档,演示代码如下:
// Configure an AccountConfig
AccountConfig acfg;
acfg.idUri = "sip:test@pjsip.org";
acfg.regConfig.registrarUri = "sip:pjsip.org";
AuthCredInfo cred("digest", "*", "test", 0, "secret");
acfg.sipConfig.authCreds.push_back( cred );
// Create the account
MyAccount *acc = new MyAccount;
acc->create(acfg);
// Here we don't have anything else to do..
pj_thread_sleep(10000);
// Delete the account. This will unregister from server
delete acc;
// This will implicitly shutdown the library
return 0;
它使用pj_thread_sleep(10000)
来避免应用程序退出。
我需要pjsua2应用程序始终作为服务器端运行,不应该退出。
所以我应该用这个函数来代替pj_thread_sleep
,比如"loop_forver",谢谢。
您可以使用Endpoint.libHandleEvents
。我使用Python绑定,但API应该是相同的。下面是一个例子。
try:
while True:
ep.libHandleEvents(60_000)
except KeyboardInterrupt:
logger.info("Exiting. Received interrupt signal.")
finally:
ep.libDestroy()
只是阻止程序退出解决了我的问题。
while (true) {
std::getchar();
}