Twitch SDK (Internal)
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ttv::StandardWebSocket Class Reference

#include <standardwebsocket.h>

Inheritance diagram for ttv::StandardWebSocket:
ttv::IWebSocket

Public Types

enum  MessageType { MessageType::None, MessageType::Binary, MessageType::Text, MessageType::Unknown }
 

Public Member Functions

 StandardWebSocket ()
 
virtual ~StandardWebSocket ()
 
TTV_ErrorCode Initialize (const std::string &uri)
 
virtual TTV_ErrorCode Connect () override
 
virtual TTV_ErrorCode Disconnect () override
 
virtual bool Connected () override
 
virtual TTV_ErrorCode Send (MessageType type, const uint8_t *buffer, size_t length) override
 
virtual TTV_ErrorCode Recv (MessageType &type, uint8_t *buffer, size_t length, size_t &received) override
 
virtual TTV_ErrorCode Peek (MessageType &type, size_t &length) override
 

Private Member Functions

TTV_ErrorCode PollBaseSocket ()
 

Private Attributes

std::unique_ptr< SocketData > mInnerData
 

Member Enumeration Documentation

◆ MessageType

enum ttv::IWebSocket::MessageType
stronginherited

The type of data in a frame.

Enumerator
None 

No data.

Binary 

A binary frame.

Text 

A text frame.

Unknown 

An unknown/unhandled frame type.

Constructor & Destructor Documentation

◆ StandardWebSocket()

ttv::StandardWebSocket::StandardWebSocket ( )

◆ ~StandardWebSocket()

virtual ttv::StandardWebSocket::~StandardWebSocket ( )
virtual

Member Function Documentation

◆ Connect()

virtual TTV_ErrorCode ttv::StandardWebSocket::Connect ( )
overridevirtual

Synchronously connects to the endpoint.

See also
Disconnect
Returns
  • TTV_EC_SUCCESS: The socket has successfully connected and is ready to exchange data.
  • TTV_EC_SOCKET_EALREADY: Already connected.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implements ttv::IWebSocket.

◆ Connected()

virtual bool ttv::StandardWebSocket::Connected ( )
overridevirtual

Determines if the socket is currently connected.

Returns
Whether or not currently connected.

Implements ttv::IWebSocket.

◆ Disconnect()

virtual TTV_ErrorCode ttv::StandardWebSocket::Disconnect ( )
overridevirtual

Synchronously disconnects from the endpoint.

See also
Connect
Returns
  • TTV_EC_SUCCESS: The socket has successfully disconnected.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implements ttv::IWebSocket.

◆ Initialize()

TTV_ErrorCode ttv::StandardWebSocket::Initialize ( const std::string &  uri)

◆ Peek()

virtual TTV_ErrorCode ttv::StandardWebSocket::Peek ( MessageType type,
size_t &  length 
)
overridevirtual

Determines the size and type of the next available message. If no messages are available then a message type of None will be returned.

See also
Recv
Parameters
[out]typeThe buffer to store the received bytes in.
[out]lengthThe number of bytes actually received.
Returns
  • TTV_EC_SUCCESS: Some bytes have been received.
  • TTV_EC_SOCKET_ENOTCONN: The socket is not connected.
  • TTV_EC_SOCKET_ECONNABORTED: The connected was dropped.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ECONNRESET: The connection was closed by the remote host.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implements ttv::IWebSocket.

◆ PollBaseSocket()

TTV_ErrorCode ttv::StandardWebSocket::PollBaseSocket ( )
private

◆ Recv()

virtual TTV_ErrorCode ttv::StandardWebSocket::Recv ( MessageType type,
uint8_t *  buffer,
size_t  length,
size_t &  received 
)
overridevirtual

Attempts to receive a message from the web socket. The next available message will be stored in buffer provided that it is large enough to store it. Use Peek() to determine how large of a buffer to provide. If the buffer is not large enough to hold the message then an error is returned and the message is not consumed.

See also
Peek
Parameters
[out]typeThe buffer to store the received bytes in.
[in]bufferThe buffer to store the received bytes in.
[in]lengthThe largest number of bytes to receive.
[out]receivedThe number of bytes actually received.
Returns
  • TTV_EC_SUCCESS: Some bytes have been received.
  • TTV_EC_SOCKET_ENOTCONN: The socket is not connected.
  • TTV_EC_SOCKET_ECONNABORTED: The connected was dropped.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ECONNRESET: The connection was closed by the remote host.
  • TTV_EC_SOCKET_ERR: A generic error occurred.
  • TTV_EC_INVALID_BUFFER: The given buffer is not big enough to store the next message.

Implements ttv::IWebSocket.

◆ Send()

virtual TTV_ErrorCode ttv::StandardWebSocket::Send ( MessageType  type,
const uint8_t *  buffer,
size_t  length 
)
overridevirtual

Sends a message of the given type.

Parameters
[in]typeThe type of data represented by the buffer.
[in]bufferThe data to send.
[in]lengthThe number of bytes in the buffer.
Returns
  • TTV_EC_SUCCESS: The socket has successfully connected and is ready to exchange data.
  • TTV_EC_SUCCESS: The message has been sent.
  • TTV_EC_SOCKET_ENOTCONN: The socket is not connected.
  • TTV_EC_SOCKET_ECONNABORTED: The connected was dropped.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ECONNRESET: The connection was closed by the remote host.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implements ttv::IWebSocket.

Member Data Documentation

◆ mInnerData

std::unique_ptr<SocketData> ttv::StandardWebSocket::mInnerData
private

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