OpenTera WebRTC API (C++) 1.2.5
Client.h
1 #ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_UTILS_CLIENT_H
2 #define OPENTERA_WEBRTC_NATIVE_CLIENT_UTILS_CLIENT_H
3 
4 #include <nlohmann/json.hpp>
5 
6 #include <string>
7 
8 namespace opentera
9 {
13  class Client
14  {
15  std::string m_id;
16  std::string m_name;
17  nlohmann::json m_data;
18 
19  public:
20  Client() = default;
21  Client(std::string id, std::string name, nlohmann::json data);
22  explicit Client(const nlohmann::json& message);
23  Client(const Client& other) = default;
24  Client(Client&& other) = default;
25  virtual ~Client() = default;
26 
27  [[nodiscard]] const std::string& id() const;
28  [[nodiscard]] const std::string& name() const;
29  [[nodiscard]] const nlohmann::json& data() const;
30 
31  static bool isValid(const nlohmann::json& message);
32 
33  Client& operator=(const Client& other) = default;
34  Client& operator=(Client&& other) = default;
35 
36  friend bool operator==(const Client& c1, const Client& c2);
37  };
38 
43  inline const std::string& Client::id() const { return m_id; }
44 
49  inline const std::string& Client::name() const { return m_name; }
50 
55  inline const nlohmann::json& Client::data() const { return m_data; }
56 
57  inline bool operator==(const Client& c1, const Client& c2)
58  {
59  return c1.m_id == c2.m_id && c1.m_name == c2.m_name && c1.m_data == c2.m_data;
60  }
61 
62  inline bool operator!=(const Client& c1, const Client& c2) { return !(c1 == c2); }
63 
67  class RoomClient
68  {
69  std::string m_id;
70  std::string m_name;
71  nlohmann::json m_data;
72  bool m_isConnected;
73 
74  public:
75  RoomClient();
76  RoomClient(std::string id, std::string name, nlohmann::json data, bool isConnected);
77  RoomClient(const Client& client, bool isConnected);
78  RoomClient(const RoomClient& other) = default;
79  RoomClient(RoomClient&& other) = default;
80  virtual ~RoomClient() = default;
81 
82  [[nodiscard]] const std::string& id() const;
83  [[nodiscard]] const std::string& name() const;
84  [[nodiscard]] const nlohmann::json& data() const;
85  [[nodiscard]] bool isConnected() const;
86 
87  explicit operator Client() const;
88 
89  RoomClient& operator=(const RoomClient& other) = default;
90  RoomClient& operator=(RoomClient&& other) = default;
91 
92  friend bool operator==(const RoomClient& c1, const RoomClient& c2);
93  };
94 
99  inline const std::string& RoomClient::id() const { return m_id; }
100 
105  inline const std::string& RoomClient::name() const { return m_name; }
106 
111  inline const nlohmann::json& RoomClient::data() const { return m_data; }
112 
117  inline bool RoomClient::isConnected() const { return m_isConnected; }
118 
119  inline RoomClient::operator Client() const { return {m_id, m_name, m_data}; }
120 
121  inline bool operator==(const RoomClient& c1, const RoomClient& c2)
122  {
123  return c1.m_id == c2.m_id && c1.m_name == c2.m_name && c1.m_data == c2.m_data &&
124  c1.m_isConnected == c2.m_isConnected;
125  }
126 
127  inline bool operator!=(const RoomClient& c1, const RoomClient& c2) { return !(c1 == c2); }
128 }
129 
130 #endif
Represents a peer client.
Definition: Client.h:14
const nlohmann::json & data() const
Returns the client data.
Definition: Client.h:55
const std::string & id() const
Returns the client id.
Definition: Client.h:43
const std::string & name() const
Returns the client name.
Definition: Client.h:49
Represents a room client.
Definition: Client.h:68
bool isConnected() const
Indicates if the client is connected (RTCPeerConnection).
Definition: Client.h:117
RoomClient()
Creates a room client with the default values.
Definition: Client.cpp:42
const nlohmann::json & data() const
Returns the client data.
Definition: Client.h:111
const std::string & id() const
Returns the client id.
Definition: Client.h:99
const std::string & name() const
Returns the client name.
Definition: Client.h:105