diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 9b428d4074..913536660d 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -288,10 +288,19 @@ void Call::startIncoming() { }).send(); } +void Call::switchVideoOutgoing() { + const auto video = _videoOutgoing->state() == Webrtc::VideoState::Active; + _delegate->callRequestPermissionsOrFail(crl::guard(this, [=] { + videoOutgoing()->setState(StartVideoState(!video)); + }), true); + +} + void Call::answer() { + const auto video = _videoOutgoing->state() == Webrtc::VideoState::Active; _delegate->callRequestPermissionsOrFail(crl::guard(this, [=] { actuallyAnswer(); - })); + }), video); } void Call::actuallyAnswer() { diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 004225ecc6..531397c1dc 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -68,7 +68,9 @@ public: Ended, }; virtual void playSound(Sound sound) = 0; - virtual void callRequestPermissionsOrFail(Fn onSuccess) = 0; + virtual void callRequestPermissionsOrFail( + Fn onSuccess, + bool video) = 0; virtual auto getVideoCapture() -> std::shared_ptr = 0; @@ -165,6 +167,7 @@ public: crl::time getDurationMs() const; float64 getWaitingSoundPeakValue() const; + void switchVideoOutgoing(); void answer(); void hangup(); void redial(); diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 672d36e53c..e5e9f95100 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -55,7 +55,7 @@ void Instance::startOutgoingCall(not_null user, bool video) { } requestPermissionsOrFail(crl::guard(this, [=] { createCall(user, Call::Type::Outgoing, video); - })); + }), video); } void Instance::startGroupCall(not_null channel) { @@ -64,7 +64,7 @@ void Instance::startGroupCall(not_null channel) { } requestPermissionsOrFail(crl::guard(this, [=] { createGroupCall(channel, MTP_inputGroupCall(MTPlong(), MTPlong())); - })); + }), false); } void Instance::joinGroupCall( @@ -75,7 +75,7 @@ void Instance::joinGroupCall( } requestPermissionsOrFail(crl::guard(this, [=] { createGroupCall(channel, call); - })); + }), false); } void Instance::callFinished(not_null call) { @@ -462,12 +462,15 @@ rpl::producer Instance::currentGroupCallValue() const { return _currentGroupCallChanges.events_starting_with(currentGroupCall()); } -void Instance::requestPermissionsOrFail(Fn onSuccess) { +void Instance::requestPermissionsOrFail(Fn onSuccess, bool video) { using Type = Platform::PermissionType; requestPermissionOrFail(Type::Microphone, [=] { - requestPermissionOrFail(Type::Camera, [=] { - crl::on_main(onSuccess); - }); + auto callback = [=] { crl::on_main(onSuccess); }; + if (video) { + requestPermissionOrFail(Type::Camera, std::move(callback)); + } else { + callback(); + } }); } diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index 6877e1422a..10d9b56b17 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -72,8 +72,10 @@ private: void callFinished(not_null call) override; void callFailed(not_null call) override; void callRedial(not_null call) override; - void callRequestPermissionsOrFail(Fn onSuccess) override { - requestPermissionsOrFail(std::move(onSuccess)); + void callRequestPermissionsOrFail( + Fn onSuccess, + bool video) override { + requestPermissionsOrFail(std::move(onSuccess), video); } void groupCallFinished(not_null call) override; @@ -89,7 +91,7 @@ private: const MTPInputGroupCall &inputCall); void destroyGroupCall(not_null call); - void requestPermissionsOrFail(Fn onSuccess); + void requestPermissionsOrFail(Fn onSuccess, bool video = true); void requestPermissionOrFail(Platform::PermissionType type, Fn onSuccess); void refreshDhConfig(); diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 14ac068f87..0d87b44c4d 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -307,10 +307,7 @@ void Panel::initControls() { }); _camera->setClickedCallback([=] { if (_call) { - _call->videoOutgoing()->setState( - (_call->videoOutgoing()->state() == Webrtc::VideoState::Active) - ? Webrtc::VideoState::Inactive - : Webrtc::VideoState::Active); + _call->switchVideoOutgoing(); } });