2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 02:37:11 +00:00
tdesktop/Telegram/SourceFiles/calls/calls_instance.h

223 lines
6.0 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "mtproto/sender.h"
namespace crl {
class semaphore;
} // namespace crl
2025-03-25 00:11:21 +05:00
namespace Data {
class GroupCall;
} // namespace Data
2020-05-17 13:12:27 +04:00
namespace Platform {
enum class PermissionType;
} // namespace Platform
namespace Media::Audio {
2017-05-03 16:43:01 +03:00
class Track;
} // namespace Media::Audio
2017-05-03 16:43:01 +03:00
2019-08-06 17:40:08 +01:00
namespace Main {
class Session;
} // namespace Main
2022-06-08 15:21:13 +04:00
namespace Ui {
class Show;
} // namespace Ui
namespace Calls::Group {
struct JoinInfo;
2025-03-25 00:11:21 +05:00
struct ConferenceInfo;
class Panel;
class ChooseJoinAsProcess;
class StartRtmpProcess;
} // namespace Calls::Group
namespace tgcalls {
class VideoCaptureInterface;
} // namespace tgcalls
namespace Calls {
class Call;
enum class CallType;
class GroupCall;
class Panel;
struct DhConfig;
struct InviteRequest;
2025-04-02 00:13:14 +05:00
struct StartConferenceInfo;
struct StartGroupCallArgs {
enum class JoinConfirm {
None,
IfNowInAnother,
Always,
};
QString joinHash;
JoinConfirm confirm = JoinConfirm::IfNowInAnother;
bool scheduleNeeded = false;
};
2025-03-31 11:44:39 +04:00
struct ConferenceInviteMessages {
base::flat_set<MsgId> incoming;
base::flat_set<MsgId> outgoing;
};
struct ConferenceInvites {
base::flat_map<not_null<UserData*>, ConferenceInviteMessages> users;
};
class Instance final : public base::has_weak_ptr {
public:
2020-06-25 21:57:36 +04:00
Instance();
~Instance();
void startOutgoingCall(not_null<UserData*> user, bool video);
void startOrJoinGroupCall(
2022-06-08 15:21:13 +04:00
std::shared_ptr<Ui::Show> show,
2021-03-11 00:03:20 +04:00
not_null<PeerData*> peer,
StartGroupCallArgs args);
2025-04-02 00:13:14 +05:00
void startOrJoinConferenceCall(StartConferenceInfo args);
2025-04-10 13:38:13 +04:00
void startedConferenceReady(
2025-04-09 14:18:14 +04:00
not_null<GroupCall*> call,
StartConferenceInfo args);
void showStartWithRtmp(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer);
2020-06-25 21:57:36 +04:00
void handleUpdate(
not_null<Main::Session*> session,
const MTPUpdate &update);
// Called by Data::GroupCall when it is appropriate by the 'version'.
void applyGroupCallUpdateChecked(
not_null<Main::Session*> session,
const MTPUpdate &update);
void showInfoPanel(not_null<Call*> call);
2020-11-24 15:54:20 +03:00
void showInfoPanel(not_null<GroupCall*> call);
2020-06-25 21:57:36 +04:00
[[nodiscard]] Call *currentCall() const;
[[nodiscard]] rpl::producer<Call*> currentCallValue() const;
2020-11-24 15:54:20 +03:00
[[nodiscard]] GroupCall *currentGroupCall() const;
[[nodiscard]] rpl::producer<GroupCall*> currentGroupCallValue() const;
2020-12-08 19:09:13 +04:00
[[nodiscard]] bool inCall() const;
[[nodiscard]] bool inGroupCall() const;
[[nodiscard]] bool hasVisiblePanel(
Main::Session *session = nullptr) const;
[[nodiscard]] bool hasActivePanel(
Main::Session *session = nullptr) const;
2021-03-11 00:03:20 +04:00
bool activateCurrentCall(const QString &joinHash = QString());
bool minimizeCurrentActiveCall();
bool toggleFullScreenCurrentActiveCall();
bool closeCurrentActiveCall();
[[nodiscard]] auto getVideoCapture(
std::optional<QString> deviceId = std::nullopt,
bool isScreenCapture = false)
-> std::shared_ptr<tgcalls::VideoCaptureInterface>;
2020-12-09 17:11:42 +04:00
void requestPermissionsOrFail(Fn<void()> onSuccess, bool video = true);
2025-03-31 11:44:39 +04:00
[[nodiscard]] const ConferenceInvites &conferenceInvites(
CallId conferenceId) const;
void registerConferenceInvite(
CallId conferenceId,
not_null<UserData*> user,
MsgId messageId,
bool incoming);
void unregisterConferenceInvite(
CallId conferenceId,
not_null<UserData*> user,
MsgId messageId,
bool incoming,
bool onlyStopCalling = false);
2025-03-31 11:44:39 +04:00
void showConferenceInvite(
not_null<UserData*> user,
MsgId conferenceInviteMsgId);
void declineIncomingConferenceInvites(CallId conferenceId);
2025-03-31 22:52:37 +05:00
void declineOutgoingConferenceInvite(
CallId conferenceId,
not_null<UserData*> user,
bool discard = false);
2025-03-31 11:44:39 +04:00
[[nodiscard]] FnMut<void()> addAsyncWaiter();
[[nodiscard]] bool isSharingScreen() const;
2020-06-25 21:57:36 +04:00
[[nodiscard]] bool isQuitPrevent();
private:
class Delegate;
friend class Delegate;
not_null<Media::Audio::Track*> ensureSoundLoaded(const QString &key);
void playSoundOnce(const QString &key);
2023-03-02 08:52:24 +03:00
void createCall(not_null<UserData*> user, CallType type, bool isVideo);
void destroyCall(not_null<Call*> call);
void finishConferenceInvitations(const StartConferenceInfo &args);
2020-11-20 22:25:35 +03:00
void createGroupCall(
Group::JoinInfo info,
const MTPInputGroupCall &inputCall);
2020-11-20 22:25:35 +03:00
void destroyGroupCall(not_null<GroupCall*> call);
void confirmLeaveCurrent(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer,
StartGroupCallArgs args,
Fn<void(StartGroupCallArgs)> confirmed);
2020-11-20 22:25:35 +03:00
void requestPermissionOrFail(
Platform::PermissionType type,
Fn<void()> onSuccess);
void refreshDhConfig();
2020-06-25 21:57:36 +04:00
void refreshServerConfig(not_null<Main::Session*> session);
bytes::const_span updateDhConfig(const MTPmessages_DhConfig &data);
2025-03-30 00:53:11 +05:00
void destroyCurrentCall(
Data::GroupCall *migrateCall = nullptr,
const QString &migrateSlug = QString());
2020-06-25 21:57:36 +04:00
void handleCallUpdate(
not_null<Main::Session*> session,
const MTPPhoneCall &call);
void handleSignalingData(
not_null<Main::Session*> session,
const MTPDupdatePhoneCallSignalingData &data);
2020-11-20 22:25:35 +03:00
void handleGroupCallUpdate(
not_null<Main::Session*> session,
const MTPUpdate &update);
2019-08-06 17:40:08 +01:00
const std::unique_ptr<Delegate> _delegate;
const std::unique_ptr<DhConfig> _cachedDhConfig;
crl::time _lastServerConfigUpdateTime = 0;
2020-06-25 21:57:36 +04:00
base::weak_ptr<Main::Session> _serverConfigRequestSession;
std::weak_ptr<tgcalls::VideoCaptureInterface> _videoCapture;
std::unique_ptr<Call> _currentCall;
2020-06-25 21:57:36 +04:00
rpl::event_stream<Call*> _currentCallChanges;
std::unique_ptr<Panel> _currentCallPanel;
2020-11-20 22:25:35 +03:00
std::unique_ptr<GroupCall> _currentGroupCall;
2025-04-10 13:38:13 +04:00
std::unique_ptr<GroupCall> _startingGroupCall;
2020-11-20 22:25:35 +03:00
rpl::event_stream<GroupCall*> _currentGroupCallChanges;
std::unique_ptr<Group::Panel> _currentGroupCallPanel;
base::flat_map<QString, std::unique_ptr<Media::Audio::Track>> _tracks;
2017-05-03 16:43:01 +03:00
const std::unique_ptr<Group::ChooseJoinAsProcess> _chooseJoinAs;
const std::unique_ptr<Group::StartRtmpProcess> _startWithRtmp;
2025-03-31 11:44:39 +04:00
base::flat_map<CallId, ConferenceInvites> _conferenceInvites;
base::flat_set<std::unique_ptr<crl::semaphore>> _asyncWaiters;
};
} // namespace Calls