llfloateractivespeakers.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /**
  2. * @file llfloateractivespeakers.h
  3. * @brief Management interface for muting and controlling volume of residents
  4. * currently speaking
  5. *
  6. * $LicenseInfo:firstyear=2005&license=viewergpl$
  7. *
  8. * Copyright (c) 2005-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLFLOATERACTIVESPEAKERS_H
  34. #define LL_LLFLOATERACTIVESPEAKERS_H
  35. #include "llavatarnamecache.h"
  36. #include "llevent.h"
  37. #include "llfloater.h"
  38. #include "llframetimer.h"
  39. #include "llpointer.h"
  40. #include "llrefcount.h"
  41. #include "llsingleton.h"
  42. class LLButton;
  43. class LLPanelActiveSpeakers;
  44. class LLScrollListCtrl;
  45. class LLSliderCtrl;
  46. class LLSpeakerMgr;
  47. class LLVoiceChannel;
  48. // Data for a given participant in a voice channel
  49. class LLSpeaker : public LLRefCount,
  50. public LLOldEvents::LLObservable,
  51. public LLHandleProvider<LLSpeaker>
  52. {
  53. public:
  54. typedef enum e_speaker_type
  55. {
  56. SPEAKER_AGENT,
  57. SPEAKER_OBJECT,
  58. // Speaker that does not map to an avatar or object (i.e. PSTN caller
  59. // in a group)
  60. SPEAKER_EXTERNAL
  61. } ESpeakerType;
  62. typedef enum e_speaker_status
  63. {
  64. STATUS_SPEAKING,
  65. STATUS_HAS_SPOKEN,
  66. STATUS_VOICE_ACTIVE,
  67. STATUS_TEXT_ONLY,
  68. STATUS_NOT_IN_CHANNEL,
  69. STATUS_MUTED
  70. } ESpeakerStatus;
  71. LLSpeaker(const LLUUID& id, const std::string& name = LLStringUtil::null,
  72. ESpeakerType type = SPEAKER_AGENT,
  73. ESpeakerStatus status = LLSpeaker::STATUS_TEXT_ONLY);
  74. LL_INLINE void setStatus(ESpeakerStatus status)
  75. {
  76. if (mStatus != status)
  77. {
  78. mStatus = status;
  79. mNeedsResort = true;
  80. }
  81. }
  82. LL_INLINE void setDisplayName(const std::string& name)
  83. {
  84. if (mDisplayName != name)
  85. {
  86. mDisplayName = name;
  87. mNeedsResort = true;
  88. }
  89. }
  90. LL_INLINE void setSpokenTime(F32 time)
  91. {
  92. if (mLastSpokeTime != time)
  93. {
  94. mLastSpokeTime = time;
  95. mHasSpoken = mNeedsResort = true;
  96. }
  97. }
  98. void lookupName();
  99. static void onAvatarNameLookup(const LLUUID& id,
  100. const LLAvatarName& avatar_name,
  101. void* user_data);
  102. public:
  103. // Current activity status in speech group
  104. ESpeakerStatus mStatus;
  105. // Timestamp when this speaker last spoke
  106. F32 mLastSpokeTime;
  107. // Current speech amplitude (timea average RMS amplitude ?);
  108. F32 mSpeechVolume;
  109. // Cache legacy name for this speaker
  110. std::string mLegacyName;
  111. // Cache display name for this speaker
  112. std::string mDisplayName;
  113. // Time out speakers when they are not part of current voice channel
  114. LLFrameTimer mActivityTimer;
  115. LLColor4 mDotColor;
  116. LLUUID mID;
  117. LLUUID mOwnerID;
  118. S32 mSortIndex;
  119. ESpeakerType mType;
  120. // Has this speaker said anything this session ?
  121. bool mHasSpoken;
  122. bool mTyping;
  123. bool mIsModerator;
  124. bool mModeratorMutedVoice;
  125. bool mModeratorMutedText;
  126. bool mNeedsResort;
  127. };
  128. class LLSpeakerTextModerationEvent : public LLOldEvents::LLEvent
  129. {
  130. public:
  131. LLSpeakerTextModerationEvent(LLSpeaker* source);
  132. LLSD getValue() override;
  133. };
  134. class LLSpeakerVoiceModerationEvent : public LLOldEvents::LLEvent
  135. {
  136. public:
  137. LLSpeakerVoiceModerationEvent(LLSpeaker* source);
  138. LLSD getValue() override;
  139. };
  140. class LLSpeakerListChangeEvent : public LLOldEvents::LLEvent
  141. {
  142. public:
  143. LLSpeakerListChangeEvent(LLSpeakerMgr* source, const LLUUID& speaker_id);
  144. LLSD getValue() override;
  145. private:
  146. const LLUUID& mSpeakerID;
  147. };
  148. class LLSpeakerMgr : public LLOldEvents::LLObservable
  149. {
  150. public:
  151. LLSpeakerMgr(LLVoiceChannel* channelp);
  152. const LLPointer<LLSpeaker> findSpeaker(const LLUUID& avatar_id);
  153. void update(bool resort_ok);
  154. void setSpeakerTyping(const LLUUID& speaker_id, bool typing);
  155. void speakerChatted(const LLUUID& speaker_id);
  156. LLPointer<LLSpeaker> setSpeaker(const LLUUID& id,
  157. const std::string& name = LLStringUtil::null,
  158. LLSpeaker::ESpeakerStatus status = LLSpeaker::STATUS_TEXT_ONLY,
  159. LLSpeaker::ESpeakerType = LLSpeaker::SPEAKER_AGENT,
  160. const LLUUID& owner_id = LLUUID::null);
  161. bool isVoiceActive();
  162. typedef std::vector<LLPointer<LLSpeaker> > speaker_list_t;
  163. void getSpeakerList(speaker_list_t* speaker_list, bool include_text);
  164. const LLUUID getSessionID();
  165. protected:
  166. void updateSpeakerList();
  167. protected:
  168. typedef fast_hmap<LLUUID, LLPointer<LLSpeaker> > speaker_map_t;
  169. speaker_map_t mSpeakers;
  170. speaker_list_t mSpeakersSorted;
  171. LLFrameTimer mSpeechTimer;
  172. LLVoiceChannel* mVoiceChannel;
  173. };
  174. class LLIMSpeakerMgr : public LLSpeakerMgr
  175. {
  176. protected:
  177. LOG_CLASS(LLIMSpeakerMgr);
  178. public:
  179. LLIMSpeakerMgr(LLVoiceChannel* channel);
  180. void updateSpeakers(const LLSD& update);
  181. void setSpeakers(const LLSD& speakers);
  182. protected:
  183. virtual void updateSpeakerList();
  184. };
  185. class LLActiveSpeakerMgr : public LLSpeakerMgr,
  186. public LLSingleton<LLActiveSpeakerMgr>
  187. {
  188. friend class LLSingleton<LLActiveSpeakerMgr>;
  189. public:
  190. LLActiveSpeakerMgr();
  191. protected:
  192. virtual void updateSpeakerList();
  193. };
  194. class LLLocalSpeakerMgr : public LLSpeakerMgr,
  195. public LLSingleton<LLLocalSpeakerMgr>
  196. {
  197. friend class LLSingleton<LLLocalSpeakerMgr>;
  198. public:
  199. LLLocalSpeakerMgr();
  200. protected:
  201. virtual void updateSpeakerList();
  202. };
  203. class LLFloaterActiveSpeakers final
  204. : public LLFloater,
  205. public LLFloaterSingleton<LLFloaterActiveSpeakers>
  206. {
  207. // Friend of singleton class to allow construction inside getInstance()
  208. // since constructor is protected to enforce singleton constraint
  209. friend class LLUISingleton<LLFloaterActiveSpeakers, VisibilityPolicy<LLFloater> >;
  210. protected:
  211. LLFloaterActiveSpeakers(const LLSD& seed);
  212. public:
  213. ~LLFloaterActiveSpeakers() override = default;
  214. bool postBuild() override;
  215. void onOpen() override;
  216. void onClose(bool app_quitting) override;
  217. void draw() override;
  218. static void* createSpeakersPanel(void* data);
  219. protected:
  220. LLPanelActiveSpeakers* mPanel;
  221. };
  222. class LLPanelActiveSpeakers final : public LLPanel
  223. {
  224. protected:
  225. LOG_CLASS(LLPanelActiveSpeakers);
  226. public:
  227. LLPanelActiveSpeakers(LLSpeakerMgr* data_source, bool show_text_chatters);
  228. bool postBuild() override;
  229. void handleSpeakerSelect();
  230. void refreshSpeakers(bool force = false);
  231. void setSpeaker(const LLUUID& id,
  232. const std::string& name = LLStringUtil::null,
  233. LLSpeaker::ESpeakerStatus status = LLSpeaker::STATUS_TEXT_ONLY,
  234. LLSpeaker::ESpeakerType = LLSpeaker::SPEAKER_AGENT,
  235. const LLUUID& owner_id = LLUUID::null);
  236. void addSpeaker(const LLUUID& id, bool force = false);
  237. void setVoiceModerationCtrlMode(const bool& moderated_voice);
  238. static void onClickMuteVoice(void* user_data);
  239. static void onClickDeviceSettings(void*);
  240. static void onClickMuteVoiceCommit(LLUICtrl* ctrl, void* user_data);
  241. static void onClickMuteTextCommit(LLUICtrl* ctrl, void* user_data);
  242. static void onVolumeChange(LLUICtrl* source, void* user_data);
  243. static void onClickProfile(void* user_data);
  244. static void onDoubleClickSpeaker(void* user_data);
  245. static void onSelectSpeaker(LLUICtrl* source, void* user_data);
  246. static void onSortChanged(void* user_data);
  247. static void onModeratorMuteVoice(LLUICtrl* ctrl, void* user_data);
  248. static void onModeratorMuteText(LLUICtrl* ctrl, void* user_data);
  249. static void onChangeModerationMode(LLUICtrl* ctrl, void* user_data);
  250. protected:
  251. class SpeakerMuteListener : public LLOldEvents::LLSimpleListener
  252. {
  253. public:
  254. SpeakerMuteListener(LLPanelActiveSpeakers* panel) : mPanel(panel) {}
  255. bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  256. const LLSD& userdata) override;
  257. public:
  258. LLPanelActiveSpeakers* mPanel;
  259. };
  260. friend class SpeakerAddListener;
  261. class SpeakerAddListener : public LLOldEvents::LLSimpleListener
  262. {
  263. public:
  264. SpeakerAddListener(LLPanelActiveSpeakers* panel) : mPanel(panel) {}
  265. bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  266. const LLSD& userdata) override;
  267. LLPanelActiveSpeakers* mPanel;
  268. };
  269. friend class SpeakerRemoveListener;
  270. class SpeakerRemoveListener : public LLOldEvents::LLSimpleListener
  271. {
  272. public:
  273. SpeakerRemoveListener(LLPanelActiveSpeakers* panel) : mPanel(panel) {}
  274. bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  275. const LLSD& userdata) override;
  276. public:
  277. LLPanelActiveSpeakers* mPanel;
  278. };
  279. friend class SpeakerClearListener;
  280. class SpeakerClearListener : public LLOldEvents::LLSimpleListener
  281. {
  282. public:
  283. SpeakerClearListener(LLPanelActiveSpeakers* panel) : mPanel(panel) {}
  284. bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  285. const LLSD& userdata) override;
  286. public:
  287. LLPanelActiveSpeakers* mPanel;
  288. };
  289. void removeSpeaker(const LLUUID& id);
  290. private:
  291. static void moderatorActionFailedCallback(const LLSD& result,
  292. LLUUID session_id);
  293. protected:
  294. LLView* mModerationPanel;
  295. LLView* mModerationControls;
  296. LLScrollListCtrl* mSpeakerList;
  297. LLSliderCtrl* mSpeakerVolumeSlider;
  298. LLUICtrl* mMuteVoiceCtrl;
  299. LLUICtrl* mMuteTextCtrl;
  300. LLUICtrl* mModeratorAllowVoiceCtrl;
  301. LLUICtrl* mModeratorAllowTextCtrl;
  302. LLUICtrl* mModerationModeCtrl;
  303. LLTextBox* mModeratorControlsText;
  304. LLTextBox* mNameText;
  305. LLButton* mDevicesBtn;
  306. LLButton* mProfileBtn;
  307. LLSpeakerMgr* mSpeakerMgr;
  308. LLPointer<SpeakerMuteListener> mSpeakerMuteListener;
  309. LLPointer<SpeakerAddListener> mSpeakerAddListener;
  310. LLPointer<SpeakerRemoveListener> mSpeakerRemoveListener;
  311. LLPointer<SpeakerClearListener> mSpeakerClearListener;
  312. LLFrameTimer mIconAnimationTimer;
  313. bool mShowTextChatters;
  314. };
  315. #endif // LL_LLFLOATERACTIVESPEAKERS_H