mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Check joined state if disconnected.
This commit is contained in:
parent
c42ef54417
commit
cf8e45ab61
2 changed files with 50 additions and 21 deletions
|
@ -36,6 +36,7 @@ namespace {
|
||||||
constexpr auto kMaxInvitePerSlice = 10;
|
constexpr auto kMaxInvitePerSlice = 10;
|
||||||
constexpr auto kCheckLastSpokeInterval = 3 * crl::time(1000);
|
constexpr auto kCheckLastSpokeInterval = 3 * crl::time(1000);
|
||||||
constexpr auto kSpeakLevelThreshold = 0.2;
|
constexpr auto kSpeakLevelThreshold = 0.2;
|
||||||
|
constexpr auto kCheckJoinedTimeout = 4 * crl::time(1000);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -46,7 +47,18 @@ GroupCall::GroupCall(
|
||||||
: _delegate(delegate)
|
: _delegate(delegate)
|
||||||
, _channel(channel)
|
, _channel(channel)
|
||||||
, _api(&_channel->session().mtp())
|
, _api(&_channel->session().mtp())
|
||||||
, _lastSpokeCheckTimer([=] { checkLastSpoke(); }) {
|
, _lastSpokeCheckTimer([=] { checkLastSpoke(); })
|
||||||
|
, _checkJoinedTimer([=] { checkJoined(); }) {
|
||||||
|
_muted.changes(
|
||||||
|
) | rpl::start_with_next([=](MuteState state) {
|
||||||
|
if (_instance) {
|
||||||
|
_instance->setIsMuted(state != MuteState::Active);
|
||||||
|
}
|
||||||
|
if (_mySsrc && state != MuteState::ForceMuted) {
|
||||||
|
sendMutedUpdate();
|
||||||
|
}
|
||||||
|
}, _lifetime);
|
||||||
|
|
||||||
const auto id = inputCall.c_inputGroupCall().vid().v;
|
const auto id = inputCall.c_inputGroupCall().vid().v;
|
||||||
if (id) {
|
if (id) {
|
||||||
if (const auto call = _channel->call(); call && call->id() == id) {
|
if (const auto call = _channel->call(); call && call->id() == id) {
|
||||||
|
@ -91,6 +103,11 @@ void GroupCall::setState(State state) {
|
||||||
case State::Failed:
|
case State::Failed:
|
||||||
_delegate->groupCallFailed(this);
|
_delegate->groupCallFailed(this);
|
||||||
break;
|
break;
|
||||||
|
case State::Connecting:
|
||||||
|
if (!_checkJoinedTimer.isActive()) {
|
||||||
|
_checkJoinedTimer.callOnce(kCheckJoinedTimeout);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +132,6 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) {
|
||||||
inputCall.match([&](const MTPDinputGroupCall &data) {
|
inputCall.match([&](const MTPDinputGroupCall &data) {
|
||||||
_id = data.vid().v;
|
_id = data.vid().v;
|
||||||
_accessHash = data.vaccess_hash().v;
|
_accessHash = data.vaccess_hash().v;
|
||||||
createAndStartController();
|
|
||||||
rejoin();
|
rejoin();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -131,9 +147,13 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::rejoin() {
|
void GroupCall::rejoin() {
|
||||||
Expects(_state.current() == State::Joining);
|
Expects(_state.current() == State::Joining
|
||||||
|
|| _state.current() == State::Joined
|
||||||
|
|| _state.current() == State::Connecting);
|
||||||
|
|
||||||
_mySsrc = 0;
|
_mySsrc = 0;
|
||||||
|
setState(State::Joining);
|
||||||
|
createAndStartController();
|
||||||
applySelfInCallLocally();
|
applySelfInCallLocally();
|
||||||
LOG(("Call Info: Requesting join payload."));
|
LOG(("Call Info: Requesting join payload."));
|
||||||
|
|
||||||
|
@ -183,7 +203,9 @@ void GroupCall::rejoin() {
|
||||||
|
|
||||||
_channel->session().api().applyUpdates(updates);
|
_channel->session().api().applyUpdates(updates);
|
||||||
}).fail([=](const RPCError &error) {
|
}).fail([=](const RPCError &error) {
|
||||||
int a = error.code();
|
LOG(("Call Error: Could not join, error: %1"
|
||||||
|
).arg(error.type()));
|
||||||
|
hangup();
|
||||||
}).send();
|
}).send();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -440,16 +462,8 @@ void GroupCall::createAndStartController() {
|
||||||
LOG(("Call Info: Creating group instance"));
|
LOG(("Call Info: Creating group instance"));
|
||||||
_instance = std::make_unique<tgcalls::GroupInstanceImpl>(
|
_instance = std::make_unique<tgcalls::GroupInstanceImpl>(
|
||||||
std::move(descriptor));
|
std::move(descriptor));
|
||||||
|
_instance->setIsMuted(_muted.current() != MuteState::Active);
|
||||||
|
|
||||||
_muted.value(
|
|
||||||
) | rpl::start_with_next([=](MuteState state) {
|
|
||||||
if (_instance) {
|
|
||||||
_instance->setIsMuted(state != MuteState::Active);
|
|
||||||
}
|
|
||||||
if (_mySsrc && state != MuteState::ForceMuted) {
|
|
||||||
sendMutedUpdate();
|
|
||||||
}
|
|
||||||
}, _lifetime);
|
|
||||||
//raw->setAudioOutputDuckingEnabled(settings.callAudioDuckingEnabled());
|
//raw->setAudioOutputDuckingEnabled(settings.callAudioDuckingEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,6 +541,24 @@ void GroupCall::checkLastSpoke() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
rejoin();
|
||||||
|
} else if (state() == State::Connecting) {
|
||||||
|
_checkJoinedTimer.callOnce(kCheckJoinedTimeout);
|
||||||
|
}
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
rejoin();
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
void GroupCall::setInstanceConnected(bool connected) {
|
void GroupCall::setInstanceConnected(bool connected) {
|
||||||
if (_instanceConnected == connected) {
|
if (_instanceConnected == connected) {
|
||||||
return;
|
return;
|
||||||
|
@ -552,10 +584,7 @@ void GroupCall::sendMutedUpdate() {
|
||||||
_channel->session().api().applyUpdates(result);
|
_channel->session().api().applyUpdates(result);
|
||||||
}).fail([=](const RPCError &error) {
|
}).fail([=](const RPCError &error) {
|
||||||
_updateMuteRequestId = 0;
|
_updateMuteRequestId = 0;
|
||||||
if (error.type() == u"GROUP_CALL_FORBIDDEN"_q
|
if (error.type() == u"GROUP_CALL_FORBIDDEN"_q) {
|
||||||
&& (_state.current() == State::Joined
|
|
||||||
|| _state.current() == State::Connecting)) {
|
|
||||||
setState(State::Joining);
|
|
||||||
rejoin();
|
rejoin();
|
||||||
}
|
}
|
||||||
}).send();
|
}).send();
|
||||||
|
@ -585,10 +614,7 @@ void GroupCall::toggleMute(not_null<UserData*> user, bool mute) {
|
||||||
)).done([=](const MTPUpdates &result) {
|
)).done([=](const MTPUpdates &result) {
|
||||||
_channel->session().api().applyUpdates(result);
|
_channel->session().api().applyUpdates(result);
|
||||||
}).fail([=](const RPCError &error) {
|
}).fail([=](const RPCError &error) {
|
||||||
if (error.type() == u"GROUP_CALL_FORBIDDEN"_q
|
if (error.type() == u"GROUP_CALL_FORBIDDEN"_q) {
|
||||||
&& (_state.current() == State::Joined
|
|
||||||
|| _state.current() == State::Connecting)) {
|
|
||||||
setState(State::Joining);
|
|
||||||
rejoin();
|
rejoin();
|
||||||
}
|
}
|
||||||
}).send();
|
}).send();
|
||||||
|
|
|
@ -129,6 +129,8 @@ private:
|
||||||
void setInstanceConnected(bool connected);
|
void setInstanceConnected(bool connected);
|
||||||
void checkLastSpoke();
|
void checkLastSpoke();
|
||||||
|
|
||||||
|
void checkJoined();
|
||||||
|
|
||||||
[[nodiscard]] MTPInputGroupCall inputCall() const;
|
[[nodiscard]] MTPInputGroupCall inputCall() const;
|
||||||
|
|
||||||
const not_null<Delegate*> _delegate;
|
const not_null<Delegate*> _delegate;
|
||||||
|
@ -150,6 +152,7 @@ private:
|
||||||
rpl::event_stream<LevelUpdate> _levelUpdates;
|
rpl::event_stream<LevelUpdate> _levelUpdates;
|
||||||
base::flat_map<uint32, crl::time> _lastSpoke;
|
base::flat_map<uint32, crl::time> _lastSpoke;
|
||||||
base::Timer _lastSpokeCheckTimer;
|
base::Timer _lastSpokeCheckTimer;
|
||||||
|
base::Timer _checkJoinedTimer;
|
||||||
|
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue