aboutsummaryrefslogtreecommitdiff
path: root/examples/example_4_callHandling
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2011-05-03 11:06:02 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2011-05-03 11:06:02 +0000
commit249aaaf51d866f1949b41849e4f3f43af522d8a0 (patch)
treea706b55aef3b72038a97333dac33c2575c575cd8 /examples/example_4_callHandling
parentcb5db292aacff60c134c1c7e1f844a9842de5132 (diff)
downloadqxmpp-249aaaf51d866f1949b41849e4f3f43af522d8a0.tar.gz
update calls example
Diffstat (limited to 'examples/example_4_callHandling')
-rw-r--r--examples/example_4_callHandling/xmppClient.cpp73
-rw-r--r--examples/example_4_callHandling/xmppClient.h8
2 files changed, 45 insertions, 36 deletions
diff --git a/examples/example_4_callHandling/xmppClient.cpp b/examples/example_4_callHandling/xmppClient.cpp
index 64219b80..95e13442 100644
--- a/examples/example_4_callHandling/xmppClient.cpp
+++ b/examples/example_4_callHandling/xmppClient.cpp
@@ -49,30 +49,12 @@ xmppClient::xmppClient(QObject *parent)
Q_ASSERT(check);
}
-/// A call was received.
-
-void xmppClient::slotCallReceived(QXmppCall *call)
-{
- qDebug() << "Got call from:" << call->jid();
-
- bool check = connect(call, SIGNAL(connected()), this, SLOT(slotConnected()));
- Q_ASSERT(check);
-
- check = connect(call, SIGNAL(finished()), this, SLOT(slotFinished()));
- Q_ASSERT(check);
-
- // accept call
- call->accept();
-}
-
-/// A call connected.
+/// The audio mode of a call changed.
-void xmppClient::slotConnected()
+void xmppClient::slotAudioModeChanged(QIODevice::OpenMode mode)
{
QXmppCall *call = qobject_cast<QXmppCall*>(sender());
Q_ASSERT(call);
-
- qDebug() << "Call connected";
QXmppRtpAudioChannel *channel = call->audioChannel();
// prepare audio format
@@ -88,22 +70,51 @@ void xmppClient::slotConnected()
// 160 ms seems to be the minimum to work consistently on Linux/Mac/Windows
const int bufferSize = (format.frequency() * format.channels() * (format.sampleSize() / 8) * 160) / 1000;
- // initialise audio output
- QAudioOutput *audioOutput = new QAudioOutput(format, this);
- audioOutput->setBufferSize(bufferSize);
- audioOutput->start(channel);
+ if (mode & QIODevice::ReadOnly) {
+ // initialise audio output
+ QAudioOutput *audioOutput = new QAudioOutput(format, this);
+ audioOutput->setBufferSize(bufferSize);
+ audioOutput->start(channel);
+ }
+
+ if (mode & QIODevice::WriteOnly) {
+ // initialise audio input
+ QAudioInput *audioInput = new QAudioInput(format, this);
+ audioInput->setBufferSize(bufferSize);
+ audioInput->start(channel);
+ }
+}
+
+
+/// A call was received.
- // initialise audio input
- QAudioInput *audioInput = new QAudioInput(format, this);
- audioInput->setBufferSize(bufferSize);
- audioInput->start(channel);
+void xmppClient::slotCallReceived(QXmppCall *call)
+{
+ qDebug() << "Got call from:" << call->jid();
+
+ bool check;
+ check = connect(call, SIGNAL(stateChanged()),
+ this, SLOT(slotCallStateChanged(QXmppCall::State)));
+ Q_ASSERT(check);
+
+ check = connect(call, SIGNAL(audioModeChanged(QIODevice::OpenMode)),
+ this, SLOT(slotAudioModeChanged(QIODevice::OpenMode)));
+ Q_ASSERT(check);
+
+ // accept call
+ call->accept();
}
-/// A call finished.
+/// A call changed state.
-void xmppClient::slotFinished()
+void xmppClient::slotCallStateChanged(QXmppCall::State state)
{
- qDebug() << "Call finished";
+ if (state == QXmppCall::ActiveState)
+ qDebug("Call active");
+ else if (state == QXmppCall::DisconnectingState)
+ qDebug("Call disconnecting");
+ else if (state == QXmppCall::FinishedState)
+ qDebug("Call finished");
}
/// A presence was received.
diff --git a/examples/example_4_callHandling/xmppClient.h b/examples/example_4_callHandling/xmppClient.h
index 6733164b..bc097430 100644
--- a/examples/example_4_callHandling/xmppClient.h
+++ b/examples/example_4_callHandling/xmppClient.h
@@ -25,11 +25,9 @@
#ifndef XMPPCLIENT_H
#define XMPPCLIENT_H
+#include "QXmppCallManager.h"
#include "QXmppClient.h"
-class QXmppCall;
-class QXmppCallManager;
-
class xmppClient : public QXmppClient
{
Q_OBJECT
@@ -38,9 +36,9 @@ public:
xmppClient(QObject *parent = 0);
private slots:
+ void slotAudioModeChanged(QIODevice::OpenMode mode);
void slotCallReceived(QXmppCall *call);
- void slotConnected();
- void slotFinished();
+ void slotCallStateChanged(QXmppCall::State state);
void slotPresenceReceived(const QXmppPresence &presence);
private: