You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
12 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2005, 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. #ifndef TALK_EXAMPLES_CALL_CALLCLIENT_H_
  28. #define TALK_EXAMPLES_CALL_CALLCLIENT_H_
  29. #include <map>
  30. #include <string>
  31. #include <vector>
  32. #include "talk/base/scoped_ptr.h"
  33. #include "talk/base/sslidentity.h"
  34. #include "talk/examples/call/console.h"
  35. #include "talk/media/base/mediachannel.h"
  36. #include "talk/p2p/base/session.h"
  37. #include "talk/session/media/mediamessages.h"
  38. #include "talk/session/media/mediasessionclient.h"
  39. #include "talk/xmpp/hangoutpubsubclient.h"
  40. #include "talk/xmpp/presencestatus.h"
  41. #include "talk/xmpp/xmppclient.h"
  42. namespace buzz {
  43. class PresencePushTask;
  44. class PresenceOutTask;
  45. class MucInviteRecvTask;
  46. class MucInviteSendTask;
  47. class FriendInviteSendTask;
  48. class DiscoInfoQueryTask;
  49. class Muc;
  50. class PresenceStatus;
  51. class IqTask;
  52. class MucRoomConfigTask;
  53. class MucRoomLookupTask;
  54. class MucPresenceStatus;
  55. class XmlElement;
  56. class HangoutPubSubClient;
  57. struct AvailableMediaEntry;
  58. struct MucRoomInfo;
  59. } // namespace buzz
  60. namespace talk_base {
  61. class Thread;
  62. class NetworkManager;
  63. } // namespace talk_base
  64. namespace cricket {
  65. class PortAllocator;
  66. class MediaEngineInterface;
  67. class MediaSessionClient;
  68. class Call;
  69. class SessionManagerTask;
  70. struct CallOptions;
  71. struct MediaStreams;
  72. struct StreamParams;
  73. } // namespace cricket
  74. struct RosterItem {
  75. buzz::Jid jid;
  76. buzz::PresenceStatus::Show show;
  77. std::string status;
  78. };
  79. struct StaticRenderedView {
  80. StaticRenderedView(const cricket::StaticVideoView& view,
  81. cricket::VideoRenderer* renderer) :
  82. view(view),
  83. renderer(renderer) {
  84. }
  85. cricket::StaticVideoView view;
  86. cricket::VideoRenderer* renderer;
  87. };
  88. // Maintain a mapping of (session, ssrc) to rendered view.
  89. typedef std::map<std::pair<cricket::Session*, uint32>,
  90. StaticRenderedView> StaticRenderedViews;
  91. class CallClient: public sigslot::has_slots<> {
  92. public:
  93. CallClient(buzz::XmppClient* xmpp_client,
  94. const std::string& caps_node,
  95. const std::string& version);
  96. ~CallClient();
  97. cricket::MediaSessionClient* media_client() const { return media_client_; }
  98. void SetMediaEngine(cricket::MediaEngineInterface* media_engine) {
  99. media_engine_ = media_engine;
  100. }
  101. void SetAutoAccept(bool auto_accept) {
  102. auto_accept_ = auto_accept;
  103. }
  104. void SetPmucDomain(const std::string &pmuc_domain) {
  105. pmuc_domain_ = pmuc_domain;
  106. }
  107. void SetRender(bool render) {
  108. render_ = render;
  109. }
  110. void SetDataChannelEnabled(bool data_channel_enabled) {
  111. data_channel_enabled_ = data_channel_enabled;
  112. }
  113. void SetMultiSessionEnabled(bool multisession_enabled) {
  114. multisession_enabled_ = multisession_enabled;
  115. }
  116. void SetConsole(Console *console) {
  117. console_ = console;
  118. }
  119. void SetPriority(int priority) {
  120. my_status_.set_priority(priority);
  121. }
  122. void SendStatus() {
  123. SendStatus(my_status_);
  124. }
  125. void SendStatus(const buzz::PresenceStatus& status);
  126. void ParseLine(const std::string &str);
  127. void SendChat(const std::string& to, const std::string msg);
  128. void SendData(const std::string& stream_name,
  129. const std::string& text);
  130. void InviteFriend(const std::string& user);
  131. void JoinMuc(const buzz::Jid& room_jid);
  132. void JoinMuc(const std::string& room_jid_str);
  133. void LookupAndJoinMuc(const std::string& room_name);
  134. void InviteToMuc(const std::string& user, const std::string& room);
  135. bool InMuc();
  136. const buzz::Jid* FirstMucJid();
  137. void LeaveMuc(const std::string& room);
  138. void SetNick(const std::string& muc_nick);
  139. void SetPortAllocatorFlags(uint32 flags) { portallocator_flags_ = flags; }
  140. void SetAllowLocalIps(bool allow_local_ips) {
  141. allow_local_ips_ = allow_local_ips;
  142. }
  143. void SetSignalingProtocol(cricket::SignalingProtocol protocol) {
  144. signaling_protocol_ = protocol;
  145. }
  146. void SetTransportProtocol(cricket::TransportProtocol protocol) {
  147. transport_protocol_ = protocol;
  148. }
  149. void SetSecurePolicy(cricket::SecurePolicy sdes_policy,
  150. cricket::SecurePolicy dtls_policy) {
  151. sdes_policy_ = sdes_policy;
  152. dtls_policy_ = dtls_policy;
  153. }
  154. void SetSslIdentity(talk_base::SSLIdentity* identity) {
  155. ssl_identity_.reset(identity);
  156. }
  157. typedef std::map<buzz::Jid, buzz::Muc*> MucMap;
  158. const MucMap& mucs() const {
  159. return mucs_;
  160. }
  161. private:
  162. void AddStream(uint32 audio_src_id, uint32 video_src_id);
  163. void RemoveStream(uint32 audio_src_id, uint32 video_src_id);
  164. void OnStateChange(buzz::XmppEngine::State state);
  165. void InitMedia();
  166. void InitPresence();
  167. void StartXmppPing();
  168. void OnPingTimeout();
  169. void OnRequestSignaling();
  170. void OnSessionCreate(cricket::Session* session, bool initiate);
  171. void OnCallCreate(cricket::Call* call);
  172. void OnCallDestroy(cricket::Call* call);
  173. void OnSessionState(cricket::Call* call,
  174. cricket::Session* session,
  175. cricket::Session::State state);
  176. void OnStatusUpdate(const buzz::PresenceStatus& status);
  177. void OnMucInviteReceived(const buzz::Jid& inviter, const buzz::Jid& room,
  178. const std::vector<buzz::AvailableMediaEntry>& avail);
  179. void OnMucJoined(const buzz::Jid& endpoint);
  180. void OnMucStatusUpdate(const buzz::Jid& jid,
  181. const buzz::MucPresenceStatus& status);
  182. void OnMucLeft(const buzz::Jid& endpoint, int error);
  183. void OnPresenterStateChange(const std::string& nick,
  184. bool was_presenting, bool is_presenting);
  185. void OnAudioMuteStateChange(const std::string& nick,
  186. bool was_muted, bool is_muted);
  187. void OnRecordingStateChange(const std::string& nick,
  188. bool was_recording, bool is_recording);
  189. void OnRemoteMuted(const std::string& mutee_nick,
  190. const std::string& muter_nick,
  191. bool should_mute_locally);
  192. void OnMediaBlocked(const std::string& blockee_nick,
  193. const std::string& blocker_nick);
  194. void OnHangoutRequestError(const std::string& node,
  195. const buzz::XmlElement* stanza);
  196. void OnHangoutPublishAudioMuteError(const std::string& task_id,
  197. const buzz::XmlElement* stanza);
  198. void OnHangoutPublishPresenterError(const std::string& task_id,
  199. const buzz::XmlElement* stanza);
  200. void OnHangoutPublishRecordingError(const std::string& task_id,
  201. const buzz::XmlElement* stanza);
  202. void OnHangoutRemoteMuteError(const std::string& task_id,
  203. const std::string& mutee_nick,
  204. const buzz::XmlElement* stanza);
  205. void OnDevicesChange();
  206. void OnMediaStreamsUpdate(cricket::Call* call,
  207. cricket::Session* session,
  208. const cricket::MediaStreams& added,
  209. const cricket::MediaStreams& removed);
  210. void OnSpeakerChanged(cricket::Call* call,
  211. cricket::Session* session,
  212. const cricket::StreamParams& speaker_stream);
  213. void OnRoomLookupResponse(buzz::MucRoomLookupTask* task,
  214. const buzz::MucRoomInfo& room_info);
  215. void OnRoomLookupError(buzz::IqTask* task,
  216. const buzz::XmlElement* stanza);
  217. void OnRoomConfigResult(buzz::MucRoomConfigTask* task);
  218. void OnRoomConfigError(buzz::IqTask* task,
  219. const buzz::XmlElement* stanza);
  220. void OnDataReceived(cricket::Call*,
  221. const cricket::ReceiveDataParams& params,
  222. const std::string& data);
  223. buzz::Jid GenerateRandomMucJid();
  224. // Depending on |enable|, render (or don't) all the streams in |session|.
  225. void RenderAllStreams(cricket::Call* call,
  226. cricket::Session* session,
  227. bool enable);
  228. // Depending on |enable|, render (or don't) the streams in |video_streams|.
  229. void RenderStreams(cricket::Call* call,
  230. cricket::Session* session,
  231. const std::vector<cricket::StreamParams>& video_streams,
  232. bool enable);
  233. // Depending on |enable|, render (or don't) the supplied |stream|.
  234. void RenderStream(cricket::Call* call,
  235. cricket::Session* session,
  236. const cricket::StreamParams& stream,
  237. bool enable);
  238. void AddStaticRenderedView(
  239. cricket::Session* session,
  240. uint32 ssrc, int width, int height, int framerate,
  241. int x_offset, int y_offset);
  242. bool RemoveStaticRenderedView(uint32 ssrc);
  243. void RemoveCallsStaticRenderedViews(cricket::Call* call);
  244. void SendViewRequest(cricket::Call* call, cricket::Session* session);
  245. bool SelectFirstDesktopScreencastId(cricket::ScreencastId* screencastid);
  246. static const std::string strerror(buzz::XmppEngine::Error err);
  247. void PrintRoster();
  248. bool FindJid(const std::string& name,
  249. buzz::Jid* found_jid,
  250. cricket::CallOptions* options);
  251. bool PlaceCall(const std::string& name, cricket::CallOptions options);
  252. bool InitiateAdditionalSession(const std::string& name,
  253. cricket::CallOptions options);
  254. void TerminateAndRemoveSession(cricket::Call* call, const std::string& id);
  255. void PrintCalls();
  256. void SwitchToCall(uint32 call_id);
  257. void Accept(const cricket::CallOptions& options);
  258. void Reject();
  259. void Quit();
  260. void GetDevices();
  261. void PrintDevices(const std::vector<std::string>& names);
  262. void SetVolume(const std::string& level);
  263. cricket::Session* GetFirstSession() { return sessions_[call_->id()][0]; }
  264. void AddSession(cricket::Session* session) {
  265. sessions_[call_->id()].push_back(session);
  266. }
  267. void PrintStats() const;
  268. void SetupAcceptedCall();
  269. typedef std::map<std::string, RosterItem> RosterMap;
  270. Console *console_;
  271. buzz::XmppClient* xmpp_client_;
  272. talk_base::Thread* worker_thread_;
  273. talk_base::NetworkManager* network_manager_;
  274. cricket::PortAllocator* port_allocator_;
  275. cricket::SessionManager* session_manager_;
  276. cricket::SessionManagerTask* session_manager_task_;
  277. cricket::MediaEngineInterface* media_engine_;
  278. cricket::DataEngineInterface* data_engine_;
  279. cricket::MediaSessionClient* media_client_;
  280. MucMap mucs_;
  281. cricket::Call* call_;
  282. typedef std::map<uint32, std::vector<cricket::Session *> > SessionMap;
  283. SessionMap sessions_;
  284. buzz::HangoutPubSubClient* hangout_pubsub_client_;
  285. bool incoming_call_;
  286. bool auto_accept_;
  287. std::string pmuc_domain_;
  288. bool render_;
  289. bool data_channel_enabled_;
  290. bool multisession_enabled_;
  291. cricket::VideoRenderer* local_renderer_;
  292. StaticRenderedViews static_rendered_views_;
  293. uint32 static_views_accumulated_count_;
  294. uint32 screencast_ssrc_;
  295. buzz::PresenceStatus my_status_;
  296. buzz::PresencePushTask* presence_push_;
  297. buzz::PresenceOutTask* presence_out_;
  298. buzz::MucInviteRecvTask* muc_invite_recv_;
  299. buzz::MucInviteSendTask* muc_invite_send_;
  300. buzz::FriendInviteSendTask* friend_invite_send_;
  301. RosterMap* roster_;
  302. uint32 portallocator_flags_;
  303. bool allow_local_ips_;
  304. cricket::SignalingProtocol signaling_protocol_;
  305. cricket::TransportProtocol transport_protocol_;
  306. cricket::SecurePolicy sdes_policy_;
  307. cricket::SecurePolicy dtls_policy_;
  308. talk_base::scoped_ptr<talk_base::SSLIdentity> ssl_identity_;
  309. std::string last_sent_to_;
  310. };
  311. #endif // TALK_EXAMPLES_CALL_CALLCLIENT_H_