既然您提到您已经尝试过winphone telnet应用程序示例,我想您已经下载了他们的wp8入门指南中提到的phone源代码。要创建一个简单的应用程序来执行您提到的传出和接收来电,您可以简单地重用这个winphone项目。
打开winphone项目并执行:
- 创建新的Windows项目并将其设置为启动项目(让我们将此项目称为SIP_UI)。这将用作UI。您可以创建一个“呼叫按钮”,稍后执行传出呼叫。
- 遵循此pjsua_wp WMAppManifest.xml的现有SIP_UI设置。尤其是能力部分。如果您只使用默认设置,您的应用程序将无法工作。
- 创建新的Windows运行时项目(让我们称之为SIP_WINPRT)。在这个类中创建一个类和一个方法,它将在以后执行实际的调用。
- 更改SIP_WINPRT的属性设置(右键单击SIP_WINPRT项目->属性),方法是遵循现有的pjsua_wp_backend。更改,特别是对引用、附加包含目录和预处理器定义的更改。相应地调整路径。
- 在winphone示例中搜索simple_pjsua.c。并尝试在您在SIP_WINPRT中创建的类中实现这一点。我创建的示例:
#包含"pch.h“#include "backend.h”#包括"pjsua.h“#define SIP_DOMAIN "dogdomain”#define SIP_USER“SIP_USER #define”SIP_PASSWD "dog“使用命名空间后端;使用命名空间平台;/* {}/*显示错误并退出应用程序*/静态空洞error_exit(const char *title,pj_status_t status) { //pjsua_perror(THIS_FILE,title,status);pjsua_destroy();}库在收到传入呼叫时调用的/*回调(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,“来自%.*s!”、// (int)ci.remote_info.slen,// ci.remote_info.ptr)的传入呼叫);/*用200/OK */ pjsua_call_answer自动应答来电(call_id,200,NULL,NULL);}当调用的媒体状态更改时由库调用/*回调(Pjsua_call_id call_id) { pjsua_call_info ci;pjsua_call_get_info(call_id &ci);if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) { //当媒体处于活动状态时,将调用连接到声音设备。pjsua_conf_connect(ci.conf_slot,0);pjsua_conf_connect(0,ci.conf_slot);}调用状态改变时调用的} /*回调(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地址){ /*创建pjsua */ pj_status_t状态;status = pjsua_create();如果(status != PJ_SUCCESS){ // pjsua_create()返回-1;} /*验证URL*/ char url50 = "sip:cat:cat@catdomain:5060";status = pjsua_verify_url( URL );if (status != PJ_SUCCESS){ /无效URL给定返回-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;log_cfg.console_level= pjsua_init(&cfg,&log_cfg,NULL);if (状态!= PJ_SUCCESS){ // pjsua_init() pjsua_destroy()中的错误;返回-1;}} /*添加UDP传输。*/ { pjsua_transport_config cfg;pjsua_transport_config_default(&cfg);cfg.port = 5060;pjsua_transport_create(PJSIP_TRANSPORT_UDP,&cfg,NULL);if (PJSIP_TRANSPORT_UDP= PJ_SUCCESS){ //错误创建传输pjsua_destroy();返回-1;} /*初始化完成,现在启动pjsua */ status = pjsua_start();if (status = PJ_SUCCESS){ //错误启动pjsua pjsua_destroy();通过创建/*帐户返回-1;}/*寄存器到SIP服务器。*/ 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.realm = pj_str(SIP_DOMAIN);cfg.cred_info.scheme =pj_str(“文摘”);cfg.cred_info.username = pj_str(SIP_USER);cfg.cred_info.data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;cfg.cred_info.data = pj_str(SIP_PASSWD);status = pjsua_acc_add(&cfg,PJ_TRUE,&acc_id);如果(status != PJ_SUCCESS){ //错误添加帐户pjsua_destroy();返回-1;} /*调用该URL。*/ pj_str_t uri = pj_str(url);acc_id= pjsua_call_make_call(acc_id,&uri,0,NULL,NULL,NULL);if (status != PJ_SUCCESS){ //错误调用pjsua_destroy();返回-1;}返回地址+ 1;
- 在SIP_WINPRT项目中添加SIP_UI作为引用。
- 按下“呼叫”按钮时,调用SIP_WINPRT。