Request mic permission only on unmute.

This commit is contained in:
John Preston 2020-12-09 17:11:42 +04:00
parent 7feb841081
commit 092e0990e8
4 changed files with 29 additions and 19 deletions

View File

@ -354,13 +354,20 @@ void GroupCall::finish(FinishType type) {
}
void GroupCall::setMuted(MuteState mute) {
const auto wasMuted = (muted() == MuteState::Muted)
|| (muted() == MuteState::PushToTalk);
_muted = mute;
const auto nowMuted = (muted() == MuteState::Muted)
|| (muted() == MuteState::PushToTalk);
if (wasMuted != nowMuted) {
applySelfInCallLocally();
const auto set = [=] {
const auto wasMuted = (muted() == MuteState::Muted)
|| (muted() == MuteState::PushToTalk);
_muted = mute;
const auto nowMuted = (muted() == MuteState::Muted)
|| (muted() == MuteState::PushToTalk);
if (wasMuted != nowMuted) {
applySelfInCallLocally();
}
};
if (mute == MuteState::Active || mute == MuteState::PushToTalk) {
_delegate->groupCallRequestPermissionsOrFail(crl::guard(this, set));
} else {
set();
}
}

View File

@ -53,7 +53,8 @@ public:
virtual void groupCallFinished(not_null<GroupCall*> call) = 0;
virtual void groupCallFailed(not_null<GroupCall*> call) = 0;
virtual void groupCallRequestPermissionsOrFail(
Fn<void()> onSuccess) = 0;
};
using GlobalShortcutManager = base::GlobalShortcutManager;

View File

@ -60,12 +60,11 @@ void Instance::startOutgoingCall(not_null<UserData*> user, bool video) {
void Instance::startOrJoinGroupCall(not_null<ChannelData*> channel) {
destroyCurrentCall();
requestPermissionsOrFail(crl::guard(this, [=] {
const auto call = channel->call();
createGroupCall(
channel,
call ? call->input() : MTP_inputGroupCall(MTPlong(), MTPlong()));
}), false);
const auto call = channel->call();
createGroupCall(
channel,
call ? call->input() : MTP_inputGroupCall(MTPlong(), MTPlong()));
}
void Instance::callFinished(not_null<Call*> call) {
@ -186,9 +185,8 @@ void Instance::destroyGroupCall(not_null<GroupCall*> call) {
void Instance::createGroupCall(
not_null<ChannelData*> channel,
const MTPInputGroupCall &inputCall) {
if (_currentGroupCall) {
destroyGroupCall(_currentGroupCall.get());
}
destroyCurrentCall();
auto call = std::make_unique<GroupCall>(
getGroupCallDelegate(),
channel,

View File

@ -55,7 +55,9 @@ public:
[[nodiscard]] bool hasActivePanel(
not_null<Main::Session*> session) const;
bool activateCurrentCall();
std::shared_ptr<tgcalls::VideoCaptureInterface> getVideoCapture() override;
auto getVideoCapture()
-> std::shared_ptr<tgcalls::VideoCaptureInterface> override;
void requestPermissionsOrFail(Fn<void()> onSuccess, bool video = true);
void setCurrentAudioDevice(bool input, const QString &deviceId);
@ -82,6 +84,9 @@ private:
void groupCallFinished(not_null<GroupCall*> call) override;
void groupCallFailed(not_null<GroupCall*> call) override;
void groupCallRequestPermissionsOrFail(Fn<void()> onSuccess) override {
requestPermissionsOrFail(std::move(onSuccess), false);
}
using Sound = Call::Delegate::Sound;
void playSound(Sound sound) override;
@ -93,7 +98,6 @@ private:
const MTPInputGroupCall &inputCall);
void destroyGroupCall(not_null<GroupCall*> call);
void requestPermissionsOrFail(Fn<void()> onSuccess, bool video = true);
void requestPermissionOrFail(Platform::PermissionType type, Fn<void()> onSuccess);
void refreshDhConfig();