diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2011-05-03 11:06:02 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2011-05-03 11:06:02 +0000 |
| commit | 249aaaf51d866f1949b41849e4f3f43af522d8a0 (patch) | |
| tree | a706b55aef3b72038a97333dac33c2575c575cd8 /examples/example_4_callHandling/xmppClient.cpp | |
| parent | cb5db292aacff60c134c1c7e1f844a9842de5132 (diff) | |
| download | qxmpp-249aaaf51d866f1949b41849e4f3f43af522d8a0.tar.gz | |
update calls example
Diffstat (limited to 'examples/example_4_callHandling/xmppClient.cpp')
| -rw-r--r-- | examples/example_4_callHandling/xmppClient.cpp | 73 |
1 files changed, 42 insertions, 31 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. |
