diff --git a/src/compat/is_debug_mode_enabled.ts b/src/compat/is_debug_mode_enabled.ts deleted file mode 100644 index 9b85f2e377..0000000000 --- a/src/compat/is_debug_mode_enabled.ts +++ /dev/null @@ -1,12 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/naming-convention -declare const __RX_PLAYER_DEBUG_MODE__: boolean | undefined; - -/** - * Some external tools set that boolean, in which case, we should enable DEBUG - * logs and various tricks to make as much logs as available to those tools. - * - * @returns {boolean} - */ -export default function isDebugModeEnabled(): boolean { - return typeof __RX_PLAYER_DEBUG_MODE__ === "boolean" && __RX_PLAYER_DEBUG_MODE__; -} diff --git a/src/index.ts b/src/index.ts index 41ebcef924..9917c82380 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,6 @@ * This is the class used from a regular build. */ -import isDebugModeEnabled from "./compat/is_debug_mode_enabled"; import patchWebkitSourceBuffer from "./compat/patch_webkit_source_buffer"; import { DASH, @@ -35,7 +34,6 @@ import { NATIVE_VTT_PARSER, SMOOTH, } from "./features/list"; -import logger from "./log"; import Player from "./main_thread/api"; import globalScope from "./utils/global_scope"; @@ -55,11 +53,6 @@ Player.addFeatures([ HTML_VTT_PARSER, HTML_SRT_PARSER, ]); -if (isDebugModeEnabled()) { - logger.setLevel("DEBUG", "standard"); -} else if ((__ENVIRONMENT__.CURRENT_ENV as number) === (__ENVIRONMENT__.DEV as number)) { - logger.setLevel(__LOGGER_LEVEL__.CURRENT_LEVEL, "standard"); -} export default Player; if (typeof __GLOBAL_SCOPE__ === "boolean" && __GLOBAL_SCOPE__) { diff --git a/src/main_thread/api/public_api.ts b/src/main_thread/api/public_api.ts index 00cc94bc86..e7e446e7db 100644 --- a/src/main_thread/api/public_api.ts +++ b/src/main_thread/api/public_api.ts @@ -31,7 +31,6 @@ import { import getStartDate from "../../compat/get_start_date"; import hasMseInWorker from "../../compat/has_mse_in_worker"; import hasWorkerApi from "../../compat/has_worker_api"; -import isDebugModeEnabled from "../../compat/is_debug_mode_enabled"; import config from "../../config"; import type { ISegmentSinkMetrics } from "../../core/segment_sinks/segment_sinks_store"; import type { @@ -107,6 +106,7 @@ import arrayIncludes from "../../utils/array_includes"; import assert, { assertUnreachable } from "../../utils/assert"; import type { IEventPayload, IListener } from "../../utils/event_emitter"; import EventEmitter from "../../utils/event_emitter"; +import globalScope from "../../utils/global_scope"; import idGenerator from "../../utils/id_generator"; import isNullOrUndefined from "../../utils/is_null_or_undefined"; import type Logger from "../../utils/logger"; @@ -141,6 +141,35 @@ import { /* eslint-disable @typescript-eslint/naming-convention */ +// Enable debug mode as soon as `RX_PLAYER_DEBUG_MODE__` is set to `true`: + +const globals: typeof globalScope & { + __RX_PLAYER_DEBUG_MODE__?: boolean; +} = globalScope; + +let isDebugModeEnabled: boolean = + typeof globals.__RX_PLAYER_DEBUG_MODE__ === "boolean" && + globals.__RX_PLAYER_DEBUG_MODE__; + +Object.defineProperty(globals, "__RX_PLAYER_DEBUG_MODE__", { + get(): boolean { + return isDebugModeEnabled; + }, + set(val: boolean) { + isDebugModeEnabled = val; + if (val) { + Player.LogLevel = "DEBUG"; + Player.LogFormat = "full"; + } + }, +}); + +if (isDebugModeEnabled) { + log.setLevel("DEBUG", "full"); +} else if ((__ENVIRONMENT__.CURRENT_ENV as number) === (__ENVIRONMENT__.DEV as number)) { + log.setLevel(__LOGGER_LEVEL__.CURRENT_LEVEL, "standard"); +} + const generateContentId = idGenerator(); /** @@ -550,7 +579,7 @@ class Player extends EventEmitter { dashWasmUrl: workerSettings.dashWasmUrl, logLevel: log.getLevel(), logFormat: log.getFormat(), - sendBackLogs: isDebugModeEnabled(), + sendBackLogs: isDebugModeEnabled, date: Date.now(), timestamp: getMonotonicTimeStamp(), hasVideo: this.videoElement?.nodeName.toLowerCase() === "video", @@ -569,7 +598,7 @@ class Player extends EventEmitter { value: { logLevel: logInfo.level, logFormat: logInfo.format, - sendBackLogs: isDebugModeEnabled(), + sendBackLogs: isDebugModeEnabled, }, }); }, diff --git a/src/minimal.ts b/src/minimal.ts index 54a2d2344c..31ed371b32 100644 --- a/src/minimal.ts +++ b/src/minimal.ts @@ -21,19 +21,11 @@ * import only features that is needed. */ -import isDebugModeEnabled from "./compat/is_debug_mode_enabled"; import patchWebkitSourceBuffer from "./compat/patch_webkit_source_buffer"; -import logger from "./log"; import Player from "./main_thread/api"; patchWebkitSourceBuffer(); -if (isDebugModeEnabled()) { - logger.setLevel("DEBUG", "standard"); -} else if ((__ENVIRONMENT__.CURRENT_ENV as number) === (__ENVIRONMENT__.DEV as number)) { - logger.setLevel(__LOGGER_LEVEL__.CURRENT_LEVEL, "standard"); -} - /** * Minimal Player which starts with no feature. */