From 85b6c88a6ddd5aa7682b307a553e5a326a1cd0a2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 5 Dec 2023 21:32:06 +0800 Subject: [PATCH] 1 --- server/robotserver/android_agent.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/server/robotserver/android_agent.cc b/server/robotserver/android_agent.cc index 601df608..b1f39c1e 100644 --- a/server/robotserver/android_agent.cc +++ b/server/robotserver/android_agent.cc @@ -122,7 +122,8 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer() std::function old_on_error; std::function old_on_connect; std::function old_on_disconnect; - bool pending = false; + bool pending = true; + bool connect_ok = false; ); context->old_on_error = owner_->GetWebSocket()->on_error; context->old_on_connect = owner_->GetWebSocket()->on_connect; @@ -130,20 +131,38 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer() owner_->GetWebSocket()->on_error = [this, context] (a8::WebSocketClient*, int err_code) { + a8::XPrintf("WebSocketClient on_error:%d\n", {err_code}); + context->pending = false; + context->connect_ok = true; }; owner_->GetWebSocket()->on_connect = [this, context] (a8::WebSocketClient* ) { + a8::XPrintf("WebSocketClient on_connect\n", {}); + context->pending = false; + context->connect_ok = false; }; owner_->GetWebSocket()->on_disconnect = [this, context] (a8::WebSocketClient* ) { + a8::XPrintf("WebSocketClient on_disconnect\n", {}); + context->pending = false; + context->connect_ok = false; }; if (owner_->GetWebSocket()->IsActive()) { owner_->GetWebSocket()->Close(); } owner_->GetWebSocket()->Open(); - return behaviac::BT_SUCCESS; + auto co = std::make_shared(context, co_id, "CoConnectBattleServer"); + co->runing_cb = + [this, context] (BtCoroutine* co) + { + if (context->pending) { + return behaviac::BT_RUNNING; + } + return context->connect_ok ? behaviac::BT_SUCCESS : behaviac::BT_FAILURE; + }; + return StartCoroutine(co); } behaviac::EBTStatus AndroidAgent::CoJoin()