diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 6dc38786a..cbb02efec 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -90,7 +90,14 @@ void CoreAV::answerCall(uint32_t friendNum) void CoreAV::startCall(uint32_t friendId, bool video) { - assert(!calls.contains(friendId)); + if(calls.contains(friendId)) + { + qWarning() << QString("Can't start call with %1, we're already in this call!").arg(friendId); + emit avCallFailed(friendId); + return; + } + + qDebug() << QString("Starting call with %1").arg(friendId); uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0; if (!toxav_call(toxav, friendId, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr)) { @@ -311,10 +318,16 @@ void CoreAV::resetCallSources() } } -void CoreAV::callCallback(ToxAV*, uint32_t friendNum, bool audio, bool video, void *_self) +void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool video, void *_self) { CoreAV* self = static_cast(_self); - const auto& callIt = calls.insert({friendNum, video, *self}); + if (self->calls.contains(friendNum)) + { + qWarning() << QString("Rejecting call invite from %1, we're already in that call!").arg(friendNum); + toxav_call_control(toxav, friendNum, TOXAV_CALL_CONTROL_CANCEL, nullptr); + return; + } + const auto& callIt = self->calls.insert({friendNum, video, *self}); // We don't get a state callback when answering, so fill the state ourselves in advance int state = 0; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 8bfab042e..7b1d3cad9 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -258,8 +258,7 @@ void ChatForm::onAvInvite(uint32_t FriendId, bool video) qDebug() << "onAvInvite"; - callButton->disconnect(); - videoButton->disconnect(); + disableCallButtons(); if (video) { callConfirm = new CallConfirmWidget(videoButton, *f); @@ -310,8 +309,7 @@ void ChatForm::onAvStart(uint32_t FriendId, bool video) audioInputFlag = true; audioOutputFlag = true; - callButton->disconnect(); - videoButton->disconnect(); + disableCallButtons(); if (video) { @@ -418,8 +416,7 @@ void ChatForm::onAvStarting(uint32_t FriendId, bool video) qDebug() << "onAvStarting"; - callButton->disconnect(); - videoButton->disconnect(); + disableCallButtons(); if (video) { callButton->setObjectName("grey"); @@ -489,7 +486,6 @@ void ChatForm::onAvRequestTimeout(uint32_t FriendId) enableCallButtons(); stopCounter(); - hideNetcam(); } @@ -520,6 +516,7 @@ void ChatForm::onAvRejected(uint32_t FriendId) callConfirm = nullptr; enableCallButtons(); + stopCounter(); insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"), ChatMessage::INFO, @@ -587,6 +584,7 @@ void ChatForm::onRejectCallTriggered() emit rejectCall(f->getFriendID()); enableCallButtons(); + stopCounter(); } void ChatForm::onCallTriggered() @@ -643,6 +641,31 @@ void ChatForm::enableCallButtons() audioInputFlag = false; audioOutputFlag = false; + disableCallButtons(); + + if (disableCallButtonsTimer == nullptr) + { + disableCallButtonsTimer = new QTimer(); + connect(disableCallButtonsTimer, SIGNAL(timeout()), + this, SLOT(onEnableCallButtons())); + disableCallButtonsTimer->start(1500); // 1.5sec + qDebug() << "timer started!!"; + } + +} + +void ChatForm::disableCallButtons() +{ + qDebug() << "disableCallButtons"; + + // Prevents race enable / disable / onEnable, when it should be disabled + if (disableCallButtonsTimer) + { + disableCallButtonsTimer->stop(); + delete disableCallButtonsTimer; + disableCallButtonsTimer = nullptr; + } + micButton->setObjectName("grey"); micButton->style()->polish(micButton); micButton->setToolTip(""); @@ -660,16 +683,6 @@ void ChatForm::enableCallButtons() videoButton->style()->polish(videoButton); videoButton->setToolTip(""); videoButton->disconnect(); - - if (disableCallButtonsTimer == nullptr) - { - disableCallButtonsTimer = new QTimer(); - connect(disableCallButtonsTimer, SIGNAL(timeout()), - this, SLOT(onEnableCallButtons())); - disableCallButtonsTimer->start(1500); // 1.5sec - qDebug() << "timer started!!"; - } - } void ChatForm::onEnableCallButtons() diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 11081795e..6a0bd43e8 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -128,6 +128,7 @@ private: QString secondsToDHMS(quint32 duration); CallConfirmWidget *callConfirm; void enableCallButtons(); + void disableCallButtons(); bool isTyping; void SendMessageStr(QString msg); };