diff --git a/source_code/agora_node_ext/agora_electron_bridge.cpp b/source_code/agora_node_ext/agora_electron_bridge.cpp index 05743f3f7..3b3a9f557 100644 --- a/source_code/agora_node_ext/agora_electron_bridge.cpp +++ b/source_code/agora_node_ext/agora_electron_bridge.cpp @@ -24,10 +24,9 @@ const char *AgoraElectronBridge::_ret_result_str = "callApiResult"; napi_ref *AgoraElectronBridge::_ref_construcotr_ptr = nullptr; AgoraElectronBridge::AgoraElectronBridge() - : _env(nullptr), _ref(nullptr), _result("\0"), + : _env(nullptr), _ref(nullptr), _iris_rtc_event_handler(new NodeIrisEventHandler) { LOG_F(INFO, __FUNCTION__); - memset(_result, '\0', kBasicResultLength); } AgoraElectronBridge::~AgoraElectronBridge() { @@ -127,6 +126,7 @@ napi_value AgoraElectronBridge::CallApi(napi_env env, napi_callback_info info) { std::string funcName = ""; std::string parameter = ""; uint32_t bufferCount = 0; + napi_value retObj; status = napi_get_value_utf8string(env, args[0], funcName); status = napi_get_value_utf8string(env, args[1], parameter); @@ -134,8 +134,6 @@ napi_value AgoraElectronBridge::CallApi(napi_env env, napi_callback_info info) { if (strcmp(parameter.c_str(), "") == 0) { parameter = "{}"; } - memset(agoraElectronBridge->_result, '\0', kBasicResultLength); - if (!agoraElectronBridge->_iris_api_engine) { agoraElectronBridge->Init(); } int ret = ERR_FAILED; @@ -179,12 +177,15 @@ napi_value AgoraElectronBridge::CallApi(napi_env env, napi_callback_info info) { funcName.c_str(), parameter.c_str(), (unsigned int) parameter.length(), - agoraElectronBridge->_result, + nullptr, buffer.data(), - length.data(), + nullptr, bufferCount, }; ret = irisApiEngine->CallIrisApi(&apiParam); + status = napi_create_object(env, &retObj); + napi_obj_set_property(env, retObj, _ret_code_str, ret); + napi_obj_set_property(env, retObj, _ret_result_str, apiParam.result); } catch (std::exception &e) { agoraElectronBridge->OnApiError(e.what()); LOG_F(INFO, "%s(func name:%s) parameter: catch excepton msg: %s", @@ -194,8 +195,9 @@ napi_value AgoraElectronBridge::CallApi(napi_env env, napi_callback_info info) { LOG_F(INFO, "%s(func name:%s) fail, not init engine", __FUNCTION__, funcName.c_str()); ret = ERR_NOT_INITIALIZED; + napi_obj_set_property(env, retObj, _ret_code_str, ret); } - RETURE_NAPI_OBJ(); + return retObj; } napi_value AgoraElectronBridge::GetBuffer(napi_env env, diff --git a/source_code/agora_node_ext/agora_electron_bridge.h b/source_code/agora_node_ext/agora_electron_bridge.h index 8e0064cbd..4c6bd13e2 100644 --- a/source_code/agora_node_ext/agora_electron_bridge.h +++ b/source_code/agora_node_ext/agora_electron_bridge.h @@ -54,9 +54,6 @@ class AgoraElectronBridge { std::shared_ptr _iris_api_engine; std::shared_ptr _iris_rtc_event_handler; std::shared_ptr _iris_rendering; - - private: - char _result[kBasicResultLength]; }; }// namespace electron diff --git a/source_code/agora_node_ext/node_api_header.h b/source_code/agora_node_ext/node_api_header.h index a8e8263d9..33ca4516b 100644 --- a/source_code/agora_node_ext/node_api_header.h +++ b/source_code/agora_node_ext/node_api_header.h @@ -16,14 +16,12 @@ namespace rtc { namespace electron { #define DECLARE_NAPI_METHOD(name, func) \ - { name, 0, func, 0, 0, 0, napi_default, 0 } + {name, 0, func, 0, 0, 0, napi_default, 0} #define RETURE_NAPI_OBJ() \ napi_value retObj; \ status = napi_create_object(env, &retObj); \ napi_obj_set_property(env, retObj, _ret_code_str, ret); \ - napi_obj_set_property(env, retObj, _ret_result_str, \ - agoraElectronBridge->_result); \ return retObj napi_status napi_get_value_utf8string(napi_env &env, napi_value &value,