2014-04-16 76 views
2

我在sip開發方面非常新穎,並嘗試使用pjsip實現windows phone 8客戶端。Windows phone 8 pjsip庫集成

我從pjsip構建示例應用程序,它使用telnet連接創建pjsua應用程序。

眼下,我不明白是,我將如何使用這個庫,並整合在我的應用程序沒有遠程登錄,

我只是需要把一個手動撥號盤,並從那裏打電話,做到這一點,是什麼將成爲程序?

pjsip for android或iphone有兩個示例應用程序,csipsimple和siphon,但用於windows phone 8的pjsip沒有這樣的應用程序。

任何關於前進方式的幫助都會非常有幫助。

感謝

回答

4

既然你提到你已經試過windows phone telnet應用示例,我假設你已經下載了他們的wp8 getting started guide中提到的PJSIP winphone源碼。要創建一個簡單的應用程序,執行傳出和接收傳入呼叫,你可以簡單地重複使用這個winphone項目。

打開winphone項目,並做到:

  1. 創建新的Windows Phone項目並將其設置爲啓動項目(我們稱之爲項目SIP_UI)。這將用作UI。您可以創建一個「呼叫按鈕」,以便稍後執行傳出呼叫。
  2. 按照此SIP_UI的現有pjsua_wp WMAppManifest.xml設置。特別是能力部分。如果您僅使用默認設置,則您的應用程序將無法工作。
  3. 創建新的Windows Phone運行時項目(我們稱之爲SIP_WINPRT)。在此類中創建一個類和一個方法,以便稍後執行實際的調用。
  4. 通過遵循現有的pjsua_wp_backend,更改SIP_WINPRT的屬性設置(右鍵單擊SIP_WINPRT項目 - >屬性)。特別改變參考文獻,其他包含目錄和預處理器定義。相應地調整路徑。
  5. 在winphone示例中搜索simple_pjsua.c。並嘗試在您在SIP_WINPRT中創建的類中實現該功能。我創建的示例:

    #include "pch.h" 
    #include "backend.h" 
    #include "pjsua.h" 
    
    #define SIP_DOMAIN "dogdomain" 
    #define SIP_USER "dog" 
    #define SIP_PASSWD "dog" 
    
    using namespace backend; 
    using namespace Platform; 
    
    SipletRuntimeComponent::SipletRuntimeComponent() 
    { 
    } 
    
    /* Display error and exit application */ 
    static void error_exit(const char *title, pj_status_t status) 
    { 
        //pjsua_perror(THIS_FILE, title, status); 
        pjsua_destroy(); 
        exit(1); 
    } 
    
    /* Callback called by the library upon receiving incoming call */ 
    static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, 
           pjsip_rx_data *rdata) 
    { 
        pjsua_call_info ci; 
    
        PJ_UNUSED_ARG(acc_id); 
        PJ_UNUSED_ARG(rdata); 
    
        pjsua_call_get_info(call_id, &ci); 
    
        //PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!", 
        //  (int)ci.remote_info.slen, 
        //  ci.remote_info.ptr)); 
    
        /* Automatically answer incoming calls with 200/OK */ 
        pjsua_call_answer(call_id, 200, NULL, NULL); 
    } 
    
    /* Callback called by the library when call's media state has changed */ 
    static void on_call_media_state(pjsua_call_id call_id) 
    { 
        pjsua_call_info ci; 
    
        pjsua_call_get_info(call_id, &ci); 
    
        if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) { 
        // When media is active, connect call to sound device. 
        pjsua_conf_connect(ci.conf_slot, 0); 
        pjsua_conf_connect(0, ci.conf_slot); 
        } 
    } 
    
    /* Callback called by the library when call's state has changed */ 
    static void on_call_state(pjsua_call_id call_id, pjsip_event *e) 
    { 
        pjsua_call_info ci; 
    
        PJ_UNUSED_ARG(e); 
    
        pjsua_call_get_info(call_id, &ci); 
        //PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, 
        //  (int)ci.state_text.slen, 
        //  ci.state_text.ptr)); 
    } 
    
    
    int SipletRuntimeComponent::SipCall(int address) 
    { 
        /* Create pjsua */ 
        pj_status_t status; 
        status = pjsua_create(); 
        if (status != PJ_SUCCESS){ 
         //Error in pjsua_create() 
         return -1; 
        } 
    
        /* Validate the URL*/ 
        char url[50] = "sip:cat:[email protected]:5060"; 
        status = pjsua_verify_url(url); 
        if (status != PJ_SUCCESS){ 
         //Invalid URL given 
         return -1; 
        } 
    
        /* Init pjsua */ 
        { 
         pjsua_config cfg; 
         pjsua_logging_config log_cfg; 
    
         pjsua_config_default(&cfg); 
         cfg.cb.on_incoming_call = &on_incoming_call; 
         cfg.cb.on_call_media_state = &on_call_media_state; 
         cfg.cb.on_call_state = &on_call_state; 
    
         pjsua_logging_config_default(&log_cfg); 
         log_cfg.console_level = 4; 
    
         status = pjsua_init(&cfg, &log_cfg, NULL); 
         if (status != PJ_SUCCESS){ 
          //Error in pjsua_init() 
          pjsua_destroy(); 
          return -1; 
         } 
        } 
    
        /* Add UDP transport. */ 
        { 
         pjsua_transport_config cfg; 
    
         pjsua_transport_config_default(&cfg); 
         cfg.port = 5060; 
         status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL); 
         if (status != PJ_SUCCESS){ 
          //Error creating transport 
          pjsua_destroy(); 
          return -1; 
         } 
        } 
    
        /* Initialization is done, now start pjsua */ 
        status = pjsua_start(); 
        if (status != PJ_SUCCESS){ 
         //Error starting pjsua 
         pjsua_destroy(); 
         return -1; 
        } 
    
        /* Register to SIP server by creating SIP account. */ 
        pjsua_acc_id acc_id; 
        { 
         pjsua_acc_config cfg; 
    
         pjsua_acc_config_default(&cfg); 
         cfg.id = pj_str("sip:" SIP_USER "@" SIP_DOMAIN); 
         cfg.reg_uri = pj_str("sip:" SIP_DOMAIN); 
         cfg.cred_count = 1; 
         cfg.cred_info[0].realm = pj_str(SIP_DOMAIN); 
         cfg.cred_info[0].scheme = pj_str("digest"); 
         cfg.cred_info[0].username = pj_str(SIP_USER); 
         cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; 
         cfg.cred_info[0].data = pj_str(SIP_PASSWD); 
    
         status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id); 
    
         if (status != PJ_SUCCESS){   
          //Error adding account 
          pjsua_destroy(); 
          return -1; 
         } 
        } 
    
        /* make call to the URL. */ 
        pj_str_t uri = pj_str(url); 
        status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL); 
        if (status != PJ_SUCCESS){ 
         //Error making call 
         pjsua_destroy(); 
         return -1; 
        } 
    
        return address + 1; 
    } 
    
  6. 在SIP_UI項目中添加SIP_WINPRT作爲參考。

  7. 當按下呼叫按鈕時調用SIP_WINPRT。
+0

這是非常有益的禮薩,是的,這是前進的方式,不幸的是,這些遺物已經老了,而且我已經知道了這一點。 現在,當應用程序存在時,我會卡在來電管理中,有沒有辦法在沒有推送通知系統的情況下處理來電? 也有你設法將音頻路由到耳機,而不是揚聲器? –

+0

謝謝。我也在幾周前開始工作,現在看起來你比我更有前途。我對windows phone開發也很新,所以現在不能真正幫助你。但這可能是由於PJSIP不能使用後臺代理。參考答案的評論[這裏](http://stackoverflow.com/questions/23908847/perform-sip-call-from-windows-phone-8-1) –

+0

實際上微軟有一個voip聊天箱示例應用程序與非常糟糕的文檔,並且pjsip有自己的客戶端,需要與喋喋不休的應用程序集成。 但由於chatterbox應用程序記錄非常糟糕,現在不可能將其與pjsip集成。 –

0

好,似乎你的問題不與PJSIP但UI發展有關。 我建議你創建你的UI(使用XAML/C#或XAML/C++,不要忘記它必須是Windows Phone 8.0 Silverlight項目)。然後你開始引用PJSip庫。

希望它有幫助!