2014-08-27 60 views
0

我有基於pjsua的voip應用程序。它工作正常,但我不知道如何正確設置STUN設置。如何在PJSIP ios應用程序中設置STUN設置?

現在我pjsua初始化之前連接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
 // 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 
+0

請用一些描述和解釋擴大你的答案。調用您的代碼內評論將提高可讀性。 – Ajean 2014-11-14 18:36:58