diff --git a/src/client/callmanager.cpp b/src/client/callmanager.cpp index 1f9771c6a63d0404202aaa07631cbe79eee84317..9735501e7265add0bd809cd8a2ccb00bcda1c701 100644 --- a/src/client/callmanager.cpp +++ b/src/client/callmanager.cpp @@ -26,6 +26,7 @@ #include "call_factory.h" #include "client/ring_signal.h" +#include "sip/siptransport.h" #include "sip/sipvoiplink.h" #include "sip/sipcall.h" #include "audio/audiolayer.h" @@ -649,7 +650,11 @@ raiseParticipantHand(const std::string& accountId, JAMI_ERR() << "raiseParticipantHand is deprecated, please use raiseHand"; if (const auto account = jami::Manager::instance().getAccount(accountId)) { if (auto conf = account->getConference(confId)) { - conf->setHandRaised(peerId, state); + if (auto call = std::static_pointer_cast<jami::SIPCall>( + conf->getCallFromPeerID(peerId))) { + if (auto* transport = call->getTransport()) + conf->setHandRaised(std::string(transport->deviceId()), state); + } } else if (auto call = account->getCall(confId)) { Json::Value root; root["handRaised"] = peerId; @@ -668,7 +673,10 @@ raiseHand(const std::string& accountId, { if (const auto account = jami::Manager::instance().getAccount<jami::JamiAccount>(accountId)) { if (auto conf = account->getConference(confId)) { - conf->setHandRaised(accountUri, state); + auto device = deviceId; + if (device.empty()) + device = std::string(account->currentDeviceId()); + conf->setHandRaised(device, state); } else if (auto call = std::static_pointer_cast<jami::SIPCall>(account->getCall(confId))) { if (call->conferenceProtocolVersion() == 1) { Json::Value deviceVal; diff --git a/src/conference.cpp b/src/conference.cpp index f4f69e1c8816044ab67e782afcedca9700931e09..71f077aa1c13e40165690dc54e057a80b9a3f0e6 100644 --- a/src/conference.cpp +++ b/src/conference.cpp @@ -124,7 +124,7 @@ Conference::Conference(const std::shared_ptr<Account>& account) } std::string_view peerId = string_remove_suffix(uri, '@'); auto isModerator = shared->isModerator(peerId); - auto isHandRaised = shared->isHandRaised(peerId); + auto isHandRaised = shared->isHandRaised(deviceId); auto isModeratorMuted = shared->isMuted(info.id); auto sinkId = shared->getConfId() + peerId; if (auto videoMixer = shared->videoMixer_) @@ -903,10 +903,11 @@ Conference::removeParticipant(const std::string& participant_id) if (!participants_.erase(participant_id)) return; } - if (auto call = getCall(participant_id)) { + if (auto call = std::dynamic_pointer_cast<SIPCall>(getCall(participant_id))) { auto peerId = std::string(string_remove_suffix(call->getPeerNumber(), '@')); participantsMuted_.erase(call->getCallId()); - handsRaised_.erase(peerId); + if (auto* transport = call->getTransport()) + handsRaised_.erase(std::string(transport->deviceId())); #ifdef ENABLE_VIDEO auto sinkId = getConfId() + peerId; // Remove if active @@ -1191,7 +1192,7 @@ void Conference::onConfOrder(const std::string& callId, const std::string& confOrder) { // Check if the peer is a master - if (auto call = Manager::instance().getCallFromCallID(callId)) { + if (auto call = getCall(callId)) { auto peerId = string_remove_suffix(call->getPeerNumber(), '@'); std::string err; @@ -1223,16 +1224,16 @@ Conference::isModerator(std::string_view uri) const } bool -Conference::isHandRaised(std::string_view uri) const +Conference::isHandRaised(std::string_view deviceId) const { - return isHost(uri) ? handsRaised_.find("host"sv) != handsRaised_.end() - : handsRaised_.find(uri) != handsRaised_.end(); + return isHostDevice(deviceId) ? handsRaised_.find("host"sv) != handsRaised_.end() + : handsRaised_.find(deviceId) != handsRaised_.end(); } void -Conference::setHandRaised(const std::string& participant_id, const bool& state) +Conference::setHandRaised(const std::string& deviceId, const bool& state) { - if (isHost(participant_id)) { + if (isHostDevice(deviceId)) { auto isPeerRequiringAttention = isHandRaised("host"sv); if (state and not isPeerRequiringAttention) { JAMI_DBG("Raise host hand"); @@ -1243,27 +1244,30 @@ Conference::setHandRaised(const std::string& participant_id, const bool& state) handsRaised_.erase("host"); updateHandsRaised(); } - return; } else { for (const auto& p : getParticipantList()) { - if (auto call = getCall(p)) { - auto isPeerRequiringAttention = isHandRaised(participant_id); - if (participant_id == string_remove_suffix(call->getPeerNumber(), '@')) { + if (auto call = std::dynamic_pointer_cast<SIPCall>(getCall(p))) { + auto isPeerRequiringAttention = isHandRaised(deviceId); + std::string callDeviceId; + if (auto* transport = call->getTransport()) + callDeviceId = transport->deviceId(); + if (deviceId == callDeviceId) { + JAMI_ERR() << "@@@X"; if (state and not isPeerRequiringAttention) { - JAMI_DBG("Raise %s hand", participant_id.c_str()); - handsRaised_.emplace(participant_id); + JAMI_DBG("Raise %s hand", deviceId.c_str()); + handsRaised_.emplace(deviceId); updateHandsRaised(); } else if (not state and isPeerRequiringAttention) { - JAMI_DBG("Remove %s raised hand", participant_id.c_str()); - handsRaised_.erase(participant_id); + JAMI_DBG("Remove %s raised hand", deviceId.c_str()); + handsRaised_.erase(deviceId); updateHandsRaised(); } return; } } } + JAMI_WARN("Fail to raise %s hand (participant not found)", deviceId.c_str()); } - JAMI_WARN("Fail to raise %s hand (participant not found)", participant_id.c_str()); } void @@ -1303,9 +1307,8 @@ void Conference::updateHandsRaised() { std::lock_guard<std::mutex> lk(confInfoMutex_); - for (auto& info : confInfo_) { - info.handRaised = isHandRaised(string_remove_suffix(info.uri, '@')); - } + for (auto& info : confInfo_) + info.handRaised = isHandRaised(info.device); sendConferenceInfos(); } @@ -1476,6 +1479,14 @@ Conference::isHost(std::string_view uri) const return false; } +bool +Conference::isHostDevice(std::string_view deviceId) const +{ + if (auto acc = std::dynamic_pointer_cast<JamiAccount>(account_.lock())) + return deviceId == acc->currentDeviceId(); + return false; +} + void Conference::updateConferenceInfo(ConfInfo confInfo) { diff --git a/src/conference.h b/src/conference.h index 4e28ca25de31693dec956c599571468b362eeb10..a992ab40d37a74bf74cc416320ee3b727555523d 100644 --- a/src/conference.h +++ b/src/conference.h @@ -424,6 +424,7 @@ private: ConfInfo getConfInfoHostUri(std::string_view localHostURI, std::string_view destURI); bool isHost(std::string_view uri) const; + bool isHostDevice(std::string_view deviceId) const; /** * If the local host is participating in the conference (attached diff --git a/src/conference_protocol.cpp b/src/conference_protocol.cpp index e7652487e2ade72f313608c29369170b04698c95..93a28b3a41457730e003947501ecc79cc397c319 100644 --- a/src/conference_protocol.cpp +++ b/src/conference_protocol.cpp @@ -75,14 +75,13 @@ ConfProtocolParser::parseV0() auto isPeerModerator = checkAuthorization_(peerId_); if (data_.isMember(ProtocolKeys::HANDRAISED)) { auto state = data_[ProtocolKeys::HANDSTATE].asString() == TRUE_STR; - std::string deviceId; auto uri = data_[ProtocolKeys::HANDRAISED].asString(); if (peerId_ == uri) { // In this case, the user want to change their state - raiseHandUri_(deviceId, state); + raiseHandUri_(uri, state); } else if (!state && isPeerModerator) { // In this case a moderator can lower the hand - raiseHandUri_(deviceId, state); + raiseHandUri_(uri, state); } } if (!isPeerModerator) {