Home | History | Annotate | Download | only in xmpp
      1 /*
      2  * libjingle
      3  * Copyright 2011, Google Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are met:
      7  *
      8  *  1. Redistributions of source code must retain the above copyright notice,
      9  *     this list of conditions and the following disclaimer.
     10  *  2. Redistributions in binary form must reproduce the above copyright notice,
     11  *     this list of conditions and the following disclaimer in the documentation
     12  *     and/or other materials provided with the distribution.
     13  *  3. The name of the author may not be used to endorse or promote products
     14  *     derived from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef TALK_XMPP_HANGOUTPUBSUBCLIENT_H_
     29 #define TALK_XMPP_HANGOUTPUBSUBCLIENT_H_
     30 
     31 #include <map>
     32 #include <string>
     33 #include <vector>
     34 
     35 #include "talk/base/scoped_ptr.h"
     36 #include "talk/base/sigslot.h"
     37 #include "talk/base/sigslotrepeater.h"
     38 #include "talk/xmpp/jid.h"
     39 #include "talk/xmpp/pubsubclient.h"
     40 #include "talk/xmpp/pubsubstateclient.h"
     41 
     42 // Gives a high-level API for MUC call PubSub needs such as
     43 // presenter state, recording state, mute state, and remote mute.
     44 
     45 namespace buzz {
     46 
     47 class Jid;
     48 class XmlElement;
     49 class XmppTaskParentInterface;
     50 
     51 // A client tied to a specific MUC jid and local nick.  Provides ways
     52 // to get updates and publish state and events.  Must call
     53 // RequestAll() to start getting updates.
     54 class HangoutPubSubClient : public sigslot::has_slots<> {
     55  public:
     56   HangoutPubSubClient(XmppTaskParentInterface* parent,
     57                       const Jid& mucjid,
     58                       const std::string& nick);
     59   ~HangoutPubSubClient();
     60   const Jid& mucjid() const { return mucjid_; }
     61   const std::string& nick() const { return nick_; }
     62 
     63   // Requests all of the different states and subscribes for updates.
     64   // Responses and updates will be signalled via the various signals.
     65   void RequestAll();
     66   // Signal (nick, was_presenting, is_presenting)
     67   sigslot::signal3<const std::string&, bool, bool> SignalPresenterStateChange;
     68   // Signal (nick, was_muted, is_muted)
     69   sigslot::signal3<const std::string&, bool, bool> SignalAudioMuteStateChange;
     70   // Signal (nick, was_muted, is_muted)
     71   sigslot::signal3<const std::string&, bool, bool> SignalVideoMuteStateChange;
     72   // Signal (nick, was_paused, is_paused)
     73   sigslot::signal3<const std::string&, bool, bool> SignalVideoPauseStateChange;
     74   // Signal (nick, was_recording, is_recording)
     75   sigslot::signal3<const std::string&, bool, bool> SignalRecordingStateChange;
     76   // Signal (mutee_nick, muter_nick, should_mute_locally)
     77   sigslot::signal3<const std::string&,
     78                    const std::string&,
     79                    bool> SignalRemoteMute;
     80   // Signal (blockee_nick, blocker_nick)
     81   sigslot::signal2<const std::string&, const std::string&> SignalMediaBlock;
     82 
     83   // Signal (node, error stanza)
     84   sigslot::signal2<const std::string&, const XmlElement*> SignalRequestError;
     85 
     86   // On each of these, provide a task_id_out to get the task_id, which
     87   // can be correlated to the error and result signals.
     88   void PublishPresenterState(
     89       bool presenting, std::string* task_id_out = NULL);
     90   void PublishAudioMuteState(
     91       bool muted, std::string* task_id_out = NULL);
     92   void PublishVideoMuteState(
     93       bool muted, std::string* task_id_out = NULL);
     94   void PublishVideoPauseState(
     95       bool paused, std::string* task_id_out = NULL);
     96   void PublishRecordingState(
     97       bool recording, std::string* task_id_out = NULL);
     98   void RemoteMute(
     99       const std::string& mutee_nick, std::string* task_id_out = NULL);
    100   void BlockMedia(
    101       const std::string& blockee_nick, std::string* task_id_out = NULL);
    102 
    103   // Signal task_id
    104   sigslot::signal1<const std::string&> SignalPublishAudioMuteResult;
    105   sigslot::signal1<const std::string&> SignalPublishVideoMuteResult;
    106   sigslot::signal1<const std::string&> SignalPublishVideoPauseResult;
    107   sigslot::signal1<const std::string&> SignalPublishPresenterResult;
    108   sigslot::signal1<const std::string&> SignalPublishRecordingResult;
    109   // Signal (task_id, mutee_nick)
    110   sigslot::signal2<const std::string&,
    111                    const std::string&> SignalRemoteMuteResult;
    112   // Signal (task_id, blockee_nick)
    113   sigslot::signal2<const std::string&,
    114                    const std::string&> SignalMediaBlockResult;
    115 
    116   // Signal (task_id, error stanza)
    117   sigslot::signal2<const std::string&,
    118                    const XmlElement*> SignalPublishAudioMuteError;
    119   sigslot::signal2<const std::string&,
    120                    const XmlElement*> SignalPublishVideoMuteError;
    121   sigslot::signal2<const std::string&,
    122                    const XmlElement*> SignalPublishVideoPauseError;
    123   sigslot::signal2<const std::string&,
    124                    const XmlElement*> SignalPublishPresenterError;
    125   sigslot::signal2<const std::string&,
    126                    const XmlElement*> SignalPublishRecordingError;
    127   sigslot::signal2<const std::string&,
    128                    const XmlElement*> SignalPublishMediaBlockError;
    129   // Signal (task_id, mutee_nick, error stanza)
    130   sigslot::signal3<const std::string&,
    131                    const std::string&,
    132                    const XmlElement*> SignalRemoteMuteError;
    133   // Signal (task_id, blockee_nick, error stanza)
    134   sigslot::signal3<const std::string&,
    135                    const std::string&,
    136                    const XmlElement*> SignalMediaBlockError;
    137 
    138 
    139  private:
    140   void OnPresenterRequestError(PubSubClient* client,
    141                                const XmlElement* stanza);
    142   void OnMediaRequestError(PubSubClient* client,
    143                            const XmlElement* stanza);
    144 
    145   void OnPresenterStateChange(const PubSubStateChange<bool>& change);
    146   void OnPresenterPublishResult(const std::string& task_id,
    147                                const XmlElement* item);
    148   void OnPresenterPublishError(const std::string& task_id,
    149                                const XmlElement* item,
    150                                const XmlElement* stanza);
    151   void OnAudioMuteStateChange(const PubSubStateChange<bool>& change);
    152   void OnAudioMutePublishResult(const std::string& task_id,
    153                                const XmlElement* item);
    154   void OnAudioMutePublishError(const std::string& task_id,
    155                                const XmlElement* item,
    156                                const XmlElement* stanza);
    157   void OnVideoMuteStateChange(const PubSubStateChange<bool>& change);
    158   void OnVideoMutePublishResult(const std::string& task_id,
    159                                const XmlElement* item);
    160   void OnVideoMutePublishError(const std::string& task_id,
    161                                const XmlElement* item,
    162                                const XmlElement* stanza);
    163   void OnVideoPauseStateChange(const PubSubStateChange<bool>& change);
    164   void OnVideoPausePublishResult(const std::string& task_id,
    165                                const XmlElement* item);
    166   void OnVideoPausePublishError(const std::string& task_id,
    167                                const XmlElement* item,
    168                                const XmlElement* stanza);
    169   void OnRecordingStateChange(const PubSubStateChange<bool>& change);
    170   void OnRecordingPublishResult(const std::string& task_id,
    171                                const XmlElement* item);
    172   void OnRecordingPublishError(const std::string& task_id,
    173                                const XmlElement* item,
    174                                const XmlElement* stanza);
    175   void OnMediaBlockStateChange(const PubSubStateChange<bool>& change);
    176   void OnMediaBlockPublishResult(const std::string& task_id,
    177                                  const XmlElement* item);
    178   void OnMediaBlockPublishError(const std::string& task_id,
    179                                 const XmlElement* item,
    180                                 const XmlElement* stanza);
    181   Jid mucjid_;
    182   std::string nick_;
    183   talk_base::scoped_ptr<PubSubClient> media_client_;
    184   talk_base::scoped_ptr<PubSubClient> presenter_client_;
    185   talk_base::scoped_ptr<PubSubStateClient<bool> > presenter_state_client_;
    186   talk_base::scoped_ptr<PubSubStateClient<bool> > audio_mute_state_client_;
    187   talk_base::scoped_ptr<PubSubStateClient<bool> > video_mute_state_client_;
    188   talk_base::scoped_ptr<PubSubStateClient<bool> > video_pause_state_client_;
    189   talk_base::scoped_ptr<PubSubStateClient<bool> > recording_state_client_;
    190   talk_base::scoped_ptr<PubSubStateClient<bool> > media_block_state_client_;
    191 };
    192 
    193 }  // namespace buzz
    194 
    195 #endif  // TALK_XMPP_HANGOUTPUBSUBCLIENT_H_
    196