~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/xmpp/hangoutpubsubclient.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_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&,
 
97
                   const std::string&,
 
98
                   bool> SignalRemoteMute;
 
99
  // Signal (blockee_nick, blocker_nick)
 
100
  sigslot::signal2<const std::string&, const std::string&> SignalMediaBlock;
 
101
 
 
102
  // Signal (node, error stanza)
 
103
  sigslot::signal2<const std::string&, const XmlElement*> SignalRequestError;
 
104
 
 
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);
 
113
  void RemoteMute(
 
114
      const std::string& mutee_nick, std::string* task_id_out = NULL);
 
115
  void BlockMedia(
 
116
      const std::string& blockee_nick, std::string* task_id_out = NULL);
 
117
 
 
118
  // Signal task_id
 
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;
 
128
 
 
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&,
 
140
                   const std::string&,
 
141
                   const XmlElement*> SignalRemoteMuteError;
 
142
  // Signal (task_id, blockee_nick, error stanza)
 
143
  sigslot::signal3<const std::string&,
 
144
                   const std::string&,
 
145
                   const XmlElement*> SignalMediaBlockError;
 
146
 
 
147
 
 
148
 private:
 
149
  void OnPresenterRequestError(PubSubClient* client,
 
150
                               const XmlElement* stanza);
 
151
  void OnMediaRequestError(PubSubClient* client,
 
152
                           const XmlElement* stanza);
 
153
 
 
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);
 
178
  Jid mucjid_;
 
179
  std::string nick_;
 
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_;
 
186
};
 
187
 
 
188
}  // namespace buzz
 
189
 
 
190
#endif  // TALK_XMPP_HANGOUTPUBSUBCLIENT_H_