Ring Daemon
Loading...
Searching...
No Matches
conference_protocol.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "conference_protocol.h"
19
20#include "logger.h"
21#include "string_utils.h"
22
23namespace jami {
24
25namespace ProtocolKeys {
26
27constexpr static const char* PROTOVERSION = "version";
28constexpr static const char* LAYOUT = "layout";
29// V0
30constexpr static const char* HANDRAISED = "handRaised";
31constexpr static const char* HANDSTATE = "handState";
32constexpr static const char* ACTIVEPART = "activeParticipant";
33constexpr static const char* MUTEPART = "muteParticipant";
34constexpr static const char* MUTESTATE = "muteState";
35constexpr static const char* HANGUPPART = "hangupParticipant";
36// V1
37constexpr static const char* DEVICES = "devices";
38constexpr static const char* MEDIAS = "medias";
39constexpr static const char* RAISEHAND = "raiseHand";
40constexpr static const char* HANGUP = "hangup";
41constexpr static const char* ACTIVE = "active";
42constexpr static const char* MUTEAUDIO = "muteAudio";
43// Future
44constexpr static const char* MUTEVIDEO = "muteVideo";
45constexpr static const char* VOICEACTIVITY = "voiceActivity";
46
47} // namespace ProtocolKeys
48
49void
51{
52 if (data_.isMember(ProtocolKeys::PROTOVERSION)) {
54 if (version_)
55 version_(version);
56 if (version == 1) {
57 parseV1();
58 } else {
59 JAMI_WARN() << "Unsupported protocol version " << version;
60 }
61 } else {
62 parseV0();
63 }
64}
65
66void
67ConfProtocolParser::parseV0()
68{
69 if (!checkAuthorization_ || !raiseHandUri_ || !setLayout_ || !setActiveParticipant_ || !muteParticipant_
70 || !kickParticipant_) {
71 JAMI_ERR() << "Missing methods for ConfProtocolParser";
72 return;
73 }
74 // Check if all lambdas set
75 auto isPeerModerator = checkAuthorization_(peerId_);
76 if (data_.isMember(ProtocolKeys::HANDRAISED)) {
77 auto state = data_[ProtocolKeys::HANDSTATE].asString() == TRUE_STR;
78 auto uri = data_[ProtocolKeys::HANDRAISED].asString();
79 if (peerId_ == uri) {
80 // In this case, the user want to change their state
81 raiseHandUri_(uri, state);
82 } else if (!state && isPeerModerator) {
83 // In this case a moderator can lower the hand
84 raiseHandUri_(uri, state);
85 }
86 }
87 if (!isPeerModerator) {
88 JAMI_WARNING("Received conference order from a non-moderator ({})", peerId_);
89 return;
90 }
91 if (data_.isMember(ProtocolKeys::LAYOUT)) {
92 setLayout_(data_[ProtocolKeys::LAYOUT].asInt());
93 }
94 if (data_.isMember(ProtocolKeys::ACTIVEPART)) {
95 setActiveParticipant_(data_[ProtocolKeys::ACTIVEPART].asString());
96 }
97 if (data_.isMember(ProtocolKeys::MUTEPART) && data_.isMember(ProtocolKeys::MUTESTATE)) {
98 muteParticipant_(data_[ProtocolKeys::MUTEPART].asString(),
100 }
101 if (data_.isMember(ProtocolKeys::HANGUPPART)) {
102 kickParticipant_(data_[ProtocolKeys::HANGUPPART].asString());
103 }
104}
105
106void
107ConfProtocolParser::parseV1()
108{
109 if (!checkAuthorization_ || !setLayout_ || !raiseHand_ || !hangupParticipant_ || !muteStreamAudio_
110 || !setActiveStream_) {
111 JAMI_ERR() << "Missing methods for ConfProtocolParser";
112 return;
113 }
114
115 auto isPeerModerator = checkAuthorization_(peerId_);
116 for (Json::Value::const_iterator itr = data_.begin(); itr != data_.end(); itr++) {
117 auto key = itr.key();
118 if (key == ProtocolKeys::LAYOUT) {
119 // Note: can be removed soon
120 if (isPeerModerator)
121 setLayout_(itr->asInt());
122 } else if (key == ProtocolKeys::PROTOVERSION) {
123 continue;
124 } else {
125 auto accValue = *itr;
126 if (accValue.isMember(ProtocolKeys::DEVICES)) {
127 auto accountUri = key.asString();
128 for (Json::Value::const_iterator itrd = accValue[ProtocolKeys::DEVICES].begin();
130 itrd++) {
131 auto deviceId = itrd.key().asString();
132 const auto& deviceValue = *itrd;
133 if (deviceValue.isMember(ProtocolKeys::RAISEHAND)) {
135 if (peerId_ == accountUri || (!newState && isPeerModerator))
136 raiseHand_(deviceId, newState);
137 }
139 hangupParticipant_(accountUri, deviceId);
140 }
141 if (deviceValue.isMember(ProtocolKeys::MEDIAS)) {
142 for (Json::Value::const_iterator itrm = accValue[ProtocolKeys::MEDIAS].begin();
144 itrm++) {
145 auto streamId = itrm.key().asString();
146 const auto& mediaVal = *itrm;
148 voiceActivity_(streamId, mediaVal[ProtocolKeys::VOICEACTIVITY].asBool());
149 }
150 if (isPeerModerator) {
151 if (mediaVal.isMember(ProtocolKeys::MUTEVIDEO) && !muteStreamVideo_) {
152 // Note: For now, it's not implemented so not set
153 muteStreamVideo_(accountUri,
154 deviceId,
155 streamId,
157 }
158 if (mediaVal.isMember(ProtocolKeys::MUTEAUDIO)) {
159 muteStreamAudio_(accountUri,
160 deviceId,
161 streamId,
163 }
164 if (mediaVal.isMember(ProtocolKeys::ACTIVE)) {
165 setActiveStream_(streamId, mediaVal[ProtocolKeys::ACTIVE].asBool());
166 }
167 }
168 }
169 }
170 }
171 }
172 }
173 }
174}
175
176} // namespace jami
void parse()
Parse the datas, this will call the methods injected if necessary.
#define JAMI_ERR(...)
Definition logger.h:230
#define JAMI_WARN(...)
Definition logger.h:229
#define JAMI_WARNING(formatstr,...)
Definition logger.h:242
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
Definition CommonData.h:100
static constexpr const char * MUTEVIDEO
static constexpr const char * ACTIVE
static constexpr const char * HANGUP
static constexpr const char * VOICEACTIVITY
static constexpr const char * HANDRAISED
static constexpr const char * MUTEPART
static constexpr const char * DEVICES
static constexpr const char * HANGUPPART
static constexpr const char * ACTIVEPART
static constexpr const char * PROTOVERSION
static constexpr const char * MUTESTATE
static constexpr const char * RAISEHAND
static constexpr const char * LAYOUT
static constexpr const char * MUTEAUDIO
static constexpr const char * MEDIAS
static constexpr const char * HANDSTATE
std::string streamId(const std::string &callId, std::string_view label)
static constexpr int version
static constexpr const char TRUE_STR[]
void emitSignal(Args... args)
Definition jami_signal.h:64