Line data Source code
1 : /* 2 : * Copyright (C) 2022-2024 Savoir-faire Linux Inc. 3 : * 4 : * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> 5 : * 6 : * This program is free software; you can redistribute it and/or modify 7 : * it under the terms of the GNU General Public License as published by 8 : * the Free Software Foundation; either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * This program is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU General Public License 17 : * along with this program; if not, write to the Free Software 18 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 : */ 20 : #pragma once 21 : 22 : #ifdef HAVE_CONFIG_H 23 : #include "config.h" 24 : #endif 25 : 26 : #include <string_view> 27 : #include <functional> 28 : #include <json/json.h> 29 : 30 : #include "logger.h" 31 : 32 : namespace jami { 33 : 34 : /** 35 : * Used to parse confOrder objects 36 : * @note the user of this class must initialize the different lambdas. 37 : */ 38 : class ConfProtocolParser 39 : { 40 : public: 41 38 : ConfProtocolParser() {}; 42 : 43 38 : void onVersion(std::function<void(uint32_t)>&& cb) { version_ = std::move(cb); } 44 : /** 45 : * Ask the caller to check if a peer is authorized (moderator of the conference) 46 : */ 47 38 : void onCheckAuthorization(std::function<bool(std::string_view)>&& cb) 48 : { 49 38 : checkAuthorization_ = std::move(cb); 50 38 : } 51 : 52 38 : void onHangupParticipant(std::function<void(const std::string&, const std::string&)>&& cb) 53 : { 54 38 : hangupParticipant_ = std::move(cb); 55 38 : } 56 38 : void onRaiseHand(std::function<void(const std::string&, bool)>&& cb) 57 : { 58 38 : raiseHand_ = std::move(cb); 59 38 : } 60 38 : void onSetActiveStream(std::function<void(const std::string&, bool)>&& cb) 61 : { 62 38 : setActiveStream_ = std::move(cb); 63 38 : } 64 38 : void onMuteStreamAudio( 65 : std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb) 66 : { 67 38 : muteStreamAudio_ = std::move(cb); 68 38 : } 69 : void onMuteStreamVideo( 70 : std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb) 71 : { 72 : muteStreamVideo_ = std::move(cb); 73 : } 74 38 : void onSetLayout(std::function<void(int)>&& cb) { setLayout_ = std::move(cb); } 75 : 76 : // Version 0, deprecated 77 38 : void onKickParticipant(std::function<void(const std::string&)>&& cb) 78 : { 79 38 : kickParticipant_ = std::move(cb); 80 38 : } 81 38 : void onSetActiveParticipant(std::function<void(const std::string&)>&& cb) 82 : { 83 38 : setActiveParticipant_ = std::move(cb); 84 38 : } 85 38 : void onMuteParticipant(std::function<void(const std::string&, bool)>&& cb) 86 : { 87 38 : muteParticipant_ = std::move(cb); 88 38 : } 89 38 : void onRaiseHandUri(std::function<void(const std::string&, bool)>&& cb) 90 : { 91 38 : raiseHandUri_ = std::move(cb); 92 38 : } 93 38 : void onVoiceActivity(std::function<void(const std::string&, bool)>&& cb) 94 : { 95 38 : voiceActivity_ = std::move(cb); 96 38 : } 97 : 98 : /** 99 : * Inject in the parser the data to parse 100 : */ 101 6 : void initData(Json::Value&& d, std::string_view peerId) 102 : { 103 6 : data_ = std::move(d); 104 6 : peerId_ = peerId; 105 6 : } 106 : 107 : /** 108 : * Parse the datas, this will call the methods injected if necessary 109 : */ 110 : void parse(); 111 : 112 : private: 113 : void parseV0(); 114 : void parseV1(); 115 : 116 : std::string_view peerId_; 117 : Json::Value data_; 118 : 119 : std::function<void(uint32_t)> version_; 120 : 121 : std::function<bool(std::string_view)> checkAuthorization_; 122 : std::function<void(const std::string&, const std::string&)> hangupParticipant_; 123 : std::function<void(const std::string&, bool)> raiseHand_; 124 : std::function<void(const std::string&, bool)> setActiveStream_; 125 : std::function<void(const std::string&, const std::string&, const std::string&, bool)> 126 : muteStreamAudio_; 127 : std::function<void(const std::string&, const std::string&, const std::string&, bool)> 128 : muteStreamVideo_; 129 : std::function<void(int)> setLayout_; 130 : 131 : std::function<void(const std::string&, bool)> raiseHandUri_; 132 : std::function<void(const std::string&)> kickParticipant_; 133 : std::function<void(const std::string&)> setActiveParticipant_; 134 : std::function<void(const std::string&, bool)> muteParticipant_; 135 : std::function<void(const std::string&, bool)> voiceActivity_; 136 : }; 137 : 138 : } // namespace jami