diff --git a/src/api/call.h b/src/api/call.h index 922449ce8d0228f1d6901025c2c6061e535c801c..3ae67479ac60f05d42e91d5791aa6d7f7dfeb1db 100644 --- a/src/api/call.h +++ b/src/api/call.h @@ -133,8 +133,8 @@ struct Info Type type = Type::INVALID; QString peerUri; bool isOutgoing; - bool audioMuted = false; - bool videoMuted = false; + bool audioMuted = false; // this flag is used to check main audio status + bool videoMuted = false; // this flag is used to check main video status bool isAudioOnly = false; Layout layout = Layout::GRID; VectorMapStringString participantsInfos = {}; diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h index 4fda31db8cd986077f5e482d3f248d75d69edefe..ca8e5479a85a3e95b83789591ea5625c081965e0 100644 --- a/src/api/newcallmodel.h +++ b/src/api/newcallmodel.h @@ -79,7 +79,7 @@ public: * @param isAudioOnly, set to false by default * @return the call uid created. Empty string is returned if call couldn't be created. */ - QString createCall(const QString& uri, bool isAudioOnly = false); + QString createCall(const QString& uri, bool isAudioOnly = false, VectorMapStringString mediaList = {}); /** * Request a media change in a ongoing call. diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp index 970b1079d56a2471e4720b6aa36a40833ddbe4fd..17f589c34c3ea78a4206924612270c0aac710d6d 100644 --- a/src/newcallmodel.cpp +++ b/src/newcallmodel.cpp @@ -314,19 +314,22 @@ NewCallModel::updateCallMediaList(const QString& callId, bool acceptVideo) } QString -NewCallModel::createCall(const QString& uri, bool isAudioOnly) +NewCallModel::createCall(const QString& uri, bool isAudioOnly, VectorMapStringString mediaList) { - VectorMapStringString mediaList {}; - MapStringString mediaAttribute = {{MediaAttributeKey::MEDIA_TYPE, MediaAttributeValue::AUDIO}, - {MediaAttributeKey::ENABLED, "true"}, - {MediaAttributeKey::MUTED, "false"}, - {MediaAttributeKey::SOURCE, ""}, - {MediaAttributeKey::LABEL, "audio_0"}}; - mediaList.push_back(mediaAttribute); - if (!isAudioOnly) { - mediaAttribute[MediaAttributeKey::MEDIA_TYPE] = MediaAttributeValue::VIDEO; - mediaAttribute[MediaAttributeKey::LABEL] = "video_0"; + if (mediaList.isEmpty()) { + MapStringString mediaAttribute = {{MediaAttributeKey::MEDIA_TYPE, + MediaAttributeValue::AUDIO}, + {MediaAttributeKey::ENABLED, "true"}, + {MediaAttributeKey::MUTED, "false"}, + {MediaAttributeKey::SOURCE, ""}, + {MediaAttributeKey::LABEL, "audio_0"}}; mediaList.push_back(mediaAttribute); + if (!isAudioOnly) { + mediaAttribute[MediaAttributeKey::MEDIA_TYPE] + = MediaAttributeValue::VIDEO; + mediaAttribute[MediaAttributeKey::LABEL] = "video_0"; + mediaList.push_back(mediaAttribute); + } } #ifdef ENABLE_LIBWRAP auto callId = CallManager::instance().placeCallWithMedia(owner.id, uri, mediaList); @@ -410,7 +413,13 @@ NewCallModel::requestMediaChange(const QString& callId, const QString& mediaLabe // mediaNegotiationStatus if (found < callInfo->mediaList.size()) { callInfo->mediaList[found][MediaAttributeKey::MUTED] - = callInfo->mediaList[found][MediaAttributeKey::MUTED] == "true" ? "false" : "true"; + = callInfo->mediaList[found][MediaAttributeKey::MUTED] == "true" ? "false" + : "true"; + if (mediaLabel.contains("audio_0")) { + callInfo->audioMuted = !callInfo->audioMuted; + } else if (mediaLabel.contains("video_0")) { + callInfo->videoMuted = !callInfo->videoMuted; + } if (callInfo->status == call::Status::IN_PROGRESS) emit callInfosChanged(owner.id, callId); } @@ -620,7 +629,7 @@ NewCallModel::joinCalls(const QString& callIdA, const QString& callIdB) const QString NewCallModel::callAndAddParticipant(const QString uri, const QString& callId, bool audioOnly) { - auto newCallId = createCall(uri, audioOnly); + auto newCallId = createCall(uri, audioOnly, pimpl_->calls[callId]->mediaList); Q_EMIT beginInsertPendingConferenceesRows(0); pimpl_->pendingConferencees_.prepend({uri, newCallId, callId}); Q_EMIT endInsertPendingConferenceesRows(); @@ -1042,11 +1051,20 @@ NewCallModelPimpl::slotMediaChangeRequested(const QString& accountId, auto& callInfo = calls[callId]; if (!callInfo) return; + + QList<QString> currentMediaLabels {}; + for (auto& currentItem : callInfo->mediaList) + currentMediaLabels.append(currentItem[MediaAttributeKey::LABEL]); + auto answerMedia = QList<MapStringString>::fromVector(mediaList); for (auto& item : answerMedia) { - if (item[MediaAttributeKey::MEDIA_TYPE] == MediaAttributeValue::VIDEO) { - item[MediaAttributeKey::MUTED] = callInfo->videoMuted ? "true" : "false"; + int index = currentMediaLabels.indexOf(item[MediaAttributeKey::LABEL]); + if (index >= 0) { + item[MediaAttributeKey::MUTED] = callInfo->mediaList[index][MediaAttributeKey::MUTED]; + item[MediaAttributeKey::ENABLED] = callInfo->mediaList[index][MediaAttributeKey::ENABLED]; + } else { + item[MediaAttributeKey::MUTED] = "true"; item[MediaAttributeKey::ENABLED] = "true"; } } @@ -1235,12 +1253,22 @@ NewCallModelPimpl::slotOnConferenceInfosUpdated(const QString& confId, emit linked.onParticipantsChanged(confId); + for (auto& info : infos) { + if (info["uri"].isEmpty()) { + it->second->videoMuted = info["videoMuted"] == "true"; + it->second->audioMuted = info["audioLocalMuted"] == "true"; + } + } + // TODO: remove when the rendez-vous UI will be done // For now, the rendez-vous account can see ongoing calls // And must be notified when a new QStringList callList = CallManager::instance().getParticipantList(confId); foreach (const auto& call, callList) { emit linked.callAddedToConference(call, confId); + calls[call]->videoMuted = it->second->videoMuted; + calls[call]->audioMuted = it->second->audioMuted; + Q_EMIT linked.callInfosChanged(linked.owner.id, call); } }