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 41 // Gives a high-level API for MUC call PubSub needs such as 42 // presenter state, recording state, mute state, and remote mute. 43 44 namespace buzz { 45 46 class Jid; 47 class XmlElement; 48 class XmppTaskParentInterface; 49 50 // To handle retracts correctly, we need to remember certain details 51 // about an item. We could just cache the entire XML element, but 52 // that would take more memory and require re-parsing. 53 struct StateItemInfo { 54 std::string published_nick; 55 std::string publisher_nick; 56 }; 57 58 // Represents a PubSub state change. Usually, the key is the nick, 59 // but not always. It's a per-state-type thing. Currently documented 60 // at https://docs.google.com/a/google.com/document/d/ 61 // 1QyHu_ufyVdf0VICdfc_DtJbrOdrdIUm4eM73RZqnivI/edit?hl=en_US 62 template <typename C> 63 struct PubSubStateChange { 64 // The nick of the user changing the state. 65 std::string publisher_nick; 66 // The nick of the user whose state is changing. 67 std::string published_nick; 68 C old_state; 69 C new_state; 70 }; 71 72 template <typename C> class PubSubStateClient; 73 74 // A client tied to a specific MUC jid and local nick. Provides ways 75 // to get updates and publish state and events. Must call 76 // RequestAll() to start getting updates. 77 class HangoutPubSubClient : public sigslot::has_slots<> { 78 public: 79 HangoutPubSubClient(XmppTaskParentInterface* parent, 80 const Jid& mucjid, 81 const std::string& nick); 82 ~HangoutPubSubClient(); 83 const Jid& mucjid() const { return mucjid_; } 84 const std::string& nick() const { return nick_; } 85 86 // Requests all of the different states and subscribes for updates. 87 // Responses and updates will be signalled via the various signals. 88 void RequestAll(); 89 // Signal (nick, was_presenting, is_presenting) 90 sigslot::signal3<const std::string&, bool, bool> SignalPresenterStateChange; 91 // Signal (nick, was_muted, is_muted) 92 sigslot::signal3<const std::string&, bool, bool> SignalAudioMuteStateChange; 93 // Signal (nick, was_muted, is_muted) 94 sigslot::signal3<const std::string&, bool, bool> SignalVideoMuteStateChange; 95 // Signal (nick, was_paused, is_paused) 96 sigslot::signal3<const std::string&, bool, bool> SignalVideoPauseStateChange; 97 // Signal (nick, was_recording, is_recording) 98 sigslot::signal3<const std::string&, bool, bool> SignalRecordingStateChange; 99 // Signal (mutee_nick, muter_nick, should_mute_locally) 100 sigslot::signal3<const std::string&, 101 const std::string&, 102 bool> SignalRemoteMute; 103 // Signal (blockee_nick, blocker_nick) 104 sigslot::signal2<const std::string&, const std::string&> SignalMediaBlock; 105 106 // Signal (node, error stanza) 107 sigslot::signal2<const std::string&, const XmlElement*> SignalRequestError; 108 109 // On each of these, provide a task_id_out to get the task_id, which 110 // can be correlated to the error and result signals. 111 void PublishPresenterState( 112 bool presenting, std::string* task_id_out = NULL); 113 void PublishAudioMuteState( 114 bool muted, std::string* task_id_out = NULL); 115 void PublishVideoMuteState( 116 bool muted, std::string* task_id_out = NULL); 117 void PublishVideoPauseState( 118 bool paused, std::string* task_id_out = NULL); 119 void PublishRecordingState( 120 bool recording, std::string* task_id_out = NULL); 121 void RemoteMute( 122 const std::string& mutee_nick, std::string* task_id_out = NULL); 123 void BlockMedia( 124 const std::string& blockee_nick, std::string* task_id_out = NULL); 125 126 // Signal task_id 127 sigslot::signal1<const std::string&> SignalPublishAudioMuteResult; 128 sigslot::signal1<const std::string&> SignalPublishVideoMuteResult; 129 sigslot::signal1<const std::string&> SignalPublishVideoPauseResult; 130 sigslot::signal1<const std::string&> SignalPublishPresenterResult; 131 sigslot::signal1<const std::string&> SignalPublishRecordingResult; 132 // Signal (task_id, mutee_nick) 133 sigslot::signal2<const std::string&, 134 const std::string&> SignalRemoteMuteResult; 135 // Signal (task_id, blockee_nick) 136 sigslot::signal2<const std::string&, 137 const std::string&> SignalMediaBlockResult; 138 139 // Signal (task_id, error stanza) 140 sigslot::signal2<const std::string&, 141 const XmlElement*> SignalPublishAudioMuteError; 142 sigslot::signal2<const std::string&, 143 const XmlElement*> SignalPublishVideoMuteError; 144 sigslot::signal2<const std::string&, 145 const XmlElement*> SignalPublishVideoPauseError; 146 sigslot::signal2<const std::string&, 147 const XmlElement*> SignalPublishPresenterError; 148 sigslot::signal2<const std::string&, 149 const XmlElement*> SignalPublishRecordingError; 150 sigslot::signal2<const std::string&, 151 const XmlElement*> SignalPublishMediaBlockError; 152 // Signal (task_id, mutee_nick, error stanza) 153 sigslot::signal3<const std::string&, 154 const std::string&, 155 const XmlElement*> SignalRemoteMuteError; 156 // Signal (task_id, blockee_nick, error stanza) 157 sigslot::signal3<const std::string&, 158 const std::string&, 159 const XmlElement*> SignalMediaBlockError; 160 161 162 private: 163 void OnPresenterRequestError(PubSubClient* client, 164 const XmlElement* stanza); 165 void OnMediaRequestError(PubSubClient* client, 166 const XmlElement* stanza); 167 168 void OnPresenterStateChange(const PubSubStateChange<bool>& change); 169 void OnPresenterPublishResult(const std::string& task_id, 170 const XmlElement* item); 171 void OnPresenterPublishError(const std::string& task_id, 172 const XmlElement* item, 173 const XmlElement* stanza); 174 void OnAudioMuteStateChange(const PubSubStateChange<bool>& change); 175 void OnAudioMutePublishResult(const std::string& task_id, 176 const XmlElement* item); 177 void OnAudioMutePublishError(const std::string& task_id, 178 const XmlElement* item, 179 const XmlElement* stanza); 180 void OnVideoMuteStateChange(const PubSubStateChange<bool>& change); 181 void OnVideoMutePublishResult(const std::string& task_id, 182 const XmlElement* item); 183 void OnVideoMutePublishError(const std::string& task_id, 184 const XmlElement* item, 185 const XmlElement* stanza); 186 void OnVideoPauseStateChange(const PubSubStateChange<bool>& change); 187 void OnVideoPausePublishResult(const std::string& task_id, 188 const XmlElement* item); 189 void OnVideoPausePublishError(const std::string& task_id, 190 const XmlElement* item, 191 const XmlElement* stanza); 192 void OnRecordingStateChange(const PubSubStateChange<bool>& change); 193 void OnRecordingPublishResult(const std::string& task_id, 194 const XmlElement* item); 195 void OnRecordingPublishError(const std::string& task_id, 196 const XmlElement* item, 197 const XmlElement* stanza); 198 void OnMediaBlockStateChange(const PubSubStateChange<bool>& change); 199 void OnMediaBlockPublishResult(const std::string& task_id, 200 const XmlElement* item); 201 void OnMediaBlockPublishError(const std::string& task_id, 202 const XmlElement* item, 203 const XmlElement* stanza); 204 Jid mucjid_; 205 std::string nick_; 206 talk_base::scoped_ptr<PubSubClient> media_client_; 207 talk_base::scoped_ptr<PubSubClient> presenter_client_; 208 talk_base::scoped_ptr<PubSubStateClient<bool> > presenter_state_client_; 209 talk_base::scoped_ptr<PubSubStateClient<bool> > audio_mute_state_client_; 210 talk_base::scoped_ptr<PubSubStateClient<bool> > video_mute_state_client_; 211 talk_base::scoped_ptr<PubSubStateClient<bool> > video_pause_state_client_; 212 talk_base::scoped_ptr<PubSubStateClient<bool> > recording_state_client_; 213 talk_base::scoped_ptr<PubSubStateClient<bool> > media_block_state_client_; 214 }; 215 216 } // namespace buzz 217 218 #endif // TALK_XMPP_HANGOUTPUBSUBCLIENT_H_ 219