10 #define CPPSERVER_WS_H
15 #include "system/uuid.h"
80 void PrepareSendFrame(uint8_t opcode,
bool mask,
const void* buffer,
size_t size,
int status = 0);
147 virtual void onWSClose(
const void* buffer,
size_t size,
int status = 1000) {}
153 virtual void onWSPing(
const void* buffer,
size_t size) {}
159 virtual void onWSPong(
const void* buffer,
size_t size) {}
size_t _ws_payload_size
Received frame payload size.
static const uint8_t WS_CLOSE
Close frame.
void PrepareSendFrame(uint8_t opcode, bool mask, const void *buffer, size_t size, int status=0)
Prepare WebSocket send frame.
static const uint8_t WS_TEXT
Text frame.
std::vector< uint8_t > _ws_receive_frame_buffer
Receive frame buffer.
WebSocket & operator=(const WebSocket &)=delete
virtual void onWSClose(const void *buffer, size_t size, int status=1000)
Handle WebSocket client close notification.
bool _ws_frame_received
Received frame flag.
static const uint8_t WS_BINARY
Binary frame.
std::string_view ws_nonce() const noexcept
Get the WebSocket random nonce.
WebSocket(const WebSocket &)=delete
static const uint8_t WS_PING
Ping frame.
void InitWSNonce()
Initialize WebSocket random nonce.
void PrepareReceiveFrame(const void *buffer, size_t size)
Prepare WebSocket receive frame.
virtual void onWSConnecting(HTTP::HTTPRequest &request)
Handle WebSocket client connecting notification.
virtual void onWSReceived(const void *buffer, size_t size)
Handle WebSocket received notification.
static const uint8_t WS_FIN
Final frame.
virtual void onWSPing(const void *buffer, size_t size)
Handle WebSocket ping notification.
std::vector< uint8_t > _ws_receive_final_buffer
Receive final buffer.
uint8_t _ws_receive_mask[4]
Receive mask.
std::array< uint8_t, 16 > _ws_nonce
WebSocket random nonce of 16 bytes.
bool PerformClientUpgrade(const HTTP::HTTPResponse &response, const CppCommon::UUID &id)
Perform WebSocket client upgrade.
std::mutex _ws_send_lock
Send buffer lock.
virtual void onWSConnected(const HTTP::HTTPRequest &request)
Handle WebSocket server session connected notification.
WebSocket(WebSocket &&)=delete
virtual void onWSConnected(const HTTP::HTTPResponse &response)
Handle WebSocket client connected notification.
uint8_t _ws_opcode
Received frame opcode.
void ClearWSBuffers()
Clear WebSocket send/receive buffers.
virtual void onWSPong(const void *buffer, size_t size)
Handle WebSocket pong notification.
static const uint8_t WS_PONG
Pong frame.
virtual void onWSError(const std::string &message)
Handle WebSocket error notification.
size_t RequiredReceiveFrameSize()
Required WebSocket receive frame size.
std::vector< uint8_t > _ws_send_buffer
Send buffer.
WebSocket & operator=(WebSocket &&)=delete
uint8_t _ws_send_mask[4]
Send mask.
virtual void SendResponse(const HTTP::HTTPResponse &response)
Send WebSocket server upgrade response.
bool _ws_final_received
Received final flag.
virtual bool onWSConnecting(const HTTP::HTTPRequest &request, HTTP::HTTPResponse &response)
Handle WebSocket server session validating notification.
size_t _ws_header_size
Received frame header size.
virtual void onWSDisconnected()
Handle WebSocket client disconnected notification.
bool PerformServerUpgrade(const HTTP::HTTPRequest &request, HTTP::HTTPResponse &response)
Perform WebSocket server upgrade.
bool _ws_handshaked
Handshaked flag.
HTTP response definition.
C++ Server project definitions.