LCOV - code coverage report
Current view: top level - src - conference_protocol.h (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 100.0 % 21 21
Test Date: 2026-06-13 09:18:46 Functions: 100.0 % 14 14

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

Generated by: LCOV version 2.0-1