Skip to content

Commit

Permalink
chore: adjust string length limit
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Oct 8, 2024
1 parent b2ce535 commit d474a70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
16 changes: 9 additions & 7 deletions source_code/agora_node_ext/agora_electron_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -127,15 +126,14 @@ 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);
status = napi_get_value_uint32(env, args[3], &bufferCount);

if (strcmp(parameter.c_str(), "") == 0) { parameter = "{}"; }

memset(agoraElectronBridge->_result, '\0', kBasicResultLength);

if (!agoraElectronBridge->_iris_api_engine) { agoraElectronBridge->Init(); }

int ret = ERR_FAILED;
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions source_code/agora_node_ext/agora_electron_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class AgoraElectronBridge {
std::shared_ptr<IApiEngineBase> _iris_api_engine;
std::shared_ptr<NodeIrisEventHandler> _iris_rtc_event_handler;
std::shared_ptr<iris::IrisRtcRendering> _iris_rendering;

private:
char _result[kBasicResultLength];
};

}// namespace electron
Expand Down
4 changes: 1 addition & 3 deletions source_code/agora_node_ext/node_api_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d474a70

Please sign in to comment.