9 #ifndef overte_WebRTCDataChannels_h
10 #define overte_WebRTCDataChannels_h
12 #include <shared/WebRTC.h>
14 #if defined(WEBRTC_DATA_CHANNELS)
21 #include <api/peer_connection_interface.h>
24 #include "../NodeType.h"
25 #include "../SockAddr.h"
43 void OnFailure(webrtc::RTCError error)
override;
57 void OnSuccess(webrtc::SessionDescriptionInterface* desc)
override;
61 void OnFailure(webrtc::RTCError error)
override;
78 void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState newState)
override;
89 void OnIceCandidate(
const webrtc::IceCandidateInterface* candidate)
override;
93 virtual void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState newState)
override;
101 void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> dataChannel)
override;
105 void OnConnectionChange(webrtc::PeerConnectionInterface::PeerConnectionState newState)
override;
125 void OnMessage(
const webrtc::DataBuffer& buffer)
override;
157 void sendAnswer(webrtc::SessionDescriptionInterface* description);
202 QString _dataChannelID;
204 rtc::scoped_refptr<WDCSetSessionDescriptionObserver> _setSessionDescriptionObserver {
nullptr };
205 rtc::scoped_refptr<WDCCreateSessionDescriptionObserver> _createSessionDescriptionObserver {
nullptr };
207 std::shared_ptr<WDCDataChannelObserver> _dataChannelObserver {
nullptr };
208 rtc::scoped_refptr<webrtc::DataChannelInterface> _dataChannel {
nullptr };
210 std::shared_ptr<WDCPeerConnectionObserver> _peerConnectionObserver {
nullptr };
211 rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection {
nullptr };
263 void emitDataMessage(
const QString& dataChannelID,
const QByteArray& byteArray);
269 bool sendDataMessage(
const SockAddr& destination,
const QByteArray& message);
280 const std::shared_ptr<WDCPeerConnectionObserver> peerConnectionObserver);
311 void dataMessage(
const SockAddr& address,
const QByteArray& byteArray);
322 NodeType_t _nodeType { NodeType::Unassigned };
324 std::unique_ptr<rtc::Thread> _rtcNetworkThread {
nullptr };
325 std::unique_ptr<rtc::Thread> _rtcWorkerThread {
nullptr };
326 std::unique_ptr<rtc::Thread> _rtcSignalingThread {
nullptr };
328 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> _peerConnectionFactory {
nullptr };
330 QHash<QString, WDCConnection*> _connectionsByID;
quint8 NodeType_t
An 8-bit value identifying the type of a node - domain server, audio mixer, etc.
Definition: NodeType.h:22
A WebRTC data channel connection.
Definition: WebRTCDataChannels.h:134
void closePeerConnection()
Closes the WebRTC peer connection.
Definition: WebRTCDataChannels.cpp:422
void addIceCandidate(QJsonObject &data)
Adds an ICE candidate received from the remote client via the signaling channel.
Definition: WebRTCDataChannels.cpp:265
void setRemoteDescription(QJsonObject &description)
Sets the remote session description received from the remote client via the signaling channel.
Definition: WebRTCDataChannels.cpp:204
void onDataChannelStateChanged()
Handles a change in the state of the WebRTC data channel.
Definition: WebRTCDataChannels.cpp:351
void setLocalDescription(webrtc::SessionDescriptionInterface *description)
Sets the local session description on the WebRTC data channel being connected.
Definition: WebRTCDataChannels.cpp:257
QString getDataChannelID() const
Gets the data channel ID.
Definition: WebRTCDataChannels.h:145
void sendIceCandidate(const webrtc::IceCandidateInterface *candidate)
Sends an ICE candidate to the remote client via the signaling channel.
Definition: WebRTCDataChannels.cpp:288
WDCConnection(WebRTCDataChannels *parent, const QString &dataChannelID)
Constructs a new WDCConnection and opens a WebRTC data connection.
Definition: WebRTCDataChannels.cpp:186
void onDataChannelMessageReceived(const webrtc::DataBuffer &buffer)
Handles a message being received on the WebRTC data channel.
Definition: WebRTCDataChannels.cpp:368
void createAnswer()
Creates an answer to an offer received from the remote client via the signaling channel.
Definition: WebRTCDataChannels.cpp:226
qint64 getBufferedAmount() const
Gets the number of bytes waiting to be sent on the WebRTC data channel.
Definition: WebRTCDataChannels.cpp:393
bool sendDataMessage(const webrtc::DataBuffer &buffer)
Sends a message on the WebRTC data channel.
Definition: WebRTCDataChannels.cpp:402
void onDataChannelOpened(rtc::scoped_refptr< webrtc::DataChannelInterface > dataChannel)
Handles the WebRTC data channel being opened.
Definition: WebRTCDataChannels.cpp:329
void sendAnswer(webrtc::SessionDescriptionInterface *description)
Sends an answer to the remote client via the signaling channel.
Definition: WebRTCDataChannels.cpp:234
void onPeerConnectionStateChanged(webrtc::PeerConnectionInterface::PeerConnectionState state)
Monitors the peer connection state.
Definition: WebRTCDataChannels.cpp:315
A WebRTC create session description observer.
Definition: WebRTCDataChannels.h:48
void OnSuccess(webrtc::SessionDescriptionInterface *desc) override
The call to CreateAnswer succeeded.
Definition: WebRTCDataChannels.cpp:53
void OnFailure(webrtc::RTCError error) override
The call to CreateAnswer failed.
Definition: WebRTCDataChannels.cpp:61
WDCCreateSessionDescriptionObserver(WDCConnection *parent)
Constructs a session description observer.
Definition: WebRTCDataChannels.cpp:49
A WebRTC data channel observer.
Definition: WebRTCDataChannels.h:113
void OnStateChange() override
The data channel state changed.
Definition: WebRTCDataChannels.cpp:171
void OnMessage(const webrtc::DataBuffer &buffer) override
A data channel message was received.
Definition: WebRTCDataChannels.cpp:178
WDCDataChannelObserver(WDCConnection *parent)
Constructs a data channel observer.
Definition: WebRTCDataChannels.cpp:167
A WebRTC peer connection observer.
Definition: WebRTCDataChannels.h:69
void OnRenegotiationNeeded() override
Called when renegotiation is needed. For example, an ICE restart has begun.
Definition: WebRTCDataChannels.cpp:86
void OnDataChannel(rtc::scoped_refptr< webrtc::DataChannelInterface > dataChannel) override
Called when a remote peer opens a data channel.
Definition: WebRTCDataChannels.cpp:143
void OnConnectionChange(webrtc::PeerConnectionInterface::PeerConnectionState newState) override
Called when the peer connection state changes.
Definition: WebRTCDataChannels.cpp:150
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState newState) override
Called when the ICE gather state changes.
Definition: WebRTCDataChannels.cpp:92
virtual void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState newState) override
Called when the legacy ICE connection state changes.
Definition: WebRTCDataChannels.cpp:110
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState newState) override
Called when the SignalingState changes.
Definition: WebRTCDataChannels.cpp:72
virtual void OnStandardizedIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState newState) override
Called when the standards-compliant ICE connection state changes.
Definition: WebRTCDataChannels.cpp:126
void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override
Called when a new ICE candidate has been gathered.
Definition: WebRTCDataChannels.cpp:103
WDCPeerConnectionObserver(WDCConnection *parent)
Constructs a peer connection observer.
Definition: WebRTCDataChannels.cpp:68
A WebRTC session description observer.
Definition: WebRTCDataChannels.h:35
void OnSuccess() override
The call to SetLocalDescription or SetRemoteDescription succeeded.
Definition: WebRTCDataChannels.cpp:36
void OnFailure(webrtc::RTCError error) override
The call to SetLocalDescription or SetRemoteDescription failed.
Definition: WebRTCDataChannels.cpp:42
Manages WebRTC data channels on the domain server or an assignment client that Interface clients can ...
Definition: WebRTCDataChannels.h:230
void closePeerConnection(WDCConnection *connection)
Initiates closing the peer connection for a WebRTC data channel.
Definition: WebRTCDataChannels.cpp:624
void sendSignalingMessage(const QJsonObject &message)
Emits a signalingMessage to be sent to the Interface client.
Definition: WebRTCDataChannels.cpp:550
rtc::scoped_refptr< webrtc::PeerConnectionInterface > createPeerConnection(const std::shared_ptr< WDCPeerConnectionObserver > peerConnectionObserver)
Creates a new WebRTC peer connection for connecting to an Interface client.
Definition: WebRTCDataChannels.cpp:599
NodeType_t getNodeType()
Gets the type of node that the WebRTCDataChannels object is being used in.
Definition: WebRTCDataChannels.h:244
void onDataChannelOpened(WDCConnection *connection, const QString &dataChannelID)
Handles a WebRTC data channel opening.
Definition: WebRTCDataChannels.cpp:493
bool sendDataMessage(const SockAddr &destination, const QByteArray &message)
Sends a data message to an Interface client.
Definition: WebRTCDataChannels.cpp:571
WebRTCDataChannels(QObject *parent)
Constructs a new WebRTCDataChannels object.
Definition: WebRTCDataChannels.cpp:435
void signalingMessage(const QJsonObject &message)
A WebRTC signaling message to be sent to the Interface client.
~WebRTCDataChannels()
Destroys a WebRTCDataChannels object.
Definition: WebRTCDataChannels.cpp:467
void emitDataMessage(const QString &dataChannelID, const QByteArray &byteArray)
Emits a dataMessage received from the Interface client.
Definition: WebRTCDataChannels.cpp:557
qint64 getBufferedAmount(const SockAddr &address) const
Gets the number of bytes waiting to be sent on a data channel.
Definition: WebRTCDataChannels.cpp:587
void closePeerConnectionSoon(WDCConnection *connection)
Signals that the peer connection for a WebRTC data channel should be closed.
void dataMessage(const SockAddr &address, const QByteArray &byteArray)
A WebRTC data message received from the Interface client.
void closePeerConnectionNow(WDCConnection *connection)
Closes the peer connection for a WebRTC data channel.
Definition: WebRTCDataChannels.cpp:635
void onSignalingMessage(const QJsonObject &message)
Handles a WebRTC signaling message received from the Interface client.
Definition: WebRTCDataChannels.cpp:500
void reset()
Immediately closes all connections and resets the socket.
Definition: WebRTCDataChannels.cpp:481