Overte C++ Documentation
WebRTCSocket Class Reference

Provides a QUdpSocket-style interface for using WebRTCDataChannels. More...

#include <WebRTCSocket.h>

Inherits QObject.

Public Slots

void onDataChannelReceivedMessage (const SockAddr &source, const QByteArray &message)
 Handles the WebRTC data channel receiving a message. More...
 

Signals

void stateChanged (QAbstractSocket::SocketState socketState)
 Emitted when the state of the socket changes. More...
 
void readyRead ()
 Emitted each time new data becomes available for reading.
 
void onSignalingMessage (const QJsonObject &json)
 Emitted when a WebRTC signaling message has been received from the signaling server for this WebRTCSocket. More...
 
void sendSignalingMessage (const QJsonObject &message)
 Emitted when there's a WebRTC signaling message to send via the signaling server. More...
 

Public Member Functions

 WebRTCSocket (QObject *parent)
 Constructs a new WebRTCSocket object. More...
 
void setSocketOption (QAbstractSocket::SocketOption option, const QVariant &value)
 Nominally sets the value of a socket option. More...
 
QVariant socketOption (QAbstractSocket::SocketOption option)
 Nominally gets the value of a socket option. More...
 
bool bind (const QHostAddress &address, quint16 port=0, QAbstractSocket::BindMode mode=QAbstractSocket::DefaultForPlatform)
 Nominally binds the WebRTC socket to an address and port. More...
 
QAbstractSocket::SocketState state () const
 Gets the state of the socket. More...
 
void abort ()
 Immediately closes all connections and resets the socket.
 
quint16 localPort () const
 Nominally gets the host port number. Included for compatibility with the QUdpSocket interface. More...
 
qintptr socketDescriptor () const
 Nominally gets the socket descriptor. Included for compatibility with the QUdpSocket interface. More...
 
qint64 writeDatagram (const QByteArray &datagram, const SockAddr &destination)
 Sends a datagram. More...
 
qint64 bytesToWrite (const SockAddr &destination) const
 Gets the number of bytes waiting to be written. More...
 
bool hasPendingDatagrams () const
 Gets whether there's a datagram waiting to be read. More...
 
qint64 pendingDatagramSize () const
 Gets the size of the first pending datagram. More...
 
qint64 readDatagram (char *data, qint64 maxSize, QHostAddress *address=nullptr, quint16 *port=nullptr)
 Reads the next datagram, up to a maximum number of bytes. More...
 
QAbstractSocket::SocketError error () const
 Gets the type of error that last occurred. More...
 
QString errorString () const
 Gets the description of the error that last occurred. More...
 

Detailed Description

Provides a QUdpSocket-style interface for using WebRTCDataChannels.

A WebRTC data channel is identified by the IP address and port of the client WebSocket that was used when opening the data channel - this is considered to be the WebRTC data channel's address. The IP address and port of the actual WebRTC connection is not used.

Constructor & Destructor Documentation

◆ WebRTCSocket()

WebRTCSocket::WebRTCSocket ( QObject *  parent)

Constructs a new WebRTCSocket object.

Parameters
parentQt parent object.

Member Function Documentation

◆ bind()

bool WebRTCSocket::bind ( const QHostAddress &  address,
quint16  port = 0,
QAbstractSocket::BindMode  mode = QAbstractSocket::DefaultForPlatform 
)

Nominally binds the WebRTC socket to an address and port.

WebRTC data connections aren't actually bound to an address or port. Their ports are negotiated as part of the WebRTC peer connection process. Included for compatibility with the QUdpSocket interface.

Parameters
addressThe address.
portThe port.
modeThe bind mode.
Returns
true.

◆ bytesToWrite()

qint64 WebRTCSocket::bytesToWrite ( const SockAddr &  destination) const

Gets the number of bytes waiting to be written.

Parameters
destinationThe destination WebRTC data channel address.
Returns
The number of bytes waiting to be written.

◆ error()

QAbstractSocket::SocketError WebRTCSocket::error ( ) const

Gets the type of error that last occurred.

Returns
The type of error that last occurred.

◆ errorString()

QString WebRTCSocket::errorString ( ) const

Gets the description of the error that last occurred.

Returns
The description of the error that last occurred.

◆ hasPendingDatagrams()

bool WebRTCSocket::hasPendingDatagrams ( ) const

Gets whether there's a datagram waiting to be read.

Returns
true if there's a datagram waiting to be read, false if there isn't.

◆ localPort()

quint16 WebRTCSocket::localPort ( ) const
inline

Nominally gets the host port number. Included for compatibility with the QUdpSocket interface.

Returns
0

◆ onDataChannelReceivedMessage

void WebRTCSocket::onDataChannelReceivedMessage ( const SockAddr &  source,
const QByteArray &  message 
)
slot

Handles the WebRTC data channel receiving a message.

Queues the message to be read via readDatagram.

Parameters
sourceThe WebRTC data channel that the message was received on.
messageThe message that was received.

◆ onSignalingMessage

void WebRTCSocket::onSignalingMessage ( const QJsonObject &  json)
signal

Emitted when a WebRTC signaling message has been received from the signaling server for this WebRTCSocket.

Parameters
jsonThe signaling message.

◆ pendingDatagramSize()

qint64 WebRTCSocket::pendingDatagramSize ( ) const

Gets the size of the first pending datagram.

Returns
the size of the first pending datagram; -1 if there is no pending datagram.

◆ readDatagram()

qint64 WebRTCSocket::readDatagram ( char *  data,
qint64  maxSize,
QHostAddress *  address = nullptr,
quint16 *  port = nullptr 
)

Reads the next datagram, up to a maximum number of bytes.

Any remaining data in the datagram is lost.

Parameters
dataThe destination to read the datagram into.
maxSizeThe maximum number of bytes to read.
addressThe destination to put the WebRTC data channel's IP address.
portThe destination to put the WebRTC data channel's port.
Returns
The number of bytes read on success; -1 if reading unsuccessful.

◆ sendSignalingMessage

void WebRTCSocket::sendSignalingMessage ( const QJsonObject &  message)
signal

Emitted when there's a WebRTC signaling message to send via the signaling server.

Parameters
jsonThe signaling message.

◆ setSocketOption()

void WebRTCSocket::setSocketOption ( QAbstractSocket::SocketOption  option,
const QVariant &  value 
)

Nominally sets the value of a socket option.

Only SendBufferSizeSocketOption and ReceiveBufferSizeSocketOption options are handled and for these no action is taken because these buffer sizes are not configurable in WebRTC. Included for compatibility with the QUdpSocket interface.

Parameters
optionThe socket option.
valueThe value of the socket option.

◆ socketDescriptor()

qintptr WebRTCSocket::socketDescriptor ( ) const
inline

Nominally gets the socket descriptor. Included for compatibility with the QUdpSocket interface.

Returns
-1

◆ socketOption()

QVariant WebRTCSocket::socketOption ( QAbstractSocket::SocketOption  option)

Nominally gets the value of a socket option.

Only SendBufferSizeSocketOption and ReceiveBufferSizeSocketOption options are handled and for these only default values are returned because these buffer sizes are not configurable in WebRTC. Included for compatibility with the QUdpSocket interface.

Parameters
optionThe socket option.
Returns
The value of the socket option.

◆ state()

QAbstractSocket::SocketState WebRTCSocket::state ( ) const

Gets the state of the socket.

In particular, QAbstractSocket::BoundState is returned if the socket is bound, QAbstractSocket::UnconnectedState if it isn't.

Returns
The state of the socket.

◆ stateChanged

void WebRTCSocket::stateChanged ( QAbstractSocket::SocketState  socketState)
signal

Emitted when the state of the socket changes.

Parameters
socketStateThe new state of the socket.

◆ writeDatagram()

qint64 WebRTCSocket::writeDatagram ( const QByteArray &  datagram,
const SockAddr &  destination 
)

Sends a datagram.

Parameters
datagramThe datagram to send.
destinationThe destination WebRTC data channel address.
Returns
The number of bytes if successfully sent, otherwise -1.

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