Skip to content

Commit aa2d0ae

Browse files
committed
Add setting to be able to disable webRTC view
1 parent 67e03e9 commit aa2d0ae

File tree

137 files changed

+501
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+501
-317
lines changed

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ if(CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$")
3838
message(STATUS "Enabling AddressSanitizer and UndefinedBehaviorSanitizer for Debug build")
3939
add_compile_options(-fsanitize=address,undefined)
4040
add_link_options(-fsanitize=address,undefined)
41+
add_compile_options(-ggdb3)
42+
43+
# improved debugging experience
44+
add_compile_options(-fno-omit-frame-pointer -fno-optimize-sibling-calls)
45+
add_compile_options(-fno-inline -fno-inline-functions)
4146
else()
4247
message(STATUS "Compiler (${CMAKE_C_COMPILER_ID}/${CMAKE_CXX_COMPILER_ID}) does not support sanitizers or build type is not Debug, skipping sanitizer flags.")
4348
endif()

include/core/config.h

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef struct {
8484
bool web_auth_enabled;
8585
char web_username[32];
8686
char web_password[32]; // Stored as hash in actual implementation
87+
bool webrtc_disabled; // Whether WebRTC is disabled (use HLS only)
8788

8889
// Web optimization settings
8990
bool web_compression_enabled; // Whether to enable gzip compression for text-based responses
@@ -214,4 +215,11 @@ const char* get_loaded_config_path(void);
214215
// Global configuration variable
215216
extern config_t g_config;
216217

218+
/**
219+
* Get a pointer to the global streaming configuration
220+
*
221+
* @return Pointer to the global configuration
222+
*/
223+
config_t* get_streaming_config(void);
224+
217225
#endif /* LIGHTNVR_CONFIG_H */

src/core/config.c

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void load_default_config(config_t *config) {
5050
config->web_auth_enabled = true;
5151
snprintf(config->web_username, 32, "admin");
5252
snprintf(config->web_password, 32, "admin"); // Default password, should be changed
53+
config->webrtc_disabled = false; // WebRTC is enabled by default
5354

5455
// Web optimization settings
5556
config->web_compression_enabled = true;
@@ -306,6 +307,8 @@ static int config_ini_handler(void* user, const char* section, const char* name,
306307
strncpy(config->web_username, value, 31);
307308
} else if (strcmp(name, "password") == 0) {
308309
strncpy(config->web_password, value, 31);
310+
} else if (strcmp(name, "webrtc_disabled") == 0) {
311+
config->webrtc_disabled = (strcmp(value, "true") == 0 || strcmp(value, "1") == 0);
309312
}
310313
}
311314
// Stream settings
@@ -850,6 +853,7 @@ int save_config(const config_t *config, const char *path) {
850853
fprintf(file, "auth_enabled = %s\n", config->web_auth_enabled ? "true" : "false");
851854
fprintf(file, "username = %s\n", config->web_username);
852855
fprintf(file, "password = %s ; IMPORTANT: Change this default password!\n", config->web_password);
856+
fprintf(file, "webrtc_disabled = %s\n", config->webrtc_disabled ? "true" : "false");
853857
fprintf(file, "\n");
854858

855859
// Write stream settings
@@ -946,6 +950,7 @@ void print_config(const config_t *config) {
946950
printf(" Web Auth Enabled: %s\n", config->web_auth_enabled ? "true" : "false");
947951
printf(" Web Username: %s\n", config->web_username);
948952
printf(" Web Password: %s\n", "********");
953+
printf(" WebRTC Disabled: %s\n", config->webrtc_disabled ? "true" : "false");
949954

950955
printf(" Stream Settings:\n");
951956
printf(" Max Streams: %d\n", config->max_streams);

src/web/api_handlers_settings.c

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void mg_handle_get_settings(struct mg_connection *c, struct mg_http_message *hm)
3737
cJSON_AddStringToObject(settings, "web_root", g_config.web_root);
3838
cJSON_AddBoolToObject(settings, "web_auth_enabled", g_config.web_auth_enabled);
3939
cJSON_AddStringToObject(settings, "web_username", g_config.web_username);
40+
cJSON_AddBoolToObject(settings, "webrtc_disabled", g_config.webrtc_disabled);
4041

4142
// Don't include the password for security reasons
4243
cJSON_AddStringToObject(settings, "web_password", "********");
@@ -135,6 +136,14 @@ void mg_handle_post_settings(struct mg_connection *c, struct mg_http_message *hm
135136
log_info("Updated web_password");
136137
}
137138

139+
// WebRTC disabled
140+
cJSON *webrtc_disabled = cJSON_GetObjectItem(settings, "webrtc_disabled");
141+
if (webrtc_disabled && cJSON_IsBool(webrtc_disabled)) {
142+
g_config.webrtc_disabled = cJSON_IsTrue(webrtc_disabled);
143+
settings_changed = true;
144+
log_info("Updated webrtc_disabled: %s", g_config.webrtc_disabled ? "true" : "false");
145+
}
146+
138147
// Storage path
139148
cJSON *storage_path = cJSON_GetObjectItem(settings, "storage_path");
140149
if (storage_path && cJSON_IsString(storage_path)) {

src/web/mongoose_server_static.c

+52-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ void mongoose_server_handle_static_file(struct mg_connection *c, struct mg_http_
7373
// Special case for HLS streaming files
7474
if (strncmp(uri, "/hls/", 5) == 0) {
7575
// This is an HLS streaming request, serve it directly from the filesystem
76-
config_t *global_config = get_streaming_config();
76+
// Use the global configuration variable directly
77+
config_t *global_config = &g_config;
7778

7879
// Check for authentication
7980
log_info("Processing HLS request: %s", uri);
@@ -223,9 +224,33 @@ void mongoose_server_handle_static_file(struct mg_connection *c, struct mg_http_
223224
}
224225
}
225226

226-
// Special handling for root path
227-
if (strcmp(uri, "/") == 0) {
228-
// Directly serve index.html for root path
227+
// Special handling for root path or index.html
228+
if (strcmp(uri, "/") == 0 || strcmp(uri, "/index.html") == 0) {
229+
// Check if WebRTC is disabled in the configuration
230+
config_t *global_config = &g_config;
231+
if (global_config->webrtc_disabled) {
232+
// WebRTC is disabled, serve hls.html directly
233+
log_info("WebRTC is disabled, serving hls.html instead of index.html");
234+
235+
// Use hls.html path instead
236+
char index_path[MAX_PATH_LENGTH * 2];
237+
snprintf(index_path, sizeof(index_path), "%s/hls.html", server->config.web_root);
238+
239+
// Log the path we're trying to serve
240+
log_info("Serving hls.html: %s", index_path);
241+
242+
// Use Mongoose's built-in file serving capabilities
243+
struct mg_http_serve_opts opts = {
244+
.root_dir = server->config.web_root,
245+
.mime_types = "html=text/html",
246+
.extra_headers = "Connection: close\r\n"
247+
};
248+
249+
mg_http_serve_file(c, hm, index_path, &opts);
250+
return;
251+
}
252+
253+
// WebRTC is enabled, serve index.html as normal
229254
char index_path[MAX_PATH_LENGTH * 2];
230255

231256
// Add debug logging to help diagnose the issue
@@ -491,7 +516,29 @@ void mongoose_server_handle_static_file(struct mg_connection *c, struct mg_http_
491516
}
492517
}
493518

494-
// For SPA routes, directly serve index.html without redirection
519+
// Check if WebRTC is disabled in the configuration
520+
config_t *global_config = &g_config;
521+
if (global_config->webrtc_disabled) {
522+
// WebRTC is disabled, redirect to hls.html
523+
log_info("WebRTC is disabled, redirecting SPA route to hls.html");
524+
525+
// Extract query string if present
526+
char redirect_url[MAX_PATH_LENGTH * 2] = "/hls.html";
527+
if (hm->query.len > 0) {
528+
strncat(redirect_url, "?", sizeof(redirect_url) - strlen(redirect_url) - 1);
529+
size_t remaining_space = sizeof(redirect_url) - strlen(redirect_url) - 1;
530+
size_t copy_len = (hm->query.len < remaining_space) ? hm->query.len : remaining_space;
531+
strncat(redirect_url, hm->query.buf, copy_len);
532+
}
533+
534+
mg_printf(c, "HTTP/1.1 302 Found\r\n");
535+
mg_printf(c, "Location: %s\r\n", redirect_url);
536+
mg_printf(c, "Content-Length: 0\r\n");
537+
mg_printf(c, "\r\n");
538+
return;
539+
}
540+
541+
// WebRTC is enabled, serve index.html as normal
495542
char index_path[MAX_PATH_LENGTH * 2];
496543
snprintf(index_path, sizeof(index_path), "%s/index.html", server->config.web_root);
497544

web/dist/assets/DetectionOverlay-9Sm7UKgb.js.map

-1
This file was deleted.

web/dist/assets/DetectionOverlay-legacy-CU-gkAue.js

-2
This file was deleted.

web/dist/assets/DetectionOverlay-legacy-CU-gkAue.js.map

-1
This file was deleted.

web/dist/assets/DetectionOverlay-9Sm7UKgb.js web/dist/assets/FullscreenManager-Crw9n3A8.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/dist/assets/FullscreenManager-Crw9n3A8.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)