Start video call from video call service message.

This commit is contained in:
John Preston 2020-07-31 21:36:20 +04:00
parent 6f90e57523
commit 83759adb5f
9 changed files with 27 additions and 23 deletions

View file

@ -317,7 +317,7 @@ void BoxController::rowActionClicked(not_null<PeerListRow*> row) {
auto user = row->peer()->asUser(); auto user = row->peer()->asUser();
Assert(user != nullptr); Assert(user != nullptr);
Core::App().calls().startOutgoingCall(user); Core::App().calls().startOutgoingCall(user, false);
} }
void BoxController::receivedCalls(const QVector<MTPMessage> &result) { void BoxController::receivedCalls(const QVector<MTPMessage> &result) {

View file

@ -148,22 +148,22 @@ uint64 ComputeFingerprint(bytes::const_span authKey) {
Call::Call( Call::Call(
not_null<Delegate*> delegate, not_null<Delegate*> delegate,
not_null<UserData*> user, not_null<UserData*> user,
Type type) Type type,
bool video)
: _delegate(delegate) : _delegate(delegate)
, _user(user) , _user(user)
, _api(&_user->session().mtp()) , _api(&_user->session().mtp())
, _type(type) , _type(type)
, _videoIncoming(std::make_unique<webrtc::VideoTrack>()) , _videoIncoming(std::make_unique<webrtc::VideoTrack>(video))
, _videoOutgoing(std::make_unique<webrtc::VideoTrack>()) { , _videoOutgoing(std::make_unique<webrtc::VideoTrack>(video)) {
_discardByTimeoutTimer.setCallback([=] { hangup(); }); _discardByTimeoutTimer.setCallback([=] { hangup(); });
if (_type == Type::Outgoing) { if (_type == Type::Outgoing) {
setState(State::Requesting); setState(State::Requesting);
setupOutgoingVideo();
} else { } else {
startWaitingTrack(); startWaitingTrack();
// setupOutgoingVideo will be called when we decide if it is enabled.
} }
setupOutgoingVideo();
} }
void Call::generateModExpFirst(bytes::const_span randomSeed) { void Call::generateModExpFirst(bytes::const_span randomSeed) {
@ -217,8 +217,11 @@ void Call::startOutgoing() {
Expects(_state.current() == State::Requesting); Expects(_state.current() == State::Requesting);
Expects(_gaHash.size() == kSha256Size); Expects(_gaHash.size() == kSha256Size);
const auto flags = _videoCapture
? MTPphone_RequestCall::Flag::f_video
: MTPphone_RequestCall::Flag(0);
_api.request(MTPphone_RequestCall( _api.request(MTPphone_RequestCall(
MTP_flags(0), MTP_flags(flags),
_user->inputUser, _user->inputUser,
MTP_int(rand_value<int32>()), MTP_int(rand_value<int32>()),
MTP_bytes(_gaHash), MTP_bytes(_gaHash),
@ -465,8 +468,6 @@ bool Call::handleUpdate(const MTPPhoneCall &call) {
_id = data.vid().v; _id = data.vid().v;
_accessHash = data.vaccess_hash().v; _accessHash = data.vaccess_hash().v;
_videoOutgoing->setEnabled(data.is_video());
setupOutgoingVideo();
auto gaHashBytes = bytes::make_span(data.vg_a_hash().v); auto gaHashBytes = bytes::make_span(data.vg_a_hash().v);
if (gaHashBytes.size() != kSha256Size) { if (gaHashBytes.size() != kSha256Size) {
LOG(("Call Error: Wrong g_a_hash size %1, expected %2." 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()); raw->setMuteMicrophone(_muted.current());
} }
_videoIncoming->setEnabled(_videoOutgoing->enabled());
raw->setIncomingVideoOutput(_videoIncoming->sink()); raw->setIncomingVideoOutput(_videoIncoming->sink());
const auto &settings = Core::App().settings(); const auto &settings = Core::App().settings();

View file

@ -65,7 +65,7 @@ public:
Incoming, Incoming,
Outgoing, Outgoing,
}; };
Call(not_null<Delegate*> delegate, not_null<UserData*> user, Type type); Call(not_null<Delegate*> delegate, not_null<UserData*> user, Type type, bool video);
[[nodiscard]] Type type() const { [[nodiscard]] Type type() const {
return _type; return _type;

View file

@ -43,7 +43,7 @@ Instance::~Instance() {
} }
} }
void Instance::startOutgoingCall(not_null<UserData*> user) { void Instance::startOutgoingCall(not_null<UserData*> user, bool video) {
if (alreadyInCall()) { // Already in a call. if (alreadyInCall()) { // Already in a call.
_currentCallPanel->showAndActivate(); _currentCallPanel->showAndActivate();
return; return;
@ -56,7 +56,7 @@ void Instance::startOutgoingCall(not_null<UserData*> user) {
return; return;
} }
requestPermissionsOrFail(crl::guard(this, [=] { 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. _pendingPanels.back()->hideAndDestroy(); // Always queues the destruction.
} }
void Instance::createCall(not_null<UserData*> user, Call::Type type) { void Instance::createCall(not_null<UserData*> user, Call::Type type, bool video) {
auto call = std::make_unique<Call>(getCallDelegate(), user, type); auto call = std::make_unique<Call>(getCallDelegate(), user, type, video);
const auto raw = call.get(); const auto raw = call.get();
user->session().account().sessionChanges( user->session().account().sessionChanges(
@ -278,8 +278,11 @@ void Instance::handleCallUpdate(
} }
const auto &config = session->serverConfig(); const auto &config = session->serverConfig();
if (alreadyInCall() || !user || user->isSelf()) { 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( session->api().request(MTPphone_DiscardCall(
MTP_flags(0), MTP_flags(flags),
MTP_inputPhoneCall(phoneCall.vid(), phoneCall.vaccess_hash()), MTP_inputPhoneCall(phoneCall.vid(), phoneCall.vaccess_hash()),
MTP_int(0), MTP_int(0),
MTP_phoneCallDiscardReasonBusy(), MTP_phoneCallDiscardReasonBusy(),
@ -289,7 +292,7 @@ void Instance::handleCallUpdate(
< base::unixtime::now()) { < base::unixtime::now()) {
LOG(("Ignoring too old call.")); LOG(("Ignoring too old call."));
} else { } else {
createCall(user, Call::Type::Incoming); createCall(user, Call::Type::Incoming, phoneCall.is_video());
_currentCall->handleUpdate(call); _currentCall->handleUpdate(call);
} }
} else if (!_currentCall || !_currentCall->handleUpdate(call)) { } else if (!_currentCall || !_currentCall->handleUpdate(call)) {

View file

@ -36,7 +36,7 @@ public:
Instance(); Instance();
~Instance(); ~Instance();
void startOutgoingCall(not_null<UserData*> user); void startOutgoingCall(not_null<UserData*> user, bool video);
void handleUpdate( void handleUpdate(
not_null<Main::Session*> session, not_null<Main::Session*> session,
const MTPUpdate &update); const MTPUpdate &update);
@ -58,7 +58,7 @@ private:
void callRedial(not_null<Call*> call) override; void callRedial(not_null<Call*> call) override;
using Sound = Call::Delegate::Sound; using Sound = Call::Delegate::Sound;
void playSound(Sound sound) override; void playSound(Sound sound) override;
void createCall(not_null<UserData*> user, Call::Type type); void createCall(not_null<UserData*> user, Call::Type type, bool video);
void destroyCall(not_null<Call*> call); void destroyCall(not_null<Call*> call);
void destroyCurrentPanel(); void destroyCurrentPanel();
void requestPermissionsOrFail(Fn<void()> onSuccess) override; void requestPermissionsOrFail(Fn<void()> onSuccess) override;

View file

@ -194,7 +194,7 @@ void TopBarWidget::onSearch() {
void TopBarWidget::onCall() { void TopBarWidget::onCall() {
if (const auto peer = _activeChat.peer()) { if (const auto peer = _activeChat.peer()) {
if (const auto user = peer->asUser()) { if (const auto user = peer->asUser()) {
Core::App().calls().startOutgoingCall(user); Core::App().calls().startOutgoingCall(user, false);
} }
} }
} }

View file

@ -56,9 +56,10 @@ Call::Call(
QSize Call::countOptimalSize() { QSize Call::countOptimalSize() {
const auto user = _parent->data()->history()->peer->asUser(); const auto user = _parent->data()->history()->peer->asUser();
const auto video = _video;
_link = std::make_shared<LambdaClickHandler>([=] { _link = std::make_shared<LambdaClickHandler>([=] {
if (user) { if (user) {
Core::App().calls().startOutgoingCall(user); Core::App().calls().startOutgoingCall(user, video);
} }
}); });

View file

@ -501,7 +501,7 @@ void WrapWidget::addProfileCallsButton() {
? st::infoLayerTopBarCall ? st::infoLayerTopBarCall
: st::infoTopBarCall)) : st::infoTopBarCall))
)->addClickHandler([=] { )->addClickHandler([=] {
Core::App().calls().startOutgoingCall(user); Core::App().calls().startOutgoingCall(user, false);
}); });
}, _topBar->lifetime()); }, _topBar->lifetime());

@ -1 +1 @@
Subproject commit ab42b2bf87bbb53b83ac46cdc1d1285b6439d064 Subproject commit 503e551331f45cbccc29cad0bc158f11c85169d3