Skip to content

Commit

Permalink
Merge branch 'fix/CHT-555-chatd-leftcall-peer-removed' into 'develop'
Browse files Browse the repository at this point in the history
CHT-555. Add check to avoid process LEFTCALL if there isn't a call (Main meeting branch)

Closes CHT-555

See merge request megachat/MEGAchat!1230
  • Loading branch information
jgandres committed Oct 5, 2021
2 parents 25a4f2b + e222340 commit f90f321
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/chatd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,11 @@ void Connection::execCommand(const StaticBuffer& buf)
rtcModule::ICall *call = mChatdClient.mKarereClient->rtc->findCall(callid);
if (!call)
{
assert(opcode != OP_LEFTCALL); // chatd should never send a LEFTCALL for an unknown call
if (opcode == OP_LEFTCALL) // If peer is removed, we can receive LEFTCALL and call has been destroyed
{
CHATDS_LOG_WARNING("Receive a LEFTCALL without a call. Unique valid option is that we have been removed from chatroom");
break;
}

promise::Promise<std::shared_ptr<std::string>> pms;
if (chat.isPublic())
Expand All @@ -2480,8 +2484,6 @@ void Connection::execCommand(const StaticBuffer& buf)

auto& chat = mChatdClient.chats(chatid);



mChatdClient.mKarereClient->rtc->handleNewCall(chatid, karere::Id::inval(), callid, false, chat.isGroup(), unifiedKey);
// in case that OP_CALLSTATE were received first, it might have created the call already
// (this is just a protection, in case chatd changes the order of the opcodes)
Expand Down Expand Up @@ -5508,6 +5510,7 @@ void Chat::onUserLeave(Id userid)
// remove call associated to chatRoom if our own user is not an active participant
if (mChatdClient.mKarereClient->rtc && !previewMode())
{
CHATID_LOG_DEBUG("remove call associated to chatRoom if our own user is not an active participant");
mChatdClient.mKarereClient->rtc->removeCall(mChatId, rtcModule::EndCallReason::kFailed);
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/megachatapi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void MegaChatApiImpl::init(MegaChatApi *chatApi, MegaApi *megaApi)
mMegaApi = megaApi;

mClient = NULL;
API_LOG_DEBUG("MegaChatApiImpl::init(): karere client is invalid");
mTerminating = false;
waiter = new MegaChatWaiter();
mWebsocketsIO = new MegaWebsocketsIO(sdkMutex, waiter, megaApi, this);
Expand Down Expand Up @@ -2568,6 +2569,7 @@ void MegaChatApiImpl::createKarereClient()
#else
mClient = new karere::Client(*mMegaApi, mWebsocketsIO, *this, mMegaApi->getBasePath(), caps, this);
#endif
API_LOG_DEBUG("createKarereClient: karere client instance created");
mTerminating = false;
}
}
Expand Down

0 comments on commit f90f321

Please sign in to comment.