From 6e4d86c774483109dee38e0c7cb6030258087b3a Mon Sep 17 00:00:00 2001 From: Gurpreet Sarngal Date: Tue, 17 Jun 2025 12:09:14 +0530 Subject: [PATCH 1/2] RDKEMW-5230: JSRuntimeLauncher component - RDKE Reason for change: Removed JSRuntimeLauncher Test Procedure: build should be successful. Risks: low Priority: P2 Signed-off-by: Gurpreet Sarngal --- CMakeLists.txt | 15 -- include/JavaScriptContextBase.h | 1 + src/JSRuntimeLauncher.cpp | 249 -------------------------------- src/JavaScriptContextBase.cpp | 5 + src/NativeJSRenderer.cpp | 28 ++-- src/jsc/JavaScriptContext.cpp | 2 + 6 files changed, 23 insertions(+), 277 deletions(-) delete mode 100644 src/JSRuntimeLauncher.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6751722..878a350 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ option(BUILD_JSRUNTIME_APP "BUILD_JSRUNTIME_APP" ON) option(ENABLE_JSRUNTIME_SERVER "ENABLE_JSRUNTIME_SERVER" OFF) option(BUILD_JSRUNTIME_CLIENT "BUILD_JSRUNTIME_CLIENT" OFF) option(NATIVEJS_DEVELOPER_MODE "NATIVEJS_DEVELOPER_MODE" OFF) -option(ENABLE_JSRUNTIME_LAUNCHER "ENABLE_JSRUNTIME_LAUNCHER" OFF) #can be jsc or node or v8 or quickjs option(JSRUNTIME_ENGINE_NAME "JSRUNTIME_ENGINE_NAME" "jsc") @@ -106,10 +105,6 @@ set(JSRUNTIME_APP_FILES ${JSRUNTIME_COMMON_SOURCE_DIRECTORY}/jsruntime.cpp ) -set(JSRUNTIME_LAUNCHER_FILES - ${JSRUNTIME_COMMON_SOURCE_DIRECTORY}/JSRuntimeLauncher.cpp -) - if ( ENABLE_JSRUNTIME_SERVER ) add_definitions("-DENABLE_JSRUNTIME_SERVER") add_definitions("-DWS_SERVER_PORT=9112") @@ -180,16 +175,6 @@ if (BUILD_JSRUNTIME_CLIENT) target_link_libraries(jsruntime_client ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -lpthread) endif (BUILD_JSRUNTIME_CLIENT) -if (ENABLE_JSRUNTIME_LAUNCHER) - message("Enabling build support for jsruntime launcher - widget") - add_executable(jsruntime_launcher ${JSRUNTIME_LAUNCHER_FILES}) - add_dependencies(${JSRUNTIME_LIBRARY_NAME} ${JSRUNTIME_ENGINE_DEPENDENT_LIBRARY_NAME}) - add_dependencies(jsruntime_launcher ${JSRUNTIME_LIBRARY_NAME} ${JSRUNTIME_ENGINE_DEPENDENT_LIBRARY_NAME} ) - target_include_directories(jsruntime_launcher PRIVATE ${JSRUNTIME_INCLUDE_DIRECTORIES}) - set_target_properties(jsruntime_launcher PROPERTIES OUTPUT_NAME "JSRuntimeLauncher") - target_link_libraries(jsruntime_launcher ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -l${JSRUNTIME_LIBRARY_NAME} ${JSRUNTIME_LINK_LIBRARIES}) -endif (ENABLE_JSRUNTIME_LAUNCHER) - set(UWEBSOCKETS_TARGET "Linux") if (APPLE) set(UWEBSOCKETS_TARGET "Darwin") diff --git a/include/JavaScriptContextBase.h b/include/JavaScriptContextBase.h index 412ae26..76a1e1d 100644 --- a/include/JavaScriptContextBase.h +++ b/include/JavaScriptContextBase.h @@ -55,6 +55,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe std::string getUrl(); virtual void onKeyPress(struct JavaScriptKeyDetails& details); virtual void onKeyRelease(struct JavaScriptKeyDetails& details); + ModuleSettings getModuleSettings(); protected: virtual void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress) = 0; virtual bool evaluateScript(const char* script, const char* name, const char *args, bool module=false) = 0; diff --git a/src/JSRuntimeLauncher.cpp b/src/JSRuntimeLauncher.cpp deleted file mode 100644 index 7f73da8..0000000 --- a/src/JSRuntimeLauncher.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "rapidjson/document.h" -#include -#include -#include -#include - -using namespace rapidjson; -using namespace std; -using namespace JsRuntime; - -string source="/package/index.js"; -std::vector flags; - -void extractJSFilePaths(const std::string& jsFilePath) { - std::ifstream file(jsFilePath); - - if (!file.is_open()) { - std::cerr << "Error: Could not open file '" << jsFilePath << "'\n"; - return; - } - - std::string line; - while (std::getline(file, line)) { - if (!line.empty()) { - std::cout<<"line:"< options; - for (SizeType i = 0; i < flagsarr.Size(); i++) { - const Value& flagOption = flagsarr[i]; - if (!flagOption.IsObject()) - continue; - - if (flagOption.HasMember("name") && flagOption.HasMember("enable")) { - const Value& name = flagOption["name"]; - const Value& enable = flagOption["enable"]; - - if(name=="player" && enable==true) - { - flags.push_back("--enablePlayer"); - } - else if(name=="xhr" && enable==true) - { - flags.push_back("--enableXHR"); - } - else if(name=="websocket" && enable==true) - { - flags.push_back("--enableWebSocket"); - } - else if(name=="http" && enable==true) - { - flags.push_back("--enableHttp"); - } - else if(name=="websocketenhanced" && enable==true) - { - flags.push_back("--enableWebSocketEnhanced"); - } - else if(name=="fetch" && enable==true) - { - flags.push_back("--enableFetch"); - } - else if(name=="jsdom" && enable==true) - { - flags.push_back("--enableJSDOM"); - } - else if(name=="window" && enable==true) - { - flags.push_back("--enableWindow"); - } - else if(name=="console" && enable==true) - { - flags.push_back("--console"); - } - else if(name=="display" && enable==true) - { - flags.push_back("--display"); - } - else{ - continue; - } - - } - } - } -} - -int main(int argc, char *argv[]) { - const char* filename = "/package/rdk.config"; - std::ifstream file(filename); - if (file.good()) - { - std::string jsonStr, line; - while (std::getline(file, line)) { - jsonStr += line + "\n"; - } - file.close(); - cJSON* root = cJSON_Parse(jsonStr.c_str()); - if (root){ - cJSON* envs = cJSON_GetObjectItem(root, "configuration"); - cJSON* envArray = cJSON_GetObjectItem(envs, "envs"); - cJSON* env; - cJSON_ArrayForEach(env, envArray) { - cJSON* key = cJSON_GetObjectItem(env, "key"); - cJSON* value = cJSON_GetObjectItem(env, "value"); - if (key && value && cJSON_IsString(key) && cJSON_IsString(value)) { - setenv(key->valuestring, value->valuestring, 1); - } - } - cJSON_Delete(root); - } - } - vector c_flags; - std::string fileName = "/package/app.config"; - Json_parsing(fileName); - extractJSFilePaths(source); - for(auto& flag : flags) - { - c_flags.push_back((char*)(flag.c_str())); - } - if (c_flags.size() < 2) - { - NativeJSLogger::log(WARN, "Pass the URL to run\n"); - return -1; - } - bool runServer = false; - std::string waylanddisplay(""); - bool enableJSDOM = false, enableWindow = false, enablePlayer = false, enableWebSocketEnhanced = false, enableFetch = false; - int i = 0, appendindex=c_flags.size()-1; - std::vector applications; - ModuleSettings moduleSettings; - bool consoleMode = false; - - while (i renderer = std::make_shared(waylanddisplay); - if (consoleMode) { - renderer->setEnvForConsoleMode(moduleSettings); - } - if (!renderer) - { - NativeJSLogger::log(ERROR, "Unable to run application\n"); - return -1; - } - - uint32_t id = renderer->createApplication(moduleSettings); - for (int j = 0; j < applications.size(); j++) { - std::string url = applications[j]; - NativeJSLogger::log(INFO, "Application URL is %s\n", (url.size() ? url.c_str() : "empty")); - renderer->runApplication(id, url); - } - - renderer->run(); - return 0; -} diff --git a/src/JavaScriptContextBase.cpp b/src/JavaScriptContextBase.cpp index c649c94..009375f 100644 --- a/src/JavaScriptContextBase.cpp +++ b/src/JavaScriptContextBase.cpp @@ -127,3 +127,8 @@ void JavaScriptContextBase::onKeyRelease(struct JavaScriptKeyDetails& details) { processKeyEvent(details, false); } + +ModuleSettings JavaScriptContextBase::getModuleSettings() +{ + return mModuleSettings; +} diff --git a/src/NativeJSRenderer.cpp b/src/NativeJSRenderer.cpp index a6152e7..c24aaf3 100644 --- a/src/NativeJSRenderer.cpp +++ b/src/NativeJSRenderer.cpp @@ -326,29 +326,31 @@ void NativeJSRenderer::runApplicationInternal(ApplicationRequest& appRequest) return ; } JavaScriptContext* context = (JavaScriptContext*)mContextMap[id].context; - #if defined(ENABLE_JSRUNTIME_LAUNCHER) - std::stringstream window; - window<<"window.location = {\"href\":\"" << url << "\"};"; - NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); - context->runScript(window.str().c_str(),true, url, nullptr, true); - #endif + if(context->getModuleSettings().enableJSDOM) + { + std::stringstream window; + window<<"window.location = {\"href\":\"" << url << "\"};"; + NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); + context->runScript(window.str().c_str(),true, url, nullptr, true); + } NativeJSLogger::log(INFO, "nativeJS application thunder execution url: %s, result: %d\n", url.c_str(), ret ? 1 : 0); ret = context->runScript(chunk.contentsBuffer, true, url, nullptr, true); NativeJSLogger::log(INFO, "nativeJS application execution result: %d\n", ret ? 1 : 0); double duration = context->getExecutionDuration(); - context->setAppdata(id, url); + context->setAppdata(id, url); NativeJSLogger::log(INFO, "Execution duration(runApplicationDuration) for ID %d | URL %s : %.3f ms\n", id, url.c_str(), duration); } else { NativeJSLogger::log(INFO, "About to launch local app\n"); JavaScriptContext* context = (JavaScriptContext*)mContextMap[id].context; - #if defined(ENABLE_JSRUNTIME_LAUNCHER) - std::stringstream window; - window<<"window.location = {\"href\":\"file:/" << url << "\"};"; - NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); - context->runScript(window.str().c_str(),true, url, nullptr, true); - #endif + if(context->getModuleSettings().enableJSDOM) + { + std::stringstream window; + window<<"window.location = {\"href\":\"file:/" << url << "\"};"; + NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); + context->runScript(window.str().c_str(),true, url, nullptr, true); + } NativeJSLogger::log(INFO, "Running test application: %s\n", url.c_str()); bool ret = context->runFile(url.c_str(), nullptr, true); NativeJSLogger::log(INFO, "Test application execution result: %d\n", ret ? 1 : 0); diff --git a/src/jsc/JavaScriptContext.cpp b/src/jsc/JavaScriptContext.cpp index f8b203f..f18cfc1 100644 --- a/src/jsc/JavaScriptContext.cpp +++ b/src/jsc/JavaScriptContext.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include #include #include From 7ec702a0b9847846ce375063c57fd04aed883dd2 Mon Sep 17 00:00:00 2001 From: Gurpreet Sarngal Date: Tue, 17 Jun 2025 12:09:14 +0530 Subject: [PATCH 2/2] RDKEMW-5230: JSRuntimeLauncher component - RDKE Reason for change: Removed JSRuntimeLauncher Test Procedure: build should be successful. Risks: low Priority: P2 --- CMakeLists.txt | 15 -- include/JavaScriptContextBase.h | 1 + src/JSRuntimeLauncher.cpp | 249 -------------------------------- src/JavaScriptContextBase.cpp | 5 + src/NativeJSRenderer.cpp | 28 ++-- src/jsc/JavaScriptContext.cpp | 2 + 6 files changed, 23 insertions(+), 277 deletions(-) delete mode 100644 src/JSRuntimeLauncher.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6751722..878a350 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ option(BUILD_JSRUNTIME_APP "BUILD_JSRUNTIME_APP" ON) option(ENABLE_JSRUNTIME_SERVER "ENABLE_JSRUNTIME_SERVER" OFF) option(BUILD_JSRUNTIME_CLIENT "BUILD_JSRUNTIME_CLIENT" OFF) option(NATIVEJS_DEVELOPER_MODE "NATIVEJS_DEVELOPER_MODE" OFF) -option(ENABLE_JSRUNTIME_LAUNCHER "ENABLE_JSRUNTIME_LAUNCHER" OFF) #can be jsc or node or v8 or quickjs option(JSRUNTIME_ENGINE_NAME "JSRUNTIME_ENGINE_NAME" "jsc") @@ -106,10 +105,6 @@ set(JSRUNTIME_APP_FILES ${JSRUNTIME_COMMON_SOURCE_DIRECTORY}/jsruntime.cpp ) -set(JSRUNTIME_LAUNCHER_FILES - ${JSRUNTIME_COMMON_SOURCE_DIRECTORY}/JSRuntimeLauncher.cpp -) - if ( ENABLE_JSRUNTIME_SERVER ) add_definitions("-DENABLE_JSRUNTIME_SERVER") add_definitions("-DWS_SERVER_PORT=9112") @@ -180,16 +175,6 @@ if (BUILD_JSRUNTIME_CLIENT) target_link_libraries(jsruntime_client ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -lpthread) endif (BUILD_JSRUNTIME_CLIENT) -if (ENABLE_JSRUNTIME_LAUNCHER) - message("Enabling build support for jsruntime launcher - widget") - add_executable(jsruntime_launcher ${JSRUNTIME_LAUNCHER_FILES}) - add_dependencies(${JSRUNTIME_LIBRARY_NAME} ${JSRUNTIME_ENGINE_DEPENDENT_LIBRARY_NAME}) - add_dependencies(jsruntime_launcher ${JSRUNTIME_LIBRARY_NAME} ${JSRUNTIME_ENGINE_DEPENDENT_LIBRARY_NAME} ) - target_include_directories(jsruntime_launcher PRIVATE ${JSRUNTIME_INCLUDE_DIRECTORIES}) - set_target_properties(jsruntime_launcher PROPERTIES OUTPUT_NAME "JSRuntimeLauncher") - target_link_libraries(jsruntime_launcher ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -l${JSRUNTIME_LIBRARY_NAME} ${JSRUNTIME_LINK_LIBRARIES}) -endif (ENABLE_JSRUNTIME_LAUNCHER) - set(UWEBSOCKETS_TARGET "Linux") if (APPLE) set(UWEBSOCKETS_TARGET "Darwin") diff --git a/include/JavaScriptContextBase.h b/include/JavaScriptContextBase.h index 412ae26..76a1e1d 100644 --- a/include/JavaScriptContextBase.h +++ b/include/JavaScriptContextBase.h @@ -55,6 +55,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe std::string getUrl(); virtual void onKeyPress(struct JavaScriptKeyDetails& details); virtual void onKeyRelease(struct JavaScriptKeyDetails& details); + ModuleSettings getModuleSettings(); protected: virtual void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress) = 0; virtual bool evaluateScript(const char* script, const char* name, const char *args, bool module=false) = 0; diff --git a/src/JSRuntimeLauncher.cpp b/src/JSRuntimeLauncher.cpp deleted file mode 100644 index 7f73da8..0000000 --- a/src/JSRuntimeLauncher.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "rapidjson/document.h" -#include -#include -#include -#include - -using namespace rapidjson; -using namespace std; -using namespace JsRuntime; - -string source="/package/index.js"; -std::vector flags; - -void extractJSFilePaths(const std::string& jsFilePath) { - std::ifstream file(jsFilePath); - - if (!file.is_open()) { - std::cerr << "Error: Could not open file '" << jsFilePath << "'\n"; - return; - } - - std::string line; - while (std::getline(file, line)) { - if (!line.empty()) { - std::cout<<"line:"< options; - for (SizeType i = 0; i < flagsarr.Size(); i++) { - const Value& flagOption = flagsarr[i]; - if (!flagOption.IsObject()) - continue; - - if (flagOption.HasMember("name") && flagOption.HasMember("enable")) { - const Value& name = flagOption["name"]; - const Value& enable = flagOption["enable"]; - - if(name=="player" && enable==true) - { - flags.push_back("--enablePlayer"); - } - else if(name=="xhr" && enable==true) - { - flags.push_back("--enableXHR"); - } - else if(name=="websocket" && enable==true) - { - flags.push_back("--enableWebSocket"); - } - else if(name=="http" && enable==true) - { - flags.push_back("--enableHttp"); - } - else if(name=="websocketenhanced" && enable==true) - { - flags.push_back("--enableWebSocketEnhanced"); - } - else if(name=="fetch" && enable==true) - { - flags.push_back("--enableFetch"); - } - else if(name=="jsdom" && enable==true) - { - flags.push_back("--enableJSDOM"); - } - else if(name=="window" && enable==true) - { - flags.push_back("--enableWindow"); - } - else if(name=="console" && enable==true) - { - flags.push_back("--console"); - } - else if(name=="display" && enable==true) - { - flags.push_back("--display"); - } - else{ - continue; - } - - } - } - } -} - -int main(int argc, char *argv[]) { - const char* filename = "/package/rdk.config"; - std::ifstream file(filename); - if (file.good()) - { - std::string jsonStr, line; - while (std::getline(file, line)) { - jsonStr += line + "\n"; - } - file.close(); - cJSON* root = cJSON_Parse(jsonStr.c_str()); - if (root){ - cJSON* envs = cJSON_GetObjectItem(root, "configuration"); - cJSON* envArray = cJSON_GetObjectItem(envs, "envs"); - cJSON* env; - cJSON_ArrayForEach(env, envArray) { - cJSON* key = cJSON_GetObjectItem(env, "key"); - cJSON* value = cJSON_GetObjectItem(env, "value"); - if (key && value && cJSON_IsString(key) && cJSON_IsString(value)) { - setenv(key->valuestring, value->valuestring, 1); - } - } - cJSON_Delete(root); - } - } - vector c_flags; - std::string fileName = "/package/app.config"; - Json_parsing(fileName); - extractJSFilePaths(source); - for(auto& flag : flags) - { - c_flags.push_back((char*)(flag.c_str())); - } - if (c_flags.size() < 2) - { - NativeJSLogger::log(WARN, "Pass the URL to run\n"); - return -1; - } - bool runServer = false; - std::string waylanddisplay(""); - bool enableJSDOM = false, enableWindow = false, enablePlayer = false, enableWebSocketEnhanced = false, enableFetch = false; - int i = 0, appendindex=c_flags.size()-1; - std::vector applications; - ModuleSettings moduleSettings; - bool consoleMode = false; - - while (i renderer = std::make_shared(waylanddisplay); - if (consoleMode) { - renderer->setEnvForConsoleMode(moduleSettings); - } - if (!renderer) - { - NativeJSLogger::log(ERROR, "Unable to run application\n"); - return -1; - } - - uint32_t id = renderer->createApplication(moduleSettings); - for (int j = 0; j < applications.size(); j++) { - std::string url = applications[j]; - NativeJSLogger::log(INFO, "Application URL is %s\n", (url.size() ? url.c_str() : "empty")); - renderer->runApplication(id, url); - } - - renderer->run(); - return 0; -} diff --git a/src/JavaScriptContextBase.cpp b/src/JavaScriptContextBase.cpp index c649c94..009375f 100644 --- a/src/JavaScriptContextBase.cpp +++ b/src/JavaScriptContextBase.cpp @@ -127,3 +127,8 @@ void JavaScriptContextBase::onKeyRelease(struct JavaScriptKeyDetails& details) { processKeyEvent(details, false); } + +ModuleSettings JavaScriptContextBase::getModuleSettings() +{ + return mModuleSettings; +} diff --git a/src/NativeJSRenderer.cpp b/src/NativeJSRenderer.cpp index a6152e7..c24aaf3 100644 --- a/src/NativeJSRenderer.cpp +++ b/src/NativeJSRenderer.cpp @@ -326,29 +326,31 @@ void NativeJSRenderer::runApplicationInternal(ApplicationRequest& appRequest) return ; } JavaScriptContext* context = (JavaScriptContext*)mContextMap[id].context; - #if defined(ENABLE_JSRUNTIME_LAUNCHER) - std::stringstream window; - window<<"window.location = {\"href\":\"" << url << "\"};"; - NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); - context->runScript(window.str().c_str(),true, url, nullptr, true); - #endif + if(context->getModuleSettings().enableJSDOM) + { + std::stringstream window; + window<<"window.location = {\"href\":\"" << url << "\"};"; + NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); + context->runScript(window.str().c_str(),true, url, nullptr, true); + } NativeJSLogger::log(INFO, "nativeJS application thunder execution url: %s, result: %d\n", url.c_str(), ret ? 1 : 0); ret = context->runScript(chunk.contentsBuffer, true, url, nullptr, true); NativeJSLogger::log(INFO, "nativeJS application execution result: %d\n", ret ? 1 : 0); double duration = context->getExecutionDuration(); - context->setAppdata(id, url); + context->setAppdata(id, url); NativeJSLogger::log(INFO, "Execution duration(runApplicationDuration) for ID %d | URL %s : %.3f ms\n", id, url.c_str(), duration); } else { NativeJSLogger::log(INFO, "About to launch local app\n"); JavaScriptContext* context = (JavaScriptContext*)mContextMap[id].context; - #if defined(ENABLE_JSRUNTIME_LAUNCHER) - std::stringstream window; - window<<"window.location = {\"href\":\"file:/" << url << "\"};"; - NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); - context->runScript(window.str().c_str(),true, url, nullptr, true); - #endif + if(context->getModuleSettings().enableJSDOM) + { + std::stringstream window; + window<<"window.location = {\"href\":\"file:/" << url << "\"};"; + NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str()); + context->runScript(window.str().c_str(),true, url, nullptr, true); + } NativeJSLogger::log(INFO, "Running test application: %s\n", url.c_str()); bool ret = context->runFile(url.c_str(), nullptr, true); NativeJSLogger::log(INFO, "Test application execution result: %d\n", ret ? 1 : 0); diff --git a/src/jsc/JavaScriptContext.cpp b/src/jsc/JavaScriptContext.cpp index f8b203f..f18cfc1 100644 --- a/src/jsc/JavaScriptContext.cpp +++ b/src/jsc/JavaScriptContext.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include #include #include