summaryrefslogtreecommitdiff
path: root/chromium/third_party/libjingle/source/talk/xmpp/hangoutpubsubclient.h
blob: a9986db15988767bd72cfb2efc50e6c16ec784a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 * libjingle
 * Copyright 2011, Google Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef TALK_XMPP_HANGOUTPUBSUBCLIENT_H_
#define TALK_XMPP_HANGOUTPUBSUBCLIENT_H_

#include <map>
#include <string>
#include <vector>

#include "talk/base/scoped_ptr.h"
#include "talk/base/sigslot.h"
#include "talk/base/sigslotrepeater.h"
#include "talk/xmpp/jid.h"
#include "talk/xmpp/pubsubclient.h"

// Gives a high-level API for MUC call PubSub needs such as
// presenter state, recording state, mute state, and remote mute.

namespace buzz {

class Jid;
class XmlElement;
class XmppTaskParentInterface;

// To handle retracts correctly, we need to remember certain details
// about an item.  We could just cache the entire XML element, but
// that would take more memory and require re-parsing.
struct StateItemInfo {
  std::string published_nick;
  std::string publisher_nick;
};

// Represents a PubSub state change.  Usually, the key is the nick,
// but not always.  It's a per-state-type thing.  Currently documented
// at https://docs.google.com/a/google.com/document/d/
// 1QyHu_ufyVdf0VICdfc_DtJbrOdrdIUm4eM73RZqnivI/edit?hl=en_US
template <typename C>
struct PubSubStateChange {
  // The nick of the user changing the state.
  std::string publisher_nick;
  // The nick of the user whose state is changing.
  std::string published_nick;
  C old_state;
  C new_state;
};

template <typename C> class PubSubStateClient;

// A client tied to a specific MUC jid and local nick.  Provides ways
// to get updates and publish state and events.  Must call
// RequestAll() to start getting updates.
class HangoutPubSubClient : public sigslot::has_slots<> {
 public:
  HangoutPubSubClient(XmppTaskParentInterface* parent,
                      const Jid& mucjid,
                      const std::string& nick);
  ~HangoutPubSubClient();
  const Jid& mucjid() const { return mucjid_; }
  const std::string& nick() const { return nick_; }

  // Requests all of the different states and subscribes for updates.
  // Responses and updates will be signalled via the various signals.
  void RequestAll();
  // Signal (nick, was_presenting, is_presenting)
  sigslot::signal3<const std::string&, bool, bool> SignalPresenterStateChange;
  // Signal (nick, was_muted, is_muted)
  sigslot::signal3<const std::string&, bool, bool> SignalAudioMuteStateChange;
  // Signal (nick, was_muted, is_muted)
  sigslot::signal3<const std::string&, bool, bool> SignalVideoMuteStateChange;
  // Signal (nick, was_paused, is_paused)
  sigslot::signal3<const std::string&, bool, bool> SignalVideoPauseStateChange;
  // Signal (nick, was_recording, is_recording)
  sigslot::signal3<const std::string&, bool, bool> SignalRecordingStateChange;
  // Signal (mutee_nick, muter_nick, should_mute_locally)
  sigslot::signal3<const std::string&,
                   const std::string&,
                   bool> SignalRemoteMute;
  // Signal (blockee_nick, blocker_nick)
  sigslot::signal2<const std::string&, const std::string&> SignalMediaBlock;

  // Signal (node, error stanza)
  sigslot::signal2<const std::string&, const XmlElement*> SignalRequestError;

  // On each of these, provide a task_id_out to get the task_id, which
  // can be correlated to the error and result signals.
  void PublishPresenterState(
      bool presenting, std::string* task_id_out = NULL);
  void PublishAudioMuteState(
      bool muted, std::string* task_id_out = NULL);
  void PublishVideoMuteState(
      bool muted, std::string* task_id_out = NULL);
  void PublishVideoPauseState(
      bool paused, std::string* task_id_out = NULL);
  void PublishRecordingState(
      bool recording, std::string* task_id_out = NULL);
  void RemoteMute(
      const std::string& mutee_nick, std::string* task_id_out = NULL);
  void BlockMedia(
      const std::string& blockee_nick, std::string* task_id_out = NULL);

  // Signal task_id
  sigslot::signal1<const std::string&> SignalPublishAudioMuteResult;
  sigslot::signal1<const std::string&> SignalPublishVideoMuteResult;
  sigslot::signal1<const std::string&> SignalPublishVideoPauseResult;
  sigslot::signal1<const std::string&> SignalPublishPresenterResult;
  sigslot::signal1<const std::string&> SignalPublishRecordingResult;
  // Signal (task_id, mutee_nick)
  sigslot::signal2<const std::string&,
                   const std::string&> SignalRemoteMuteResult;
  // Signal (task_id, blockee_nick)
  sigslot::signal2<const std::string&,
                   const std::string&> SignalMediaBlockResult;

  // Signal (task_id, error stanza)
  sigslot::signal2<const std::string&,
                   const XmlElement*> SignalPublishAudioMuteError;
  sigslot::signal2<const std::string&,
                   const XmlElement*> SignalPublishVideoMuteError;
  sigslot::signal2<const std::string&,
                   const XmlElement*> SignalPublishVideoPauseError;
  sigslot::signal2<const std::string&,
                   const XmlElement*> SignalPublishPresenterError;
  sigslot::signal2<const std::string&,
                   const XmlElement*> SignalPublishRecordingError;
  sigslot::signal2<const std::string&,
                   const XmlElement*> SignalPublishMediaBlockError;
  // Signal (task_id, mutee_nick, error stanza)
  sigslot::signal3<const std::string&,
                   const std::string&,
                   const XmlElement*> SignalRemoteMuteError;
  // Signal (task_id, blockee_nick, error stanza)
  sigslot::signal3<const std::string&,
                   const std::string&,
                   const XmlElement*> SignalMediaBlockError;


 private:
  void OnPresenterRequestError(PubSubClient* client,
                               const XmlElement* stanza);
  void OnMediaRequestError(PubSubClient* client,
                           const XmlElement* stanza);

  void OnPresenterStateChange(const PubSubStateChange<bool>& change);
  void OnPresenterPublishResult(const std::string& task_id,
                               const XmlElement* item);
  void OnPresenterPublishError(const std::string& task_id,
                               const XmlElement* item,
                               const XmlElement* stanza);
  void OnAudioMuteStateChange(const PubSubStateChange<bool>& change);
  void OnAudioMutePublishResult(const std::string& task_id,
                               const XmlElement* item);
  void OnAudioMutePublishError(const std::string& task_id,
                               const XmlElement* item,
                               const XmlElement* stanza);
  void OnVideoMuteStateChange(const PubSubStateChange<bool>& change);
  void OnVideoMutePublishResult(const std::string& task_id,
                               const XmlElement* item);
  void OnVideoMutePublishError(const std::string& task_id,
                               const XmlElement* item,
                               const XmlElement* stanza);
  void OnVideoPauseStateChange(const PubSubStateChange<bool>& change);
  void OnVideoPausePublishResult(const std::string& task_id,
                               const XmlElement* item);
  void OnVideoPausePublishError(const std::string& task_id,
                               const XmlElement* item,
                               const XmlElement* stanza);
  void OnRecordingStateChange(const PubSubStateChange<bool>& change);
  void OnRecordingPublishResult(const std::string& task_id,
                               const XmlElement* item);
  void OnRecordingPublishError(const std::string& task_id,
                               const XmlElement* item,
                               const XmlElement* stanza);
  void OnMediaBlockStateChange(const PubSubStateChange<bool>& change);
  void OnMediaBlockPublishResult(const std::string& task_id,
                                 const XmlElement* item);
  void OnMediaBlockPublishError(const std::string& task_id,
                                const XmlElement* item,
                                const XmlElement* stanza);
  Jid mucjid_;
  std::string nick_;
  talk_base::scoped_ptr<PubSubClient> media_client_;
  talk_base::scoped_ptr<PubSubClient> presenter_client_;
  talk_base::scoped_ptr<PubSubStateClient<bool> > presenter_state_client_;
  talk_base::scoped_ptr<PubSubStateClient<bool> > audio_mute_state_client_;
  talk_base::scoped_ptr<PubSubStateClient<bool> > video_mute_state_client_;
  talk_base::scoped_ptr<PubSubStateClient<bool> > video_pause_state_client_;
  talk_base::scoped_ptr<PubSubStateClient<bool> > recording_state_client_;
  talk_base::scoped_ptr<PubSubStateClient<bool> > media_block_state_client_;
};

}  // namespace buzz

#endif  // TALK_XMPP_HANGOUTPUBSUBCLIENT_H_