Babel
Epitech's C++ VoIP project
HomePage.hpp
Go to the documentation of this file.
1 //
2 // Created by cbihan on 14/10/2021.
3 //
4 
5 #pragma once
6 
7 #include "ui/UIHomePage.hpp"
9 #include <QMainWindow>
10 #include <functional>
11 #include <map>
12 #include <QObject>
13 #include "SoundHandler.hpp"
14 
15 namespace Babel
16 {
18  class HomePage : public QObject
19  {
20  Q_OBJECT
21  public:
23  HomePage();
24 
26  ~HomePage() override= default;
27 
30  const uint16_t startUdpPort = 0;
31 
32  private:
34  QMainWindow *_window;
35 
38 
41 
44 
47 
50  void sendHandler(const Message<RFCCodes> &m);
51 
54 
56  void doConnect();
57 
59  void doLogin();
60 
62  void doListUsers();
63 
65  void doCallUser();
66 
68  void doJoinCall(int callId, std::string &address, uint16_t port);
69 
71  void doDenyCall(int callId);
72 
74  void doHangUp();
75 
77  void onLoginResponse(const Message<RFCCodes> &m);
78 
81 
84 
86  void onJoinCall(const Message<RFCCodes> &m);
87 
89  static void onBasicResponse(const Message<RFCCodes> &m);
90 
93 
95  void handleUserJoined(const Message<RFCCodes> &m);
96 
98  void handleUserLeft(const Message<RFCCodes> &m);
99 
102 
104  inline void changeCurrentUITab(QWidget *tab)
105  {
106  this->_ui.tab_handler->setCurrentWidget(tab);
107  };
108 
111  {
113  std::function<void(const Message<RFCCodes> &m)> method;
114  };
115 
118  std::map<RFCCodes, MessageHandler> _messageHandlers;
119 
122  struct UserInfo
123  {
125  std::string address;
127  uint16_t port;
130 
132  explicit UserInfo(bool canBeCalled);
133 
135  explicit UserInfo();
136  };
137 
139  std::map<std::string, UserInfo> _usersInfos;
140 
142  std::list<std::string> _usersInCurrentCall;
143 
145  static constexpr int CurrentlyNotInCall = -1;
146 
150 
153  std::string _address;
154 
157  std::string _username;
158 
159  };
160 }
161 
162 
Babel::HomePage::_connection
QtTCPConnection _connection
tcp connection handler
Definition: HomePage.hpp:40
Babel::HomePage::doDenyCall
void doDenyCall(int callId)
deny a callId
Definition: HomePage.cpp:345
Babel::HomePage::doLogin
void doLogin()
send a login request, look into field inputs for username
Definition: HomePage.cpp:106
Babel::HomePage::onCallUserResponse
void onCallUserResponse(const Message< RFCCodes > &m)
handler for any responses of the callUser request
Definition: HomePage.cpp:237
Babel::HomePage::changeCurrentUITab
void changeCurrentUITab(QWidget *tab)
Change the currently selected tab.
Definition: HomePage.hpp:104
Babel::HomePage::startUdpPort
const uint16_t startUdpPort
The port to receive udp audio packets.
Definition: HomePage.hpp:30
Babel::HomePage::doCallUser
void doCallUser()
Call a specific user look in the list for the selected username.
Definition: HomePage.cpp:215
Babel::HomePage
Main client Class.
Definition: HomePage.hpp:18
Babel::QtTCPConnection
Definition: QtTCPConnection.hpp:17
Babel::HomePage::_usersInfos
std::map< std::string, UserInfo > _usersInfos
Userinfo holder the username is the key.
Definition: HomePage.hpp:139
Babel::HomePage::doHangUp
void doHangUp()
quit a call
Definition: HomePage.cpp:306
SoundHandler.hpp
Babel::HomePage::MessageHandler
All the necessary information to handle a response.
Definition: HomePage.hpp:110
Babel::HomePage::UserInfo::canBeCalled
bool canBeCalled
Tell the client if he can call this user.
Definition: HomePage.hpp:129
Babel::HomePage::sendHandler
void sendHandler(const Message< RFCCodes > &m)
send the message to the server and add it to the message send queue to handle responses type
Definition: HomePage.cpp:162
Babel::HomePage::_requestsMade
TSQueue< RFCCodes > _requestsMade
all the request made by the client (expecting a response)
Definition: HomePage.hpp:43
Babel::HomePage::onMessage
void onMessage(Message< RFCCodes > m)
is used to redirect responses from request to the correct handling functions
Definition: HomePage.cpp:117
UIHomePage.hpp
Babel::HomePage::handleUserLeft
void handleUserLeft(const Message< RFCCodes > &m)
handle user left request
Definition: HomePage.cpp:415
Babel::HomePage::updateDisplaySelectedUser
void updateDisplaySelectedUser()
Update qt interface to display the correct username and infos.
Definition: HomePage.cpp:205
Babel::Message< RFCCodes >
Babel::HomePage::UserInfo::address
std::string address
The udp address to send our voice to this user.
Definition: HomePage.hpp:125
Babel::HomePage::UserInfo
All the necessary information for a user in call or in the display list.
Definition: HomePage.hpp:122
Babel::HomePage::onJoinCall
void onJoinCall(const Message< RFCCodes > &m)
handler for any responses of the joinCall request
Definition: HomePage.cpp:265
Babel::HomePage::HomePage
HomePage()
ctor
Definition: HomePage.cpp:17
Babel::HomePage::handleIncomingCall
void handleIncomingCall(const Message< RFCCodes > &m)
handle incoming call request
Definition: HomePage.cpp:363
Babel::HomePage::_usersInCurrentCall
std::list< std::string > _usersInCurrentCall
a list containing all users in the currentCall
Definition: HomePage.hpp:142
Babel
Definition: IAudioManager.hpp:13
Babel::HomePage::_messageHandlers
std::map< RFCCodes, MessageHandler > _messageHandlers
Used to call the correct handling function.
Definition: HomePage.hpp:118
Babel::HomePage::_ui
Ui::babelHome _ui
The UI Class.
Definition: HomePage.hpp:37
Babel::HomePage::~HomePage
~HomePage() override=default
dtor
Ui_babelHome::tab_handler
QTabWidget * tab_handler
Definition: UIHomePage.hpp:39
Babel::HomePage::handleUserJoined
void handleUserJoined(const Message< RFCCodes > &m)
handle user joined request
Definition: HomePage.cpp:391
Babel::TSQueue< RFCCodes >
Babel::HomePage::doJoinCall
void doJoinCall(int callId, std::string &address, uint16_t port)
join the callId given
Definition: HomePage.cpp:353
Babel::HomePage::_audio
SoundHandler _audio
Audio call manager.
Definition: HomePage.hpp:46
Babel::HomePage::CurrentlyNotInCall
static constexpr int CurrentlyNotInCall
Used to set and verify the _currentCallId if a call is ongoing.
Definition: HomePage.hpp:145
QtTCPConnection.hpp
Babel::HomePage::MessageHandler::method
std::function< void(const Message< RFCCodes > &m)> method
the function to handle the request response type
Definition: HomePage.hpp:113
Babel::HomePage::onLoginResponse
void onLoginResponse(const Message< RFCCodes > &m)
handler for any responses of the login request
Definition: HomePage.cpp:138
Babel::HomePage::UserInfo::port
uint16_t port
The udp port to send our voice to this user.
Definition: HomePage.hpp:127
Babel::HomePage::_address
std::string _address
The local ip.
Definition: HomePage.hpp:153
Babel::SoundHandler
Definition: SoundHandler.hpp:23
Babel::HomePage::UserInfo::UserInfo
UserInfo()
needed ctor without args
Definition: HomePage.cpp:445
Ui::babelHome
Definition: UIHomePage.hpp:267
Babel::HomePage::doListUsers
void doListUsers()
send a listUsers request
Definition: HomePage.cpp:199
Babel::HomePage::onBasicResponse
static void onBasicResponse(const Message< RFCCodes > &m)
handler for any simple responses (opens a dialog if error) otherwise do nothing
Definition: HomePage.cpp:332
Babel::HomePage::_username
std::string _username
The username of the connected user.
Definition: HomePage.hpp:157
Babel::HomePage::_window
QMainWindow * _window
The display window.
Definition: HomePage.hpp:34
Babel::HomePage::_currentCallId
int _currentCallId
handling the callId of the current call (to be able to hang up, ...)
Definition: HomePage.hpp:149
Babel::HomePage::onListUsersResponse
void onListUsersResponse(const Message< RFCCodes > &m)
handler for any responses of the listuser request
Definition: HomePage.cpp:167
Babel::HomePage::doConnect
void doConnect()
Connects to the server with tcp.
Definition: HomePage.cpp:102