@@ -395,7 +395,7 @@ void ApiServer::start() {
395395 }
396396
397397 if (config.use_ws_reverse /* use ws reverse */
398- && ws_reverse_api_client_is_wss_.has_value () /* client successfully initialized */ ) {
398+ && ws_reverse_api_client_is_wss_.has_value () /* successfully initialized */ ) {
399399 ws_reverse_api_client_started_ = true ;
400400 ws_reverse_api_thread_ = thread ([&]() {
401401 if (ws_reverse_api_client_is_wss_.value () == false ) {
@@ -466,28 +466,31 @@ static bool push_ws_reverse_event(const string &server_port_path, const json &pa
466466 return succeeded;
467467}
468468
469- size_t ApiServer::push_event (const json &payload) const {
470- if (!ws_server_started_) {
471- return 0 ;
472- }
473-
474- size_t count = 0 ;
475- for (const auto &connection : ws_server_->get_connections ()) {
476- if (boost::algorithm::starts_with (connection->path , " /event" )) {
477- const auto send_stream = make_shared<WsServer::SendStream>();
478- *send_stream << payload.dump ();
479- connection->send (send_stream);
480- count++;
469+ void ApiServer::push_event (const json &payload) const {
470+ if (ws_server_started_) {
471+ Log::d (TAG, u8" 开始通过 WebSocket 服务端推送事件" );
472+ size_t count = 0 ;
473+ for (const auto &connection : ws_server_->get_connections ()) {
474+ if (boost::algorithm::starts_with (connection->path , " /event" )) {
475+ const auto send_stream = make_shared<WsServer::SendStream>();
476+ *send_stream << payload.dump ();
477+ connection->send (send_stream);
478+ count++;
479+ }
481480 }
481+ Log::d (TAG, u8" 已成功向 " + to_string (count) + u8" 个客户端推送事件" );
482482 }
483483
484- if (ws_reverse_event_client_is_wss_.has_value ()) {
484+ if (config.use_ws_reverse /* use ws reverse */
485+ && ws_reverse_event_client_is_wss_.has_value () /* successfully initialized */ ) {
486+ Log::d (TAG, u8" 开始通过 WebSocket 反向客户端上报事件" );
487+ bool succeeded;
485488 if (ws_reverse_event_client_is_wss_.value () == false ) {
486- push_ws_reverse_event<WsClient>(ws_reverse_event_server_port_path_, payload);
489+ succeeded = push_ws_reverse_event<WsClient>(ws_reverse_event_server_port_path_, payload);
487490 } else {
488- push_ws_reverse_event<WssClient>(ws_reverse_event_server_port_path_, payload);
491+ succeeded = push_ws_reverse_event<WssClient>(ws_reverse_event_server_port_path_, payload);
489492 }
490- }
491493
492- return count;
494+ Log::d (TAG, u8" 通过 WebSocket 反向客户端上报数据到 " + config.ws_reverse_event_url + (succeeded ? u8" 成功" : u8" 失败" ));
495+ }
493496}
0 commit comments