From 38970add900a314e84386fc99b6a82907db0ce0d Mon Sep 17 00:00:00 2001 From: jiangkui Date: Mon, 6 Jan 2025 16:19:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0socket.io-client-cpp?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangkui --- socketio/library/src/main/cpp/socket.io-client-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socketio/library/src/main/cpp/socket.io-client-cpp b/socketio/library/src/main/cpp/socket.io-client-cpp index 8e1f1a3a..a2197d63 160000 --- a/socketio/library/src/main/cpp/socket.io-client-cpp +++ b/socketio/library/src/main/cpp/socket.io-client-cpp @@ -1 +1 @@ -Subproject commit 8e1f1a3ad224240bb1a09692990e35a3dc04f3cd +Subproject commit a2197d638a338e65521fd310e5d50ac4e5c83fcc -- Gitee From a2a181b8b0595ddcf9df3b893627ef43fb9cc76c Mon Sep 17 00:00:00 2001 From: jiangkui Date: Mon, 6 Jan 2025 17:11:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0disconnect=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BA=8B=E4=BB=B6=E5=8F=8A=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E7=8A=B6=E6=80=81status=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangkui --- .../library/src/main/cpp/native-bridge.cpp | 1 + .../library/src/main/cpp/socket.io-client-cpp | 2 +- .../src/main/cpp/socketio_module_napi.cpp | 19 +++++++++++++++++++ .../src/main/cpp/socketio_module_napi.h | 1 + .../src/main/cpp/types/libentry/index.d.ts | 2 ++ .../library/src/main/ets/client_socket.ets | 4 ++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/socketio/library/src/main/cpp/native-bridge.cpp b/socketio/library/src/main/cpp/native-bridge.cpp index 35a5d7c9..75e778a3 100644 --- a/socketio/library/src/main/cpp/native-bridge.cpp +++ b/socketio/library/src/main/cpp/native-bridge.cpp @@ -63,6 +63,7 @@ static napi_property_descriptor classProp[] = { {"off_error", nullptr, SocketIOClient::off_error, nullptr, nullptr, nullptr, napi_default, nullptr}, {"emit", nullptr, SocketIOClient::emit, nullptr, nullptr, nullptr, napi_default, nullptr}, {"emitAckBinary", nullptr, SocketIOClient::emitAckBinary, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"get_current_state",nullptr, SocketIOClient::get_current_state, nullptr, nullptr, nullptr, napi_default, nullptr} }; static napi_value Init(napi_env env, napi_value exports) diff --git a/socketio/library/src/main/cpp/socket.io-client-cpp b/socketio/library/src/main/cpp/socket.io-client-cpp index a2197d63..0df3d7c7 160000 --- a/socketio/library/src/main/cpp/socket.io-client-cpp +++ b/socketio/library/src/main/cpp/socket.io-client-cpp @@ -1 +1 @@ -Subproject commit a2197d638a338e65521fd310e5d50ac4e5c83fcc +Subproject commit 0df3d7c79c92132cc178bd8e8847035bac04aba5 diff --git a/socketio/library/src/main/cpp/socketio_module_napi.cpp b/socketio/library/src/main/cpp/socketio_module_napi.cpp index d709087f..3bb15459 100644 --- a/socketio/library/src/main/cpp/socketio_module_napi.cpp +++ b/socketio/library/src/main/cpp/socketio_module_napi.cpp @@ -683,6 +683,25 @@ napi_value SocketIOClient::set_reconnect_listener(napi_env env, napi_callback_in std::placeholders::_1, std::placeholders::_2)); return 0; } +napi_value SocketIOClient::get_current_state(napi_env env, napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + char classId[CLASSID_BUF_SIZE] = {0}; + size_t charLen = 0; + napi_get_value_string_utf8(env, args[0], classId, CLASSID_BUF_SIZE, &charLen); + std::string classIdStr = classId; + + SocketIOClient* client = getClient(classIdStr); + if (!client) { + return nullptr; + } + + napi_value state; + napi_create_int32(env, static_cast(client->clientInstance.get_current_state()), &state); + return state; +} napi_value SocketIOClient::set_close_listener(napi_env env, napi_callback_info info) { diff --git a/socketio/library/src/main/cpp/socketio_module_napi.h b/socketio/library/src/main/cpp/socketio_module_napi.h index e15085d3..5c5e4819 100644 --- a/socketio/library/src/main/cpp/socketio_module_napi.h +++ b/socketio/library/src/main/cpp/socketio_module_napi.h @@ -57,6 +57,7 @@ public: static napi_value off_error(napi_env env, napi_callback_info info); static napi_value emit(napi_env env, napi_callback_info info); static napi_value emitAckBinary(napi_env env, napi_callback_info info); + static napi_value get_current_state(napi_env env, napi_callback_info info); std::string classIdStr; std::string nsp = ""; diff --git a/socketio/library/src/main/cpp/types/libentry/index.d.ts b/socketio/library/src/main/cpp/types/libentry/index.d.ts index 8ff2221b..4c38d726 100644 --- a/socketio/library/src/main/cpp/types/libentry/index.d.ts +++ b/socketio/library/src/main/cpp/types/libentry/index.d.ts @@ -81,4 +81,6 @@ export class newSocketIOClient { emitAckBinary: (name: string, message: any, b: boolean, on_emit_callback: (code: number, emit_callback_data: Uint8Array) => void, classId: number) => void; + + get_current_state: (classId: number) => number; } \ No newline at end of file diff --git a/socketio/library/src/main/ets/client_socket.ets b/socketio/library/src/main/ets/client_socket.ets index 276d1b73..d5bb4962 100644 --- a/socketio/library/src/main/ets/client_socket.ets +++ b/socketio/library/src/main/ets/client_socket.ets @@ -171,5 +171,9 @@ export class client_socket { this.mSocketIOClient.emitAckBinary(name, message, false, on_emit_callback, this.classId); } } + + public get_current_state(): number { + return this.mSocketIOClient.get_current_state(this.classId); + } } -- Gitee