calls_instance.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "mtproto/sender.h"
  9. namespace crl {
  10. class semaphore;
  11. } // namespace crl
  12. namespace Platform {
  13. enum class PermissionType;
  14. } // namespace Platform
  15. namespace Media::Audio {
  16. class Track;
  17. } // namespace Media::Audio
  18. namespace Main {
  19. class Session;
  20. } // namespace Main
  21. namespace Ui {
  22. class Show;
  23. } // namespace Ui
  24. namespace Calls::Group {
  25. struct JoinInfo;
  26. class Panel;
  27. class ChooseJoinAsProcess;
  28. class StartRtmpProcess;
  29. } // namespace Calls::Group
  30. namespace tgcalls {
  31. class VideoCaptureInterface;
  32. } // namespace tgcalls
  33. namespace Calls {
  34. class Call;
  35. enum class CallType;
  36. class GroupCall;
  37. class Panel;
  38. struct DhConfig;
  39. struct StartGroupCallArgs {
  40. enum class JoinConfirm {
  41. None,
  42. IfNowInAnother,
  43. Always,
  44. };
  45. QString joinHash;
  46. JoinConfirm confirm = JoinConfirm::IfNowInAnother;
  47. bool scheduleNeeded = false;
  48. };
  49. class Instance final : public base::has_weak_ptr {
  50. public:
  51. Instance();
  52. ~Instance();
  53. void startOutgoingCall(not_null<UserData*> user, bool video);
  54. void startOrJoinGroupCall(
  55. std::shared_ptr<Ui::Show> show,
  56. not_null<PeerData*> peer,
  57. StartGroupCallArgs args);
  58. void showStartWithRtmp(
  59. std::shared_ptr<Ui::Show> show,
  60. not_null<PeerData*> peer);
  61. void handleUpdate(
  62. not_null<Main::Session*> session,
  63. const MTPUpdate &update);
  64. // Called by Data::GroupCall when it is appropriate by the 'version'.
  65. void applyGroupCallUpdateChecked(
  66. not_null<Main::Session*> session,
  67. const MTPUpdate &update);
  68. void showInfoPanel(not_null<Call*> call);
  69. void showInfoPanel(not_null<GroupCall*> call);
  70. [[nodiscard]] Call *currentCall() const;
  71. [[nodiscard]] rpl::producer<Call*> currentCallValue() const;
  72. [[nodiscard]] GroupCall *currentGroupCall() const;
  73. [[nodiscard]] rpl::producer<GroupCall*> currentGroupCallValue() const;
  74. [[nodiscard]] bool inCall() const;
  75. [[nodiscard]] bool inGroupCall() const;
  76. [[nodiscard]] bool hasVisiblePanel(
  77. Main::Session *session = nullptr) const;
  78. [[nodiscard]] bool hasActivePanel(
  79. Main::Session *session = nullptr) const;
  80. bool activateCurrentCall(const QString &joinHash = QString());
  81. bool minimizeCurrentActiveCall();
  82. bool toggleFullScreenCurrentActiveCall();
  83. bool closeCurrentActiveCall();
  84. [[nodiscard]] auto getVideoCapture(
  85. std::optional<QString> deviceId = std::nullopt,
  86. bool isScreenCapture = false)
  87. -> std::shared_ptr<tgcalls::VideoCaptureInterface>;
  88. void requestPermissionsOrFail(Fn<void()> onSuccess, bool video = true);
  89. [[nodiscard]] FnMut<void()> addAsyncWaiter();
  90. [[nodiscard]] bool isSharingScreen() const;
  91. [[nodiscard]] bool isQuitPrevent();
  92. private:
  93. class Delegate;
  94. friend class Delegate;
  95. not_null<Media::Audio::Track*> ensureSoundLoaded(const QString &key);
  96. void playSoundOnce(const QString &key);
  97. void createCall(not_null<UserData*> user, CallType type, bool isVideo);
  98. void destroyCall(not_null<Call*> call);
  99. void createGroupCall(
  100. Group::JoinInfo info,
  101. const MTPInputGroupCall &inputCall);
  102. void destroyGroupCall(not_null<GroupCall*> call);
  103. void confirmLeaveCurrent(
  104. std::shared_ptr<Ui::Show> show,
  105. not_null<PeerData*> peer,
  106. StartGroupCallArgs args,
  107. Fn<void(StartGroupCallArgs)> confirmed);
  108. void requestPermissionOrFail(
  109. Platform::PermissionType type,
  110. Fn<void()> onSuccess);
  111. void refreshDhConfig();
  112. void refreshServerConfig(not_null<Main::Session*> session);
  113. bytes::const_span updateDhConfig(const MTPmessages_DhConfig &data);
  114. void destroyCurrentCall();
  115. void handleCallUpdate(
  116. not_null<Main::Session*> session,
  117. const MTPPhoneCall &call);
  118. void handleSignalingData(
  119. not_null<Main::Session*> session,
  120. const MTPDupdatePhoneCallSignalingData &data);
  121. void handleGroupCallUpdate(
  122. not_null<Main::Session*> session,
  123. const MTPUpdate &update);
  124. const std::unique_ptr<Delegate> _delegate;
  125. const std::unique_ptr<DhConfig> _cachedDhConfig;
  126. crl::time _lastServerConfigUpdateTime = 0;
  127. base::weak_ptr<Main::Session> _serverConfigRequestSession;
  128. std::weak_ptr<tgcalls::VideoCaptureInterface> _videoCapture;
  129. std::unique_ptr<Call> _currentCall;
  130. rpl::event_stream<Call*> _currentCallChanges;
  131. std::unique_ptr<Panel> _currentCallPanel;
  132. std::unique_ptr<GroupCall> _currentGroupCall;
  133. rpl::event_stream<GroupCall*> _currentGroupCallChanges;
  134. std::unique_ptr<Group::Panel> _currentGroupCallPanel;
  135. base::flat_map<QString, std::unique_ptr<Media::Audio::Track>> _tracks;
  136. const std::unique_ptr<Group::ChooseJoinAsProcess> _chooseJoinAs;
  137. const std::unique_ptr<Group::StartRtmpProcess> _startWithRtmp;
  138. base::flat_set<std::unique_ptr<crl::semaphore>> _asyncWaiters;
  139. };
  140. } // namespace Calls