diff --git a/CHANGELOG.md b/CHANGELOG.md index 94d956b0..0f693e8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- `DebugConfig.isDebugLoggingEnabled` and `DebugConfig.setDebugLoggingEnabled(value: boolean)` to check and set whether debug logging is enabled. Debug logging helps diagnose problems and trace the flow of execution within the Player and **should not be enabled in production** as it may log sensitive or confidential information to the console. + ### Changed - Update Bitmovin's native iOS SDK version to `3.78.0` diff --git a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt new file mode 100644 index 00000000..98cff642 --- /dev/null +++ b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt @@ -0,0 +1,23 @@ +package com.bitmovin.player.reactnative + +import com.bitmovin.player.api.DebugConfig +import com.facebook.react.bridge.* +import com.facebook.react.module.annotations.ReactModule + +private const val MODULE_NAME = "DebugModule" + +@ReactModule(name = MODULE_NAME) +class DebugModule(context: ReactApplicationContext) : BitmovinBaseModule(context) { + override fun getName() = MODULE_NAME + + /** + * Enable/disable verbose logging for the console logger. + * @param enabled Whether to set verbose logging as enabled or disabled. + */ + @ReactMethod + fun setDebugLoggingEnabled(enabled: Boolean, promise: Promise) { + promise.unit.resolveOnUiThread { + DebugConfig.isLoggingEnabled = enabled + } + } +} diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt index 807f6f54..7d3ab01f 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt @@ -30,6 +30,7 @@ class RNPlayerViewPackage : ReactPackage { BitmovinCastManagerModule(reactContext), BufferModule(reactContext), NetworkModule(reactContext), + DebugModule(reactContext), ) } diff --git a/ios/DebugModule.m b/ios/DebugModule.m new file mode 100644 index 00000000..777bb0c8 --- /dev/null +++ b/ios/DebugModule.m @@ -0,0 +1,7 @@ +#import + +@interface RCT_EXTERN_REMAP_MODULE(DebugModule, DebugModule, NSObject) + +RCT_EXTERN_METHOD(setDebugLoggingEnabled:(nonnull BOOL)enabled) + +@end diff --git a/ios/DebugModule.swift b/ios/DebugModule.swift new file mode 100644 index 00000000..341a7749 --- /dev/null +++ b/ios/DebugModule.swift @@ -0,0 +1,33 @@ +import BitmovinPlayer + +@objc(DebugModule) +public class DebugModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! + + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { + "DebugModule" + } + + /// Module requires main thread initialization. + public static func requiresMainQueueSetup() -> Bool { + true + } + + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { + bridge.uiManager.methodQueue + } +} + +extension DebugModule { + /// Enable/disable verbose logging for the console logger. + /// - Parameter enabled: Whether to set verbose logging as enabled or disabled. + @objc(setDebugLoggingEnabled:) + func setDebugLoggingEnabled(enabled: Bool) { + bridge.uiManager.addUIBlock { [weak self] _, _ in + DebugConfig.logging.logger?.level = enabled ? .verbose : .warning + } + } +} diff --git a/src/debug.ts b/src/debug.ts new file mode 100644 index 00000000..960dec72 --- /dev/null +++ b/src/debug.ts @@ -0,0 +1,56 @@ +import { NativeModules } from 'react-native'; + +const DebugModule = NativeModules.DebugModule; + +/** + * Global debug configuration for all Bitmovin components. + */ +export class DebugConfig { + private static _isDebugEnabled = false; + + /** + * Retrieves the current debug logging state. + * + * @returns `true` if debug logging is enabled, otherwise `false`. + */ + static get isDebugLoggingEnabled(): boolean { + return DebugConfig._isDebugEnabled; + } + + /** + * Enables or disables global debug logging for all Bitmovin components. + * + * Debug logging provides detailed information primarily for debugging purposes, + * helping to diagnose problems and trace the flow of execution within the Player. + * + * ### Warning: + * This option **should not be enabled in production** as it may log sensitive or confidential + * information to the console. + * + * ## Platform-Specific Logging Behavior + * --- + * - **iOS:** logs are printed using `NSLog` at the verbose log level. + * - **Android:** logs are printed using `android.util.Log` with the following tags: + * - `BitmovinPlayer` + * - `BitmovinPlayerView` + * - `BitmovinOffline` + * - `BitmovinSource` + * - `BitmovinExoPlayer` + * + * ## Limitations + * --- + * **Android** + * - This flag **must** be set **before** creating any Bitmovin component to take effect. + * + * ## Usage Notes + * --- + * - We recommend setting this flag during your app's initialization phase, such as in the + * application's entry point (e.g. `App.tsx`). + * + * @defaultValue `false` + */ + static async setDebugLoggingEnabled(value: boolean): Promise { + DebugConfig._isDebugEnabled = value; + await DebugModule.setDebugLoggingEnabled(value); + } +} diff --git a/src/index.ts b/src/index.ts index 20d34fc7..4ec7abdd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,3 +25,4 @@ export * from './liveConfig'; export * from './bufferApi'; export * from './network'; export * from './mediaControlConfig'; +export * from './debug';