summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2015-07-13 07:56:19 +0000
committerLiong Sauw Ming <ming@teluu.com>2015-07-13 07:56:19 +0000
commitae906a72e5e50853aa7f1a370c7ed4d933e35971 (patch)
treeeb60a62f52bd6de609387e7a310145632aa5a53a
parent4f6e3282805a7ddb564c8a101a1a6b73e9018eef (diff)
Fixed #1867: Add pjsua callback to notify when STUN resolution completes
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5131 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsua-lib/pjsua.h31
-rw-r--r--pjsip/include/pjsua2/endpoint.hpp3
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c3
-rw-r--r--pjsip/src/pjsua2/endpoint.cpp2
4 files changed, 31 insertions, 8 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index e6e0507c..7ffd7062 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -283,6 +283,9 @@ typedef struct pjsua_srv_pres pjsua_srv_pres;
/** Forward declaration for pjsua_msg_data */
typedef struct pjsua_msg_data pjsua_msg_data;
+/** Forward declaration for pj_stun_resolve_result */
+typedef struct pj_stun_resolve_result pj_stun_resolve_result;
+
/**
* Maximum proxies in account.
@@ -560,6 +563,13 @@ typedef pj_status_t
/**
+ * Typedef of callback to be registered to #pjsua_resolve_stun_servers()
+ * and to be called when STUN resolution completes.
+ */
+typedef void (*pj_stun_resolve_cb)(const pj_stun_resolve_result *result);
+
+
+/**
* This enumeration specifies the options for custom media transport creation.
*/
typedef enum pjsua_create_media_transport_flag
@@ -1351,6 +1361,18 @@ typedef struct pjsua_callback
void (*on_acc_find_for_incoming)(const pjsip_rx_data *rdata,
pjsua_acc_id* acc_id);
+ /**
+ * Calling #pjsua_init() will initiate an async process to resolve and
+ * contact each of the STUN server entries to find which is usable.
+ * This callback is called when the process is complete, and can be
+ * used by the application to start creating and registering accounts.
+ * This way, the accounts can avoid call setup delay caused by pending
+ * STUN resolution.
+ *
+ * See also #pj_stun_resolve_cb.
+ */
+ pj_stun_resolve_cb on_stun_resolution_complete;
+
} pjsua_callback;
@@ -1969,7 +1991,7 @@ PJ_DECL(pj_pool_factory*) pjsua_get_pool_factory(void);
* resolution and testing, the #pjsua_resolve_stun_servers() function.
* This structure will be passed in #pj_stun_resolve_cb callback.
*/
-typedef struct pj_stun_resolve_result
+struct pj_stun_resolve_result
{
/**
* Arbitrary data that was passed to #pjsua_resolve_stun_servers()
@@ -1996,13 +2018,8 @@ typedef struct pj_stun_resolve_result
*/
pj_sockaddr addr;
-} pj_stun_resolve_result;
-
+};
-/**
- * Typedef of callback to be registered to #pjsua_resolve_stun_servers().
- */
-typedef void (*pj_stun_resolve_cb)(const pj_stun_resolve_result *result);
/**
* This is a utility function to detect NAT type in front of this
diff --git a/pjsip/include/pjsua2/endpoint.hpp b/pjsip/include/pjsua2/endpoint.hpp
index 7d71231a..ac97ea89 100644
--- a/pjsip/include/pjsua2/endpoint.hpp
+++ b/pjsip/include/pjsua2/endpoint.hpp
@@ -1181,7 +1181,8 @@ public:
/**
* Callback when the Endpoint has finished performing STUN server
- * checking that is initiated with natCheckStunServers().
+ * checking that is initiated when calling libInit(), or by
+ * calling natCheckStunServers().
*
* @param prm Callback parameters.
*/
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 0d40b142..29febd60 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1471,6 +1471,9 @@ static void internal_stun_resolve_cb(const pj_stun_resolve_result *result)
pjsua_detect_nat_type();
}
}
+
+ if (pjsua_var.ua_cfg.cb.on_stun_resolution_complete)
+ (*pjsua_var.ua_cfg.cb.on_stun_resolution_complete)(result);
}
/*
diff --git a/pjsip/src/pjsua2/endpoint.cpp b/pjsip/src/pjsua2/endpoint.cpp
index 6b8ab942..a522c679 100644
--- a/pjsip/src/pjsua2/endpoint.cpp
+++ b/pjsip/src/pjsua2/endpoint.cpp
@@ -1277,6 +1277,8 @@ void Endpoint::libInit(const EpConfig &prmEpConfig) throw(Error)
&Endpoint::on_call_media_transport_state;
ua_cfg.cb.on_call_media_event = &Endpoint::on_call_media_event;
ua_cfg.cb.on_create_media_transport = &Endpoint::on_create_media_transport;
+ ua_cfg.cb.on_stun_resolution_complete =
+ &Endpoint::stun_resolve_cb;
/* Init! */
PJSUA2_CHECK_EXPR( pjsua_init(&ua_cfg, &log_cfg, &med_cfg) );