Skip to content
This repository was archived by the owner on Aug 2, 2020. It is now read-only.

Commit b67895e

Browse files
committed
Allow to echo something in WebSocket API call
1 parent afaf769 commit b67895e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/service/impl/service_impl_common.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ static void ws_api_on_message(std::shared_ptr<typename WsT::Connection> connecti
6565

6666
ApiResult result;
6767

68-
auto send_result = [&connection, &result]() {
69-
auto resp_body = result.json().dump();
68+
auto send_result = [&connection, &result](const json &echo = nullptr) {
69+
auto resp_json = result.json();
70+
if (!echo.is_null()) {
71+
resp_json["echo"] = echo;
72+
}
73+
auto resp_body = resp_json.dump();
7074
Log::d(TAG, u8"响应数据已准备完毕:" + resp_body);
7175
auto send_stream = std::make_shared<typename WsT::SendStream>();
7276
*send_stream << resp_body;
@@ -103,5 +107,10 @@ static void ws_api_on_message(std::shared_ptr<typename WsT::Connection> connecti
103107
result.retcode = ApiResult::RetCodes::HTTP_NOT_FOUND;
104108
}
105109

106-
send_result();
110+
json echo;
111+
try {
112+
echo = payload.at("echo");
113+
} catch (...) {}
114+
115+
send_result(echo);
107116
}

0 commit comments

Comments
 (0)