tdesktop/Telegram/SourceFiles/calls/calls_group_call.h

186 lines
4.3 KiB
C
Raw Normal View History

2020-11-20 19:25:35 +00:00
/*
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 "base/weak_ptr.h"
#include "base/timer.h"
#include "base/bytes.h"
#include "mtproto/sender.h"
#include "mtproto/mtproto_auth_key.h"
2020-11-30 15:51:04 +00:00
class History;
2020-11-20 19:25:35 +00:00
namespace tgcalls {
class GroupInstanceImpl;
} // namespace tgcalls
namespace base {
namespace Platform {
class GlobalShortcutManager;
class GlobalShortcutValue;
} // namespace Platform
} // namespace base
2020-11-20 19:25:35 +00:00
namespace Calls {
2020-11-28 07:18:46 +00:00
enum class MuteState {
Active,
Muted,
ForceMuted,
};
struct LevelUpdate {
uint32 ssrc = 0;
float value = 0.;
bool self = false;
};
2020-11-20 19:25:35 +00:00
class GroupCall final : public base::has_weak_ptr {
public:
class Delegate {
public:
virtual ~Delegate() = default;
2020-11-24 11:56:46 +00:00
virtual void groupCallFinished(not_null<GroupCall*> call) = 0;
virtual void groupCallFailed(not_null<GroupCall*> call) = 0;
2020-11-20 19:25:35 +00:00
};
using GlobalShortcutManager = base::Platform::GlobalShortcutManager;
2020-11-20 19:25:35 +00:00
GroupCall(
not_null<Delegate*> delegate,
not_null<ChannelData*> channel,
const MTPInputGroupCall &inputCall);
~GroupCall();
[[nodiscard]] uint64 id() const {
return _id;
}
2020-11-20 19:25:35 +00:00
[[nodiscard]] not_null<ChannelData*> channel() const {
return _channel;
}
void start();
2020-11-24 11:56:46 +00:00
void hangup();
void discard();
2020-11-20 19:25:35 +00:00
void join(const MTPInputGroupCall &inputCall);
void handleUpdate(const MTPGroupCall &call);
void handleUpdate(const MTPDupdateGroupCallParticipants &data);
2020-11-20 19:25:35 +00:00
2020-11-28 07:18:46 +00:00
void setMuted(MuteState mute);
[[nodiscard]] MuteState muted() const {
2020-11-20 19:25:35 +00:00
return _muted.current();
}
2020-11-28 07:18:46 +00:00
[[nodiscard]] rpl::producer<MuteState> mutedValue() const {
2020-11-20 19:25:35 +00:00
return _muted.value();
}
2020-11-24 11:56:46 +00:00
enum State {
Creating,
Joining,
Connecting,
2020-11-24 11:56:46 +00:00
Joined,
FailedHangingUp,
Failed,
HangingUp,
Ended,
};
[[nodiscard]] State state() const {
return _state.current();
}
[[nodiscard]] rpl::producer<State> stateValue() const {
return _state.value();
}
2020-11-20 19:25:35 +00:00
[[nodiscard]] rpl::producer<LevelUpdate> levelUpdates() const {
return _levelUpdates.events();
}
static constexpr auto kSpeakLevelThreshold = 0.2;
2020-11-20 19:25:35 +00:00
void setCurrentAudioDevice(bool input, const QString &deviceId);
//void setAudioVolume(bool input, float level);
2020-11-20 19:25:35 +00:00
void setAudioDuckingEnabled(bool enabled);
void toggleMute(not_null<UserData*> user, bool mute);
std::variant<int, not_null<UserData*>> inviteUsers(
const std::vector<not_null<UserData*>> &users);
std::shared_ptr<GlobalShortcutManager> ensureGlobalShortcutManager();
void applyGlobalShortcutChanges();
2020-11-20 19:25:35 +00:00
[[nodiscard]] rpl::lifetime &lifetime() {
return _lifetime;
}
private:
using GlobalShortcutValue = base::Platform::GlobalShortcutValue;
2020-11-24 11:56:46 +00:00
enum class FinishType {
None,
Ended,
Failed,
};
2020-11-20 19:25:35 +00:00
void handleRequestError(const RPCError &error);
void handleControllerError(const QString &error);
void createAndStartController();
void destroyController();
2020-11-24 11:56:46 +00:00
void setState(State state);
void finish(FinishType type);
void sendMutedUpdate();
void applySelfInCallLocally();
void rejoin();
2020-11-20 19:25:35 +00:00
2020-11-28 06:38:55 +00:00
void myLevelUpdated(float level);
void audioLevelsUpdated(
const std::vector<std::pair<std::uint32_t, float>> &data);
void handleLevelsUpdated(
gsl::span<const std::pair<std::uint32_t, float>> data);
void setInstanceConnected(bool connected);
void checkLastSpoke();
2020-11-28 06:38:55 +00:00
2020-11-29 14:42:34 +00:00
void checkJoined();
2020-11-20 19:25:35 +00:00
[[nodiscard]] MTPInputGroupCall inputCall() const;
const not_null<Delegate*> _delegate;
const not_null<ChannelData*> _channel;
2020-11-30 15:51:04 +00:00
const not_null<History*> _history;
2020-11-20 19:25:35 +00:00
MTP::Sender _api;
2020-11-24 11:56:46 +00:00
rpl::variable<State> _state = State::Creating;
bool _instanceConnected = false;
2020-11-20 19:25:35 +00:00
2020-11-28 07:18:46 +00:00
rpl::variable<MuteState> _muted = MuteState::Muted;
2020-11-24 11:56:46 +00:00
bool _acceptFields = false;
2020-11-20 19:25:35 +00:00
uint64 _id = 0;
uint64 _accessHash = 0;
2020-11-24 11:56:46 +00:00
uint32 _mySsrc = 0;
mtpRequestId _createRequestId = 0;
mtpRequestId _updateMuteRequestId = 0;
2020-11-20 19:25:35 +00:00
std::unique_ptr<tgcalls::GroupInstanceImpl> _instance;
rpl::event_stream<LevelUpdate> _levelUpdates;
base::flat_map<uint32, crl::time> _lastSpoke;
base::Timer _lastSpokeCheckTimer;
2020-11-29 14:42:34 +00:00
base::Timer _checkJoinedTimer;
2020-11-20 19:25:35 +00:00
2020-11-30 15:51:04 +00:00
crl::time _lastSendProgressUpdate = 0;
std::shared_ptr<GlobalShortcutManager> _shortcutManager;
std::shared_ptr<GlobalShortcutValue> _pushToTalk;
bool _pushToTalkStarted = false;
2020-11-20 19:25:35 +00:00
rpl::lifetime _lifetime;
};
} // namespace Calls