- WebSocket::send() sends message in TEXT mode by default
- WebSocketMessage sets a new binary field, which tells whether the received incoming message is binary or text
This commit is contained in:
parent
a11aa3e0dd
commit
55c65b08bf
@ -1,8 +1,10 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased] - 2019-06-xx
|
||||
## [4.0.0] - 2019-06-09
|
||||
### Changed
|
||||
- WebSocket::send() sends message in TEXT mode by default
|
||||
- WebSocketMessage sets a new binary field, which tells whether the received incoming message is binary or text
|
||||
- WebSocket::send takes a third arg, binary which default to true (can be text too)
|
||||
- WebSocket callback only take one object, a const ix::WebSocketMessagePtr& msg
|
||||
- Add explicite WebSocket::sendBinary
|
||||
|
@ -1 +1 @@
|
||||
3.1.2
|
||||
4.0.0
|
||||
|
@ -325,8 +325,8 @@ namespace ix
|
||||
WebSocketMessageType webSocketMessageType;
|
||||
switch (messageKind)
|
||||
{
|
||||
default:
|
||||
case WebSocketTransport::MessageKind::MSG:
|
||||
case WebSocketTransport::MessageKind::MSG_TEXT:
|
||||
case WebSocketTransport::MessageKind::MSG_BINARY:
|
||||
{
|
||||
webSocketMessageType = WebSocketMessageType::Message;
|
||||
} break;
|
||||
@ -350,11 +350,13 @@ namespace ix
|
||||
WebSocketErrorInfo webSocketErrorInfo;
|
||||
webSocketErrorInfo.decompressionError = decompressionError;
|
||||
|
||||
bool binary = messageKind == WebSocketTransport::MessageKind::MSG_BINARY;
|
||||
|
||||
_onMessageCallback(
|
||||
std::make_shared<WebSocketMessage>(
|
||||
webSocketMessageType, msg, wireSize,
|
||||
webSocketErrorInfo, WebSocketOpenInfo(),
|
||||
WebSocketCloseInfo()));
|
||||
WebSocketCloseInfo(), binary));
|
||||
|
||||
WebSocket::invokeTrafficTrackerCallback(msg.size(), true);
|
||||
});
|
||||
@ -385,8 +387,8 @@ namespace ix
|
||||
}
|
||||
|
||||
WebSocketSendInfo WebSocket::send(const std::string& data,
|
||||
const OnProgressCallback& onProgressCallback,
|
||||
bool binary)
|
||||
bool binary,
|
||||
const OnProgressCallback& onProgressCallback)
|
||||
{
|
||||
return sendMessage(data,
|
||||
(binary) ? SendMessageKind::Binary: SendMessageKind::Text,
|
||||
|
@ -66,8 +66,8 @@ namespace ix
|
||||
|
||||
// send is in binary mode by default
|
||||
WebSocketSendInfo send(const std::string& data,
|
||||
const OnProgressCallback& onProgressCallback = nullptr,
|
||||
bool binary = true);
|
||||
bool binary = false,
|
||||
const OnProgressCallback& onProgressCallback = nullptr);
|
||||
WebSocketSendInfo sendBinary(const std::string& text,
|
||||
const OnProgressCallback& onProgressCallback = nullptr);
|
||||
WebSocketSendInfo sendText(const std::string& text,
|
||||
|
@ -31,13 +31,15 @@ namespace ix
|
||||
size_t w,
|
||||
WebSocketErrorInfo e,
|
||||
WebSocketOpenInfo o,
|
||||
WebSocketCloseInfo c)
|
||||
WebSocketCloseInfo c,
|
||||
bool b = false)
|
||||
: type(t)
|
||||
, str(std::move(s))
|
||||
, wireSize(w)
|
||||
, errorInfo(e)
|
||||
, openInfo(o)
|
||||
, closeInfo(c)
|
||||
, binary(b)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
@ -542,12 +542,17 @@ namespace ix
|
||||
) {
|
||||
unmaskReceiveBuffer(ws);
|
||||
|
||||
MessageKind messageKind =
|
||||
(ws.opcode == wsheader_type::TEXT_FRAME)
|
||||
? MessageKind::MSG_TEXT
|
||||
: MessageKind::MSG_BINARY;
|
||||
|
||||
//
|
||||
// Usual case. Small unfragmented messages
|
||||
//
|
||||
if (ws.fin && _chunks.empty())
|
||||
{
|
||||
emitMessage(MessageKind::MSG,
|
||||
emitMessage(messageKind,
|
||||
std::string(_rxbuf.begin()+ws.header_size,
|
||||
_rxbuf.begin()+ws.header_size+(size_t) ws.N),
|
||||
ws,
|
||||
@ -567,7 +572,7 @@ namespace ix
|
||||
_rxbuf.begin()+ws.header_size+(size_t)ws.N));
|
||||
if (ws.fin)
|
||||
{
|
||||
emitMessage(MessageKind::MSG, getMergedChunks(), ws, onMessageCallback);
|
||||
emitMessage(messageKind, getMergedChunks(), ws, onMessageCallback);
|
||||
_chunks.clear();
|
||||
}
|
||||
else
|
||||
|
@ -50,7 +50,8 @@ namespace ix
|
||||
|
||||
enum class MessageKind
|
||||
{
|
||||
MSG,
|
||||
MSG_TEXT,
|
||||
MSG_BINARY,
|
||||
PING,
|
||||
PONG,
|
||||
FRAGMENT
|
||||
|
@ -200,7 +200,7 @@ namespace ix
|
||||
{
|
||||
if (client != webSocket)
|
||||
{
|
||||
client->send(msg->str);
|
||||
client->send(msg->str, msg->binary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ namespace ix
|
||||
if (client != webSocket)
|
||||
{
|
||||
client->send(msg->str,
|
||||
msg->binary,
|
||||
[](int current, int total) -> bool
|
||||
{
|
||||
std::cerr << "Step " << current
|
||||
|
@ -59,7 +59,7 @@ namespace ix
|
||||
std::cerr << "Received "
|
||||
<< msg->wireSize << " bytes"
|
||||
<< std::endl;
|
||||
webSocket->send(msg->str);
|
||||
webSocket->send(msg->str, msg->binary);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -62,6 +62,7 @@ namespace ix
|
||||
if (client != webSocket)
|
||||
{
|
||||
client->send(msg->str,
|
||||
msg->binary,
|
||||
[](int current, int total) -> bool
|
||||
{
|
||||
std::cerr << "ws_transfer: Step " << current
|
||||
|
Loading…
Reference in New Issue
Block a user