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