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
|
|
|
|
*/
|
|
|
|
#include "calls/calls_group_call.h"
|
|
|
|
|
2021-01-14 00:25:59 +00:00
|
|
|
#include "calls/calls_group_common.h"
|
2020-11-20 19:25:35 +00:00
|
|
|
#include "main/main_session.h"
|
2020-11-30 15:51:04 +00:00
|
|
|
#include "api/api_send_progress.h"
|
2020-11-20 19:25:35 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2020-12-07 13:15:34 +00:00
|
|
|
#include "lang/lang_hardcoded.h"
|
2020-12-14 12:52:18 +00:00
|
|
|
#include "boxes/peers/edit_participants_box.h" // SubscribeToMigration.
|
2020-11-30 07:52:53 +00:00
|
|
|
#include "ui/toasts/common_toasts.h"
|
2020-11-27 14:50:41 +00:00
|
|
|
#include "base/unixtime.h"
|
2020-11-27 10:35:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2020-11-24 11:56:46 +00:00
|
|
|
#include "data/data_changes.h"
|
2020-11-27 15:51:24 +00:00
|
|
|
#include "data/data_user.h"
|
2020-12-14 12:52:18 +00:00
|
|
|
#include "data/data_chat.h"
|
2020-11-20 19:25:35 +00:00
|
|
|
#include "data/data_channel.h"
|
2020-11-24 11:56:46 +00:00
|
|
|
#include "data/data_group_call.h"
|
2020-11-28 18:17:13 +00:00
|
|
|
#include "data/data_session.h"
|
2020-12-06 08:41:45 +00:00
|
|
|
#include "base/global_shortcuts.h"
|
2021-01-23 22:34:40 +00:00
|
|
|
#include "base/openssl_help.h"
|
2020-12-18 14:43:49 +00:00
|
|
|
#include "webrtc/webrtc_media_devices.h"
|
2021-01-05 15:02:48 +00:00
|
|
|
#include "webrtc/webrtc_create_adm.h"
|
2020-11-20 19:25:35 +00:00
|
|
|
|
2021-03-08 07:57:00 +00:00
|
|
|
#include <tgcalls/group/GroupInstanceCustomImpl.h>
|
2020-11-20 19:25:35 +00:00
|
|
|
|
|
|
|
#include <QtCore/QJsonDocument>
|
|
|
|
#include <QtCore/QJsonObject>
|
|
|
|
#include <QtCore/QJsonArray>
|
|
|
|
|
|
|
|
namespace Calls {
|
2020-11-28 18:17:13 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMaxInvitePerSlice = 10;
|
2020-12-01 11:59:09 +00:00
|
|
|
constexpr auto kCheckLastSpokeInterval = crl::time(1000);
|
2020-11-29 14:42:34 +00:00
|
|
|
constexpr auto kCheckJoinedTimeout = 4 * crl::time(1000);
|
2020-11-30 15:51:04 +00:00
|
|
|
constexpr auto kUpdateSendActionEach = crl::time(500);
|
2020-12-18 08:44:19 +00:00
|
|
|
constexpr auto kPlayConnectingEach = crl::time(1056) + 2 * crl::time(1000);
|
2020-11-28 18:17:13 +00:00
|
|
|
|
2020-12-18 14:43:49 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<Webrtc::MediaDevices> CreateMediaDevices() {
|
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
return Webrtc::CreateMediaDevices(
|
|
|
|
settings.callInputDeviceId(),
|
|
|
|
settings.callOutputDeviceId(),
|
|
|
|
settings.callVideoInputDeviceId());
|
|
|
|
}
|
|
|
|
|
2020-12-29 15:17:50 +00:00
|
|
|
[[nodiscard]] const Data::GroupCall::Participant *LookupParticipant(
|
2021-03-03 15:29:33 +00:00
|
|
|
not_null<PeerData*> peer,
|
2020-12-29 15:17:50 +00:00
|
|
|
uint64 id,
|
2021-03-03 15:29:33 +00:00
|
|
|
not_null<PeerData*> participantPeer) {
|
|
|
|
const auto call = peer->groupCall();
|
2020-12-29 15:17:50 +00:00
|
|
|
if (!id || !call || call->id() != id) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto &participants = call->participants();
|
|
|
|
const auto i = ranges::find(
|
|
|
|
participants,
|
2021-03-03 15:29:33 +00:00
|
|
|
participantPeer,
|
|
|
|
&Data::GroupCall::Participant::peer);
|
2020-12-29 15:17:50 +00:00
|
|
|
return (i != end(participants)) ? &*i : nullptr;
|
|
|
|
}
|
|
|
|
|
2021-03-12 10:58:10 +00:00
|
|
|
[[nodiscard]] double TimestampFromMsgId(mtpMsgId msgId) {
|
|
|
|
return msgId / double(1ULL << 32);
|
|
|
|
}
|
|
|
|
|
2020-11-28 18:17:13 +00:00
|
|
|
} // namespace
|
2020-11-20 19:25:35 +00:00
|
|
|
|
2021-03-08 14:39:36 +00:00
|
|
|
class GroupCall::LoadPartTask final : public tgcalls::BroadcastPartTask {
|
|
|
|
public:
|
|
|
|
LoadPartTask(
|
|
|
|
base::weak_ptr<GroupCall> call,
|
2021-03-09 08:33:01 +00:00
|
|
|
int64 time,
|
|
|
|
int64 period,
|
2021-03-08 14:39:36 +00:00
|
|
|
Fn<void(tgcalls::BroadcastPart&&)> done);
|
|
|
|
|
2021-03-09 08:33:01 +00:00
|
|
|
[[nodiscard]] int64 time() const {
|
|
|
|
return _time;
|
|
|
|
}
|
|
|
|
[[nodiscard]] int32 scale() const {
|
|
|
|
return _scale;
|
2021-03-08 14:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void done(tgcalls::BroadcastPart &&part);
|
|
|
|
void cancel() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const base::weak_ptr<GroupCall> _call;
|
2021-03-09 08:33:01 +00:00
|
|
|
const int64 _time = 0;
|
|
|
|
const int32 _scale = 0;
|
2021-03-08 14:39:36 +00:00
|
|
|
Fn<void(tgcalls::BroadcastPart &&)> _done;
|
|
|
|
QMutex _mutex;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-02-22 08:31:35 +00:00
|
|
|
[[nodiscard]] bool IsGroupCallAdmin(
|
|
|
|
not_null<PeerData*> peer,
|
2021-03-03 15:29:33 +00:00
|
|
|
not_null<PeerData*> participantPeer) {
|
|
|
|
const auto user = participantPeer->asUser();
|
|
|
|
if (!user) {
|
2021-03-12 10:58:10 +00:00
|
|
|
return false;
|
2021-03-03 15:29:33 +00:00
|
|
|
}
|
2021-02-22 08:31:35 +00:00
|
|
|
if (const auto chat = peer->asChat()) {
|
|
|
|
return chat->admins.contains(user)
|
|
|
|
|| (chat->creator == user->bareId());
|
2021-03-08 14:39:36 +00:00
|
|
|
} else if (const auto group = peer->asChannel()) {
|
2021-02-22 08:31:35 +00:00
|
|
|
if (const auto mgInfo = group->mgInfo.get()) {
|
|
|
|
if (mgInfo->creator == user) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto i = mgInfo->lastAdmins.find(user);
|
|
|
|
if (i == mgInfo->lastAdmins.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto &rights = i->second.rights;
|
|
|
|
return rights.c_chatAdminRights().is_manage_call();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-08 14:39:36 +00:00
|
|
|
GroupCall::LoadPartTask::LoadPartTask(
|
|
|
|
base::weak_ptr<GroupCall> call,
|
2021-03-09 08:33:01 +00:00
|
|
|
int64 time,
|
|
|
|
int64 period,
|
2021-03-08 14:39:36 +00:00
|
|
|
Fn<void(tgcalls::BroadcastPart &&)> done)
|
|
|
|
: _call(std::move(call))
|
2021-03-09 08:33:01 +00:00
|
|
|
, _time(time ? time : (base::unixtime::now() * int64(1000)))
|
|
|
|
, _scale([&] {
|
|
|
|
switch (period) {
|
|
|
|
case 1000: return 0;
|
|
|
|
case 500: return 1;
|
|
|
|
case 250: return 2;
|
|
|
|
case 125: return 3;
|
|
|
|
}
|
|
|
|
Unexpected("Period in LoadPartTask.");
|
|
|
|
}())
|
2021-03-08 14:39:36 +00:00
|
|
|
, _done(std::move(done)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::LoadPartTask::done(tgcalls::BroadcastPart &&part) {
|
|
|
|
QMutexLocker lock(&_mutex);
|
|
|
|
if (_done) {
|
|
|
|
base::take(_done)(std::move(part));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::LoadPartTask::cancel() {
|
|
|
|
QMutexLocker lock(&_mutex);
|
|
|
|
if (!_done) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_done = nullptr;
|
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
if (_call) {
|
|
|
|
const auto that = this;
|
|
|
|
crl::on_main(_call, [weak = _call, that] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
strong->broadcastPartCancel(that);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
GroupCall::GroupCall(
|
|
|
|
not_null<Delegate*> delegate,
|
2021-03-05 15:21:11 +00:00
|
|
|
Group::JoinInfo info,
|
|
|
|
const MTPInputGroupCall &inputCall)
|
2020-11-20 19:25:35 +00:00
|
|
|
: _delegate(delegate)
|
2021-03-05 15:21:11 +00:00
|
|
|
, _peer(info.peer)
|
|
|
|
, _history(_peer->owner().history(_peer))
|
|
|
|
, _api(&_peer->session().mtp())
|
|
|
|
, _joinAs(info.joinAs)
|
|
|
|
, _possibleJoinAs(std::move(info.possibleJoinAs))
|
2021-03-10 20:03:20 +00:00
|
|
|
, _joinHash(info.joinHash)
|
2020-11-29 14:42:34 +00:00
|
|
|
, _lastSpokeCheckTimer([=] { checkLastSpoke(); })
|
2020-12-06 12:44:20 +00:00
|
|
|
, _checkJoinedTimer([=] { checkJoined(); })
|
2020-12-18 08:44:19 +00:00
|
|
|
, _pushToTalkCancelTimer([=] { pushToTalkCancel(); })
|
2020-12-18 14:43:49 +00:00
|
|
|
, _connectingSoundTimer([=] { playConnectingSoundOnce(); })
|
|
|
|
, _mediaDevices(CreateMediaDevices()) {
|
2020-12-06 10:13:50 +00:00
|
|
|
_muted.value(
|
|
|
|
) | rpl::combine_previous(
|
|
|
|
) | rpl::start_with_next([=](MuteState previous, MuteState state) {
|
2020-11-29 14:42:34 +00:00
|
|
|
if (_instance) {
|
2020-12-06 10:13:50 +00:00
|
|
|
updateInstanceMuteState();
|
2020-11-29 14:42:34 +00:00
|
|
|
}
|
2021-03-09 10:05:02 +00:00
|
|
|
if (_mySsrc
|
|
|
|
&& (!_initialMuteStateSent || state == MuteState::Active)) {
|
2021-03-08 16:08:43 +00:00
|
|
|
_initialMuteStateSent = true;
|
2020-12-06 10:13:50 +00:00
|
|
|
maybeSendMutedUpdate(previous);
|
2020-11-29 14:42:34 +00:00
|
|
|
}
|
|
|
|
}, _lifetime);
|
|
|
|
|
2020-12-07 11:47:39 +00:00
|
|
|
checkGlobalShortcutAvailability();
|
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
const auto id = inputCall.c_inputGroupCall().vid().v;
|
|
|
|
if (id) {
|
2020-12-14 12:52:18 +00:00
|
|
|
if (const auto call = _peer->groupCall(); call && call->id() == id) {
|
|
|
|
if (!_peer->canManageGroupCall() && call->joinMuted()) {
|
2020-11-28 16:18:51 +00:00
|
|
|
_muted = MuteState::ForceMuted;
|
|
|
|
}
|
|
|
|
}
|
2020-11-24 11:56:46 +00:00
|
|
|
_state = State::Joining;
|
2020-11-20 19:25:35 +00:00
|
|
|
join(inputCall);
|
|
|
|
} else {
|
|
|
|
start();
|
|
|
|
}
|
2020-12-18 14:43:49 +00:00
|
|
|
|
|
|
|
_mediaDevices->audioInputId(
|
|
|
|
) | rpl::start_with_next([=](QString id) {
|
|
|
|
_audioInputId = id;
|
|
|
|
if (_instance) {
|
|
|
|
_instance->setAudioInputDevice(id.toStdString());
|
|
|
|
}
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
_mediaDevices->audioOutputId(
|
|
|
|
) | rpl::start_with_next([=](QString id) {
|
|
|
|
_audioOutputId = id;
|
|
|
|
if (_instance) {
|
|
|
|
_instance->setAudioOutputDevice(id.toStdString());
|
|
|
|
}
|
|
|
|
}, _lifetime);
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GroupCall::~GroupCall() {
|
|
|
|
destroyController();
|
|
|
|
}
|
|
|
|
|
2020-12-07 11:47:39 +00:00
|
|
|
void GroupCall::checkGlobalShortcutAvailability() {
|
|
|
|
auto &settings = Core::App().settings();
|
|
|
|
if (!settings.groupCallPushToTalk()) {
|
|
|
|
return;
|
|
|
|
} else if (!base::GlobalShortcutsAllowed()) {
|
|
|
|
settings.setGroupCallPushToTalk(false);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:56:46 +00:00
|
|
|
void GroupCall::setState(State state) {
|
|
|
|
if (_state.current() == State::Failed) {
|
|
|
|
return;
|
|
|
|
} else if (_state.current() == State::FailedHangingUp
|
|
|
|
&& state != State::Failed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_state.current() == state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_state = state;
|
|
|
|
|
2020-12-18 08:44:19 +00:00
|
|
|
if (state == State::Joined) {
|
|
|
|
stopConnectingSound();
|
|
|
|
if (!_hadJoinedState) {
|
|
|
|
_hadJoinedState = true;
|
2020-12-11 11:04:34 +00:00
|
|
|
applyGlobalShortcutChanges();
|
2020-12-18 08:44:19 +00:00
|
|
|
_delegate->groupCallPlaySound(Delegate::GroupCallSound::Started);
|
2020-12-11 11:04:34 +00:00
|
|
|
}
|
2020-12-14 12:52:18 +00:00
|
|
|
if (const auto call = _peer->groupCall(); call && call->id() == _id) {
|
2020-12-11 11:04:34 +00:00
|
|
|
call->setInCall();
|
|
|
|
}
|
2020-12-18 08:44:19 +00:00
|
|
|
} else if (state == State::Connecting || state == State::Joining) {
|
|
|
|
if (_hadJoinedState) {
|
|
|
|
playConnectingSound();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stopConnectingSound();
|
2020-12-03 18:17:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 11:56:46 +00:00
|
|
|
if (false
|
|
|
|
|| state == State::Ended
|
|
|
|
|| state == State::Failed) {
|
|
|
|
// Destroy controller before destroying Call Panel,
|
|
|
|
// so that the panel hide animation is smooth.
|
|
|
|
destroyController();
|
|
|
|
}
|
|
|
|
switch (state) {
|
2020-12-18 08:44:19 +00:00
|
|
|
case State::HangingUp:
|
|
|
|
case State::FailedHangingUp:
|
|
|
|
_delegate->groupCallPlaySound(Delegate::GroupCallSound::Ended);
|
|
|
|
break;
|
2020-11-24 11:56:46 +00:00
|
|
|
case State::Ended:
|
|
|
|
_delegate->groupCallFinished(this);
|
|
|
|
break;
|
|
|
|
case State::Failed:
|
|
|
|
_delegate->groupCallFailed(this);
|
|
|
|
break;
|
2020-11-29 14:42:34 +00:00
|
|
|
case State::Connecting:
|
|
|
|
if (!_checkJoinedTimer.isActive()) {
|
|
|
|
_checkJoinedTimer.callOnce(kCheckJoinedTimeout);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-24 11:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 08:44:19 +00:00
|
|
|
void GroupCall::playConnectingSound() {
|
|
|
|
if (_connectingSoundTimer.isActive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
playConnectingSoundOnce();
|
|
|
|
_connectingSoundTimer.callEach(kPlayConnectingEach);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::stopConnectingSound() {
|
|
|
|
_connectingSoundTimer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::playConnectingSoundOnce() {
|
|
|
|
_delegate->groupCallPlaySound(Delegate::GroupCallSound::Connecting);
|
|
|
|
}
|
|
|
|
|
2021-03-10 12:29:09 +00:00
|
|
|
bool GroupCall::showChooseJoinAs() const {
|
|
|
|
return (_possibleJoinAs.size() > 1)
|
|
|
|
|| (_possibleJoinAs.size() == 1
|
|
|
|
&& !_possibleJoinAs.front()->isSelf());
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
void GroupCall::start() {
|
2020-11-28 14:07:36 +00:00
|
|
|
_createRequestId = _api.request(MTPphone_CreateGroupCall(
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->input,
|
2021-01-23 22:34:40 +00:00
|
|
|
MTP_int(openssl::RandomValue<int32>())
|
2020-11-20 19:25:35 +00:00
|
|
|
)).done([=](const MTPUpdates &result) {
|
2020-11-24 11:56:46 +00:00
|
|
|
_acceptFields = true;
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().api().applyUpdates(result);
|
2020-11-24 11:56:46 +00:00
|
|
|
_acceptFields = false;
|
2020-11-20 19:25:35 +00:00
|
|
|
}).fail([=](const RPCError &error) {
|
2020-11-30 07:52:53 +00:00
|
|
|
LOG(("Call Error: Could not create, error: %1"
|
|
|
|
).arg(error.type()));
|
|
|
|
hangup();
|
2020-12-08 08:45:40 +00:00
|
|
|
if (error.type() == u"GROUPCALL_ANONYMOUS_FORBIDDEN"_q) {
|
2020-11-30 07:52:53 +00:00
|
|
|
Ui::ShowMultilineToast({
|
2021-02-16 16:34:55 +00:00
|
|
|
.text = { tr::lng_group_call_no_anonymous(tr::now) },
|
2020-11-30 07:52:53 +00:00
|
|
|
});
|
|
|
|
}
|
2020-11-20 19:25:35 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::join(const MTPInputGroupCall &inputCall) {
|
2020-11-24 11:56:46 +00:00
|
|
|
setState(State::Joining);
|
2020-12-14 12:52:18 +00:00
|
|
|
if (const auto chat = _peer->asChat()) {
|
|
|
|
chat->setGroupCall(inputCall);
|
2021-03-08 14:39:36 +00:00
|
|
|
} else if (const auto group = _peer->asChannel()) {
|
2020-12-14 12:52:18 +00:00
|
|
|
group->setGroupCall(inputCall);
|
|
|
|
} else {
|
|
|
|
Unexpected("Peer type in GroupCall::join.");
|
|
|
|
}
|
2020-11-27 14:50:41 +00:00
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
inputCall.match([&](const MTPDinputGroupCall &data) {
|
|
|
|
_id = data.vid().v;
|
|
|
|
_accessHash = data.vaccess_hash().v;
|
2020-11-26 16:01:26 +00:00
|
|
|
rejoin();
|
2020-11-20 19:25:35 +00:00
|
|
|
});
|
2020-11-24 11:56:46 +00:00
|
|
|
|
2020-11-27 14:50:41 +00:00
|
|
|
using Update = Data::GroupCall::ParticipantUpdate;
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->groupCall()->participantUpdated(
|
2020-11-27 14:50:41 +00:00
|
|
|
) | rpl::filter([=](const Update &update) {
|
2020-12-29 14:54:17 +00:00
|
|
|
return (_instance != nullptr);
|
2020-11-27 14:50:41 +00:00
|
|
|
}) | rpl::start_with_next([=](const Update &update) {
|
2020-12-29 14:54:17 +00:00
|
|
|
if (!update.now) {
|
|
|
|
_instance->removeSsrcs({ update.was->ssrc });
|
|
|
|
} else {
|
|
|
|
const auto &now = *update.now;
|
|
|
|
const auto &was = update.was;
|
|
|
|
const auto volumeChanged = was
|
|
|
|
? (was->volume != now.volume || was->mutedByMe != now.mutedByMe)
|
2021-01-14 00:25:59 +00:00
|
|
|
: (now.volume != Group::kDefaultVolume || now.mutedByMe);
|
2020-12-29 14:54:17 +00:00
|
|
|
if (volumeChanged) {
|
|
|
|
_instance->setVolume(
|
|
|
|
now.ssrc,
|
|
|
|
(now.mutedByMe
|
|
|
|
? 0.
|
|
|
|
: (now.volume
|
2021-01-14 00:25:59 +00:00
|
|
|
/ float64(Group::kDefaultVolume))));
|
2020-12-29 14:54:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-24 11:56:46 +00:00
|
|
|
}, _lifetime);
|
2020-12-14 12:52:18 +00:00
|
|
|
|
2021-03-08 07:57:00 +00:00
|
|
|
addParticipantsToInstance();
|
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
SubscribeToMigration(_peer, _lifetime, [=](not_null<ChannelData*> group) {
|
|
|
|
_peer = group;
|
|
|
|
});
|
2020-11-24 11:56:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:26 +00:00
|
|
|
void GroupCall::rejoin() {
|
2021-03-09 15:12:37 +00:00
|
|
|
rejoin(_joinAs);
|
|
|
|
}
|
|
|
|
|
2021-03-10 20:03:20 +00:00
|
|
|
void GroupCall::rejoinWithHash(const QString &hash) {
|
|
|
|
if (!hash.isEmpty()
|
|
|
|
&& (muted() == MuteState::ForceMuted
|
|
|
|
|| muted() == MuteState::RaisedHand)) {
|
|
|
|
_joinHash = hash;
|
|
|
|
rejoin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 15:12:37 +00:00
|
|
|
void GroupCall::rejoin(not_null<PeerData*> as) {
|
2020-11-30 15:51:04 +00:00
|
|
|
if (state() != State::Joining
|
|
|
|
&& state() != State::Joined
|
|
|
|
&& state() != State::Connecting) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-26 16:01:26 +00:00
|
|
|
|
|
|
|
_mySsrc = 0;
|
2021-03-08 16:08:43 +00:00
|
|
|
_initialMuteStateSent = false;
|
2020-11-29 14:42:34 +00:00
|
|
|
setState(State::Joining);
|
2021-03-08 14:39:36 +00:00
|
|
|
ensureControllerCreated();
|
|
|
|
setInstanceMode(InstanceMode::None);
|
2021-03-05 11:36:07 +00:00
|
|
|
applyMeInCallLocally();
|
2020-11-27 14:50:41 +00:00
|
|
|
LOG(("Call Info: Requesting join payload."));
|
|
|
|
|
2021-03-09 15:12:37 +00:00
|
|
|
_joinAs = as;
|
|
|
|
|
2020-11-26 16:01:26 +00:00
|
|
|
const auto weak = base::make_weak(this);
|
|
|
|
_instance->emitJoinPayload([=](tgcalls::GroupJoinPayload payload) {
|
|
|
|
crl::on_main(weak, [=, payload = std::move(payload)]{
|
|
|
|
auto fingerprints = QJsonArray();
|
|
|
|
for (const auto print : payload.fingerprints) {
|
|
|
|
auto object = QJsonObject();
|
|
|
|
object.insert("hash", QString::fromStdString(print.hash));
|
|
|
|
object.insert("setup", QString::fromStdString(print.setup));
|
|
|
|
object.insert(
|
|
|
|
"fingerprint",
|
|
|
|
QString::fromStdString(print.fingerprint));
|
|
|
|
fingerprints.push_back(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto root = QJsonObject();
|
|
|
|
const auto ssrc = payload.ssrc;
|
|
|
|
root.insert("ufrag", QString::fromStdString(payload.ufrag));
|
|
|
|
root.insert("pwd", QString::fromStdString(payload.pwd));
|
|
|
|
root.insert("fingerprints", fingerprints);
|
|
|
|
root.insert("ssrc", double(payload.ssrc));
|
|
|
|
|
2020-12-01 09:06:06 +00:00
|
|
|
LOG(("Call Info: Join payload received, joining with ssrc: %1."
|
2020-11-27 14:50:41 +00:00
|
|
|
).arg(ssrc));
|
|
|
|
|
2020-11-26 16:01:26 +00:00
|
|
|
const auto json = QJsonDocument(root).toJson(
|
|
|
|
QJsonDocument::Compact);
|
2020-12-06 10:13:50 +00:00
|
|
|
const auto wasMuteState = muted();
|
2021-03-03 15:29:33 +00:00
|
|
|
using Flag = MTPphone_JoinGroupCall::Flag;
|
2020-11-26 16:01:26 +00:00
|
|
|
_api.request(MTPphone_JoinGroupCall(
|
2021-03-10 20:03:20 +00:00
|
|
|
MTP_flags((wasMuteState != MuteState::Active
|
2021-03-05 11:36:07 +00:00
|
|
|
? Flag::f_muted
|
2021-03-10 20:03:20 +00:00
|
|
|
: Flag(0)) | (_joinHash.isEmpty()
|
|
|
|
? Flag(0)
|
|
|
|
: Flag::f_invite_hash)),
|
2020-11-26 16:01:26 +00:00
|
|
|
inputCall(),
|
2021-03-05 08:14:34 +00:00
|
|
|
_joinAs->input,
|
2021-03-10 20:03:20 +00:00
|
|
|
MTP_string(_joinHash),
|
2020-11-26 16:01:26 +00:00
|
|
|
MTP_dataJSON(MTP_bytes(json))
|
|
|
|
)).done([=](const MTPUpdates &updates) {
|
|
|
|
_mySsrc = ssrc;
|
2020-11-28 14:07:36 +00:00
|
|
|
setState(_instanceConnected
|
|
|
|
? State::Joined
|
|
|
|
: State::Connecting);
|
2021-03-05 11:36:07 +00:00
|
|
|
applyMeInCallLocally();
|
2020-12-06 10:13:50 +00:00
|
|
|
maybeSendMutedUpdate(wasMuteState);
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().api().applyUpdates(updates);
|
2020-11-26 16:01:26 +00:00
|
|
|
}).fail([=](const RPCError &error) {
|
2020-12-07 13:15:34 +00:00
|
|
|
const auto type = error.type();
|
|
|
|
LOG(("Call Error: Could not join, error: %1").arg(type));
|
|
|
|
|
2020-12-08 16:05:55 +00:00
|
|
|
if (type == u"GROUPCALL_SSRC_DUPLICATE_MUCH") {
|
|
|
|
rejoin();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hangup();
|
2020-12-07 13:15:34 +00:00
|
|
|
Ui::ShowMultilineToast({
|
2021-02-16 16:34:55 +00:00
|
|
|
.text = { type == u"GROUPCALL_ANONYMOUS_FORBIDDEN"_q
|
2020-12-07 13:15:34 +00:00
|
|
|
? tr::lng_group_call_no_anonymous(tr::now)
|
|
|
|
: type == u"GROUPCALL_PARTICIPANTS_TOO_MUCH"_q
|
|
|
|
? tr::lng_group_call_too_many(tr::now)
|
2020-12-08 09:39:54 +00:00
|
|
|
: type == u"GROUPCALL_FORBIDDEN"_q
|
|
|
|
? tr::lng_group_not_accessible(tr::now)
|
2021-02-16 16:34:55 +00:00
|
|
|
: Lang::Hard::ServerError() },
|
2020-12-07 13:15:34 +00:00
|
|
|
});
|
2020-11-26 16:01:26 +00:00
|
|
|
}).send();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-05 11:36:07 +00:00
|
|
|
void GroupCall::applyMeInCallLocally() {
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto call = _peer->groupCall();
|
2020-11-24 11:56:46 +00:00
|
|
|
if (!call || call->id() != _id) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-28 07:41:33 +00:00
|
|
|
using Flag = MTPDgroupCallParticipant::Flag;
|
|
|
|
const auto &participants = call->participants();
|
|
|
|
const auto i = ranges::find(
|
|
|
|
participants,
|
2021-03-05 11:36:07 +00:00
|
|
|
_joinAs,
|
2021-03-03 15:29:33 +00:00
|
|
|
&Data::GroupCall::Participant::peer);
|
2020-11-28 07:41:33 +00:00
|
|
|
const auto date = (i != end(participants))
|
|
|
|
? i->date
|
|
|
|
: base::unixtime::now();
|
|
|
|
const auto lastActive = (i != end(participants))
|
|
|
|
? i->lastActive
|
|
|
|
: TimeId(0);
|
2021-02-09 08:58:19 +00:00
|
|
|
const auto volume = (i != end(participants))
|
|
|
|
? i->volume
|
|
|
|
: Group::kDefaultVolume;
|
2021-03-08 16:08:43 +00:00
|
|
|
const auto canSelfUnmute = (muted() != MuteState::ForceMuted)
|
|
|
|
&& (muted() != MuteState::RaisedHand);
|
2021-03-12 10:58:10 +00:00
|
|
|
const auto raisedHandRating = (i != end(participants))
|
|
|
|
? i->raisedHandRating
|
|
|
|
: uint64(0);
|
2020-12-06 10:13:50 +00:00
|
|
|
const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0))
|
2020-11-28 07:41:33 +00:00
|
|
|
| (lastActive ? Flag::f_active_date : Flag(0))
|
|
|
|
| (_mySsrc ? Flag(0) : Flag::f_left)
|
2021-03-03 15:29:33 +00:00
|
|
|
| Flag::f_self
|
2021-02-09 08:58:19 +00:00
|
|
|
| Flag::f_volume // Without flag the volume is reset to 100%.
|
|
|
|
| Flag::f_volume_by_admin // Self volume can only be set by admin.
|
2021-03-12 10:58:10 +00:00
|
|
|
| ((muted() != MuteState::Active) ? Flag::f_muted : Flag(0))
|
|
|
|
| (raisedHandRating > 0 ? Flag::f_raise_hand_rating : Flag(0));
|
2020-11-27 14:50:41 +00:00
|
|
|
call->applyUpdateChecked(
|
|
|
|
MTP_updateGroupCallParticipants(
|
|
|
|
inputCall(),
|
2020-11-28 07:41:33 +00:00
|
|
|
MTP_vector<MTPGroupCallParticipant>(
|
|
|
|
1,
|
|
|
|
MTP_groupCallParticipant(
|
|
|
|
MTP_flags(flags),
|
2021-03-05 11:36:07 +00:00
|
|
|
peerToMTP(_joinAs->id),
|
2020-11-28 07:41:33 +00:00
|
|
|
MTP_int(date),
|
|
|
|
MTP_int(lastActive),
|
2020-12-29 12:39:10 +00:00
|
|
|
MTP_int(_mySsrc),
|
2021-03-03 15:29:33 +00:00
|
|
|
MTP_int(volume),
|
2021-03-12 10:58:10 +00:00
|
|
|
MTPstring(), // Don't update about text in local updates.
|
|
|
|
MTP_long(raisedHandRating))),
|
2020-11-27 14:50:41 +00:00
|
|
|
MTP_int(0)).c_updateGroupCallParticipants());
|
2020-11-24 11:56:46 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 15:17:50 +00:00
|
|
|
void GroupCall::applyParticipantLocally(
|
2021-03-03 15:29:33 +00:00
|
|
|
not_null<PeerData*> participantPeer,
|
2020-12-29 15:17:50 +00:00
|
|
|
bool mute,
|
|
|
|
std::optional<int> volume) {
|
2021-03-03 15:29:33 +00:00
|
|
|
const auto participant = LookupParticipant(_peer, _id, participantPeer);
|
2020-12-29 15:17:50 +00:00
|
|
|
if (!participant || !participant->ssrc) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-22 08:31:35 +00:00
|
|
|
const auto canManageCall = _peer->canManageGroupCall();
|
|
|
|
const auto isMuted = participant->muted || (mute && canManageCall);
|
|
|
|
const auto canSelfUnmute = !canManageCall
|
|
|
|
? participant->canSelfUnmute
|
2021-03-03 15:29:33 +00:00
|
|
|
: (!mute || IsGroupCallAdmin(_peer, participantPeer));
|
2021-02-22 08:31:35 +00:00
|
|
|
const auto isMutedByYou = mute && !canManageCall;
|
2020-12-29 15:17:50 +00:00
|
|
|
const auto mutedCount = 0/*participant->mutedCount*/;
|
|
|
|
using Flag = MTPDgroupCallParticipant::Flag;
|
|
|
|
const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0))
|
2021-01-29 16:56:56 +00:00
|
|
|
| Flag::f_volume // Without flag the volume is reset to 100%.
|
2021-02-09 08:58:19 +00:00
|
|
|
| ((participant->applyVolumeFromMin && !volume)
|
|
|
|
? Flag::f_volume_by_admin
|
|
|
|
: Flag(0))
|
2020-12-29 15:17:50 +00:00
|
|
|
| (participant->lastActive ? Flag::f_active_date : Flag(0))
|
2021-02-22 08:31:35 +00:00
|
|
|
| (isMuted ? Flag::f_muted : Flag(0))
|
2021-03-05 11:36:07 +00:00
|
|
|
| (isMutedByYou ? Flag::f_muted_by_you : Flag(0))
|
2021-03-12 10:58:10 +00:00
|
|
|
| (participantPeer == _joinAs ? Flag::f_self : Flag(0))
|
|
|
|
| (participant->raisedHandRating
|
|
|
|
? Flag::f_raise_hand_rating
|
|
|
|
: Flag(0));
|
2020-12-29 15:17:50 +00:00
|
|
|
_peer->groupCall()->applyUpdateChecked(
|
|
|
|
MTP_updateGroupCallParticipants(
|
|
|
|
inputCall(),
|
|
|
|
MTP_vector<MTPGroupCallParticipant>(
|
|
|
|
1,
|
|
|
|
MTP_groupCallParticipant(
|
|
|
|
MTP_flags(flags),
|
2021-03-03 15:29:33 +00:00
|
|
|
peerToMTP(participantPeer->id),
|
2020-12-29 15:17:50 +00:00
|
|
|
MTP_int(participant->date),
|
|
|
|
MTP_int(participant->lastActive),
|
|
|
|
MTP_int(participant->ssrc),
|
2021-03-03 15:29:33 +00:00
|
|
|
MTP_int(volume.value_or(participant->volume)),
|
2021-03-12 10:58:10 +00:00
|
|
|
MTPstring(), // Don't update about text in local updates.
|
|
|
|
MTP_long(participant->raisedHandRating))),
|
2020-12-29 15:17:50 +00:00
|
|
|
MTP_int(0)).c_updateGroupCallParticipants());
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:56:46 +00:00
|
|
|
void GroupCall::hangup() {
|
|
|
|
finish(FinishType::Ended);
|
|
|
|
}
|
|
|
|
|
2020-11-28 14:07:36 +00:00
|
|
|
void GroupCall::discard() {
|
|
|
|
if (!_id) {
|
|
|
|
_api.request(_createRequestId).cancel();
|
|
|
|
hangup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_api.request(MTPphone_DiscardGroupCall(
|
|
|
|
inputCall()
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
// Here 'this' could be destroyed by updates, so we set Ended after
|
|
|
|
// updates being handled, but in a guarded way.
|
|
|
|
crl::on_main(this, [=] { hangup(); });
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().api().applyUpdates(result);
|
2020-11-28 14:07:36 +00:00
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
hangup();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2021-03-05 15:21:11 +00:00
|
|
|
void GroupCall::rejoinAs(Group::JoinInfo info) {
|
|
|
|
_possibleJoinAs = std::move(info.possibleJoinAs);
|
|
|
|
if (info.joinAs == _joinAs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto event = Group::RejoinEvent{
|
|
|
|
.wasJoinAs = _joinAs,
|
|
|
|
.nowJoinAs = info.joinAs,
|
|
|
|
};
|
|
|
|
setState(State::Joining);
|
2021-03-09 15:12:37 +00:00
|
|
|
rejoin(info.joinAs);
|
2021-03-05 15:21:11 +00:00
|
|
|
_rejoinEvents.fire_copy(event);
|
|
|
|
}
|
|
|
|
|
2020-11-24 11:56:46 +00:00
|
|
|
void GroupCall::finish(FinishType type) {
|
|
|
|
Expects(type != FinishType::None);
|
|
|
|
|
|
|
|
const auto finalState = (type == FinishType::Ended)
|
|
|
|
? State::Ended
|
|
|
|
: State::Failed;
|
|
|
|
const auto hangupState = (type == FinishType::Ended)
|
|
|
|
? State::HangingUp
|
|
|
|
: State::FailedHangingUp;
|
|
|
|
const auto state = _state.current();
|
|
|
|
if (state == State::HangingUp
|
|
|
|
|| state == State::FailedHangingUp
|
|
|
|
|| state == State::Ended
|
|
|
|
|| state == State::Failed) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-26 11:04:00 +00:00
|
|
|
if (!_mySsrc) {
|
2020-11-24 11:56:46 +00:00
|
|
|
setState(finalState);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(hangupState);
|
2020-12-08 15:09:13 +00:00
|
|
|
|
|
|
|
// We want to leave request still being sent and processed even if
|
|
|
|
// the call is already destroyed.
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto session = &_peer->session();
|
2020-12-08 15:09:13 +00:00
|
|
|
const auto weak = base::make_weak(this);
|
|
|
|
session->api().request(MTPphone_LeaveGroupCall(
|
2020-11-26 11:04:00 +00:00
|
|
|
inputCall(),
|
|
|
|
MTP_int(_mySsrc)
|
2020-11-24 11:56:46 +00:00
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
// Here 'this' could be destroyed by updates, so we set Ended after
|
|
|
|
// updates being handled, but in a guarded way.
|
2020-12-08 15:09:13 +00:00
|
|
|
crl::on_main(weak, [=] { setState(finalState); });
|
|
|
|
session->api().applyUpdates(result);
|
|
|
|
}).fail(crl::guard(weak, [=](const RPCError &error) {
|
2020-11-24 11:56:46 +00:00
|
|
|
setState(finalState);
|
2020-12-08 15:09:13 +00:00
|
|
|
})).send();
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 07:18:46 +00:00
|
|
|
void GroupCall::setMuted(MuteState mute) {
|
2020-12-09 13:11:42 +00:00
|
|
|
const auto set = [=] {
|
|
|
|
const auto wasMuted = (muted() == MuteState::Muted)
|
|
|
|
|| (muted() == MuteState::PushToTalk);
|
2021-03-08 16:08:43 +00:00
|
|
|
const auto wasRaiseHand = (muted() == MuteState::RaisedHand);
|
2020-12-09 13:11:42 +00:00
|
|
|
_muted = mute;
|
|
|
|
const auto nowMuted = (muted() == MuteState::Muted)
|
|
|
|
|| (muted() == MuteState::PushToTalk);
|
2021-03-08 16:08:43 +00:00
|
|
|
const auto nowRaiseHand = (muted() == MuteState::RaisedHand);
|
|
|
|
if (wasMuted != nowMuted || wasRaiseHand != nowRaiseHand) {
|
2021-03-05 11:36:07 +00:00
|
|
|
applyMeInCallLocally();
|
2020-12-09 13:11:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
if (mute == MuteState::Active || mute == MuteState::PushToTalk) {
|
|
|
|
_delegate->groupCallRequestPermissionsOrFail(crl::guard(this, set));
|
|
|
|
} else {
|
|
|
|
set();
|
2020-12-06 12:16:11 +00:00
|
|
|
}
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 16:08:43 +00:00
|
|
|
void GroupCall::setMutedAndUpdate(MuteState mute) {
|
|
|
|
const auto was = muted();
|
2021-03-09 10:05:02 +00:00
|
|
|
|
|
|
|
// Active state is sent from _muted changes,
|
|
|
|
// because it may be set delayed, after permissions request, not now.
|
|
|
|
const auto send = _initialMuteStateSent && (mute != MuteState::Active);
|
2021-03-08 16:08:43 +00:00
|
|
|
setMuted(mute);
|
|
|
|
if (send) {
|
|
|
|
maybeSendMutedUpdate(was);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:26 +00:00
|
|
|
void GroupCall::handleUpdate(const MTPGroupCall &call) {
|
2020-11-20 19:25:35 +00:00
|
|
|
return call.match([&](const MTPDgroupCall &data) {
|
2020-11-24 11:56:46 +00:00
|
|
|
if (_acceptFields) {
|
2020-11-26 16:01:26 +00:00
|
|
|
if (!_instance && !_id) {
|
|
|
|
join(MTP_inputGroupCall(data.vid(), data.vaccess_hash()));
|
2020-11-24 11:56:46 +00:00
|
|
|
}
|
2020-11-26 16:01:26 +00:00
|
|
|
return;
|
2020-11-24 11:56:46 +00:00
|
|
|
} else if (_id != data.vid().v
|
2020-11-20 19:25:35 +00:00
|
|
|
|| _accessHash != data.vaccess_hash().v
|
|
|
|
|| !_instance) {
|
2020-11-26 16:01:26 +00:00
|
|
|
return;
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
2021-03-08 14:39:36 +00:00
|
|
|
const auto streamDcId = MTP::BareDcId(
|
|
|
|
data.vstream_dc_id().value_or_empty());
|
2020-11-20 19:25:35 +00:00
|
|
|
if (const auto params = data.vparams()) {
|
|
|
|
params->match([&](const MTPDdataJSON &data) {
|
2021-03-08 14:39:36 +00:00
|
|
|
using ConnectionMode = tgcalls::GroupConnectionMode;
|
2020-11-20 19:25:35 +00:00
|
|
|
auto error = QJsonParseError{ 0, QJsonParseError::NoError };
|
|
|
|
const auto document = QJsonDocument::fromJson(
|
|
|
|
data.vdata().v,
|
|
|
|
&error);
|
|
|
|
if (error.error != QJsonParseError::NoError) {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"Failed to parse group call params, error: %1."
|
|
|
|
).arg(error.errorString()));
|
|
|
|
return;
|
|
|
|
} else if (!document.isObject()) {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"Not an object received in group call params."));
|
|
|
|
return;
|
|
|
|
}
|
2021-03-08 14:39:36 +00:00
|
|
|
|
|
|
|
const auto guard = gsl::finally([&] {
|
|
|
|
addParticipantsToInstance();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (document.object().value("stream").toBool()) {
|
|
|
|
if (!streamDcId) {
|
|
|
|
LOG(("Api Error: Empty stream_dc_id in groupCall."));
|
|
|
|
}
|
|
|
|
_broadcastDcId = streamDcId
|
|
|
|
? streamDcId
|
|
|
|
: _peer->session().mtp().mainDcId();
|
|
|
|
setInstanceMode(InstanceMode::Stream);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
const auto readString = [](
|
|
|
|
const QJsonObject &object,
|
|
|
|
const char *key) {
|
|
|
|
return object.value(key).toString().toStdString();
|
|
|
|
};
|
|
|
|
const auto root = document.object().value("transport").toObject();
|
|
|
|
auto payload = tgcalls::GroupJoinResponsePayload();
|
|
|
|
payload.ufrag = readString(root, "ufrag");
|
|
|
|
payload.pwd = readString(root, "pwd");
|
|
|
|
const auto prints = root.value("fingerprints").toArray();
|
|
|
|
const auto candidates = root.value("candidates").toArray();
|
|
|
|
for (const auto &print : prints) {
|
|
|
|
const auto object = print.toObject();
|
|
|
|
payload.fingerprints.push_back(tgcalls::GroupJoinPayloadFingerprint{
|
|
|
|
.hash = readString(object, "hash"),
|
|
|
|
.setup = readString(object, "setup"),
|
|
|
|
.fingerprint = readString(object, "fingerprint"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
for (const auto &candidate : candidates) {
|
|
|
|
const auto object = candidate.toObject();
|
|
|
|
payload.candidates.push_back(tgcalls::GroupJoinResponseCandidate{
|
|
|
|
.port = readString(object, "port"),
|
|
|
|
.protocol = readString(object, "protocol"),
|
|
|
|
.network = readString(object, "network"),
|
|
|
|
.generation = readString(object, "generation"),
|
|
|
|
.id = readString(object, "id"),
|
|
|
|
.component = readString(object, "component"),
|
|
|
|
.foundation = readString(object, "foundation"),
|
|
|
|
.priority = readString(object, "priority"),
|
|
|
|
.ip = readString(object, "ip"),
|
|
|
|
.type = readString(object, "type"),
|
|
|
|
.tcpType = readString(object, "tcpType"),
|
|
|
|
.relAddr = readString(object, "relAddr"),
|
|
|
|
.relPort = readString(object, "relPort"),
|
|
|
|
});
|
|
|
|
}
|
2021-03-08 14:39:36 +00:00
|
|
|
setInstanceMode(InstanceMode::Rtc);
|
2021-03-08 07:57:00 +00:00
|
|
|
_instance->setJoinResponsePayload(payload, {});
|
2020-11-20 19:25:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [&](const MTPDgroupCallDiscarded &data) {
|
2020-11-26 16:01:26 +00:00
|
|
|
if (data.vid().v == _id) {
|
|
|
|
_mySsrc = 0;
|
|
|
|
hangup();
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-08 07:57:00 +00:00
|
|
|
void GroupCall::addParticipantsToInstance() {
|
|
|
|
const auto real = _peer->groupCall();
|
2021-03-08 14:39:36 +00:00
|
|
|
if (!real
|
|
|
|
|| (real->id() != _id)
|
|
|
|
|| (_instanceMode == InstanceMode::None)) {
|
2021-03-08 07:57:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const auto &participant : real->participants()) {
|
|
|
|
prepareParticipantForAdding(participant);
|
|
|
|
}
|
|
|
|
addPreparedParticipants();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::prepareParticipantForAdding(
|
|
|
|
const Data::GroupCallParticipant &participant) {
|
|
|
|
_preparedParticipants.push_back(tgcalls::GroupParticipantDescription());
|
|
|
|
auto &added = _preparedParticipants.back();
|
|
|
|
added.audioSsrc = participant.ssrc;
|
|
|
|
_unresolvedSsrcs.remove(added.audioSsrc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::addPreparedParticipants() {
|
|
|
|
_addPreparedParticipantsScheduled = false;
|
|
|
|
if (!_preparedParticipants.empty()) {
|
|
|
|
_instance->addParticipants(base::take(_preparedParticipants));
|
|
|
|
}
|
|
|
|
if (const auto real = _peer->groupCall(); real && real->id() == _id) {
|
|
|
|
if (!_unresolvedSsrcs.empty()) {
|
|
|
|
real->resolveParticipants(base::take(_unresolvedSsrcs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::addPreparedParticipantsDelayed() {
|
|
|
|
if (_addPreparedParticipantsScheduled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_addPreparedParticipantsScheduled = true;
|
|
|
|
crl::on_main(this, [=] { addPreparedParticipants(); });
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:26 +00:00
|
|
|
void GroupCall::handleUpdate(const MTPDupdateGroupCallParticipants &data) {
|
|
|
|
const auto state = _state.current();
|
2020-11-28 14:07:36 +00:00
|
|
|
if (state != State::Joined && state != State::Connecting) {
|
2020-11-26 16:01:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-15 16:05:34 +00:00
|
|
|
const auto handleOtherParticipants = [=](
|
|
|
|
const MTPDgroupCallParticipant &data) {
|
2021-02-01 12:25:38 +00:00
|
|
|
if (data.is_min()) {
|
|
|
|
// No real information about mutedByMe or my custom volume.
|
|
|
|
return;
|
|
|
|
}
|
2021-03-03 15:29:33 +00:00
|
|
|
const auto participantPeer = _peer->owner().peer(
|
|
|
|
peerFromMTP(data.vpeer()));
|
|
|
|
const auto participant = LookupParticipant(
|
|
|
|
_peer,
|
|
|
|
_id,
|
|
|
|
participantPeer);
|
2021-01-15 16:05:34 +00:00
|
|
|
if (!participant) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_otherParticipantStateValue.fire(Group::ParticipantState{
|
2021-03-03 15:29:33 +00:00
|
|
|
.peer = participantPeer,
|
2021-01-15 16:05:34 +00:00
|
|
|
.volume = data.vvolume().value_or_empty(),
|
2021-01-26 08:15:00 +00:00
|
|
|
.mutedByMe = data.is_muted_by_you(),
|
2021-01-15 16:05:34 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-11-26 16:01:26 +00:00
|
|
|
for (const auto &participant : data.vparticipants().v) {
|
|
|
|
participant.match([&](const MTPDgroupCallParticipant &data) {
|
2021-03-08 14:39:36 +00:00
|
|
|
const auto isSelf = data.is_self()
|
|
|
|
|| (data.is_min()
|
|
|
|
&& peerFromMTP(data.vpeer()) == _joinAs->id);
|
|
|
|
if (!isSelf) {
|
2021-01-15 16:05:34 +00:00
|
|
|
handleOtherParticipants(data);
|
2020-11-26 16:01:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-03-05 15:21:11 +00:00
|
|
|
if (data.is_left() && data.vsource().v == _mySsrc) {
|
2020-11-26 16:01:26 +00:00
|
|
|
// I was removed from the call, rejoin.
|
2020-12-01 09:06:06 +00:00
|
|
|
LOG(("Call Info: Rejoin after got 'left' with my ssrc."));
|
2020-11-26 16:01:26 +00:00
|
|
|
setState(State::Joining);
|
|
|
|
rejoin();
|
2021-03-05 15:21:11 +00:00
|
|
|
} else if (!data.is_left() && data.vsource().v != _mySsrc) {
|
2020-11-26 16:01:26 +00:00
|
|
|
// I joined from another device, hangup.
|
2020-12-01 09:06:06 +00:00
|
|
|
LOG(("Call Info: Hangup after '!left' with ssrc %1, my %2."
|
2021-03-05 15:21:11 +00:00
|
|
|
).arg(data.vsource().v
|
2020-11-30 07:52:53 +00:00
|
|
|
).arg(_mySsrc));
|
2020-11-26 16:01:26 +00:00
|
|
|
_mySsrc = 0;
|
|
|
|
hangup();
|
|
|
|
}
|
2020-11-28 07:18:46 +00:00
|
|
|
if (data.is_muted() && !data.is_can_self_unmute()) {
|
2021-03-08 16:08:43 +00:00
|
|
|
setMuted(data.vraise_hand_rating().value_or_empty()
|
|
|
|
? MuteState::RaisedHand
|
|
|
|
: MuteState::ForceMuted);
|
2021-03-08 14:39:36 +00:00
|
|
|
} else if (_instanceMode == InstanceMode::Stream) {
|
|
|
|
LOG(("Call Info: Rejoin after unforcemute in stream mode."));
|
|
|
|
setState(State::Joining);
|
|
|
|
rejoin();
|
2021-03-08 16:08:43 +00:00
|
|
|
} else if (muted() == MuteState::ForceMuted
|
|
|
|
|| muted() == MuteState::RaisedHand) {
|
2020-11-28 07:18:46 +00:00
|
|
|
setMuted(MuteState::Muted);
|
2021-01-29 15:19:07 +00:00
|
|
|
} else if (data.is_muted() && muted() != MuteState::Muted) {
|
|
|
|
setMuted(MuteState::Muted);
|
2020-11-28 07:18:46 +00:00
|
|
|
}
|
2020-11-26 16:01:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 16:59:35 +00:00
|
|
|
void GroupCall::changeTitle(const QString &title) {
|
|
|
|
const auto real = _peer->groupCall();
|
|
|
|
if (!real || real->id() != _id || real->title() == title) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
real->setTitle(title);
|
|
|
|
_api.request(MTPphone_EditGroupCallTitle(
|
|
|
|
inputCall(),
|
|
|
|
MTP_string(title)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
_peer->session().api().applyUpdates(result);
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2021-03-09 09:27:17 +00:00
|
|
|
void GroupCall::toggleRecording(bool enabled, const QString &title) {
|
|
|
|
const auto real = _peer->groupCall();
|
|
|
|
if (!real || real->id() != _id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto already = (real->recordStartDate() != 0);
|
|
|
|
if (already == enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-10 14:46:02 +00:00
|
|
|
if (!enabled) {
|
|
|
|
_recordingStoppedByMe = true;
|
|
|
|
}
|
2021-03-09 09:27:17 +00:00
|
|
|
using Flag = MTPphone_ToggleGroupCallRecord::Flag;
|
|
|
|
_api.request(MTPphone_ToggleGroupCallRecord(
|
|
|
|
MTP_flags((enabled ? Flag::f_start : Flag(0))
|
|
|
|
| (title.isEmpty() ? Flag(0) : Flag::f_title)),
|
|
|
|
inputCall(),
|
|
|
|
MTP_string(title)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
_peer->session().api().applyUpdates(result);
|
2021-03-10 14:46:02 +00:00
|
|
|
_recordingStoppedByMe = false;
|
2021-03-09 09:27:17 +00:00
|
|
|
}).fail([=](const RPCError &error) {
|
2021-03-10 14:46:02 +00:00
|
|
|
_recordingStoppedByMe = false;
|
2021-03-09 09:27:17 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2021-03-08 14:39:36 +00:00
|
|
|
void GroupCall::ensureControllerCreated() {
|
|
|
|
if (_instance) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-27 10:35:16 +00:00
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
const auto weak = base::make_weak(this);
|
2020-12-15 10:16:44 +00:00
|
|
|
const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>();
|
2020-11-20 19:25:35 +00:00
|
|
|
tgcalls::GroupInstanceDescriptor descriptor = {
|
|
|
|
.config = tgcalls::GroupConfig{
|
|
|
|
},
|
2021-03-09 14:49:09 +00:00
|
|
|
.networkStateUpdated = [=](tgcalls::GroupNetworkState networkState) {
|
|
|
|
crl::on_main(weak, [=] { setInstanceConnected(networkState); });
|
2020-11-20 19:25:35 +00:00
|
|
|
},
|
2020-12-15 10:16:44 +00:00
|
|
|
.audioLevelsUpdated = [=](const tgcalls::GroupLevelsUpdate &data) {
|
|
|
|
const auto &updates = data.updates;
|
|
|
|
if (updates.empty()) {
|
|
|
|
return;
|
|
|
|
} else if (updates.size() == 1 && !updates.front().ssrc) {
|
|
|
|
const auto &value = updates.front().value;
|
|
|
|
// Don't send many 0 while we're muted.
|
|
|
|
if (myLevel->level == value.level
|
|
|
|
&& myLevel->voice == value.voice) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*myLevel = updates.front().value;
|
2020-11-28 09:01:50 +00:00
|
|
|
}
|
2020-12-15 10:16:44 +00:00
|
|
|
crl::on_main(weak, [=] { audioLevelsUpdated(data); });
|
2020-11-27 10:35:16 +00:00
|
|
|
},
|
2020-12-18 14:43:49 +00:00
|
|
|
.initialInputDeviceId = _audioInputId.toStdString(),
|
|
|
|
.initialOutputDeviceId = _audioOutputId.toStdString(),
|
2021-01-07 15:27:11 +00:00
|
|
|
.createAudioDeviceModule = Webrtc::AudioDeviceModuleCreator(
|
|
|
|
settings.callAudioBackend()),
|
2021-03-08 07:57:00 +00:00
|
|
|
.participantDescriptionsRequired = [=](
|
|
|
|
const std::vector<uint32_t> &ssrcs) {
|
|
|
|
crl::on_main(weak, [=] {
|
|
|
|
requestParticipantsInformation(ssrcs);
|
|
|
|
});
|
|
|
|
},
|
2021-03-08 14:39:36 +00:00
|
|
|
.requestBroadcastPart = [=](
|
2021-03-09 08:33:01 +00:00
|
|
|
int64_t time,
|
|
|
|
int64_t period,
|
2021-03-08 14:39:36 +00:00
|
|
|
std::function<void(tgcalls::BroadcastPart &&)> done) {
|
|
|
|
auto result = std::make_shared<LoadPartTask>(
|
|
|
|
weak,
|
2021-03-09 08:33:01 +00:00
|
|
|
time,
|
|
|
|
period,
|
2021-03-08 14:39:36 +00:00
|
|
|
std::move(done));
|
|
|
|
crl::on_main(weak, [=]() mutable {
|
|
|
|
broadcastPartStart(std::move(result));
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
2020-11-20 19:25:35 +00:00
|
|
|
};
|
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
auto callLogFolder = cWorkingDir() + qsl("DebugLogs");
|
|
|
|
auto callLogPath = callLogFolder + qsl("/last_group_call_log.txt");
|
|
|
|
auto callLogNative = QDir::toNativeSeparators(callLogPath);
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
descriptor.config.logPath.data = callLogNative.toStdWString();
|
|
|
|
#else // Q_OS_WIN
|
|
|
|
const auto callLogUtf = QFile::encodeName(callLogNative);
|
|
|
|
descriptor.config.logPath.data.resize(callLogUtf.size());
|
|
|
|
ranges::copy(callLogUtf, descriptor.config.logPath.data.begin());
|
|
|
|
#endif // Q_OS_WIN
|
|
|
|
QFile(callLogPath).remove();
|
|
|
|
QDir().mkpath(callLogFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(("Call Info: Creating group instance"));
|
2021-03-08 07:57:00 +00:00
|
|
|
_instance = std::make_unique<tgcalls::GroupInstanceCustomImpl>(
|
2020-11-20 19:25:35 +00:00
|
|
|
std::move(descriptor));
|
2020-12-18 14:43:49 +00:00
|
|
|
|
2020-12-06 10:13:50 +00:00
|
|
|
updateInstanceMuteState();
|
2020-12-29 14:54:17 +00:00
|
|
|
updateInstanceVolumes();
|
2020-11-20 19:25:35 +00:00
|
|
|
|
|
|
|
//raw->setAudioOutputDuckingEnabled(settings.callAudioDuckingEnabled());
|
|
|
|
}
|
|
|
|
|
2021-03-08 14:39:36 +00:00
|
|
|
void GroupCall::broadcastPartStart(std::shared_ptr<LoadPartTask> task) {
|
|
|
|
const auto raw = task.get();
|
2021-03-09 08:33:01 +00:00
|
|
|
const auto time = raw->time();
|
|
|
|
const auto scale = raw->scale();
|
2021-03-08 14:39:36 +00:00
|
|
|
const auto finish = [=](tgcalls::BroadcastPart &&part) {
|
|
|
|
raw->done(std::move(part));
|
|
|
|
_broadcastParts.erase(raw);
|
|
|
|
};
|
|
|
|
using Status = tgcalls::BroadcastPart::Status;
|
|
|
|
const auto requestId = _api.request(MTPupload_GetFile(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_inputGroupCallStream(
|
|
|
|
inputCall(),
|
2021-03-09 08:33:01 +00:00
|
|
|
MTP_long(time),
|
|
|
|
MTP_int(scale)),
|
2021-03-08 14:39:36 +00:00
|
|
|
MTP_int(0),
|
|
|
|
MTP_int(128 * 1024)
|
2021-03-12 10:58:10 +00:00
|
|
|
)).done([=](
|
|
|
|
const MTPupload_File &result,
|
|
|
|
const MTP::Response &response) {
|
2021-03-08 14:39:36 +00:00
|
|
|
result.match([&](const MTPDupload_file &data) {
|
|
|
|
const auto size = data.vbytes().v.size();
|
|
|
|
auto bytes = std::vector<uint8_t>(size);
|
|
|
|
memcpy(bytes.data(), data.vbytes().v.constData(), size);
|
|
|
|
finish({
|
2021-03-09 08:33:01 +00:00
|
|
|
.timestampMilliseconds = time,
|
2021-03-12 10:58:10 +00:00
|
|
|
.responseTimestamp = TimestampFromMsgId(response.outerMsgId),
|
2021-03-08 14:39:36 +00:00
|
|
|
.status = Status::Success,
|
|
|
|
.oggData = std::move(bytes),
|
|
|
|
});
|
|
|
|
}, [&](const MTPDupload_fileCdnRedirect &data) {
|
|
|
|
LOG(("Voice Chat Stream Error: fileCdnRedirect received."));
|
|
|
|
finish({
|
2021-03-09 08:33:01 +00:00
|
|
|
.timestampMilliseconds = time,
|
2021-03-12 10:58:10 +00:00
|
|
|
.responseTimestamp = TimestampFromMsgId(response.outerMsgId),
|
2021-03-09 08:33:01 +00:00
|
|
|
.status = Status::ResyncNeeded,
|
2021-03-08 14:39:36 +00:00
|
|
|
});
|
|
|
|
});
|
2021-03-12 10:58:10 +00:00
|
|
|
}).fail([=](const RPCError &error, const MTP::Response &response) {
|
2021-03-09 08:33:01 +00:00
|
|
|
if (error.type() == u"GROUPCALL_JOIN_MISSING"_q) {
|
|
|
|
for (const auto &[task, part] : _broadcastParts) {
|
|
|
|
_api.request(part.requestId).cancel();
|
|
|
|
}
|
|
|
|
setState(State::Joining);
|
|
|
|
rejoin();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto status = MTP::isFloodError(error)
|
2021-03-08 14:39:36 +00:00
|
|
|
? Status::NotReady
|
2021-03-09 08:33:01 +00:00
|
|
|
: Status::ResyncNeeded;
|
2021-03-08 14:39:36 +00:00
|
|
|
finish({
|
2021-03-09 08:33:01 +00:00
|
|
|
.timestampMilliseconds = time,
|
2021-03-12 10:58:10 +00:00
|
|
|
.responseTimestamp = TimestampFromMsgId(response.outerMsgId),
|
2021-03-08 14:39:36 +00:00
|
|
|
.status = status,
|
|
|
|
});
|
|
|
|
}).handleAllErrors().toDC(
|
|
|
|
MTP::groupCallStreamDcId(_broadcastDcId)
|
|
|
|
).send();
|
|
|
|
_broadcastParts.emplace(raw, LoadingPart{ std::move(task), requestId });
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::broadcastPartCancel(not_null<LoadPartTask*> task) {
|
|
|
|
const auto i = _broadcastParts.find(task);
|
|
|
|
if (i != _broadcastParts.end()) {
|
|
|
|
_api.request(i->second.requestId).cancel();
|
|
|
|
_broadcastParts.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 07:57:00 +00:00
|
|
|
void GroupCall::requestParticipantsInformation(
|
|
|
|
const std::vector<uint32_t> &ssrcs) {
|
|
|
|
const auto real = _peer->groupCall();
|
2021-03-08 14:39:36 +00:00
|
|
|
if (!real
|
|
|
|
|| (real->id() != _id)
|
|
|
|
|| (_instanceMode == InstanceMode::None)) {
|
2021-03-08 07:57:00 +00:00
|
|
|
for (const auto ssrc : ssrcs) {
|
|
|
|
_unresolvedSsrcs.emplace(ssrc);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &existing = real->participants();
|
|
|
|
for (const auto ssrc : ssrcs) {
|
|
|
|
const auto participantPeer = real->participantPeerBySsrc(ssrc);
|
|
|
|
if (!participantPeer) {
|
|
|
|
_unresolvedSsrcs.emplace(ssrc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto i = ranges::find(
|
|
|
|
existing,
|
|
|
|
not_null{ participantPeer },
|
|
|
|
&Data::GroupCall::Participant::peer);
|
|
|
|
Assert(i != end(existing));
|
|
|
|
|
|
|
|
prepareParticipantForAdding(*i);
|
|
|
|
}
|
|
|
|
addPreparedParticipants();
|
|
|
|
}
|
|
|
|
|
2020-12-06 10:13:50 +00:00
|
|
|
void GroupCall::updateInstanceMuteState() {
|
|
|
|
Expects(_instance != nullptr);
|
|
|
|
|
|
|
|
const auto state = muted();
|
|
|
|
_instance->setIsMuted(state != MuteState::Active
|
|
|
|
&& state != MuteState::PushToTalk);
|
|
|
|
}
|
|
|
|
|
2020-12-29 14:54:17 +00:00
|
|
|
void GroupCall::updateInstanceVolumes() {
|
|
|
|
const auto real = _peer->groupCall();
|
|
|
|
if (!real || real->id() != _id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &participants = real->participants();
|
|
|
|
for (const auto &participant : participants) {
|
|
|
|
const auto setVolume = participant.mutedByMe
|
2021-01-14 00:25:59 +00:00
|
|
|
|| (participant.volume != Group::kDefaultVolume);
|
2020-12-29 14:54:17 +00:00
|
|
|
if (setVolume && participant.ssrc) {
|
|
|
|
_instance->setVolume(
|
|
|
|
participant.ssrc,
|
|
|
|
(participant.mutedByMe
|
|
|
|
? 0.
|
2021-01-14 00:25:59 +00:00
|
|
|
: (participant.volume / float64(Group::kDefaultVolume))));
|
2020-12-29 14:54:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-15 10:16:44 +00:00
|
|
|
void GroupCall::audioLevelsUpdated(const tgcalls::GroupLevelsUpdate &data) {
|
|
|
|
Expects(!data.updates.empty());
|
2020-11-28 09:01:50 +00:00
|
|
|
|
2020-11-29 09:20:33 +00:00
|
|
|
auto check = false;
|
|
|
|
auto checkNow = false;
|
|
|
|
const auto now = crl::now();
|
2020-12-15 10:16:44 +00:00
|
|
|
for (const auto &[ssrcOrZero, value] : data.updates) {
|
|
|
|
const auto ssrc = ssrcOrZero ? ssrcOrZero : _mySsrc;
|
|
|
|
const auto level = value.level;
|
|
|
|
const auto voice = value.voice;
|
2021-03-05 11:36:07 +00:00
|
|
|
const auto me = (ssrc == _mySsrc);
|
2020-11-28 09:01:50 +00:00
|
|
|
_levelUpdates.fire(LevelUpdate{
|
2020-12-01 09:06:06 +00:00
|
|
|
.ssrc = ssrc,
|
2020-11-28 09:01:50 +00:00
|
|
|
.value = level,
|
2020-12-15 10:16:44 +00:00
|
|
|
.voice = voice,
|
2021-03-05 11:36:07 +00:00
|
|
|
.me = me
|
2020-11-28 09:01:50 +00:00
|
|
|
});
|
2020-11-29 09:20:33 +00:00
|
|
|
if (level <= kSpeakLevelThreshold) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-05 11:36:07 +00:00
|
|
|
if (me
|
2020-12-15 10:16:44 +00:00
|
|
|
&& voice
|
2020-11-30 15:51:04 +00:00
|
|
|
&& (!_lastSendProgressUpdate
|
|
|
|
|| _lastSendProgressUpdate + kUpdateSendActionEach < now)) {
|
|
|
|
_lastSendProgressUpdate = now;
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().sendProgressManager().update(
|
2020-11-30 15:51:04 +00:00
|
|
|
_history,
|
|
|
|
Api::SendProgressType::Speaking);
|
|
|
|
}
|
2020-11-29 09:20:33 +00:00
|
|
|
|
|
|
|
check = true;
|
2020-12-01 09:06:06 +00:00
|
|
|
const auto i = _lastSpoke.find(ssrc);
|
2020-11-29 09:20:33 +00:00
|
|
|
if (i == _lastSpoke.end()) {
|
2020-12-15 10:16:44 +00:00
|
|
|
_lastSpoke.emplace(ssrc, Data::LastSpokeTimes{
|
|
|
|
.anything = now,
|
|
|
|
.voice = voice ? now : 0,
|
|
|
|
});
|
2020-11-29 09:20:33 +00:00
|
|
|
checkNow = true;
|
|
|
|
} else {
|
2020-12-15 10:16:44 +00:00
|
|
|
if ((i->second.anything + kCheckLastSpokeInterval / 3 <= now)
|
|
|
|
|| (voice
|
|
|
|
&& i->second.voice + kCheckLastSpokeInterval / 3 <= now)) {
|
2020-11-29 09:20:33 +00:00
|
|
|
checkNow = true;
|
|
|
|
}
|
2020-12-15 10:16:44 +00:00
|
|
|
i->second.anything = now;
|
|
|
|
if (voice) {
|
|
|
|
i->second.voice = now;
|
|
|
|
}
|
2020-11-29 09:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checkNow) {
|
|
|
|
checkLastSpoke();
|
|
|
|
} else if (check && !_lastSpokeCheckTimer.isActive()) {
|
|
|
|
_lastSpokeCheckTimer.callEach(kCheckLastSpokeInterval / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::checkLastSpoke() {
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto real = _peer->groupCall();
|
2020-11-29 09:20:33 +00:00
|
|
|
if (!real || real->id() != _id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto hasRecent = false;
|
|
|
|
const auto now = crl::now();
|
|
|
|
auto list = base::take(_lastSpoke);
|
|
|
|
for (auto i = list.begin(); i != list.end();) {
|
2020-12-01 09:06:06 +00:00
|
|
|
const auto [ssrc, when] = *i;
|
2020-12-15 10:16:44 +00:00
|
|
|
if (when.anything + kCheckLastSpokeInterval >= now) {
|
2020-11-29 09:20:33 +00:00
|
|
|
hasRecent = true;
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
i = list.erase(i);
|
|
|
|
}
|
2020-12-01 09:06:06 +00:00
|
|
|
real->applyLastSpoke(ssrc, when, now);
|
2020-11-29 09:20:33 +00:00
|
|
|
}
|
|
|
|
_lastSpoke = std::move(list);
|
|
|
|
|
|
|
|
if (!hasRecent) {
|
|
|
|
_lastSpokeCheckTimer.cancel();
|
|
|
|
} else if (!_lastSpokeCheckTimer.isActive()) {
|
|
|
|
_lastSpokeCheckTimer.callEach(kCheckLastSpokeInterval / 3);
|
2020-11-28 09:01:50 +00:00
|
|
|
}
|
2020-11-28 06:38:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 14:42:34 +00:00
|
|
|
void GroupCall::checkJoined() {
|
|
|
|
if (state() != State::Connecting || !_id || !_mySsrc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_api.request(MTPphone_CheckGroupCall(
|
|
|
|
inputCall(),
|
|
|
|
MTP_int(_mySsrc)
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
if (!mtpIsTrue(result)) {
|
2020-11-30 07:52:53 +00:00
|
|
|
LOG(("Call Info: Rejoin after FALSE in checkGroupCall."));
|
2020-11-29 14:42:34 +00:00
|
|
|
rejoin();
|
|
|
|
} else if (state() == State::Connecting) {
|
|
|
|
_checkJoinedTimer.callOnce(kCheckJoinedTimeout);
|
|
|
|
}
|
|
|
|
}).fail([=](const RPCError &error) {
|
2020-11-30 07:52:53 +00:00
|
|
|
LOG(("Call Info: Rejoin after error '%1' in checkGroupCall."
|
|
|
|
).arg(error.type()));
|
2020-11-29 14:42:34 +00:00
|
|
|
rejoin();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2021-03-09 14:49:09 +00:00
|
|
|
void GroupCall::setInstanceConnected(
|
|
|
|
tgcalls::GroupNetworkState networkState) {
|
|
|
|
const auto connected = networkState.isConnected;
|
2020-11-28 14:07:36 +00:00
|
|
|
if (_instanceConnected == connected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_instanceConnected = connected;
|
|
|
|
if (state() == State::Connecting && connected) {
|
|
|
|
setState(State::Joined);
|
2021-03-09 14:49:09 +00:00
|
|
|
if (networkState.isTransitioningFromBroadcastToRtc) {
|
|
|
|
// #TODO calls play sound?..
|
|
|
|
}
|
2020-11-28 14:07:36 +00:00
|
|
|
} else if (state() == State::Joined && !connected) {
|
|
|
|
setState(State::Connecting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 14:39:36 +00:00
|
|
|
void GroupCall::setInstanceMode(InstanceMode mode) {
|
|
|
|
Expects(_instance != nullptr);
|
|
|
|
|
|
|
|
_instanceMode = mode;
|
|
|
|
|
|
|
|
using Mode = tgcalls::GroupConnectionMode;
|
|
|
|
_instance->setConnectionMode([&] {
|
|
|
|
switch (_instanceMode) {
|
|
|
|
case InstanceMode::None: return Mode::GroupConnectionModeNone;
|
|
|
|
case InstanceMode::Rtc: return Mode::GroupConnectionModeRtc;
|
|
|
|
case InstanceMode::Stream: return Mode::GroupConnectionModeBroadcast;
|
|
|
|
}
|
|
|
|
Unexpected("Mode in GroupCall::setInstanceMode.");
|
2021-03-09 14:49:09 +00:00
|
|
|
}(), true);
|
2021-03-08 14:39:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-06 10:13:50 +00:00
|
|
|
void GroupCall::maybeSendMutedUpdate(MuteState previous) {
|
2021-03-09 10:05:02 +00:00
|
|
|
// Send Active <-> !Active or ForceMuted <-> RaisedHand changes.
|
2020-12-06 10:13:50 +00:00
|
|
|
const auto now = muted();
|
2021-03-09 10:05:02 +00:00
|
|
|
if ((previous == MuteState::Active && now == MuteState::Muted)
|
|
|
|
|| (now == MuteState::Active
|
2021-03-08 16:08:43 +00:00
|
|
|
&& (previous == MuteState::Muted
|
2021-03-09 10:05:02 +00:00
|
|
|
|| previous == MuteState::PushToTalk))) {
|
|
|
|
sendSelfUpdate(SendUpdateType::Mute);
|
|
|
|
} else if ((now == MuteState::ForceMuted
|
|
|
|
&& previous == MuteState::RaisedHand)
|
2021-03-08 16:08:43 +00:00
|
|
|
|| (now == MuteState::RaisedHand
|
|
|
|
&& previous == MuteState::ForceMuted)) {
|
2021-03-09 10:05:02 +00:00
|
|
|
sendSelfUpdate(SendUpdateType::RaiseHand);
|
2020-12-06 10:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 10:05:02 +00:00
|
|
|
void GroupCall::sendSelfUpdate(SendUpdateType type) {
|
2020-11-26 16:01:26 +00:00
|
|
|
_api.request(_updateMuteRequestId).cancel();
|
2021-03-03 15:29:33 +00:00
|
|
|
using Flag = MTPphone_EditGroupCallParticipant::Flag;
|
|
|
|
_updateMuteRequestId = _api.request(MTPphone_EditGroupCallParticipant(
|
2021-03-09 10:05:02 +00:00
|
|
|
MTP_flags((type == SendUpdateType::RaiseHand)
|
|
|
|
? Flag::f_raise_hand
|
|
|
|
: (muted() != MuteState::Active)
|
|
|
|
? Flag::f_muted
|
|
|
|
: Flag(0)),
|
2020-11-26 16:01:26 +00:00
|
|
|
inputCall(),
|
2021-03-05 11:36:07 +00:00
|
|
|
_joinAs->input,
|
|
|
|
MTP_int(100000), // volume
|
2021-03-08 16:08:43 +00:00
|
|
|
MTP_bool(muted() == MuteState::RaisedHand)
|
2020-11-26 16:01:26 +00:00
|
|
|
)).done([=](const MTPUpdates &result) {
|
2020-11-27 15:51:24 +00:00
|
|
|
_updateMuteRequestId = 0;
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().api().applyUpdates(result);
|
2020-11-26 16:01:26 +00:00
|
|
|
}).fail([=](const RPCError &error) {
|
2020-11-27 15:51:24 +00:00
|
|
|
_updateMuteRequestId = 0;
|
2020-12-08 08:45:40 +00:00
|
|
|
if (error.type() == u"GROUPCALL_FORBIDDEN"_q) {
|
2020-11-30 07:52:53 +00:00
|
|
|
LOG(("Call Info: Rejoin after error '%1' in editGroupCallMember."
|
|
|
|
).arg(error.type()));
|
2020-11-26 16:01:26 +00:00
|
|
|
rejoin();
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:02:19 +00:00
|
|
|
rpl::producer<bool> GroupCall::connectingValue() const {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
return _state.value() | rpl::map(
|
|
|
|
_1 == State::Creating
|
|
|
|
|| _1 == State::Joining
|
|
|
|
|| _1 == State::Connecting
|
|
|
|
) | rpl::distinct_until_changed();
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:25:35 +00:00
|
|
|
void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) {
|
2020-12-18 14:43:49 +00:00
|
|
|
if (input) {
|
|
|
|
_mediaDevices->switchToAudioInput(deviceId);
|
|
|
|
} else {
|
|
|
|
_mediaDevices->switchToAudioOutput(deviceId);
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 11:22:12 +00:00
|
|
|
void GroupCall::toggleMute(const Group::MuteRequest &data) {
|
|
|
|
if (data.locallyOnly) {
|
2021-03-03 15:29:33 +00:00
|
|
|
applyParticipantLocally(data.peer, data.mute, std::nullopt);
|
2021-01-15 11:22:12 +00:00
|
|
|
} else {
|
2021-03-03 15:29:33 +00:00
|
|
|
editParticipant(data.peer, data.mute, std::nullopt);
|
2021-01-15 11:22:12 +00:00
|
|
|
}
|
2020-12-29 14:54:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 11:22:12 +00:00
|
|
|
void GroupCall::changeVolume(const Group::VolumeRequest &data) {
|
|
|
|
if (data.locallyOnly) {
|
2021-03-03 15:29:33 +00:00
|
|
|
applyParticipantLocally(data.peer, false, data.volume);
|
2021-01-15 11:22:12 +00:00
|
|
|
} else {
|
2021-03-03 15:29:33 +00:00
|
|
|
editParticipant(data.peer, false, data.volume);
|
2021-01-15 11:22:12 +00:00
|
|
|
}
|
2020-12-29 14:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::editParticipant(
|
2021-03-03 15:29:33 +00:00
|
|
|
not_null<PeerData*> participantPeer,
|
2020-12-29 14:54:17 +00:00
|
|
|
bool mute,
|
|
|
|
std::optional<int> volume) {
|
2021-03-03 15:29:33 +00:00
|
|
|
const auto participant = LookupParticipant(_peer, _id, participantPeer);
|
2020-12-29 14:54:17 +00:00
|
|
|
if (!participant) {
|
2020-11-28 18:17:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-03-03 15:29:33 +00:00
|
|
|
applyParticipantLocally(participantPeer, mute, volume);
|
2020-12-29 15:17:50 +00:00
|
|
|
|
2021-03-03 15:29:33 +00:00
|
|
|
using Flag = MTPphone_EditGroupCallParticipant::Flag;
|
2020-12-29 14:54:17 +00:00
|
|
|
const auto flags = (mute ? Flag::f_muted : Flag(0))
|
|
|
|
| (volume.has_value() ? Flag::f_volume : Flag(0));
|
2021-03-03 15:29:33 +00:00
|
|
|
_api.request(MTPphone_EditGroupCallParticipant(
|
2020-12-29 14:54:17 +00:00
|
|
|
MTP_flags(flags),
|
2020-11-27 15:51:24 +00:00
|
|
|
inputCall(),
|
2021-03-03 15:29:33 +00:00
|
|
|
participantPeer->input,
|
2021-03-05 11:36:07 +00:00
|
|
|
MTP_int(std::clamp(volume.value_or(0), 1, Group::kMaxVolume)),
|
2021-03-12 10:58:10 +00:00
|
|
|
MTPBool()
|
2020-11-27 15:51:24 +00:00
|
|
|
)).done([=](const MTPUpdates &result) {
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().api().applyUpdates(result);
|
2020-11-27 15:51:24 +00:00
|
|
|
}).fail([=](const RPCError &error) {
|
2020-12-08 08:45:40 +00:00
|
|
|
if (error.type() == u"GROUPCALL_FORBIDDEN"_q) {
|
2020-11-30 07:52:53 +00:00
|
|
|
LOG(("Call Info: Rejoin after error '%1' in editGroupCallMember."
|
|
|
|
).arg(error.type()));
|
2020-11-27 15:51:24 +00:00
|
|
|
rejoin();
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2020-11-28 18:17:13 +00:00
|
|
|
std::variant<int, not_null<UserData*>> GroupCall::inviteUsers(
|
|
|
|
const std::vector<not_null<UserData*>> &users) {
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto real = _peer->groupCall();
|
2020-11-28 18:17:13 +00:00
|
|
|
if (!real || real->id() != _id) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto owner = &_peer->owner();
|
2020-11-28 18:17:13 +00:00
|
|
|
const auto &invited = owner->invitedToCallUsers(_id);
|
|
|
|
const auto &participants = real->participants();
|
|
|
|
auto &&toInvite = users | ranges::view::filter([&](
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
return !invited.contains(user) && !ranges::contains(
|
|
|
|
participants,
|
|
|
|
user,
|
2021-03-03 15:29:33 +00:00
|
|
|
&Data::GroupCall::Participant::peer);
|
2020-11-28 18:17:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto count = 0;
|
|
|
|
auto slice = QVector<MTPInputUser>();
|
|
|
|
auto result = std::variant<int, not_null<UserData*>>(0);
|
|
|
|
slice.reserve(kMaxInvitePerSlice);
|
|
|
|
const auto sendSlice = [&] {
|
|
|
|
count += slice.size();
|
|
|
|
_api.request(MTPphone_InviteToGroupCall(
|
|
|
|
inputCall(),
|
|
|
|
MTP_vector<MTPInputUser>(slice)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
2020-12-14 12:52:18 +00:00
|
|
|
_peer->session().api().applyUpdates(result);
|
2020-11-28 18:17:13 +00:00
|
|
|
}).send();
|
|
|
|
slice.clear();
|
|
|
|
};
|
|
|
|
for (const auto user : users) {
|
|
|
|
if (!count && slice.empty()) {
|
|
|
|
result = user;
|
|
|
|
}
|
2020-12-14 12:52:18 +00:00
|
|
|
owner->registerInvitedToCallUser(_id, _peer, user);
|
2020-11-28 18:17:13 +00:00
|
|
|
slice.push_back(user->inputUser);
|
|
|
|
if (slice.size() == kMaxInvitePerSlice) {
|
|
|
|
sendSlice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count != 0 || slice.size() != 1) {
|
|
|
|
result = int(count + slice.size());
|
|
|
|
}
|
|
|
|
if (!slice.empty()) {
|
|
|
|
sendSlice();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-12-03 18:17:15 +00:00
|
|
|
auto GroupCall::ensureGlobalShortcutManager()
|
|
|
|
-> std::shared_ptr<GlobalShortcutManager> {
|
|
|
|
if (!_shortcutManager) {
|
2020-12-06 08:41:45 +00:00
|
|
|
_shortcutManager = base::CreateGlobalShortcutManager();
|
2020-12-03 18:17:15 +00:00
|
|
|
}
|
|
|
|
return _shortcutManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::applyGlobalShortcutChanges() {
|
|
|
|
auto &settings = Core::App().settings();
|
2020-12-06 15:13:18 +00:00
|
|
|
if (!settings.groupCallPushToTalk()
|
2020-12-07 11:47:39 +00:00
|
|
|
|| settings.groupCallPushToTalkShortcut().isEmpty()
|
|
|
|
|| !base::GlobalShortcutsAvailable()
|
|
|
|
|| !base::GlobalShortcutsAllowed()) {
|
2020-12-03 18:17:15 +00:00
|
|
|
_shortcutManager = nullptr;
|
|
|
|
_pushToTalk = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ensureGlobalShortcutManager();
|
|
|
|
const auto shortcut = _shortcutManager->shortcutFromSerialized(
|
|
|
|
settings.groupCallPushToTalkShortcut());
|
|
|
|
if (!shortcut) {
|
|
|
|
settings.setGroupCallPushToTalkShortcut(QByteArray());
|
|
|
|
settings.setGroupCallPushToTalk(false);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
_shortcutManager = nullptr;
|
|
|
|
_pushToTalk = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_pushToTalk) {
|
|
|
|
if (shortcut->serialize() == _pushToTalk->serialize()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_shortcutManager->stopWatching(_pushToTalk);
|
|
|
|
}
|
|
|
|
_pushToTalk = shortcut;
|
|
|
|
_shortcutManager->startWatching(_pushToTalk, [=](bool pressed) {
|
2020-12-16 09:14:52 +00:00
|
|
|
pushToTalk(
|
|
|
|
pressed,
|
|
|
|
Core::App().settings().groupCallPushToTalkDelay());
|
2020-12-03 18:17:15 +00:00
|
|
|
});
|
|
|
|
}
|
2020-12-06 12:44:20 +00:00
|
|
|
|
2020-12-16 09:14:52 +00:00
|
|
|
void GroupCall::pushToTalk(bool pressed, crl::time delay) {
|
|
|
|
if (muted() == MuteState::ForceMuted
|
2021-03-08 16:08:43 +00:00
|
|
|
|| muted() == MuteState::RaisedHand
|
2020-12-16 09:14:52 +00:00
|
|
|
|| muted() == MuteState::Active) {
|
|
|
|
return;
|
|
|
|
} else if (pressed) {
|
|
|
|
_pushToTalkCancelTimer.cancel();
|
|
|
|
setMuted(MuteState::PushToTalk);
|
|
|
|
} else if (delay) {
|
|
|
|
_pushToTalkCancelTimer.callOnce(delay);
|
|
|
|
} else {
|
|
|
|
pushToTalkCancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-06 12:44:20 +00:00
|
|
|
void GroupCall::pushToTalkCancel() {
|
|
|
|
_pushToTalkCancelTimer.cancel();
|
|
|
|
if (muted() == MuteState::PushToTalk) {
|
|
|
|
setMuted(MuteState::Muted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 16:05:34 +00:00
|
|
|
auto GroupCall::otherParticipantStateValue() const
|
|
|
|
-> rpl::producer<Group::ParticipantState> {
|
|
|
|
return _otherParticipantStateValue.events();
|
|
|
|
}
|
|
|
|
|
2020-11-27 10:35:16 +00:00
|
|
|
//void GroupCall::setAudioVolume(bool input, float level) {
|
|
|
|
// if (_instance) {
|
|
|
|
// if (input) {
|
|
|
|
// _instance->setInputVolume(level);
|
|
|
|
// } else {
|
|
|
|
// _instance->setOutputVolume(level);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
2020-11-20 19:25:35 +00:00
|
|
|
|
|
|
|
void GroupCall::setAudioDuckingEnabled(bool enabled) {
|
|
|
|
if (_instance) {
|
|
|
|
//_instance->setAudioOutputDuckingEnabled(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::handleRequestError(const RPCError &error) {
|
|
|
|
//if (error.type() == qstr("USER_PRIVACY_RESTRICTED")) {
|
|
|
|
// Ui::show(Box<InformBox>(tr::lng_call_error_not_available(tr::now, lt_user, _user->name)));
|
|
|
|
//} else if (error.type() == qstr("PARTICIPANT_VERSION_OUTDATED")) {
|
|
|
|
// Ui::show(Box<InformBox>(tr::lng_call_error_outdated(tr::now, lt_user, _user->name)));
|
|
|
|
//} else if (error.type() == qstr("CALL_PROTOCOL_LAYER_INVALID")) {
|
|
|
|
// Ui::show(Box<InformBox>(Lang::Hard::CallErrorIncompatible().replace("{user}", _user->name)));
|
|
|
|
//}
|
|
|
|
//finish(FinishType::Failed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::handleControllerError(const QString &error) {
|
|
|
|
if (error == u"ERROR_INCOMPATIBLE"_q) {
|
|
|
|
//Ui::show(Box<InformBox>(
|
|
|
|
// Lang::Hard::CallErrorIncompatible().replace(
|
|
|
|
// "{user}",
|
|
|
|
// _user->name)));
|
|
|
|
} else if (error == u"ERROR_AUDIO_IO"_q) {
|
2020-12-14 12:52:18 +00:00
|
|
|
//Ui::show(Box<InformBox>(tr::lng_call_error_audio_io(tr::now)));
|
2020-11-20 19:25:35 +00:00
|
|
|
}
|
|
|
|
//finish(FinishType::Failed);
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputGroupCall GroupCall::inputCall() const {
|
|
|
|
Expects(_id != 0);
|
|
|
|
|
|
|
|
return MTP_inputGroupCall(
|
|
|
|
MTP_long(_id),
|
|
|
|
MTP_long(_accessHash));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupCall::destroyController() {
|
|
|
|
if (_instance) {
|
|
|
|
//_instance->stop([](tgcalls::FinalState) {
|
|
|
|
//});
|
|
|
|
|
|
|
|
DEBUG_LOG(("Call Info: Destroying call controller.."));
|
|
|
|
_instance.reset();
|
|
|
|
DEBUG_LOG(("Call Info: Call controller destroyed."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Calls
|