tdesktop/Telegram/SourceFiles/calls/calls_group_call.h

127 lines
2.7 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"
namespace tgcalls {
class GroupInstanceImpl;
} // namespace tgcalls
namespace Calls {
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
};
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();
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
void setMuted(bool mute);
[[nodiscard]] bool muted() const {
return _muted.current();
}
[[nodiscard]] rpl::producer<bool> mutedValue() const {
return _muted.value();
}
2020-11-24 11:56:46 +00:00
[[nodiscard]] bool joined() const {
2020-11-24 14:40:10 +00:00
return (_state.current() == State::Joined);
2020-11-24 11:56:46 +00:00
}
enum State {
Creating,
Joining,
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
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);
[[nodiscard]] rpl::lifetime &lifetime() {
return _lifetime;
}
private:
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
[[nodiscard]] MTPInputGroupCall inputCall() const;
const not_null<Delegate*> _delegate;
const not_null<ChannelData*> _channel;
MTP::Sender _api;
2020-11-24 11:56:46 +00:00
rpl::variable<State> _state = State::Creating;
2020-11-20 19:25:35 +00:00
2020-11-24 14:40:10 +00:00
rpl::variable<bool> _muted = true;
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 _updateMuteRequestId = 0;
2020-11-20 19:25:35 +00:00
std::unique_ptr<tgcalls::GroupInstanceImpl> _instance;
rpl::lifetime _lifetime;
};
} // namespace Calls