QXmppCallManager.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Author:
  5. * Jeremy Lainé
  6. *
  7. * Source:
  8. * http://code.google.com/p/qxmpp
  9. *
  10. * This file is a part of QXmpp library.
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. */
  23. #ifndef QXMPPCALLMANAGER_H
  24. #define QXMPPCALLMANAGER_H
  25. #include <QObject>
  26. #include <QIODevice>
  27. #include <QMetaType>
  28. #include "QXmppClientExtension.h"
  29. #include "QXmppLogger.h"
  30. class QHostAddress;
  31. class QXmppCallPrivate;
  32. class QXmppCallManager;
  33. class QXmppCallManagerPrivate;
  34. class QXmppIq;
  35. class QXmppJingleCandidate;
  36. class QXmppJingleIq;
  37. class QXmppJinglePayloadType;
  38. class QXmppPresence;
  39. class QXmppRtpAudioChannel;
  40. class QXmppRtpVideoChannel;
  41. /// \brief The QXmppCall class represents a Voice-Over-IP call to a remote party.
  42. ///
  43. /// To get the QIODevice from which you can read / write audio samples, call
  44. /// audioChannel().
  45. ///
  46. /// \note THIS API IS NOT FINALIZED YET
  47. class QXMPP_EXPORT QXmppCall : public QXmppLoggable
  48. {
  49. Q_OBJECT
  50. Q_ENUMS(Direction State)
  51. Q_FLAGS(QIODevice::OpenModeFlag QIODevice::OpenMode)
  52. Q_PROPERTY(Direction direction READ direction CONSTANT)
  53. Q_PROPERTY(QString jid READ jid CONSTANT)
  54. Q_PROPERTY(State state READ state NOTIFY stateChanged)
  55. Q_PROPERTY(QIODevice::OpenMode audioMode READ audioMode NOTIFY audioModeChanged)
  56. Q_PROPERTY(QIODevice::OpenMode videoMode READ videoMode NOTIFY videoModeChanged)
  57. public:
  58. /// This enum is used to describe the direction of a call.
  59. enum Direction
  60. {
  61. IncomingDirection, ///< The call is incoming.
  62. OutgoingDirection, ///< The call is outgoing.
  63. };
  64. /// This enum is used to describe the state of a call.
  65. enum State
  66. {
  67. ConnectingState = 0, ///< The call is being connected.
  68. ActiveState = 1, ///< The call is active.
  69. DisconnectingState = 2, ///< The call is being disconnected.
  70. FinishedState = 3, ///< The call is finished.
  71. };
  72. ~QXmppCall();
  73. QXmppCall::Direction direction() const;
  74. QString jid() const;
  75. QString sid() const;
  76. QXmppCall::State state() const;
  77. QXmppRtpAudioChannel *audioChannel() const;
  78. QIODevice::OpenMode audioMode() const;
  79. QXmppRtpVideoChannel *videoChannel() const;
  80. QIODevice::OpenMode videoMode() const;
  81. signals:
  82. /// \brief This signal is emitted when a call is connected.
  83. ///
  84. /// Once this signal is emitted, you can connect a QAudioOutput and
  85. /// QAudioInput to the call. You can determine the appropriate clockrate
  86. /// and the number of channels by calling payloadType().
  87. void connected();
  88. /// \brief This signal is emitted when a call is finished.
  89. ///
  90. /// Note: Do not delete the call in the slot connected to this signal,
  91. /// instead use deleteLater().
  92. void finished();
  93. /// \brief This signal is emitted when the remote party is ringing.
  94. void ringing();
  95. /// \brief This signal is emitted when the call state changes.
  96. void stateChanged(QXmppCall::State state);
  97. /// \brief This signal is emitted when the audio channel changes.
  98. void audioModeChanged(QIODevice::OpenMode mode);
  99. /// \brief This signal is emitted when the video channel changes.
  100. void videoModeChanged(QIODevice::OpenMode mode);
  101. public slots:
  102. void accept();
  103. void hangup();
  104. void startVideo();
  105. void stopVideo();
  106. private slots:
  107. void localCandidatesChanged();
  108. void terminated();
  109. void updateOpenMode();
  110. private:
  111. QXmppCall(const QString &jid, QXmppCall::Direction direction, QXmppCallManager *parent);
  112. QXmppCallPrivate *d;
  113. friend class QXmppCallManager;
  114. friend class QXmppCallManagerPrivate;
  115. friend class QXmppCallPrivate;
  116. };
  117. /// \brief The QXmppCallManager class provides support for making and
  118. /// receiving voice calls.
  119. ///
  120. /// Session initiation is performed as described by XEP-0166: Jingle,
  121. /// XEP-0167: Jingle RTP Sessions and XEP-0176: Jingle ICE-UDP Transport
  122. /// Method.
  123. ///
  124. /// The data stream is connected using Interactive Connectivity Establishment
  125. /// (RFC 5245) and data is transferred using Real Time Protocol (RFC 3550)
  126. /// packets.
  127. ///
  128. /// To make use of this manager, you need to instantiate it and load it into
  129. /// the QXmppClient instance as follows:
  130. ///
  131. /// \code
  132. /// QXmppCallManager *manager = new QXmppCallManager;
  133. /// client->addExtension(manager);
  134. /// \endcode
  135. ///
  136. /// \ingroup Managers
  137. class QXMPP_EXPORT QXmppCallManager : public QXmppClientExtension
  138. {
  139. Q_OBJECT
  140. public:
  141. QXmppCallManager();
  142. ~QXmppCallManager();
  143. void setStunServer(const QHostAddress &host, quint16 port = 3478);
  144. void setTurnServer(const QHostAddress &host, quint16 port = 3478);
  145. void setTurnUser(const QString &user);
  146. void setTurnPassword(const QString &password);
  147. /// \cond
  148. QStringList discoveryFeatures() const;
  149. bool handleStanza(const QDomElement &element);
  150. /// \endcond
  151. signals:
  152. /// This signal is emitted when a new incoming call is received.
  153. ///
  154. /// To accept the call, invoke the call's QXmppCall::accept() method.
  155. /// To refuse the call, invoke the call's QXmppCall::hangup() method.
  156. void callReceived(QXmppCall *call);
  157. /// This signal is emitted when a call (incoming or outgoing) is started.
  158. void callStarted(QXmppCall *call);
  159. public slots:
  160. QXmppCall *call(const QString &jid);
  161. protected:
  162. /// \cond
  163. void setClient(QXmppClient* client);
  164. /// \endcond
  165. private slots:
  166. void _q_callDestroyed(QObject *object);
  167. void _q_disconnected();
  168. void _q_iqReceived(const QXmppIq &iq);
  169. void _q_jingleIqReceived(const QXmppJingleIq &iq);
  170. void _q_presenceReceived(const QXmppPresence &presence);
  171. private:
  172. QXmppCallManagerPrivate *d;
  173. friend class QXmppCall;
  174. friend class QXmppCallPrivate;
  175. friend class QXmppCallManagerPrivate;
  176. };
  177. Q_DECLARE_METATYPE(QXmppCall::State)
  178. #endif