From 83759adb5f6795118ad9f8cc0bda72f9e509187c Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 31 Jul 2020 21:36:20 +0400 Subject: [PATCH] Start video call from video call service message. --- .../SourceFiles/calls/calls_box_controller.cpp | 2 +- Telegram/SourceFiles/calls/calls_call.cpp | 18 +++++++++--------- Telegram/SourceFiles/calls/calls_call.h | 2 +- Telegram/SourceFiles/calls/calls_instance.cpp | 15 +++++++++------ Telegram/SourceFiles/calls/calls_instance.h | 4 ++-- .../view/history_view_top_bar_widget.cpp | 2 +- .../history/view/media/history_view_call.cpp | 3 ++- Telegram/SourceFiles/info/info_wrap_widget.cpp | 2 +- Telegram/lib_webrtc | 2 +- 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index 5f0cc6dcb..6f8781c54 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -317,7 +317,7 @@ void BoxController::rowActionClicked(not_null row) { auto user = row->peer()->asUser(); Assert(user != nullptr); - Core::App().calls().startOutgoingCall(user); + Core::App().calls().startOutgoingCall(user, false); } void BoxController::receivedCalls(const QVector &result) { diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index b0ca41115..9cd65387b 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -148,22 +148,22 @@ uint64 ComputeFingerprint(bytes::const_span authKey) { Call::Call( not_null delegate, not_null user, - Type type) + Type type, + bool video) : _delegate(delegate) , _user(user) , _api(&_user->session().mtp()) , _type(type) -, _videoIncoming(std::make_unique()) -, _videoOutgoing(std::make_unique()) { +, _videoIncoming(std::make_unique(video)) +, _videoOutgoing(std::make_unique(video)) { _discardByTimeoutTimer.setCallback([=] { hangup(); }); if (_type == Type::Outgoing) { setState(State::Requesting); - setupOutgoingVideo(); } else { startWaitingTrack(); - // setupOutgoingVideo will be called when we decide if it is enabled. } + setupOutgoingVideo(); } void Call::generateModExpFirst(bytes::const_span randomSeed) { @@ -217,8 +217,11 @@ void Call::startOutgoing() { Expects(_state.current() == State::Requesting); Expects(_gaHash.size() == kSha256Size); + const auto flags = _videoCapture + ? MTPphone_RequestCall::Flag::f_video + : MTPphone_RequestCall::Flag(0); _api.request(MTPphone_RequestCall( - MTP_flags(0), + MTP_flags(flags), _user->inputUser, MTP_int(rand_value()), MTP_bytes(_gaHash), @@ -465,8 +468,6 @@ bool Call::handleUpdate(const MTPPhoneCall &call) { _id = data.vid().v; _accessHash = data.vaccess_hash().v; - _videoOutgoing->setEnabled(data.is_video()); - setupOutgoingVideo(); auto gaHashBytes = bytes::make_span(data.vg_a_hash().v); if (gaHashBytes.size() != kSha256Size) { LOG(("Call Error: Wrong g_a_hash size %1, expected %2." @@ -766,7 +767,6 @@ void Call::createAndStartController(const MTPDphoneCall &call) { raw->setMuteMicrophone(_muted.current()); } - _videoIncoming->setEnabled(_videoOutgoing->enabled()); raw->setIncomingVideoOutput(_videoIncoming->sink()); const auto &settings = Core::App().settings(); diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 02fd6879d..776be1c8f 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -65,7 +65,7 @@ public: Incoming, Outgoing, }; - Call(not_null delegate, not_null user, Type type); + Call(not_null delegate, not_null user, Type type, bool video); [[nodiscard]] Type type() const { return _type; diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 0ae72fc19..c131ade2c 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -43,7 +43,7 @@ Instance::~Instance() { } } -void Instance::startOutgoingCall(not_null user) { +void Instance::startOutgoingCall(not_null user, bool video) { if (alreadyInCall()) { // Already in a call. _currentCallPanel->showAndActivate(); return; @@ -56,7 +56,7 @@ void Instance::startOutgoingCall(not_null user) { return; } requestPermissionsOrFail(crl::guard(this, [=] { - createCall(user, Call::Type::Outgoing); + createCall(user, Call::Type::Outgoing, video); })); } @@ -130,8 +130,8 @@ void Instance::destroyCurrentPanel() { _pendingPanels.back()->hideAndDestroy(); // Always queues the destruction. } -void Instance::createCall(not_null user, Call::Type type) { - auto call = std::make_unique(getCallDelegate(), user, type); +void Instance::createCall(not_null user, Call::Type type, bool video) { + auto call = std::make_unique(getCallDelegate(), user, type, video); const auto raw = call.get(); user->session().account().sessionChanges( @@ -278,8 +278,11 @@ void Instance::handleCallUpdate( } const auto &config = session->serverConfig(); if (alreadyInCall() || !user || user->isSelf()) { + const auto flags = phoneCall.is_video() + ? MTPphone_DiscardCall::Flag::f_video + : MTPphone_DiscardCall::Flag(0); session->api().request(MTPphone_DiscardCall( - MTP_flags(0), + MTP_flags(flags), MTP_inputPhoneCall(phoneCall.vid(), phoneCall.vaccess_hash()), MTP_int(0), MTP_phoneCallDiscardReasonBusy(), @@ -289,7 +292,7 @@ void Instance::handleCallUpdate( < base::unixtime::now()) { LOG(("Ignoring too old call.")); } else { - createCall(user, Call::Type::Incoming); + createCall(user, Call::Type::Incoming, phoneCall.is_video()); _currentCall->handleUpdate(call); } } else if (!_currentCall || !_currentCall->handleUpdate(call)) { diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index 4bd159acd..53e5cd6a2 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -36,7 +36,7 @@ public: Instance(); ~Instance(); - void startOutgoingCall(not_null user); + void startOutgoingCall(not_null user, bool video); void handleUpdate( not_null session, const MTPUpdate &update); @@ -58,7 +58,7 @@ private: void callRedial(not_null call) override; using Sound = Call::Delegate::Sound; void playSound(Sound sound) override; - void createCall(not_null user, Call::Type type); + void createCall(not_null user, Call::Type type, bool video); void destroyCall(not_null call); void destroyCurrentPanel(); void requestPermissionsOrFail(Fn onSuccess) override; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 464b7e418..34eb81b8e 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -194,7 +194,7 @@ void TopBarWidget::onSearch() { void TopBarWidget::onCall() { if (const auto peer = _activeChat.peer()) { if (const auto user = peer->asUser()) { - Core::App().calls().startOutgoingCall(user); + Core::App().calls().startOutgoingCall(user, false); } } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_call.cpp b/Telegram/SourceFiles/history/view/media/history_view_call.cpp index 8c95497d9..50518f0a2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_call.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_call.cpp @@ -56,9 +56,10 @@ Call::Call( QSize Call::countOptimalSize() { const auto user = _parent->data()->history()->peer->asUser(); + const auto video = _video; _link = std::make_shared([=] { if (user) { - Core::App().calls().startOutgoingCall(user); + Core::App().calls().startOutgoingCall(user, video); } }); diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index ae5753a00..4925d1202 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -501,7 +501,7 @@ void WrapWidget::addProfileCallsButton() { ? st::infoLayerTopBarCall : st::infoTopBarCall)) )->addClickHandler([=] { - Core::App().calls().startOutgoingCall(user); + Core::App().calls().startOutgoingCall(user, false); }); }, _topBar->lifetime()); diff --git a/Telegram/lib_webrtc b/Telegram/lib_webrtc index ab42b2bf8..503e55133 160000 --- a/Telegram/lib_webrtc +++ b/Telegram/lib_webrtc @@ -1 +1 @@ -Subproject commit ab42b2bf87bbb53b83ac46cdc1d1285b6439d064 +Subproject commit 503e551331f45cbccc29cad0bc158f11c85169d3