Line data Source code
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 : #pragma once 18 : 19 : #ifdef HAVE_CONFIG_H 20 : #include "config.h" 21 : #endif 22 : 23 : #include <string_view> 24 : #include <functional> 25 : #include <json/json.h> 26 : 27 : #include "logger.h" 28 : 29 : namespace jami { 30 : 31 : /** 32 : * Used to parse confOrder objects 33 : * @note the user of this class must initialize the different lambdas. 34 : */ 35 : class ConfProtocolParser 36 : { 37 : public: 38 37 : ConfProtocolParser() {}; 39 : 40 37 : void onVersion(std::function<void(uint32_t)>&& cb) { version_ = std::move(cb); } 41 : /** 42 : * Ask the caller to check if a peer is authorized (moderator of the conference) 43 : */ 44 37 : void onCheckAuthorization(std::function<bool(std::string_view)>&& cb) { checkAuthorization_ = std::move(cb); } 45 : 46 37 : void onHangupParticipant(std::function<void(const std::string&, const std::string&)>&& cb) 47 : { 48 37 : hangupParticipant_ = std::move(cb); 49 37 : } 50 37 : void onRaiseHand(std::function<void(const std::string&, bool)>&& cb) { raiseHand_ = std::move(cb); } 51 37 : void onSetActiveStream(std::function<void(const std::string&, bool)>&& cb) { setActiveStream_ = std::move(cb); } 52 37 : void onMuteStreamAudio(std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb) 53 : { 54 37 : muteStreamAudio_ = std::move(cb); 55 37 : } 56 : void onMuteStreamVideo(std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb) 57 : { 58 : muteStreamVideo_ = std::move(cb); 59 : } 60 37 : void onSetLayout(std::function<void(int)>&& cb) { setLayout_ = std::move(cb); } 61 : 62 : // Version 0, deprecated 63 37 : void onKickParticipant(std::function<void(const std::string&)>&& cb) { kickParticipant_ = std::move(cb); } 64 37 : void onSetActiveParticipant(std::function<void(const std::string&)>&& cb) { setActiveParticipant_ = std::move(cb); } 65 37 : void onMuteParticipant(std::function<void(const std::string&, bool)>&& cb) { muteParticipant_ = std::move(cb); } 66 37 : void onRaiseHandUri(std::function<void(const std::string&, bool)>&& cb) { raiseHandUri_ = std::move(cb); } 67 37 : void onVoiceActivity(std::function<void(const std::string&, bool)>&& cb) { voiceActivity_ = std::move(cb); } 68 : 69 : /** 70 : * Inject in the parser the data to parse 71 : */ 72 6 : void initData(Json::Value&& d, std::string_view peerId) 73 : { 74 6 : data_ = std::move(d); 75 6 : peerId_ = peerId; 76 6 : } 77 : 78 : /** 79 : * Parse the datas, this will call the methods injected if necessary 80 : */ 81 : void parse(); 82 : 83 : private: 84 : void parseV0(); 85 : void parseV1(); 86 : 87 : std::string_view peerId_; 88 : Json::Value data_; 89 : 90 : std::function<void(uint32_t)> version_; 91 : 92 : std::function<bool(std::string_view)> checkAuthorization_; 93 : std::function<void(const std::string&, const std::string&)> hangupParticipant_; 94 : std::function<void(const std::string&, bool)> raiseHand_; 95 : std::function<void(const std::string&, bool)> setActiveStream_; 96 : std::function<void(const std::string&, const std::string&, const std::string&, bool)> muteStreamAudio_; 97 : std::function<void(const std::string&, const std::string&, const std::string&, bool)> muteStreamVideo_; 98 : std::function<void(int)> setLayout_; 99 : 100 : std::function<void(const std::string&, bool)> raiseHandUri_; 101 : std::function<void(const std::string&)> kickParticipant_; 102 : std::function<void(const std::string&)> setActiveParticipant_; 103 : std::function<void(const std::string&, bool)> muteParticipant_; 104 : std::function<void(const std::string&, bool)> voiceActivity_; 105 : }; 106 : 107 : } // namespace jami