3
* Copyright 2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
#ifndef TALK_XMPP_HANGOUTPUBSUBCLIENT_H_
29
#define TALK_XMPP_HANGOUTPUBSUBCLIENT_H_
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"
41
// Gives a high-level API for MUC call PubSub needs such as
42
// presenter state, recording state, mute state, and remote mute.
48
class XmppTaskParentInterface;
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;
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
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;
72
template <typename C> class PubSubStateClient;
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<> {
79
HangoutPubSubClient(XmppTaskParentInterface* parent,
81
const std::string& nick);
82
~HangoutPubSubClient();
83
const Jid& mucjid() const { return mucjid_; }
84
const std::string& nick() const { return nick_; }
86
// Requests all of the different states and subscribes for updates.
87
// Responses and updates will be signalled via the various signals.
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_recording, is_recording)
94
sigslot::signal3<const std::string&, bool, bool> SignalRecordingStateChange;
95
// Signal (mutee_nick, muter_nick, should_mute_locally)
96
sigslot::signal3<const std::string&,
98
bool> SignalRemoteMute;
99
// Signal (blockee_nick, blocker_nick)
100
sigslot::signal2<const std::string&, const std::string&> SignalMediaBlock;
102
// Signal (node, error stanza)
103
sigslot::signal2<const std::string&, const XmlElement*> SignalRequestError;
105
// On each of these, provide a task_id_out to get the task_id, which
106
// can be correlated to the error and result signals.
107
void PublishPresenterState(
108
bool presenting, std::string* task_id_out = NULL);
109
void PublishAudioMuteState(
110
bool muted, std::string* task_id_out = NULL);
111
void PublishRecordingState(
112
bool recording, std::string* task_id_out = NULL);
114
const std::string& mutee_nick, std::string* task_id_out = NULL);
116
const std::string& blockee_nick, std::string* task_id_out = NULL);
119
sigslot::signal1<const std::string&> SignalPublishAudioMuteResult;
120
sigslot::signal1<const std::string&> SignalPublishPresenterResult;
121
sigslot::signal1<const std::string&> SignalPublishRecordingResult;
122
// Signal (task_id, mutee_nick)
123
sigslot::signal2<const std::string&,
124
const std::string&> SignalRemoteMuteResult;
125
// Signal (task_id, blockee_nick)
126
sigslot::signal2<const std::string&,
127
const std::string&> SignalMediaBlockResult;
129
// Signal (task_id, error stanza)
130
sigslot::signal2<const std::string&,
131
const XmlElement*> SignalPublishAudioMuteError;
132
sigslot::signal2<const std::string&,
133
const XmlElement*> SignalPublishPresenterError;
134
sigslot::signal2<const std::string&,
135
const XmlElement*> SignalPublishRecordingError;
136
sigslot::signal2<const std::string&,
137
const XmlElement*> SignalPublishMediaBlockError;
138
// Signal (task_id, mutee_nick, error stanza)
139
sigslot::signal3<const std::string&,
141
const XmlElement*> SignalRemoteMuteError;
142
// Signal (task_id, blockee_nick, error stanza)
143
sigslot::signal3<const std::string&,
145
const XmlElement*> SignalMediaBlockError;
149
void OnPresenterRequestError(PubSubClient* client,
150
const XmlElement* stanza);
151
void OnMediaRequestError(PubSubClient* client,
152
const XmlElement* stanza);
154
void OnPresenterStateChange(const PubSubStateChange<bool>& change);
155
void OnPresenterPublishResult(const std::string& task_id,
156
const XmlElement* item);
157
void OnPresenterPublishError(const std::string& task_id,
158
const XmlElement* item,
159
const XmlElement* stanza);
160
void OnAudioMuteStateChange(const PubSubStateChange<bool>& change);
161
void OnAudioMutePublishResult(const std::string& task_id,
162
const XmlElement* item);
163
void OnAudioMutePublishError(const std::string& task_id,
164
const XmlElement* item,
165
const XmlElement* stanza);
166
void OnRecordingStateChange(const PubSubStateChange<bool>& change);
167
void OnRecordingPublishResult(const std::string& task_id,
168
const XmlElement* item);
169
void OnRecordingPublishError(const std::string& task_id,
170
const XmlElement* item,
171
const XmlElement* stanza);
172
void OnMediaBlockStateChange(const PubSubStateChange<bool>& change);
173
void OnMediaBlockPublishResult(const std::string& task_id,
174
const XmlElement* item);
175
void OnMediaBlockPublishError(const std::string& task_id,
176
const XmlElement* item,
177
const XmlElement* stanza);
180
talk_base::scoped_ptr<PubSubClient> media_client_;
181
talk_base::scoped_ptr<PubSubClient> presenter_client_;
182
talk_base::scoped_ptr<PubSubStateClient<bool> > presenter_state_client_;
183
talk_base::scoped_ptr<PubSubStateClient<bool> > audio_mute_state_client_;
184
talk_base::scoped_ptr<PubSubStateClient<bool> > recording_state_client_;
185
talk_base::scoped_ptr<PubSubStateClient<bool> > media_block_state_client_;
190
#endif // TALK_XMPP_HANGOUTPUBSUBCLIENT_H_