auto-load rmt.js when rmt option is set

This commit is contained in:
Jean Le Feuvre
2026-01-09 09:20:28 +01:00
parent 8e57db1d80
commit 971e3e9aa4
3 changed files with 33 additions and 22 deletions

View File

@@ -585,7 +585,6 @@ int gpac_main(int _argc, char **_argv)
gf_sys_init(mem_track, profile);
#ifdef GPAC_CONFIG_ANDROID
//prevent destruction of JSRT until we unload the JNI gpac wrapper (see applications/gpac_android/src/main/jni/gpac_jni.cpp)
gf_opts_set_key("temp", "static-jsrt", "true");
@@ -659,6 +658,11 @@ int gpac_main(int _argc, char **_argv)
use_step_mode = GF_TRUE;
#endif
if (gf_opts_get_bool("core", "rmt")) {
if (!session_js) session_js = gf_list_new();
gf_list_insert(session_js, "$GSHARE/scripts/rmt.js", 0);
}
for (i=1; i<argc; i++) {
char szArgName[1024];
char *arg = argv[i];
@@ -1216,8 +1220,12 @@ restart:
const char *js_src = gf_list_get(session_js, ijs);
e = gf_fs_load_script(session, js_src);
if (e) {
GF_LOG(GF_LOG_ERROR, GF_LOG_APP, ("Failed to load JS for session: %s\n", gf_error_to_string(e) ));
ERR_EXIT
if ((e==GF_URL_ERROR) && strstr(js_src, "/rmt.js")) {
GF_LOG(GF_LOG_WARNING, GF_LOG_APP, ("Monitoring script %s not found, check your installation\n Disabling remote monitoring\n", js_src));
} else {
GF_LOG(GF_LOG_ERROR, GF_LOG_APP, ("Failed to load JS for session: %s\n", gf_error_to_string(e) ));
ERR_EXIT
}
}
}
}

View File

@@ -2077,6 +2077,25 @@ static GF_Err gf_fs_load_script_ex(GF_FilterSession *fs, const char *jsfile, JSC
if (!fs) return GF_BAD_PARAM;
//load script
if (!strncmp(jsfile, "$GSHARE/", 8)) {
char szPath[GF_MAX_PATH];
if (gf_opts_default_shared_directory(szPath)) {
strcat(szPath, jsfile + 7);
e = gf_file_load_data(szPath, &buf, &buf_len);
} else {
e = GF_URL_ERROR;
}
} else {
e = gf_file_load_data(jsfile, &buf, &buf_len);
}
if (e) {
if (e!=GF_URL_ERROR) {
GF_LOG(GF_LOG_ERROR, GF_LOG_SCRIPT, ("[JSF] Error loading script file %s: %s\n", jsfile, gf_error_to_string(e) ));
}
return e;
}
if (in_ctx) {
ctx = in_ctx;
} else if (fs->js_ctx) {
@@ -2099,25 +2118,6 @@ static GF_Err gf_fs_load_script_ex(GF_FilterSession *fs, const char *jsfile, JSC
JS_FreeValue(fs->js_ctx, global_obj);
}
//load script
if (!strncmp(jsfile, "$GSHARE/", 8)) {
char szPath[GF_MAX_PATH];
if (gf_opts_default_shared_directory(szPath)) {
strcat(szPath, jsfile + 7);
e = gf_file_load_data(szPath, &buf, &buf_len);
} else {
e = GF_NOT_FOUND;
}
} else {
e = gf_file_load_data(jsfile, &buf, &buf_len);
}
if (e) {
if (e!=GF_NOT_FOUND) {
GF_LOG(GF_LOG_ERROR, GF_LOG_SCRIPT, ("[JSF] Error loading script file %s: %s\n", jsfile, gf_error_to_string(e) ));
}
return e;
}
if (in_ctx || (!gf_opts_get_bool("core", "no-js-mods") && JS_DetectModule((char *)buf, buf_len))) {
if (!skip_modules)
qjs_init_all_modules(ctx, GF_FALSE, GF_FALSE);

View File

@@ -3088,6 +3088,9 @@ GF_Err gf_file_load_data(const char *file_name, u8 **out_data, u32 *out_size)
FILE *file = gf_fopen(file_name, "rb");
if (!file) {
if (!gf_file_exists(file_name))
return GF_URL_ERROR;
GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Cannot open file %s\n", file_name));
return GF_IO_ERR;
}