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();
Assert(user != nullptr);
Core::App().calls().startOutgoingCall(user);
Core::App().calls().startOutgoingCall(user, false);
}
void BoxController::receivedCalls(const QVector<MTPMessage> &result) {

View file

@ -148,22 +148,22 @@ uint64 ComputeFingerprint(bytes::const_span authKey) {
Call::Call(
not_null<Delegate*> delegate,
not_null<UserData*> user,
Type type)
Type type,
bool video)
: _delegate(delegate)
, _user(user)
, _api(&_user->session().mtp())
, _type(type)
, _videoIncoming(std::make_unique<webrtc::VideoTrack>())
, _videoOutgoing(std::make_unique<webrtc::VideoTrack>()) {
, _videoIncoming(std::make_unique<webrtc::VideoTrack>(video))
, _videoOutgoing(std::make_unique<webrtc::VideoTrack>(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<int32>()),
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();

View file

@ -65,7 +65,7 @@ public:
Incoming,
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 {
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.
_currentCallPanel->showAndActivate();
return;
@ -56,7 +56,7 @@ void Instance::startOutgoingCall(not_null<UserData*> 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<UserData*> user, Call::Type type) {
auto call = std::make_unique<Call>(getCallDelegate(), user, type);
void Instance::createCall(not_null<UserData*> user, Call::Type type, bool video) {
auto call = std::make_unique<Call>(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)) {

View file

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

View file

@ -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);
}
}
}

View file

@ -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<LambdaClickHandler>([=] {
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::infoTopBarCall))
)->addClickHandler([=] {
Core::App().calls().startOutgoingCall(user);
Core::App().calls().startOutgoingCall(user, false);
});
}, _topBar->lifetime());

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