Twitch SDK (Internal)
Public Types | Public Member Functions | List of all members
ttv::IWebSocket Class Referenceabstract

#include <socket.h>

Inheritance diagram for ttv::IWebSocket:
ttv::binding::java::JavaWebSocket ttv::StandardWebSocket

Public Types

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

Public Member Functions

virtual ~IWebSocket ()=default
 
virtual TTV_ErrorCode Connect ()=0
 
virtual TTV_ErrorCode Disconnect ()=0
 
virtual TTV_ErrorCode Send (MessageType type, const uint8_t *buffer, size_t length)=0
 
virtual TTV_ErrorCode Recv (MessageType &type, uint8_t *buffer, size_t length, size_t &received)=0
 
virtual TTV_ErrorCode Peek (MessageType &type, size_t &length)=0
 
virtual bool Connected ()=0
 

Detailed Description

This interface provides generic, synchronous access to a web socket (ws protocol). An instance of IWebSocket is generally bound to a single endpoint. The connection can be opened and closed as many times as desired but it can't be changed to point to another peer.

Member Enumeration Documentation

◆ MessageType

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

◆ ~IWebSocket()

virtual ttv::IWebSocket::~IWebSocket ( )
virtualdefault

Destructor.

Member Function Documentation

◆ Connect()

virtual TTV_ErrorCode ttv::IWebSocket::Connect ( )
pure virtual

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.

Implemented in ttv::binding::java::JavaWebSocket, and ttv::StandardWebSocket.

◆ Connected()

virtual bool ttv::IWebSocket::Connected ( )
pure virtual

Determines if the socket is currently connected.

Returns
Whether or not currently connected.

Implemented in ttv::binding::java::JavaWebSocket, and ttv::StandardWebSocket.

◆ Disconnect()

virtual TTV_ErrorCode ttv::IWebSocket::Disconnect ( )
pure virtual

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.

Implemented in ttv::binding::java::JavaWebSocket, and ttv::StandardWebSocket.

◆ Peek()

virtual TTV_ErrorCode ttv::IWebSocket::Peek ( MessageType type,
size_t &  length 
)
pure virtual

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.

Implemented in ttv::binding::java::JavaWebSocket, and ttv::StandardWebSocket.

◆ Recv()

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

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.

Implemented in ttv::binding::java::JavaWebSocket, and ttv::StandardWebSocket.

◆ Send()

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

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.

Implemented in ttv::binding::java::JavaWebSocket, and ttv::StandardWebSocket.


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