aboutsummaryrefslogtreecommitdiff
path: root/examples/example_4_callHandling
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-09-18 16:19:13 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-09-18 16:19:13 +0200
commitead44f83d5f00d6ae4dc05c251e13ce89cd5a6c6 (patch)
tree5b92f17b4da18d0dcb151926813ce04915298196 /examples/example_4_callHandling
parentb0ab0287f7c8a16e1f8db39ba2e202574fbd6ac2 (diff)
downloadqxmpp-ead44f83d5f00d6ae4dc05c251e13ce89cd5a6c6.tar.gz
start adding code to lookup TURN server
Diffstat (limited to 'examples/example_4_callHandling')
-rw-r--r--examples/example_4_callHandling/example_4_callHandling.cpp58
-rw-r--r--examples/example_4_callHandling/example_4_callHandling.h8
2 files changed, 62 insertions, 4 deletions
diff --git a/examples/example_4_callHandling/example_4_callHandling.cpp b/examples/example_4_callHandling/example_4_callHandling.cpp
index b73c9caa..d5c5d1bf 100644
--- a/examples/example_4_callHandling/example_4_callHandling.cpp
+++ b/examples/example_4_callHandling/example_4_callHandling.cpp
@@ -29,6 +29,7 @@
#include <QAudioOutput>
#include <QCoreApplication>
#include <QDebug>
+#include <QHostInfo>
#include "QXmppCallManager.h"
#include "QXmppJingleIq.h"
@@ -40,17 +41,28 @@
xmppClient::xmppClient(QObject *parent)
: QXmppClient(parent)
{
+ bool check;
+ Q_UNUSED(check);
+
// add QXmppCallManager extension
callManager = new QXmppCallManager;
addExtension(callManager);
- bool check = connect(this, SIGNAL(presenceReceived(QXmppPresence)),
- this, SLOT(slotPresenceReceived(QXmppPresence)));
+ check = connect(this, SIGNAL(connected()),
+ this, SLOT(slotConnected()));
+ Q_ASSERT(check);
+
+ check = connect(this, SIGNAL(presenceReceived(QXmppPresence)),
+ this, SLOT(slotPresenceReceived(QXmppPresence)));
Q_ASSERT(check);
check = connect(callManager, SIGNAL(callReceived(QXmppCall*)),
this, SLOT(slotCallReceived(QXmppCall*)));
Q_ASSERT(check);
+
+ check = connect(&m_dns, SIGNAL(finished()),
+ this, SLOT(slotDnsLookupFinished()));
+ Q_ASSERT(check);
}
void xmppClient::setRecipient(const QString &recipient)
@@ -99,9 +111,11 @@ void xmppClient::slotAudioModeChanged(QIODevice::OpenMode mode)
void xmppClient::slotCallReceived(QXmppCall *call)
{
+ bool check;
+ Q_UNUSED(check);
+
qDebug() << "Got call from:" << call->jid();
- bool check;
check = connect(call, SIGNAL(stateChanged(QXmppCall::State)),
this, SLOT(slotCallStateChanged(QXmppCall::State)));
Q_ASSERT(check);
@@ -126,10 +140,47 @@ void xmppClient::slotCallStateChanged(QXmppCall::State state)
qDebug("Call finished");
}
+void xmppClient::slotConnected()
+{
+ // lookup TURN server
+ const QString domain = configuration().domain();
+ debug(QString("Looking up STUN server for domain %1").arg(domain));
+ m_dns.setType(QDnsLookup::SRV);
+ m_dns.setName("_turn._udp." + domain);
+ m_dns.lookup();
+}
+
+/// The DNS SRV lookup for TURN completed.
+
+void xmppClient::slotDnsLookupFinished()
+{
+ QString serverName;
+
+ if (m_dns.error() == QDnsLookup::NoError && !m_dns.serviceRecords().isEmpty()) {
+ m_turnPort = m_dns.serviceRecords().first().port();
+ QHostInfo::lookupHost(m_dns.serviceRecords().first().target(),
+ this, SLOT(slotHostInfoFinished(QHostInfo)));
+ } else {
+ warning("Could not find STUN server for domain " + configuration().domain());
+ }
+}
+
+void xmppClient::slotHostInfoFinished(const QHostInfo &hostInfo)
+{
+ if (!hostInfo.addresses().isEmpty()) {
+ callManager->setTurnServer(hostInfo.addresses().first(), m_turnPort);
+ callManager->setTurnUser(configuration().user());
+ callManager->setTurnPassword(configuration().password());
+ }
+}
+
/// A presence was received.
void xmppClient::slotPresenceReceived(const QXmppPresence &presence)
{
+ bool check;
+ Q_UNUSED(check);
+
// if we don't have a recipient, or if the presence is not from the recipient,
// do nothing
if (m_recipient.isEmpty() ||
@@ -140,7 +191,6 @@ void xmppClient::slotPresenceReceived(const QXmppPresence &presence)
// start the call and connect to the its signals
QXmppCall *call = callManager->call(presence.from());
- bool check;
check = connect(call, SIGNAL(stateChanged(QXmppCall:State)),
this, SLOT(slotCallStateChanged(QXmppCall::State)));
Q_ASSERT(check);
diff --git a/examples/example_4_callHandling/example_4_callHandling.h b/examples/example_4_callHandling/example_4_callHandling.h
index 788d932c..e1287016 100644
--- a/examples/example_4_callHandling/example_4_callHandling.h
+++ b/examples/example_4_callHandling/example_4_callHandling.h
@@ -27,6 +27,9 @@
#include "QXmppCallManager.h"
#include "QXmppClient.h"
+#include "qdnslookup.h"
+
+class QHostInfo;
class xmppClient : public QXmppClient
{
@@ -40,11 +43,16 @@ private slots:
void slotAudioModeChanged(QIODevice::OpenMode mode);
void slotCallReceived(QXmppCall *call);
void slotCallStateChanged(QXmppCall::State state);
+ void slotConnected();
+ void slotDnsLookupFinished();
+ void slotHostInfoFinished(const QHostInfo &hostInfo);
void slotPresenceReceived(const QXmppPresence &presence);
private:
QXmppCallManager *callManager;
+ QDnsLookup m_dns;
QString m_recipient;
+ quint16 m_turnPort;
};
#endif // IBBCLIENT_H