Skip to content

Commit

Permalink
Merge branch 'fix/CHT-998-fix-wr-non-received-changes' into 'develop'
Browse files Browse the repository at this point in the history
CHT-998. Waiting room leave changes not received

Closes CHT-998

See merge request megachat/MEGAchat!1698
  • Loading branch information
jgandres committed Sep 5, 2023
2 parents 03a05c2 + 99af8d6 commit 8dce56e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 38 deletions.
14 changes: 4 additions & 10 deletions src/rtcModule/webrtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,7 @@ void Call::clearResources(const TermCode& termCode)
RTCM_LOG_DEBUG("clearResources, termcode (%u): %s", termCode, connectionTermCodeToString(termCode).c_str());
disableStats();
mSessions.clear(); // session dtor will notify apps through onDestroySession callback

mModerators.clear(); // clear moderators list and ownModerator
mMyPeer->setModerator(false);

mVThumb.reset();
mHiRes.reset();
mAudio.reset();
Expand Down Expand Up @@ -1399,8 +1396,7 @@ bool Call::handleAvCommand(Cid_t cid, unsigned av, uint32_t aMid)

bool Call::handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> sdp, uint64_t callJoinOffset, std::vector<sfu::Peer>& peers,
const std::map<Cid_t, std::string>& keystrmap,
const std::map<Cid_t, sfu::TrackDescriptor>& vthumbs, const std::map<Cid_t, sfu::TrackDescriptor>& speakers
, std::set<karere::Id>& moderators, bool ownMod)
const std::map<Cid_t, sfu::TrackDescriptor>& vthumbs, const std::map<Cid_t, sfu::TrackDescriptor>& speakers)
{
if (mState != kStateJoining)
{
Expand All @@ -1423,10 +1419,6 @@ bool Call::handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> sdp, uint64_
// update max peers seen in call
mMaxPeers = static_cast<uint8_t> (peers.size() > mMaxPeers ? peers.size() : mMaxPeers);

// set moderator list and ownModerator value
setOwnModerator(ownMod);
mModerators = moderators;

// set join offset
setJoinOffset(static_cast<int64_t>(callJoinOffset));

Expand Down Expand Up @@ -1485,6 +1477,8 @@ bool Call::handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> sdp, uint64_
const auto& it = keystrmap.find(peer.getCid());
const auto& keyStr = it != keystrmap.end() ? it->second : std::string();

// check if peerid is included in mods list received upon HELLO
peer.setModerator(mModerators.find(peer.getPeerid()) != mModerators.end());
if (sfu::isInitialSfuVersion(peer.getPeerSfuVersion())) // there's no ephemeral key, just add peer
{
addPeerWithEphemKey(peer, true, std::string());
Expand Down Expand Up @@ -2224,7 +2218,7 @@ bool Call::handleHello(const Cid_t cid, const unsigned int nAudioTracks,
// Set the maximum number of simultaneous audio tracks the call supports. If no received nAudioTracks or nVideoTracks set as max default
mNumInputAudioTracks = nAudioTracks ? nAudioTracks : static_cast<uint32_t>(RtcConstant::kMaxCallAudioSenders);

// set moderator list and ownModerator value
// copy moderator list, and check if our own user is moderator
setOwnModerator(mods.find(mMyPeer->getPeerid()) != mods.end());
mModerators = mods;

Expand Down
2 changes: 1 addition & 1 deletion src/rtcModule/webrtcPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class Call final : public karere::DeleteTrackable, public sfu::SfuInterface, pub

// --- SfuInterface methods ---
bool handleAvCommand(Cid_t cid, unsigned av, uint32_t aMid) override;
bool handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> spd, uint64_t callJoinOffset, std::vector<sfu::Peer>& peers, const std::map<Cid_t, std::string>& keystrmap, const std::map<Cid_t, sfu::TrackDescriptor>& vthumbs, const std::map<Cid_t, sfu::TrackDescriptor>& speakers, std::set<karere::Id>& moderators, bool ownMod) override;
bool handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> spd, uint64_t callJoinOffset, std::vector<sfu::Peer>& peers, const std::map<Cid_t, std::string>& keystrmap, const std::map<Cid_t, sfu::TrackDescriptor>& vthumbs, const std::map<Cid_t, sfu::TrackDescriptor>& speakers) override;
bool handleKeyCommand(const Keyid_t& keyid, const Cid_t& cid, const std::string& key) override;
bool handleVThumbsCommand(const std::map<Cid_t, sfu::TrackDescriptor> &videoTrackDescriptors) override;
bool handleVThumbsStartCommand() override;
Expand Down
28 changes: 6 additions & 22 deletions src/sfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,28 +462,12 @@ bool AnswerCommand::processCommand(const rapidjson::Document &command)
// offset ts when we join within the call respect the call start (ms)
uint64_t callJoinOffset = tsIterator->value.GetUint64();

// parse moderators list
std::set<karere::Id> moderators;
rapidjson::Value::ConstMemberIterator modsIterator = command.FindMember("mods");
if (modsIterator != command.MemberEnd() && modsIterator->value.IsArray())
{
parseUsersArray(moderators, modsIterator);
}

// parse own moderator permission
bool ownModerator = false;
rapidjson::Value::ConstMemberIterator modIterator = command.FindMember("mod");
if (modIterator != command.MemberEnd() && modIterator->value.IsUint())
{
ownModerator = modIterator->value.GetUint();
}

std::vector<Peer> peers;
std::map<Cid_t, std::string> keystrmap;
rapidjson::Value::ConstMemberIterator peersIterator = command.FindMember("peers");
if (peersIterator != command.MemberEnd() && peersIterator->value.IsArray())
{
parsePeerObject(peers, keystrmap, moderators, peersIterator);
parsePeerObject(peers, keystrmap, peersIterator);
}

std::map<Cid_t, TrackDescriptor> speakers;
Expand All @@ -492,10 +476,10 @@ bool AnswerCommand::processCommand(const rapidjson::Document &command)
std::map<Cid_t, TrackDescriptor> vthumbs;
parseTracks(command, "vthumbs", vthumbs);

return mComplete(cid, sdp, callJoinOffset, peers, keystrmap, vthumbs, speakers, moderators, ownModerator);
return mComplete(cid, sdp, callJoinOffset, peers, keystrmap, vthumbs, speakers);
}

void AnswerCommand::parsePeerObject(std::vector<Peer> &peers, std::map<Cid_t, std::string>& keystrmap, const std::set<karere::Id>& moderators, rapidjson::Value::ConstMemberIterator &it) const
void AnswerCommand::parsePeerObject(std::vector<Peer> &peers, std::map<Cid_t, std::string>& keystrmap, rapidjson::Value::ConstMemberIterator &it) const
{
assert(it->value.IsArray());
for (unsigned int j = 0; j < it->value.Capacity(); ++j)
Expand Down Expand Up @@ -559,9 +543,9 @@ void AnswerCommand::parsePeerObject(std::vector<Peer> &peers, std::map<Cid_t, st
return;
}

bool isModerator = moderators.find(userId) != moderators.end();
unsigned av = avIterator->value.GetUint();
Peer peer(userId, static_cast<sfu::SfuProtocol>(sfuVersion), av, &ivs, cid, isModerator);
// default initialization of isModerator. It gets updated for every peer at handleAnwerCommand with mod list received at HELLO command later in the run flow
Peer peer(userId, static_cast<sfu::SfuProtocol>(sfuVersion), av, &ivs, cid, false /*isModerator*/);
peers.push_back(std::move(peer));
}
else
Expand Down Expand Up @@ -1594,7 +1578,7 @@ const karere::Url& SfuConnection::getSfuUrl()
void SfuConnection::setCallbackToCommands(sfu::SfuInterface &call, std::map<std::string, std::unique_ptr<sfu::Command>>& commands)
{
commands[AVCommand::COMMAND_NAME] = mega::make_unique<AVCommand>(std::bind(&sfu::SfuInterface::handleAvCommand, &call, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), call);
commands[AnswerCommand::COMMAND_NAME] = mega::make_unique<AnswerCommand>(std::bind(&sfu::SfuInterface::handleAnswerCommand, &call, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9), call);
commands[AnswerCommand::COMMAND_NAME] = mega::make_unique<AnswerCommand>(std::bind(&sfu::SfuInterface::handleAnswerCommand, &call, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7), call);
commands[KeyCommand::COMMAND_NAME] = mega::make_unique<KeyCommand>(std::bind(&sfu::SfuInterface::handleKeyCommand, &call, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), call);
commands[VthumbsCommand::COMMAND_NAME] = mega::make_unique<VthumbsCommand>(std::bind(&sfu::SfuInterface::handleVThumbsCommand, &call, std::placeholders::_1), call);
commands[VthumbsStartCommand::COMMAND_NAME] = mega::make_unique<VthumbsStartCommand>(std::bind(&sfu::SfuInterface::handleVThumbsStartCommand, &call), call);
Expand Down
6 changes: 3 additions & 3 deletions src/sfu.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SfuInterface
public:
// SFU -> Client commands
virtual bool handleAvCommand(Cid_t cid, unsigned av, uint32_t amid) = 0; // audio/video/on-hold flags
virtual bool handleAnswerCommand(Cid_t cid, std::shared_ptr<Sdp> spd, uint64_t, std::vector<Peer>& peers, const std::map<Cid_t, std::string>& keystrmap, const std::map<Cid_t, TrackDescriptor>& vthumbs, const std::map<Cid_t, TrackDescriptor>& speakers, std::set<karere::Id>& moderators, bool ownMod) = 0;
virtual bool handleAnswerCommand(Cid_t cid, std::shared_ptr<Sdp> spd, uint64_t, std::vector<Peer>& peers, const std::map<Cid_t, std::string>& keystrmap, const std::map<Cid_t, TrackDescriptor>& vthumbs, const std::map<Cid_t, TrackDescriptor>& speakers) = 0;
virtual bool handleKeyCommand(const Keyid_t& keyid, const Cid_t& cid, const std::string& key) = 0;
virtual bool handleVThumbsCommand(const std::map<Cid_t, TrackDescriptor>& videoTrackDescriptors) = 0;
virtual bool handleVThumbsStartCommand() = 0;
Expand Down Expand Up @@ -293,14 +293,14 @@ class AVCommand : public Command
class AnswerCommand : public Command
{
public:
typedef std::function<bool(Cid_t, std::shared_ptr<Sdp>, uint64_t, std::vector<Peer>&, const std::map<Cid_t, std::string>& keystrmap, std::map<Cid_t, TrackDescriptor>, std::map<Cid_t, TrackDescriptor>, std::set<karere::Id>&, bool)> AnswerCompleteFunction;
typedef std::function<bool(Cid_t, std::shared_ptr<Sdp>, uint64_t, std::vector<Peer>&, const std::map<Cid_t, std::string>& keystrmap, std::map<Cid_t, TrackDescriptor>, std::map<Cid_t, TrackDescriptor>)> AnswerCompleteFunction;
AnswerCommand(const AnswerCompleteFunction& complete, SfuInterface& call);
bool processCommand(const rapidjson::Document& command) override;
static const std::string COMMAND_NAME;
AnswerCompleteFunction mComplete;

private:
void parsePeerObject(std::vector<Peer>& peers, std::map<Cid_t, std::string>& keystrmap, const std::set<karere::Id>& moderators, rapidjson::Value::ConstMemberIterator& it) const;
void parsePeerObject(std::vector<Peer>& peers, std::map<Cid_t, std::string>& keystrmap, rapidjson::Value::ConstMemberIterator& it) const;
};

class KeyCommand : public Command
Expand Down
2 changes: 1 addition & 1 deletion tests/sdk_test/sdk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8209,7 +8209,7 @@ bool MockupCall::handleAvCommand(Cid_t, unsigned, uint32_t)
return true;
}

bool MockupCall::handleAnswerCommand(Cid_t, std::shared_ptr<sfu::Sdp>, uint64_t, std::vector<sfu::Peer>&, const std::map<Cid_t, std::string>&, const std::map<Cid_t, sfu::TrackDescriptor>&, const std::map<Cid_t, sfu::TrackDescriptor>&, std::set<karere::Id>&, bool)
bool MockupCall::handleAnswerCommand(Cid_t, std::shared_ptr<sfu::Sdp>, uint64_t, std::vector<sfu::Peer>&, const std::map<Cid_t, std::string>&, const std::map<Cid_t, sfu::TrackDescriptor>&, const std::map<Cid_t, sfu::TrackDescriptor>&)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sdk_test/sdk_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class MockupCall : public sfu::SfuInterface
{
public:
bool handleAvCommand(Cid_t cid, unsigned av, uint32_t amid) override;
bool handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> sdp, uint64_t callJoinOffset, std::vector<sfu::Peer>& peers, const std::map<Cid_t, std::string>& keystrmap, const std::map<Cid_t, sfu::TrackDescriptor>& vthumbs, const std::map<Cid_t, sfu::TrackDescriptor>& speakers, std::set<karere::Id>& moderators, bool ownMod) override;
bool handleAnswerCommand(Cid_t cid, std::shared_ptr<sfu::Sdp> sdp, uint64_t callJoinOffset, std::vector<sfu::Peer>& peers, const std::map<Cid_t, std::string>& keystrmap, const std::map<Cid_t, sfu::TrackDescriptor>& vthumbs, const std::map<Cid_t, sfu::TrackDescriptor>& speakers) override;
bool handleKeyCommand(const Keyid_t& keyid, const Cid_t& cid, const std::string&key) override;
bool handleVThumbsCommand(const std::map<Cid_t, sfu::TrackDescriptor> &) override;
bool handleVThumbsStartCommand() override;
Expand Down

0 comments on commit 8dce56e

Please sign in to comment.