Overte C++ Documentation
WebRTCSignalingServer.h
1 //
2 // WebRTCSignalingServer.h
3 // libraries/networking/src/webrtc
4 //
5 // Created by David Rowe on 16 May 2021.
6 // Copyright 2021 Vircadia contributors.
7 //
8 
9 #ifndef overte_WebRTCSignalingServer_h
10 #define overte_WebRTCSignalingServer_h
11 
12 #include <shared/WebRTC.h>
13 
14 #if defined(WEBRTC_DATA_CHANNELS)
15 
16 #include <QObject>
17 #include <QtCore/QTimer>
18 #include <QWebSocketServer>
19 
20 #include "../SockAddr.h"
21 
24 
57 class WebRTCSignalingServer : public QObject {
58  Q_OBJECT
59 
60 public:
61 
65  WebRTCSignalingServer(QObject* parent, bool isWSSEnabled);
66 
71  bool bind(const QHostAddress& address, quint16 port);
72 
73 public slots:
74 
78  void sendMessage(const QJsonObject& message);
79 
80 signals:
81 
86  void messageReceived(const QJsonObject& message);
87 
88 private slots:
89 
90  void newWebSocketConnection();
91  void webSocketTextMessageReceived(const QString& message);
92  void webSocketDisconnected();
93 
94 private:
95 
96  void checkWebSocketServerIsListening();
97 
98  QWebSocketServer* _webSocketServer;
99  QHostAddress _address;
100  quint16 _port { 0 };
101 
102  QHash<QString, QWebSocket*> _webSockets; // <client WebSocket IP address and port, client connection WebSocket object>
103  // The WebSocket IP address and port is formatted as "n.n.n.n:n".
104  // A QString is used rather than a SockAddr, to make signaling easier.
105 
106  QTimer* _isWebSocketServerListeningTimer;
107 };
108 
110 
111 #endif // WEBRTC_DATA_CHANNELS
112 
113 #endif // overte_WebRTCSignalingServer_h
Provides a WebRTC signaling server that Interface clients can use to initiate WebRTC connections to t...
Definition: WebRTCSignalingServer.h:57
void messageReceived(const QJsonObject &message)
A WebRTC signaling channel message was received from an Interface client.
void sendMessage(const QJsonObject &message)
Send a WebRTC signaling channel message to an Interface client.
Definition: WebRTCSignalingServer.cpp:121
WebRTCSignalingServer(QObject *parent, bool isWSSEnabled)
Constructs a new WebRTCSignalingServer object.
Definition: WebRTCSignalingServer.cpp:26
bool bind(const QHostAddress &address, quint16 port)
Binds the WebRTC signaling server's WebSocket to an address and port.
Definition: WebRTCSignalingServer.cpp:81