From 4f1f88c217d23e17a06012bb942783017c193c7f Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Thu, 21 Nov 2024 16:53:40 +0100 Subject: [PATCH 01/13] Add debug config --- src/debugConfig.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/debugConfig.ts diff --git a/src/debugConfig.ts b/src/debugConfig.ts new file mode 100644 index 00000000..bc8563ea --- /dev/null +++ b/src/debugConfig.ts @@ -0,0 +1,32 @@ +/** + * Global debug configuration for all Bitmovin components. + */ +export interface DebugConfig { + /** + * Enables global debug logging for all Bitmovin components. + * + * Provides detailed information primarily for debugging purposes, helping to + * diagnose problems and trace the flow of execution within the Player. + * + * ### 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` + * + * ### Usage Notes: + * - On Android, this flag **must** be set **before** creating any Bitmovin component to take effect. + * - We recommend setting this flag during your app's initialization phase, such as in the + * `Application.onCreate` function on Android or equivalent initialization on iOS. + * + * ### Warning: + * This option **should not be enabled in production** as it may log sensitive or confidential + * information to the console. + * + * @defaultValue `false` + */ + isLoggingEnabled?: boolean; +} From d54fa8aca482843a60b7a7ff3a6cd263a98222de Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 11:12:37 +0100 Subject: [PATCH 02/13] first version --- DebugModule.m | 8 +++ DebugModule.swift | 56 +++++++++++++++++ ios/RCTConvert+BitmovinPlayer.swift | 16 +++++ src/{ => debug}/debugConfig.ts | 6 +- src/debug/index.ts | 95 +++++++++++++++++++++++++++++ 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 DebugModule.m create mode 100644 DebugModule.swift rename src/{ => debug}/debugConfig.ts (88%) create mode 100644 src/debug/index.ts diff --git a/DebugModule.m b/DebugModule.m new file mode 100644 index 00000000..06a5ce30 --- /dev/null +++ b/DebugModule.m @@ -0,0 +1,8 @@ +// +// DebugModule.m +// Pods +// +// Created by Michele Pozzi on 21.11.24. +// + +#import diff --git a/DebugModule.swift b/DebugModule.swift new file mode 100644 index 00000000..e9dd8c78 --- /dev/null +++ b/DebugModule.swift @@ -0,0 +1,56 @@ +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 + } + + /** + - Gets the `LogLevel` from the debug Log. + - Parameter nativeId: Native Id of the the player instance. + - Parameter resolver: JS promise resolver. + - Parameter rejecter: JS promise rejecter. + */ + @objc(getLevel:resolver:rejecter:) + func getLevel( + _ playerId: NativeId, + resolver resolve: @escaping RCTPromiseResolveBlock, + rejecter reject: @escaping RCTPromiseRejectBlock + ) { + bridge.uiManager.addUIBlock { [weak self] _, _ in + guard let logger = DebugConfig.logging.logger else { + reject("[DebugModule]", "Invalid logger for player with ID: (\(playerId))", nil) + return + } + let level = logger.level + resolve(RCTConvert.toJson(logLevel: level)) + } + } + + /** + * Sets the level for the debug log. + - Parameter nativeId: Target player id. + - Parameter level: The level of the log to set. + */ + @objc(setLogLevel:level:) + func enableDebugging(_ playerId: NativeId, level: LogLevel) { + bridge.uiManager.addUIBlock { [weak self] _, _ in + DebugConfig.logging.logger?.level = level + } + } +} diff --git a/ios/RCTConvert+BitmovinPlayer.swift b/ios/RCTConvert+BitmovinPlayer.swift index 4cef95dd..b0cc184c 100644 --- a/ios/RCTConvert+BitmovinPlayer.swift +++ b/ios/RCTConvert+BitmovinPlayer.swift @@ -1347,6 +1347,18 @@ extension RCTConvert { } return nowPlayingConfig } + + static func debugConfig(_ json: Any?) -> DebugConfig? { + guard let json = json as? [String: Any?] else { return DebugConfig() } + var debugConfig = DebugConfig() + let isLoggingEnabled = json["isLoggingEnabled"] as? Bool ?? false + debugConfig.isLoggingEnabled = isLoggingEnabled + return debugConfig + } + + static func toJson(logLevel: LogLevel) -> Int { + logLevel.rawValue + } } /** * React native specific PlayerViewConfig. @@ -1401,3 +1413,7 @@ internal struct RNBufferLevels { let audio: BufferLevel let video: BufferLevel } + +//internal struct DebugConfig { +// var isLoggingEnabled: Bool = false +//} diff --git a/src/debugConfig.ts b/src/debug/debugConfig.ts similarity index 88% rename from src/debugConfig.ts rename to src/debug/debugConfig.ts index bc8563ea..50877d46 100644 --- a/src/debugConfig.ts +++ b/src/debug/debugConfig.ts @@ -1,7 +1,9 @@ +import { NativeInstanceConfig } from 'src/nativeInstance'; + /** * Global debug configuration for all Bitmovin components. */ -export interface DebugConfig { +export interface DebugConfig extends NativeInstanceConfig { /** * Enables global debug logging for all Bitmovin components. * @@ -28,5 +30,5 @@ export interface DebugConfig { * * @defaultValue `false` */ - isLoggingEnabled?: boolean; + isDebugLoggingEnabled?: boolean; } diff --git a/src/debug/index.ts b/src/debug/index.ts new file mode 100644 index 00000000..d459b2a1 --- /dev/null +++ b/src/debug/index.ts @@ -0,0 +1,95 @@ +import { NativeModules } from 'react-native'; +import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge'; +import NativeInstance from '../nativeInstance'; +import { DebugConfig } from './debugConfig'; + +const DebugModule = NativeModules.DebugModule; + +/** + * Represents a native Network configuration object. + * @internal + */ +export class Debug extends NativeInstance { + /** + * Whether this object's native instance has been created. + */ + isInitialized = false; + /** + * Whether this object's native instance has been disposed. + */ + isDestroyed = false; + + /** + * Allocates the Network config instance and its resources natively. + */ + initialize = () => { + if (!this.isInitialized) { + // Register this object as a callable module so it's possible to + // call functions on it from native code, e.g `onPreprocessHttpResponse`. + BatchedBridge.registerCallableModule(`Debug-${this.nativeId}`, this); + // Create native configuration object. + DebugModule.initWithConfig(this.nativeId, this.config); + this.isInitialized = true; + } + }; + + /** + * Destroys the native Network config and releases all of its allocated resources. + */ + destroy = () => { + if (!this.isDestroyed) { + DebugModule.destroy(this.nativeId); + this.isDestroyed = true; + } + }; + + /** + * Applies the user-defined `preprocessHttpRequest` function to native's `type` and `request` data and store + * the result back in `NetworkModule`. + * + * Called from native code when `NetworkConfig.preprocessHttpRequest` is dispatched. + * + * @param requestId Passed through to identify the completion handler of the request on native. + * @param type Type of the request to be made. + * @param request The HTTP request to process. + */ + onPreprocessHttpRequest = ( + requestId: string, + type: HttpRequestType, + request: HttpRequest + ) => { + this.config + ?.preprocessHttpRequest?.(type, request) + .then((resultRequest) => { + NetworkModule.setPreprocessedHttpRequest(requestId, resultRequest); + }) + .catch(() => { + NetworkModule.setPreprocessedHttpRequest(requestId, request); + }); + }; + + /** + * Applies the user-defined `preprocessHttpResponse` function to native's `type` and `response` data and store + * the result back in `NetworkModule`. + * + * Called from native code when `NetworkConfig.preprocessHttpResponse` is dispatched. + * + * @param responseId Passed through to identify the completion handler of the response on native. + * @param type Type of the request to be made. + * @param response The HTTP response to process. + */ + onPreprocessHttpResponse = ( + responseId: string, + type: HttpRequestType, + response: HttpResponse + ) => { + this.config + ?.preprocessHttpResponse?.(type, response) + .then((resultResponse) => { + NetworkModule.setPreprocessedHttpResponse(responseId, resultResponse); + }) + .catch(() => { + NetworkModule.setPreprocessedHttpResponse(responseId, response); + }); + }; +} From e35a0feb0484b542e7a0287bdf7c71152ba2e1d1 Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 11:13:57 +0100 Subject: [PATCH 03/13] moving to static class --- DebugModule.m | 13 +- DebugModule.swift | 39 ++---- .../player/reactnative/RNPlayerViewPackage.kt | 1 + ios/RCTConvert+BitmovinPlayer.swift | 16 --- src/debug/debugConfig.ts | 2 +- src/debug/index.ts | 123 ++++++------------ src/index.ts | 1 + 7 files changed, 59 insertions(+), 136 deletions(-) diff --git a/DebugModule.m b/DebugModule.m index 06a5ce30..321a9e8a 100644 --- a/DebugModule.m +++ b/DebugModule.m @@ -1,8 +1,7 @@ -// -// DebugModule.m -// Pods -// -// Created by Michele Pozzi on 21.11.24. -// +#import -#import +@interface RCT_EXTERN_REMAP_MODULE(DebugModule, DebugModule, NSObject) + +RCT_EXTERN_METHOD(setLoggingEnabled:(nonnull BOOL)enabled) + +@end diff --git a/DebugModule.swift b/DebugModule.swift index e9dd8c78..bc75f894 100644 --- a/DebugModule.swift +++ b/DebugModule.swift @@ -19,38 +19,19 @@ public class DebugModule: NSObject, RCTBridgeModule { public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } +} - /** - - Gets the `LogLevel` from the debug Log. - - Parameter nativeId: Native Id of the the player instance. - - Parameter resolver: JS promise resolver. - - Parameter rejecter: JS promise rejecter. - */ - @objc(getLevel:resolver:rejecter:) - func getLevel( - _ playerId: NativeId, - resolver resolve: @escaping RCTPromiseResolveBlock, - rejecter reject: @escaping RCTPromiseRejectBlock - ) { +extension DebugModule { + // TODO: docs + @objc(setLoggingEnabled:) + func setLoggingEnabled(enabled: Bool) { bridge.uiManager.addUIBlock { [weak self] _, _ in - guard let logger = DebugConfig.logging.logger else { - reject("[DebugModule]", "Invalid logger for player with ID: (\(playerId))", nil) - return + if enabled { + DebugConfig.logging.logger?.level = .warning// TODO: .verbose } - let level = logger.level - resolve(RCTConvert.toJson(logLevel: level)) - } - } - - /** - * Sets the level for the debug log. - - Parameter nativeId: Target player id. - - Parameter level: The level of the log to set. - */ - @objc(setLogLevel:level:) - func enableDebugging(_ playerId: NativeId, level: LogLevel) { - bridge.uiManager.addUIBlock { [weak self] _, _ in - DebugConfig.logging.logger?.level = level + // else {// TODO: else necessary?? + // DebugConfig.logging.logger?.level + // } } } } 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/RCTConvert+BitmovinPlayer.swift b/ios/RCTConvert+BitmovinPlayer.swift index b0cc184c..4cef95dd 100644 --- a/ios/RCTConvert+BitmovinPlayer.swift +++ b/ios/RCTConvert+BitmovinPlayer.swift @@ -1347,18 +1347,6 @@ extension RCTConvert { } return nowPlayingConfig } - - static func debugConfig(_ json: Any?) -> DebugConfig? { - guard let json = json as? [String: Any?] else { return DebugConfig() } - var debugConfig = DebugConfig() - let isLoggingEnabled = json["isLoggingEnabled"] as? Bool ?? false - debugConfig.isLoggingEnabled = isLoggingEnabled - return debugConfig - } - - static func toJson(logLevel: LogLevel) -> Int { - logLevel.rawValue - } } /** * React native specific PlayerViewConfig. @@ -1413,7 +1401,3 @@ internal struct RNBufferLevels { let audio: BufferLevel let video: BufferLevel } - -//internal struct DebugConfig { -// var isLoggingEnabled: Bool = false -//} diff --git a/src/debug/debugConfig.ts b/src/debug/debugConfig.ts index 50877d46..bbee1f70 100644 --- a/src/debug/debugConfig.ts +++ b/src/debug/debugConfig.ts @@ -3,7 +3,7 @@ import { NativeInstanceConfig } from 'src/nativeInstance'; /** * Global debug configuration for all Bitmovin components. */ -export interface DebugConfig extends NativeInstanceConfig { +export interface DebugConfigOld extends NativeInstanceConfig { /** * Enables global debug logging for all Bitmovin components. * diff --git a/src/debug/index.ts b/src/debug/index.ts index d459b2a1..fd271daa 100644 --- a/src/debug/index.ts +++ b/src/debug/index.ts @@ -1,95 +1,52 @@ import { NativeModules } from 'react-native'; -import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge'; -import NativeInstance from '../nativeInstance'; -import { DebugConfig } from './debugConfig'; const DebugModule = NativeModules.DebugModule; -/** - * Represents a native Network configuration object. - * @internal - */ -export class Debug extends NativeInstance { - /** - * Whether this object's native instance has been created. - */ - isInitialized = false; - /** - * Whether this object's native instance has been disposed. - */ - isDestroyed = false; +export class DebugConfig { + private static _isDebugEnabled = false; /** - * Allocates the Network config instance and its resources natively. - */ - initialize = () => { - if (!this.isInitialized) { - // Register this object as a callable module so it's possible to - // call functions on it from native code, e.g `onPreprocessHttpResponse`. - BatchedBridge.registerCallableModule(`Debug-${this.nativeId}`, this); - // Create native configuration object. - DebugModule.initWithConfig(this.nativeId, this.config); - this.isInitialized = true; - } - }; - - /** - * Destroys the native Network config and releases all of its allocated resources. - */ - destroy = () => { - if (!this.isDestroyed) { - DebugModule.destroy(this.nativeId); - this.isDestroyed = true; - } - }; - - /** - * Applies the user-defined `preprocessHttpRequest` function to native's `type` and `request` data and store - * the result back in `NetworkModule`. + * Enables global debug logging for all Bitmovin components. * - * Called from native code when `NetworkConfig.preprocessHttpRequest` is dispatched. + * Provides detailed information primarily for debugging purposes, helping to + * diagnose problems and trace the flow of execution within the Player. * - * @param requestId Passed through to identify the completion handler of the request on native. - * @param type Type of the request to be made. - * @param request The HTTP request to process. - */ - onPreprocessHttpRequest = ( - requestId: string, - type: HttpRequestType, - request: HttpRequest - ) => { - this.config - ?.preprocessHttpRequest?.(type, request) - .then((resultRequest) => { - NetworkModule.setPreprocessedHttpRequest(requestId, resultRequest); - }) - .catch(() => { - NetworkModule.setPreprocessedHttpRequest(requestId, request); - }); - }; - - /** - * Applies the user-defined `preprocessHttpResponse` function to native's `type` and `response` data and store - * the result back in `NetworkModule`. + * ### 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` * - * Called from native code when `NetworkConfig.preprocessHttpResponse` is dispatched. + * ### Usage Notes: + * - On Android, this flag **must** be set **before** creating any Bitmovin component to take effect. + * - We recommend setting this flag during your app's initialization phase, such as in the + * `Application.onCreate` function on Android or equivalent initialization on iOS. * - * @param responseId Passed through to identify the completion handler of the response on native. - * @param type Type of the request to be made. - * @param response The HTTP response to process. + * ### Warning: + * This option **should not be enabled in production** as it may log sensitive or confidential + * information to the console. + * + * @defaultValue `false` */ - onPreprocessHttpResponse = ( - responseId: string, - type: HttpRequestType, - response: HttpResponse - ) => { - this.config - ?.preprocessHttpResponse?.(type, response) - .then((resultResponse) => { - NetworkModule.setPreprocessedHttpResponse(responseId, resultResponse); - }) - .catch(() => { - NetworkModule.setPreprocessedHttpResponse(responseId, response); - }); - }; + static get isDebugLoggingEnabled(): boolean { + return DebugConfig._isDebugEnabled; + } + + static set isDebugLoggingEnabled(value: boolean) { + DebugConfig._isDebugEnabled = value; + DebugModule.setLoggingEnabled(value).then(() => {}); + } + // getter sync, setter sync (empty promise) } + +// const DebugConfig = { +// set isDebugLoggingEnabled(value: boolean) { +// DebugModule.setLoggingEnabled(value).then(() => {}); // TODO: do I need a promise here? +// }, +// // use get and set if cannot figure it out +// }; + +// export default DebugConfig; 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'; From 2d781967275e20f13194315cc74f15bf533e80bc Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 11:42:42 +0100 Subject: [PATCH 04/13] add module on android --- .../player/reactnative/DebugModule.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt 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..d970ed2e --- /dev/null +++ b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt @@ -0,0 +1,20 @@ +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 + + // TODO: docs + @ReactMethod + fun setLoggingEnabled(enabled: Boolean, promise: Promise) { + promise.unit.resolveOnUiThread { + DebugConfig.isLoggingEnabled = enabled + } + } +} \ No newline at end of file From b91464fd1be2938fe5af2a036bc3e1b3e2f50ea4 Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 12:36:05 +0100 Subject: [PATCH 05/13] Refactoring --- DebugModule.m => ios/DebugModule.m | 0 DebugModule.swift => ios/DebugModule.swift | 11 +++-- src/{debug/index.ts => debug.ts} | 56 ++++++++++++---------- src/debug/debugConfig.ts | 34 ------------- 4 files changed, 36 insertions(+), 65 deletions(-) rename DebugModule.m => ios/DebugModule.m (100%) rename DebugModule.swift => ios/DebugModule.swift (69%) rename src/{debug/index.ts => debug.ts} (55%) delete mode 100644 src/debug/debugConfig.ts diff --git a/DebugModule.m b/ios/DebugModule.m similarity index 100% rename from DebugModule.m rename to ios/DebugModule.m diff --git a/DebugModule.swift b/ios/DebugModule.swift similarity index 69% rename from DebugModule.swift rename to ios/DebugModule.swift index bc75f894..70950476 100644 --- a/DebugModule.swift +++ b/ios/DebugModule.swift @@ -22,16 +22,17 @@ public class DebugModule: NSObject, RCTBridgeModule { } extension DebugModule { - // TODO: docs + /// Enable/disable verbose logging for the console logger. + /// - Parameter enabled: Whether to set verbose logging as enabled or disabled. @objc(setLoggingEnabled:) func setLoggingEnabled(enabled: Bool) { bridge.uiManager.addUIBlock { [weak self] _, _ in + let defaultMinimumLevel: LogLevel = .warning if enabled { - DebugConfig.logging.logger?.level = .warning// TODO: .verbose + DebugConfig.logging.logger?.level = .verbose + } else { + DebugConfig.logging.logger?.level = defaultMinimumLevel } - // else {// TODO: else necessary?? - // DebugConfig.logging.logger?.level - // } } } } diff --git a/src/debug/index.ts b/src/debug.ts similarity index 55% rename from src/debug/index.ts rename to src/debug.ts index fd271daa..feb1325d 100644 --- a/src/debug/index.ts +++ b/src/debug.ts @@ -2,16 +2,33 @@ import { NativeModules } from 'react-native'; const DebugModule = NativeModules.DebugModule; +/** + * Global debug configuration for all Bitmovin components. + */ export class DebugConfig { private static _isDebugEnabled = false; /** - * Enables global debug logging for all Bitmovin components. + * Retrieves the current debug logging state. * - * Provides detailed information primarily for debugging purposes, helping to - * diagnose problems and trace the flow of execution within the Player. + * @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: + * ## 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` @@ -20,33 +37,20 @@ export class DebugConfig { * - `BitmovinSource` * - `BitmovinExoPlayer` * - * ### Usage Notes: - * - On Android, this flag **must** be set **before** creating any Bitmovin component to take effect. + * ## 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.onCreate` function on Android or equivalent initialization on iOS. * - * ### Warning: - * This option **should not be enabled in production** as it may log sensitive or confidential - * information to the console. - * * @defaultValue `false` */ - static get isDebugLoggingEnabled(): boolean { - return DebugConfig._isDebugEnabled; - } - - static set isDebugLoggingEnabled(value: boolean) { + static async setDebugLogging(value: boolean): Promise { DebugConfig._isDebugEnabled = value; - DebugModule.setLoggingEnabled(value).then(() => {}); + await DebugModule.setLoggingEnabled(value); } - // getter sync, setter sync (empty promise) } - -// const DebugConfig = { -// set isDebugLoggingEnabled(value: boolean) { -// DebugModule.setLoggingEnabled(value).then(() => {}); // TODO: do I need a promise here? -// }, -// // use get and set if cannot figure it out -// }; - -// export default DebugConfig; diff --git a/src/debug/debugConfig.ts b/src/debug/debugConfig.ts deleted file mode 100644 index bbee1f70..00000000 --- a/src/debug/debugConfig.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { NativeInstanceConfig } from 'src/nativeInstance'; - -/** - * Global debug configuration for all Bitmovin components. - */ -export interface DebugConfigOld extends NativeInstanceConfig { - /** - * Enables global debug logging for all Bitmovin components. - * - * Provides detailed information primarily for debugging purposes, helping to - * diagnose problems and trace the flow of execution within the Player. - * - * ### 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` - * - * ### Usage Notes: - * - On Android, this flag **must** be set **before** creating any Bitmovin component to take effect. - * - We recommend setting this flag during your app's initialization phase, such as in the - * `Application.onCreate` function on Android or equivalent initialization on iOS. - * - * ### Warning: - * This option **should not be enabled in production** as it may log sensitive or confidential - * information to the console. - * - * @defaultValue `false` - */ - isDebugLoggingEnabled?: boolean; -} From e0ff572ce730a864077e87f53acdd4b430bbe2ef Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 12:53:21 +0100 Subject: [PATCH 06/13] Add docs --- .../main/java/com/bitmovin/player/reactnative/DebugModule.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt index d970ed2e..e3295893 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt @@ -10,7 +10,10 @@ private const val MODULE_NAME = "DebugModule" class DebugModule(context: ReactApplicationContext) : BitmovinBaseModule(context) { override fun getName() = MODULE_NAME - // TODO: docs + /** + * Enable/disable verbose logging for the console logger. + * @param enabled Whether to set verbose logging as enabled or disabled. + */ @ReactMethod fun setLoggingEnabled(enabled: Boolean, promise: Promise) { promise.unit.resolveOnUiThread { From 9454d91edbce0d353424786bf8f01cdea4ddb084 Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 13:00:20 +0100 Subject: [PATCH 07/13] Add newline --- .../main/java/com/bitmovin/player/reactnative/DebugModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt index e3295893..5499d025 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt @@ -20,4 +20,4 @@ class DebugModule(context: ReactApplicationContext) : BitmovinBaseModule(context DebugConfig.isLoggingEnabled = enabled } } -} \ No newline at end of file +} From f5b48c17f25366bb315942a8f05f239d6ffc86f5 Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 13:16:17 +0100 Subject: [PATCH 08/13] Add entry about debug logging getter and setter --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c074951..e88279c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Added + +- `isDebugLoggingEnabled` and `setDebugLogging(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. + ## [0.32.0] - 2024-11-14 ### Added From e83380d5b405bc4f715fdd7716358c42dbaca139 Mon Sep 17 00:00:00 2001 From: Michele Pozzi <96702967+123mpozzi@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:34:25 +0100 Subject: [PATCH 09/13] Rephrase in React-Native terms instead of native MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roland Kákonyi --- src/debug.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug.ts b/src/debug.ts index feb1325d..8ecff105 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -45,7 +45,7 @@ export class DebugConfig { * ## Usage Notes * --- * - We recommend setting this flag during your app's initialization phase, such as in the - * `Application.onCreate` function on Android or equivalent initialization on iOS. + * application's entry point (e.g. `App.tsx`). * * @defaultValue `false` */ From a2d6bb1b90de5c55b571ccf0845ddf788b76b7fb Mon Sep 17 00:00:00 2001 From: Michele Pozzi <96702967+123mpozzi@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:48:15 +0100 Subject: [PATCH 10/13] Add missing class name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roland Kákonyi --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e88279c6..77ff4290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- `isDebugLoggingEnabled` and `setDebugLogging(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. +- `DebugConfig.isDebugLoggingEnabled` and `DebugConfig.setDebugLogging(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. ## [0.32.0] - 2024-11-14 From 10b027f45ed357e4eccc9d4c7105ca3ec10ee15f Mon Sep 17 00:00:00 2001 From: Michele Pozzi <96702967+123mpozzi@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:48:45 +0100 Subject: [PATCH 11/13] Shortify branch with ternary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Roland Kákonyi --- ios/DebugModule.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ios/DebugModule.swift b/ios/DebugModule.swift index 70950476..ec04fbb2 100644 --- a/ios/DebugModule.swift +++ b/ios/DebugModule.swift @@ -27,12 +27,7 @@ extension DebugModule { @objc(setLoggingEnabled:) func setLoggingEnabled(enabled: Bool) { bridge.uiManager.addUIBlock { [weak self] _, _ in - let defaultMinimumLevel: LogLevel = .warning - if enabled { - DebugConfig.logging.logger?.level = .verbose - } else { - DebugConfig.logging.logger?.level = defaultMinimumLevel - } + DebugConfig.logging.logger?.level = enabled ? .verbose : .warning } } } From 6ccf48a777249ede7d1d107d255ee9b2320f0b77 Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 14:37:07 +0100 Subject: [PATCH 12/13] Rename setter --- CHANGELOG.md | 2 +- src/debug.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ff4290..bc4d3c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- `DebugConfig.isDebugLoggingEnabled` and `DebugConfig.setDebugLogging(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. +- `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. ## [0.32.0] - 2024-11-14 diff --git a/src/debug.ts b/src/debug.ts index 8ecff105..cbe0ee4f 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -49,7 +49,7 @@ export class DebugConfig { * * @defaultValue `false` */ - static async setDebugLogging(value: boolean): Promise { + static async setDebugLoggingEnabled(value: boolean): Promise { DebugConfig._isDebugEnabled = value; await DebugModule.setLoggingEnabled(value); } From d1b0ed2232af581273c5e7a03380f27d484d4a5e Mon Sep 17 00:00:00 2001 From: Michele Pozzi <123.mpozzi@gmail.com> Date: Fri, 22 Nov 2024 14:39:27 +0100 Subject: [PATCH 13/13] Rename setter --- .../main/java/com/bitmovin/player/reactnative/DebugModule.kt | 2 +- ios/DebugModule.m | 2 +- ios/DebugModule.swift | 4 ++-- src/debug.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt index 5499d025..98cff642 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/DebugModule.kt @@ -15,7 +15,7 @@ class DebugModule(context: ReactApplicationContext) : BitmovinBaseModule(context * @param enabled Whether to set verbose logging as enabled or disabled. */ @ReactMethod - fun setLoggingEnabled(enabled: Boolean, promise: Promise) { + fun setDebugLoggingEnabled(enabled: Boolean, promise: Promise) { promise.unit.resolveOnUiThread { DebugConfig.isLoggingEnabled = enabled } diff --git a/ios/DebugModule.m b/ios/DebugModule.m index 321a9e8a..777bb0c8 100644 --- a/ios/DebugModule.m +++ b/ios/DebugModule.m @@ -2,6 +2,6 @@ @interface RCT_EXTERN_REMAP_MODULE(DebugModule, DebugModule, NSObject) -RCT_EXTERN_METHOD(setLoggingEnabled:(nonnull BOOL)enabled) +RCT_EXTERN_METHOD(setDebugLoggingEnabled:(nonnull BOOL)enabled) @end diff --git a/ios/DebugModule.swift b/ios/DebugModule.swift index ec04fbb2..341a7749 100644 --- a/ios/DebugModule.swift +++ b/ios/DebugModule.swift @@ -24,8 +24,8 @@ public class DebugModule: NSObject, RCTBridgeModule { extension DebugModule { /// Enable/disable verbose logging for the console logger. /// - Parameter enabled: Whether to set verbose logging as enabled or disabled. - @objc(setLoggingEnabled:) - func setLoggingEnabled(enabled: Bool) { + @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 index cbe0ee4f..960dec72 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -51,6 +51,6 @@ export class DebugConfig { */ static async setDebugLoggingEnabled(value: boolean): Promise { DebugConfig._isDebugEnabled = value; - await DebugModule.setLoggingEnabled(value); + await DebugModule.setDebugLoggingEnabled(value); } }