如何在PJSIP ios应用程序中设置STUN设置?

时间:2014-08-27 11:19:03

标签: ios nat pjsip stun

我有基于pjsua的voip应用程序。它工作正常,但我不知道如何设置正确的STUN设置。

现在我在pjsua init之前连接STUN -

cfg.stun_host = pj_str(&stunAdr);

之后,如果客户端不在同一网络中,则一切正常。但是当他们在同一个网络中时,他们不使用NAT,因此他们不需要STUN但STUN连接和使用,客户端不会互相听到。

那么如何在需要时才设置STUN的使用?取决于客户之间的NAT不存在? 我正在连接

cfg.cb.on_nat_detect = &on_nat; 

static void on_nat(const pj_stun_nat_detect_result *result) {
    if (result->status != PJ_SUCCESS) {
        pjsua_perror(THIS_FILE, "NAT detection failed", result->status);


    } else {

        PJ_LOG(3, (THIS_FILE, "NAT detected as %s", result->nat_type_name));

    }
}
  • 它的工作也很好,检测NAT但是如何使用它..

请帮忙!

1 个答案:

答案 0 :(得分:1)

        // Disable STUN for a new config obtained from the old one, where acc_id is
        // old config id

        // declare a new account config
        pjsua_acc_config acc_cfg_new;

        // create a new pj pool used when copying the existing config
        pj_pool_t *pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);

        // default the new account configuration
        pjsua_acc_config_default(&acc_cfg_new);

        // now copy the existing account config - if you already have one
        pjsua_acc_get_config(acc_id, pool, &acc_cfg_new);

        // disable all stun on new account config
        acc_cfg_new.sip_stun_use = PJSUA_STUN_USE_DISABLED;
        acc_cfg_new.media_stun_use = PJSUA_STUN_USE_DISABLED; 


        // Now apply the new config without STUN to the current config
        pjsua_acc_modify(acc_id, &acc_cfg_new);

        // and make a call