/* 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" #include "calls/calls_call.h" #include "calls/calls_group_call.h" namespace Platform { enum class PermissionType; } // namespace Platform namespace Media { namespace Audio { class Track; } // namespace Audio } // namespace Media namespace Main { class Session; } // namespace Main namespace Calls { class Panel; class GroupPanel; class Instance : private Call::Delegate , private GroupCall::Delegate , private base::Subscriber , public base::has_weak_ptr { public: Instance(); ~Instance(); void startOutgoingCall(not_null user, bool video); void startOrJoinGroupCall(not_null peer); void handleUpdate( not_null session, const MTPUpdate &update); void showInfoPanel(not_null call); void showInfoPanel(not_null call); [[nodiscard]] Call *currentCall() const; [[nodiscard]] rpl::producer currentCallValue() const; [[nodiscard]] GroupCall *currentGroupCall() const; [[nodiscard]] rpl::producer currentGroupCallValue() const; [[nodiscard]] bool inCall() const; [[nodiscard]] bool inGroupCall() const; [[nodiscard]] bool hasActivePanel( not_null session) const; bool activateCurrentCall(); auto getVideoCapture() -> std::shared_ptr override; void requestPermissionsOrFail(Fn onSuccess, bool video = true); void setCurrentAudioDevice(bool input, const QString &deviceId); [[nodiscard]] bool isQuitPrevent(); private: using CallSound = Call::Delegate::CallSound; using GroupCallSound = GroupCall::Delegate::GroupCallSound; [[nodiscard]] not_null getCallDelegate() { return static_cast(this); } [[nodiscard]] not_null getGroupCallDelegate() { return static_cast(this); } [[nodiscard]] DhConfig getDhConfig() const override { return _dhConfig; } not_null ensureSoundLoaded(const QString &key); void playSoundOnce(const QString &key); void callFinished(not_null call) override; void callFailed(not_null call) override; void callRedial(not_null call) override; void callRequestPermissionsOrFail( Fn onSuccess, bool video) override { requestPermissionsOrFail(std::move(onSuccess), video); } void callPlaySound(CallSound sound) override; void groupCallFinished(not_null call) override; void groupCallFailed(not_null call) override; void groupCallRequestPermissionsOrFail(Fn onSuccess) override { requestPermissionsOrFail(std::move(onSuccess), false); } void groupCallPlaySound(GroupCallSound sound) override; void createCall(not_null user, Call::Type type, bool video); void destroyCall(not_null call); void createGroupCall( not_null peer, const MTPInputGroupCall &inputCall); void destroyGroupCall(not_null call); void requestPermissionOrFail( Platform::PermissionType type, Fn onSuccess); void refreshDhConfig(); void refreshServerConfig(not_null session); bytes::const_span updateDhConfig(const MTPmessages_DhConfig &data); void destroyCurrentCall(); void handleCallUpdate( not_null session, const MTPPhoneCall &call); void handleSignalingData( not_null session, const MTPDupdatePhoneCallSignalingData &data); void handleGroupCallUpdate( not_null session, const MTPGroupCall &call); void handleGroupCallUpdate( not_null session, const MTPDupdateGroupCallParticipants &update); DhConfig _dhConfig; crl::time _lastServerConfigUpdateTime = 0; base::weak_ptr _serverConfigRequestSession; std::weak_ptr _videoCapture; std::unique_ptr _currentCall; rpl::event_stream _currentCallChanges; std::unique_ptr _currentCallPanel; std::unique_ptr _currentGroupCall; rpl::event_stream _currentGroupCallChanges; std::unique_ptr _currentGroupCallPanel; base::flat_map> _tracks; }; } // namespace Calls