Cancel outgoing video when muted by admin.

This commit is contained in:
John Preston 2021-05-26 15:12:00 +04:00
parent c6f44e7928
commit f3e6f5e772
5 changed files with 37 additions and 15 deletions

View file

@ -280,8 +280,7 @@ void TopBar::initControls() {
if (const auto call = _call.get()) {
call->setMuted(!call->muted());
} else if (const auto group = _groupCall.get()) {
if (group->muted() == MuteState::ForceMuted
|| group->muted() == MuteState::RaisedHand) {
if (group->mutedByAdmin()) {
Ui::Toast::Show(tr::lng_group_call_force_muted_sub(tr::now));
} else {
group->setMuted((group->muted() == MuteState::Muted)

View file

@ -467,8 +467,16 @@ QString GroupCall::screenSharingDeviceId() const {
return isSharingScreen() ? _screenDeviceId : QString();
}
bool GroupCall::mutedByAdmin() const {
const auto mute = muted();
return mute == MuteState::ForceMuted || mute == MuteState::RaisedHand;
}
void GroupCall::toggleVideo(bool active) {
if (!_instance || !_id) {
if (!_instance
|| !_id
|| (active && mutedByAdmin())
|| (!active && !_cameraOutgoing)) {
return;
}
ensureOutgoingVideo();
@ -481,6 +489,12 @@ void GroupCall::toggleVideo(bool active) {
}
void GroupCall::toggleScreenSharing(std::optional<QString> uniqueId) {
if (!_instance
|| !_id
|| (uniqueId && mutedByAdmin())
|| (!uniqueId && !_screenOutgoing)) {
return;
}
ensureOutgoingVideo();
if (!uniqueId) {
_screenOutgoing->setState(Webrtc::VideoState::Inactive);
@ -853,9 +867,7 @@ void GroupCall::rejoin() {
}
void GroupCall::rejoinWithHash(const QString &hash) {
if (!hash.isEmpty()
&& (muted() == MuteState::ForceMuted
|| muted() == MuteState::RaisedHand)) {
if (!hash.isEmpty() && mutedByAdmin()) {
_joinHash = hash;
rejoin();
}
@ -1060,8 +1072,7 @@ void GroupCall::applyMeInCallLocally() {
const auto volume = participant
? participant->volume
: Group::kDefaultVolume;
const auto canSelfUnmute = (muted() != MuteState::ForceMuted)
&& (muted() != MuteState::RaisedHand);
const auto canSelfUnmute = !mutedByAdmin();
const auto raisedHandRating = (muted() != MuteState::RaisedHand)
? uint64(0)
: participant
@ -1282,6 +1293,10 @@ void GroupCall::setMuted(MuteState mute) {
if (wasMuted != nowMuted || wasRaiseHand != nowRaiseHand) {
applyMeInCallLocally();
}
if (mutedByAdmin()) {
toggleVideo(false);
toggleScreenSharing(std::nullopt);
}
};
if (mute == MuteState::Active || mute == MuteState::PushToTalk) {
_delegate->groupCallRequestPermissionsOrFail(crl::guard(this, set));
@ -1484,8 +1499,7 @@ void GroupCall::applySelfUpdate(const MTPDgroupCallParticipant &data) {
LOG(("Call Info: Rejoin after unforcemute in stream mode."));
setState(State::Joining);
rejoin();
} else if (muted() == MuteState::ForceMuted
|| muted() == MuteState::RaisedHand) {
} else if (mutedByAdmin()) {
setMuted(MuteState::Muted);
if (!_instanceTransitioning) {
notifyAboutAllowedToSpeak();
@ -2508,9 +2522,7 @@ void GroupCall::applyGlobalShortcutChanges() {
}
void GroupCall::pushToTalk(bool pressed, crl::time delay) {
if (muted() == MuteState::ForceMuted
|| muted() == MuteState::RaisedHand
|| muted() == MuteState::Active) {
if (mutedByAdmin() || muted() == MuteState::Active) {
return;
} else if (pressed) {
_pushToTalkCancelTimer.cancel();

View file

@ -327,6 +327,7 @@ public:
}
static constexpr auto kSpeakLevelThreshold = 0.2;
[[nodiscard]] bool mutedByAdmin() const;
void setCurrentAudioDevice(bool input, const QString &deviceId);
void setCurrentVideoDevice(const QString &deviceId);
[[nodiscard]] bool isSharingScreen() const;

View file

@ -774,6 +774,10 @@ void Panel::refreshVideoButtons(std::optional<bool> overrideWideMode) {
) | rpl::start_with_next([=](bool sharing) {
_video->setProgress(sharing ? 1. : 0.);
}, _video->lifetime());
_call->mutedValue(
) | rpl::start_with_next([=] {
updateButtonsGeometry();
}, _video->lifetime());
}
if (!_screenShare) {
_screenShare.create(widget(), st::groupCallScreenShareSmall);
@ -2040,13 +2044,14 @@ void Panel::updateButtonsGeometry() {
if (_callShare) {
_callShare->moveToLeft(leftButtonLeft, buttonsTop);
}
const auto showVideoButton = videoButtonInNarrowMode();
if (_video) {
_video->setVisible(!_callShare);
_video->setVisible(!_callShare && showVideoButton);
_video->setStyle(st::groupCallVideo, &st::groupCallVideoActive);
_video->moveToLeft(leftButtonLeft, buttonsTop);
}
if (_settings) {
_settings->setVisible(!_callShare && !_video);
_settings->setVisible(!_callShare && !showVideoButton);
_settings->moveToLeft(leftButtonLeft, buttonsTop);
}
_hangup->moveToRight(leftButtonLeft, buttonsTop);
@ -2073,6 +2078,10 @@ void Panel::updateButtonsGeometry() {
}
}
bool Panel::videoButtonInNarrowMode() const {
return (_video != nullptr) && !_call->mutedByAdmin();
}
void Panel::updateMembersGeometry() {
if (!_members) {
return;

View file

@ -113,6 +113,7 @@ private:
std::optional<bool> overrideWideMode = std::nullopt);
void refreshTilesGeometry();
void toggleWideControls(bool shown);
[[nodiscard]] bool videoButtonInNarrowMode() const;
void endCall();