【问题标题】:How to setup STUN settings in PJSIP ios application?如何在 PJSIP ios 应用程序中设置 STUN 设置?
【发布时间】:2014-08-27 11:19:03
【问题描述】:

我有基于 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 但如何使用它..

请帮忙!

【问题讨论】:

    标签: ios nat pjsip stun


    【解决方案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
    

    【讨论】:

    • 请用一些描述和解释扩展您的答案。调出您的代码内 cmets 将提高可读性。
    • 这段代码将设置一个没有 STUN 的 acc_cfg。当代码中需要不需要 STUN 的情况时可以使用它。 // 禁用新帐户配置上的所有眩晕 acc_cfg_new.sip_stun_use = PJSUA_STUN_USE_DISABLED; acc_cfg_new.media_stun_use = PJSUA_STUN_USE_DISABLED;以上是关键代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-12
    • 1970-01-01
    相关资源
    最近更新 更多