UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
Client Class Reference

#include <client.hpp>

Inheritance diagram for Client:
Inheritance graph
Collaboration diagram for Client:
Collaboration graph

Public Types

using CompletionCallback = std::function<void(Client&, CompletionStatus)>
 

Public Member Functions

 Client (asio::ip::tcp::socket &&socket)
 
 Client (Client &&)=delete
 
 Client (const Client &)=delete
 
const std::vector< std::string > & getCandidates ()
 
std::string getClientName ()
 
std::string getRoomName ()
 
std::string getSdpDesc ()
 
bool isSendCallbackPending () const
 
Client & operator= (Client &&)=delete
 
Client & operator= (const Client &)=delete
 
void readCandidate (CompletionCallback onComplete)
 
void readDescription (CompletionCallback onComplete)
 
void sendMsg (std::string_view msg)
 

Private Member Functions

void onMsgSent (CompletionStatus status)
 
void readCandidateComplete (CompletionCallback onComplete, CompletionStatus status)
 
void readDescComplete (CompletionCallback onComplete, CompletionStatus status)
 
void readNameComplete (asio::ip::tcp::socket &socket, CompletionCallback onComplete, CompletionStatus status)
 
void readRoomComplete (asio::ip::tcp::socket &socket, CompletionCallback onComplete, CompletionStatus status)
 

Private Attributes

std::vector< std::string > candidates
 
std::string clientName
 
Message inMsg
 
Message outMsg
 
std::string roomName
 
std::string sdpDesc
 
std::queue< std::string > sendQueue
 
asio::ip::tcp::socket socket
 

Detailed Description

Definition at line 49 of file client.hpp.

Member Typedef Documentation

◆ CompletionCallback

using Client::CompletionCallback = std::function<void(Client&, CompletionStatus)>

Definition at line 51 of file client.hpp.

Constructor & Destructor Documentation

◆ Client() [1/3]

Client::Client ( asio::ip::tcp::socket && socket)

Definition at line 40 of file client.cpp.

40: socket(std::move(socket)) { }
asio::ip::tcp::socket socket
Definition client.hpp:96

◆ Client() [2/3]

Client::Client ( const Client & )
delete

◆ Client() [3/3]

Client::Client ( Client && )
delete

Member Function Documentation

◆ getCandidates()

const std::vector< std::string > & Client::getCandidates ( )
inline

Definition at line 68 of file client.hpp.

68{ return candidates; }
std::vector< std::string > candidates
Definition client.hpp:90

References candidates.

◆ getClientName()

std::string Client::getClientName ( )
inline

Definition at line 61 of file client.hpp.

61{ return clientName; }
std::string clientName
Definition client.hpp:87

References clientName.

Referenced by Room::addClient().

◆ getRoomName()

std::string Client::getRoomName ( )
inline

Definition at line 62 of file client.hpp.

62{ return roomName; }
std::string roomName
Definition client.hpp:88

References roomName.

◆ getSdpDesc()

std::string Client::getSdpDesc ( )
inline

Definition at line 63 of file client.hpp.

63{ return sdpDesc; }
std::string sdpDesc
Definition client.hpp:89

References sdpDesc.

Referenced by Room::addClient().

◆ isSendCallbackPending()

bool Client::isSendCallbackPending ( ) const

Definition at line 118 of file client.cpp.

118 {
119 return !sendQueue.empty() || outMsg.isSendingNow();
120}
std::queue< std::string > sendQueue
Definition client.hpp:92
Message outMsg
Definition client.hpp:95
bool isSendingNow() const
Definition message.hpp:61

References Message::isSendingNow(), outMsg, and sendQueue.

Referenced by sendMsg().

Here is the call graph for this function:

◆ onMsgSent()

void Client::onMsgSent ( CompletionStatus status)
private

Definition at line 134 of file client.cpp.

134 {
136 std::cerr << "Failed to send a message\n";
137 }
138
139 if(sendQueue.empty())
140 return;
141
142 using namespace std::placeholders;
143 outMsg.setStr(sendQueue.front());
144 sendQueue.pop();
145 outMsg.async_sendMsg(socket, std::bind(&Client::onMsgSent, shared_from_this(), _1));
146}
void onMsgSent(CompletionStatus status)
Definition client.cpp:134
void async_sendMsg(asio::ip::tcp::socket &socket, CompletionCallback onComplete)
Definition message.cpp:67
void setStr(std::string_view msg)
Definition message.cpp:57

References Message::async_sendMsg(), onMsgSent(), outMsg, sendQueue, Message::setStr(), socket, and Success.

Referenced by onMsgSent(), and sendMsg().

Here is the call graph for this function:

◆ operator=() [1/2]

Client & Client::operator= ( Client && )
delete

◆ operator=() [2/2]

Client & Client::operator= ( const Client & )
delete

◆ readCandidate()

void Client::readCandidate ( CompletionCallback onComplete)

Definition at line 93 of file client.cpp.

93 {
94 using namespace std::placeholders;
97 shared_from_this(), onComplete, _1));
98}
Message inMsg
Definition client.hpp:94
void readCandidateComplete(CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:100
void async_readMsg(asio::ip::tcp::socket &socket, CompletionCallback onComplete)
Definition message.cpp:47

References Message::async_readMsg(), inMsg, readCandidateComplete(), and socket.

Referenced by Room::addClient().

Here is the call graph for this function:

◆ readCandidateComplete()

void Client::readCandidateComplete ( CompletionCallback onComplete,
CompletionStatus status )
private

Definition at line 100 of file client.cpp.

103{
105 onComplete(*this, status);
106 return;
107 }
108
109 if(inMsg.getStr() == "disconnect"){
110 onComplete(*this, CompletionStatus::GracefulDisconnect);
111 return;
112 }
113
114 candidates.emplace_back(inMsg.getStr());
115 onComplete(*this, CompletionStatus::Success);
116}
std::string_view getStr() const
Definition message.cpp:43

References candidates, Message::getStr(), GracefulDisconnect, inMsg, and Success.

Referenced by readCandidate().

Here is the call graph for this function:

◆ readDescComplete()

void Client::readDescComplete ( CompletionCallback onComplete,
CompletionStatus status )
private

Definition at line 80 of file client.cpp.

83{
85 onComplete(*this, status);
86 return;
87 }
88
89 sdpDesc = std::string(inMsg.getStr());
90 onComplete(*this, CompletionStatus::Success);
91}

References Message::getStr(), inMsg, sdpDesc, and Success.

Referenced by readRoomComplete().

Here is the call graph for this function:

◆ readDescription()

void Client::readDescription ( CompletionCallback onComplete)

Definition at line 42 of file client.cpp.

42 {
43 using namespace std::placeholders;
45 std::bind(&Client::readNameComplete,
46 shared_from_this(), std::ref(socket), onComplete, _1));
47}
void readNameComplete(asio::ip::tcp::socket &socket, CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:49

References Message::async_readMsg(), inMsg, readNameComplete(), and socket.

Here is the call graph for this function:

◆ readNameComplete()

void Client::readNameComplete ( asio::ip::tcp::socket & socket,
CompletionCallback onComplete,
CompletionStatus status )
private

Definition at line 49 of file client.cpp.

52{
54 onComplete(*this, status);
55 return;
56 }
57
58 clientName = std::string(inMsg.getStr());
59 using namespace std::placeholders;
61 std::bind(&Client::readRoomComplete,
62 shared_from_this(), std::ref(socket), onComplete, _1));
63}
void readRoomComplete(asio::ip::tcp::socket &socket, CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:65

References Message::async_readMsg(), clientName, Message::getStr(), inMsg, readRoomComplete(), socket, and Success.

Referenced by readDescription().

Here is the call graph for this function:

◆ readRoomComplete()

void Client::readRoomComplete ( asio::ip::tcp::socket & socket,
CompletionCallback onComplete,
CompletionStatus status )
private

Definition at line 65 of file client.cpp.

68{
70 onComplete(*this, status);
71 return;
72 }
73
74 roomName = std::string(inMsg.getStr());
75 using namespace std::placeholders;
77 std::bind(&Client::readDescComplete, shared_from_this(), onComplete, _1));
78}
void readDescComplete(CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:80

References Message::async_readMsg(), Message::getStr(), inMsg, readDescComplete(), roomName, socket, and Success.

Referenced by readNameComplete().

Here is the call graph for this function:

◆ sendMsg()

void Client::sendMsg ( std::string_view msg)

Definition at line 123 of file client.cpp.

123 {
125 sendQueue.emplace(msg);
126 return;
127 }
128
130 using namespace std::placeholders;
131 outMsg.async_sendMsg(socket, std::bind(&Client::onMsgSent, shared_from_this(), _1));
132}
bool isSendCallbackPending() const
Definition client.cpp:118

References Message::async_sendMsg(), isSendCallbackPending(), onMsgSent(), outMsg, sendQueue, Message::setStr(), and socket.

Referenced by Room::addClient().

Here is the call graph for this function:

Member Data Documentation

◆ candidates

std::vector<std::string> Client::candidates
private

Definition at line 90 of file client.hpp.

Referenced by getCandidates(), and readCandidateComplete().

◆ clientName

std::string Client::clientName
private

Definition at line 87 of file client.hpp.

Referenced by getClientName(), and readNameComplete().

◆ inMsg

◆ outMsg

Message Client::outMsg
private

Definition at line 95 of file client.hpp.

Referenced by isSendCallbackPending(), onMsgSent(), and sendMsg().

◆ roomName

std::string Client::roomName
private

Definition at line 88 of file client.hpp.

Referenced by getRoomName(), and readRoomComplete().

◆ sdpDesc

std::string Client::sdpDesc
private

Definition at line 89 of file client.hpp.

Referenced by getSdpDesc(), and readDescComplete().

◆ sendQueue

std::queue<std::string> Client::sendQueue
private

Definition at line 92 of file client.hpp.

Referenced by isSendCallbackPending(), onMsgSent(), and sendMsg().

◆ socket

asio::ip::tcp::socket Client::socket
private

The documentation for this class was generated from the following files: