LCOV - code coverage report
Current view: top level - src - conference_protocol.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 37 37 100.0 %
Date: 2024-12-21 08:56:24 Functions: 14 14 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 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          38 :     ConfProtocolParser() {};
      39             : 
      40          38 :     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          38 :     void onCheckAuthorization(std::function<bool(std::string_view)>&& cb)
      45             :     {
      46          38 :         checkAuthorization_ = std::move(cb);
      47          38 :     }
      48             : 
      49          38 :     void onHangupParticipant(std::function<void(const std::string&, const std::string&)>&& cb)
      50             :     {
      51          38 :         hangupParticipant_ = std::move(cb);
      52          38 :     }
      53          38 :     void onRaiseHand(std::function<void(const std::string&, bool)>&& cb)
      54             :     {
      55          38 :         raiseHand_ = std::move(cb);
      56          38 :     }
      57          38 :     void onSetActiveStream(std::function<void(const std::string&, bool)>&& cb)
      58             :     {
      59          38 :         setActiveStream_ = std::move(cb);
      60          38 :     }
      61          38 :     void onMuteStreamAudio(
      62             :         std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb)
      63             :     {
      64          38 :         muteStreamAudio_ = std::move(cb);
      65          38 :     }
      66             :     void onMuteStreamVideo(
      67             :         std::function<void(const std::string&, const std::string&, const std::string&, bool)>&& cb)
      68             :     {
      69             :         muteStreamVideo_ = std::move(cb);
      70             :     }
      71          38 :     void onSetLayout(std::function<void(int)>&& cb) { setLayout_ = std::move(cb); }
      72             : 
      73             :     // Version 0, deprecated
      74          38 :     void onKickParticipant(std::function<void(const std::string&)>&& cb)
      75             :     {
      76          38 :         kickParticipant_ = std::move(cb);
      77          38 :     }
      78          38 :     void onSetActiveParticipant(std::function<void(const std::string&)>&& cb)
      79             :     {
      80          38 :         setActiveParticipant_ = std::move(cb);
      81          38 :     }
      82          38 :     void onMuteParticipant(std::function<void(const std::string&, bool)>&& cb)
      83             :     {
      84          38 :         muteParticipant_ = std::move(cb);
      85          38 :     }
      86          38 :     void onRaiseHandUri(std::function<void(const std::string&, bool)>&& cb)
      87             :     {
      88          38 :         raiseHandUri_ = std::move(cb);
      89          38 :     }
      90          38 :     void onVoiceActivity(std::function<void(const std::string&, bool)>&& cb)
      91             :     {
      92          38 :         voiceActivity_ = std::move(cb);
      93          38 :     }
      94             : 
      95             :     /**
      96             :      * Inject in the parser the data to parse
      97             :      */
      98           6 :     void initData(Json::Value&& d, std::string_view peerId)
      99             :     {
     100           6 :         data_ = std::move(d);
     101           6 :         peerId_ = peerId;
     102           6 :     }
     103             : 
     104             :     /**
     105             :      * Parse the datas, this will call the methods injected if necessary
     106             :      */
     107             :     void parse();
     108             : 
     109             : private:
     110             :     void parseV0();
     111             :     void parseV1();
     112             : 
     113             :     std::string_view peerId_;
     114             :     Json::Value data_;
     115             : 
     116             :     std::function<void(uint32_t)> version_;
     117             : 
     118             :     std::function<bool(std::string_view)> checkAuthorization_;
     119             :     std::function<void(const std::string&, const std::string&)> hangupParticipant_;
     120             :     std::function<void(const std::string&, bool)> raiseHand_;
     121             :     std::function<void(const std::string&, bool)> setActiveStream_;
     122             :     std::function<void(const std::string&, const std::string&, const std::string&, bool)>
     123             :         muteStreamAudio_;
     124             :     std::function<void(const std::string&, const std::string&, const std::string&, bool)>
     125             :         muteStreamVideo_;
     126             :     std::function<void(int)> setLayout_;
     127             : 
     128             :     std::function<void(const std::string&, bool)> raiseHandUri_;
     129             :     std::function<void(const std::string&)> kickParticipant_;
     130             :     std::function<void(const std::string&)> setActiveParticipant_;
     131             :     std::function<void(const std::string&, bool)> muteParticipant_;
     132             :     std::function<void(const std::string&, bool)> voiceActivity_;
     133             : };
     134             : 
     135             : } // namespace jami

Generated by: LCOV version 1.14