#include "WebsocketHandler.hpp"
namespace httpsserver {
/**
* @brief Dump the content of the WebSocket frame for debugging.
* @param [in] frame The frame to dump.
*/
static void dumpFrame(WebsocketFrame frame) {
std::ostringstream oss;
oss writeBuffer((uint8_t *)&frame, sizeof(frame));
uint16_t net_len = htons((uint16_t)data.length());
_con->writeBuffer((uint8_t *)&net_len, sizeof(uint16_t)); // Convert to network byte order from host byte order
}
_con->writeBuffer((uint8_t*)data.data(), data.length());
HTTPS_DLOG("[ ] > Websocket.send: Length: ", length);
WebsocketFrame frame;
frame.fin = 1;
frame.rsv1 = 0;
frame.rsv2 = 0;
frame.rsv3 = 0;
frame.opCode = sendType==SEND_TYPE_TEXT?OPCODE_TEXT:OPCODE_BINARY;
frame.mask = 0;
if (length < 126) {
frame.len = length;
_con->writeBuffer((uint8_t *)&frame, sizeof(frame));
} else {
frame.len = 126;
_con->writeBuffer((uint8_t *)&frame, sizeof(frame));
uint16_t net_len = htons(length);
_con->writeBuffer((uint8_t *) net_len, sizeof(uint16_t)); // Convert to network byte order from host byte order
}
_con->writeBuffer(data, length);
HTTPS_DLOG("[ ]