Ring Daemon 16.0.0
Loading...
Searching...
No Matches
conference_protocol.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 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 "string_utils.h"
21
22namespace jami {
23
24namespace ProtocolKeys {
25
26constexpr static const char* PROTOVERSION = "version";
27constexpr static const char* LAYOUT = "layout";
28// V0
29constexpr static const char* HANDRAISED = "handRaised";
30constexpr static const char* HANDSTATE = "handState";
31constexpr static const char* ACTIVEPART = "activeParticipant";
32constexpr static const char* MUTEPART = "muteParticipant";
33constexpr static const char* MUTESTATE = "muteState";
34constexpr static const char* HANGUPPART = "hangupParticipant";
35// V1
36constexpr static const char* DEVICES = "devices";
37constexpr static const char* MEDIAS = "medias";
38constexpr static const char* RAISEHAND = "raiseHand";
39constexpr static const char* HANGUP = "hangup";
40constexpr static const char* ACTIVE = "active";
41constexpr static const char* MUTEAUDIO = "muteAudio";
42// Future
43constexpr static const char* MUTEVIDEO = "muteVideo";
44constexpr static const char* VOICEACTIVITY = "voiceActivity";
45
46} // namespace ProtocolKeys
47
48void
50{
51 if (data_.isMember(ProtocolKeys::PROTOVERSION)) {
53 if (version_)
54 version_(version);
55 if (version == 1) {
56 parseV1();
57 } else {
58 JAMI_WARN() << "Unsupported protocol version " << version;
59 }
60 } else {
61 parseV0();
62 }
63}
64
65void
66ConfProtocolParser::parseV0()
67{
68 if (!checkAuthorization_ || !raiseHandUri_ || !setLayout_ || !setActiveParticipant_
69 || !muteParticipant_ || !kickParticipant_) {
70 JAMI_ERR() << "Missing methods for ConfProtocolParser";
71 return;
72 }
73 // Check if all lambdas set
74 auto isPeerModerator = checkAuthorization_(peerId_);
75 if (data_.isMember(ProtocolKeys::HANDRAISED)) {
76 auto state = data_[ProtocolKeys::HANDSTATE].asString() == TRUE_STR;
77 auto uri = data_[ProtocolKeys::HANDRAISED].asString();
78 if (peerId_ == uri) {
79 // In this case, the user want to change their state
80 raiseHandUri_(uri, state);
81 } else if (!state && isPeerModerator) {
82 // In this case a moderator can lower the hand
83 raiseHandUri_(uri, state);
84 }
85 }
86 if (!isPeerModerator) {
87 JAMI_WARNING("Received conference order from a non-moderator ({})", peerId_);
88 return;
89 }
90 if (data_.isMember(ProtocolKeys::LAYOUT)) {
91 setLayout_(data_[ProtocolKeys::LAYOUT].asInt());
92 }
93 if (data_.isMember(ProtocolKeys::ACTIVEPART)) {
94 setActiveParticipant_(data_[ProtocolKeys::ACTIVEPART].asString());
95 }
96 if (data_.isMember(ProtocolKeys::MUTEPART) && data_.isMember(ProtocolKeys::MUTESTATE)) {
97 muteParticipant_(data_[ProtocolKeys::MUTEPART].asString(),
99 }
100 if (data_.isMember(ProtocolKeys::HANGUPPART)) {
101 kickParticipant_(data_[ProtocolKeys::HANGUPPART].asString());
102 }
103}
104
105void
106ConfProtocolParser::parseV1()
107{
108 if (!checkAuthorization_ || !setLayout_ || !raiseHand_ || !hangupParticipant_
109 || !muteStreamAudio_ || !setActiveStream_) {
110 JAMI_ERR() << "Missing methods for ConfProtocolParser";
111 return;
112 }
113
114 auto isPeerModerator = checkAuthorization_(peerId_);
115 for (Json::Value::const_iterator itr = data_.begin(); itr != data_.end(); itr++) {
116 auto key = itr.key();
117 if (key == ProtocolKeys::LAYOUT) {
118 // Note: can be removed soon
119 if (isPeerModerator)
120 setLayout_(itr->asInt());
121 } else if (key == ProtocolKeys::PROTOVERSION) {
122 continue;
123 } else {
124 auto accValue = *itr;
125 if (accValue.isMember(ProtocolKeys::DEVICES)) {
126 auto accountUri = key.asString();
127 for (Json::Value::const_iterator itrd = accValue[ProtocolKeys::DEVICES].begin();
129 itrd++) {
130 auto deviceId = itrd.key().asString();
131 auto deviceValue = *itrd;
132 if (deviceValue.isMember(ProtocolKeys::RAISEHAND)) {
134 if (peerId_ == accountUri || (!newState && isPeerModerator))
135 raiseHand_(deviceId, newState);
136 }
138 hangupParticipant_(accountUri, deviceId);
139 }
140 if (deviceValue.isMember(ProtocolKeys::MEDIAS)) {
141 for (Json::Value::const_iterator itrm = accValue[ProtocolKeys::MEDIAS]
142 .begin();
144 itrm++) {
145 auto streamId = itrm.key().asString();
146 auto mediaVal = *itrm;
148 voiceActivity_(streamId,
150 }
151 if (isPeerModerator) {
153 && !muteStreamVideo_) {
154 // Note: For now, it's not implemented so not set
155 muteStreamVideo_(accountUri,
156 deviceId,
157 streamId,
159 }
160 if (mediaVal.isMember(ProtocolKeys::MUTEAUDIO)) {
161 muteStreamAudio_(accountUri,
162 deviceId,
163 streamId,
165 }
166 if (mediaVal.isMember(ProtocolKeys::ACTIVE)) {
167 setActiveStream_(streamId,
169 }
170 }
171 }
172 }
173 }
174 }
175 }
176 }
177}
178
179} // namespace jami
void parse()
Parse the datas, this will call the methods injected if necessary.
#define JAMI_ERR(...)
Definition logger.h:218
#define JAMI_WARN(...)
Definition logger.h:217
#define JAMI_WARNING(formatstr,...)
Definition logger.h:227
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
Definition CommonData.h:101
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 ring_signal.h:64