From 0d49eab2057370e57ed61d617903427b00bd7da8 Mon Sep 17 00:00:00 2001 From: Roland Kakonyi Date: Mon, 16 Oct 2023 12:06:33 +0200 Subject: [PATCH 1/2] feat(swiftlint-warnings): fix SwiftLint warnings --- .swiftlint.yml | 4 + ios/AudioSessionModule.swift | 18 +-- ios/BitmovinCastManagerModule.swift | 19 ++- ios/CustomMessageHandlerBridge.swift | 14 +- ios/CustomMessageHandlerModule.swift | 32 +++-- ios/DrmModule.swift | 93 +++++++----- ios/Event+JSON.swift | 13 +- ios/FullscreenHandlerBridge.swift | 2 +- ios/FullscreenHandlerModule.swift | 20 +-- ios/OfflineContentManagerBridge.swift | 77 ++++++---- ios/OfflineModule.swift | 81 ++++++----- ios/PlayerAnalyticsModule.swift | 20 ++- ios/PlayerModule.swift | 50 ++++--- ios/RCTConvert+BitmovinPlayer.swift | 143 +++++++++++-------- ios/RNPlayerView+PlayerListener.swift | 104 +++++++------- ios/RNPlayerView+UserInterfaceListener.swift | 16 +-- ios/RNPlayerView.swift | 4 +- ios/RNPlayerViewManager.swift | 31 ++-- ios/Registry.swift | 4 +- ios/SourceModule.swift | 32 +++-- ios/UuidModule.swift | 11 +- 21 files changed, 457 insertions(+), 331 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 890206c5..15967fb7 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,3 +1,7 @@ +excluded: + # folders that are excluded from linting, external dependencies or generated files + - ${PWD}/example/ios/Pods + disabled_rules: - todo - trailing_comma diff --git a/ios/AudioSessionModule.swift b/ios/AudioSessionModule.swift index 2e1f6ef9..1b93a2ae 100644 --- a/ios/AudioSessionModule.swift +++ b/ios/AudioSessionModule.swift @@ -1,19 +1,18 @@ import AVFAudio @objc(AudioSessionModule) -class AudioSessionModule: NSObject, RCTBridgeModule { - // Run this module methods on main thread. - var methodQueue: DispatchQueue! { +public class AudioSessionModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { DispatchQueue.main } - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "AudioSessionModule" } - // Requires module initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } @@ -23,7 +22,8 @@ class AudioSessionModule: NSObject, RCTBridgeModule { - Parameter resolver: JS promise resolver block. - Parameter rejecter: JS promise rejecter block. */ - @objc func setCategory( + @objc + func setCategory( _ category: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock @@ -45,7 +45,7 @@ class AudioSessionModule: NSObject, RCTBridgeModule { Parse any category string to an `AVAudioSession.Category` type. */ private func parseCategory(_ category: String) -> AVAudioSession.Category? { - switch (category) { + switch category { case "ambient": return .ambient case "multiRoute": diff --git a/ios/BitmovinCastManagerModule.swift b/ios/BitmovinCastManagerModule.swift index f636c2f1..fb4e05be 100644 --- a/ios/BitmovinCastManagerModule.swift +++ b/ios/BitmovinCastManagerModule.swift @@ -1,22 +1,21 @@ import BitmovinPlayer @objc(BitmovinCastManagerModule) -class BitmovinCastManagerModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class BitmovinCastManagerModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "BitmovinCastManagerModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Since most `BitmovinCastManagerModule` operations are UI related and need to be executed on the main thread, they are scheduled with `UIManager.addBlock`. - var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } @@ -31,7 +30,7 @@ class BitmovinCastManagerModule: NSObject, RCTBridgeModule { ) { #if os(iOS) bridge.uiManager.addUIBlock { _, _ in - if let config = config { + if let config { guard let options = RCTConvert.castManagerOptions(config) else { reject("BitmovinCastManagerModule", "Could not deserialize BitmovinCastManagerOptions", nil) return diff --git a/ios/CustomMessageHandlerBridge.swift b/ios/CustomMessageHandlerBridge.swift index 742aeb58..d1b6f089 100644 --- a/ios/CustomMessageHandlerBridge.swift +++ b/ios/CustomMessageHandlerBridge.swift @@ -1,6 +1,6 @@ import BitmovinPlayer -class CustomMessageHandlerBridge: NSObject { +internal class CustomMessageHandlerBridge: NSObject { #if os(iOS) private(set) lazy var customMessageHandler: CustomMessageHandler = { let customMessageHandler = CustomMessageHandler() @@ -21,11 +21,19 @@ class CustomMessageHandlerBridge: NSObject { } func receivedSynchronousMessage(_ message: String, withData data: String?) -> String? { - bridge[CustomMessageHandlerModule.self]?.receivedSynchronousMessage(nativeId: nativeId, message: message, withData: data) + bridge[CustomMessageHandlerModule.self]?.receivedSynchronousMessage( + nativeId: nativeId, + message: message, + withData: data + ) } func receivedAsynchronousMessage(_ message: String, withData data: String?) { - bridge[CustomMessageHandlerModule.self]?.receivedAsynchronousMessage(nativeId: nativeId, message: message, withData: data) + bridge[CustomMessageHandlerModule.self]?.receivedAsynchronousMessage( + nativeId: nativeId, + message: message, + withData: data + ) } func sendMessage(_ message: String, withData data: String?) { diff --git a/ios/CustomMessageHandlerModule.swift b/ios/CustomMessageHandlerModule.swift index 4e64c5fa..645351b9 100644 --- a/ios/CustomMessageHandlerModule.swift +++ b/ios/CustomMessageHandlerModule.swift @@ -1,22 +1,21 @@ import BitmovinPlayer @objc(CustomMessageHandlerModule) -class CustomMessageHandlerModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class CustomMessageHandlerModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "CustomMessageHandlerModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Use `UIManager.addBlock` to enqueue module methods on UI thread. - var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } @@ -31,7 +30,8 @@ class CustomMessageHandlerModule: NSObject, RCTBridgeModule { - Parameter nativeId: `CustomMessageHandlerBridge` instance ID. - Returns: The associated `CustomMessageHandlerBridge` instance or `nil`. */ - @objc func retrieve(_ nativeId: NativeId) -> CustomMessageHandlerBridge? { + @objc + func retrieve(_ nativeId: NativeId) -> CustomMessageHandlerBridge? { customMessageHandlers[nativeId] } @@ -68,7 +68,11 @@ class CustomMessageHandlerModule: NSObject, RCTBridgeModule { withData data: String? ) -> String? { customMessageHandlerDispatchGroup.enter() - bridge.enqueueJSCall("CustomMessageBridge-\(nativeId)", method: "receivedSynchronousMessage", args: [message, data]) {} + bridge.enqueueJSCall( + "CustomMessageBridge-\(nativeId)", + method: "receivedSynchronousMessage", + args: [message, data] + ) {} customMessageHandlerDispatchGroup.wait() return customMessageHandlers[nativeId]?.popSynchronousResult() } @@ -78,6 +82,10 @@ class CustomMessageHandlerModule: NSObject, RCTBridgeModule { message: String, withData data: String? ) { - bridge.enqueueJSCall("CustomMessageBridge-\(nativeId)", method: "receivedAsynchronousMessage", args: [message, data]) {} + bridge.enqueueJSCall( + "CustomMessageBridge-\(nativeId)", + method: "receivedAsynchronousMessage", + args: [message, data] + ) {} } } diff --git a/ios/DrmModule.swift b/ios/DrmModule.swift index 9229eabc..c750cef9 100644 --- a/ios/DrmModule.swift +++ b/ios/DrmModule.swift @@ -1,34 +1,34 @@ import BitmovinPlayer @objc(DrmModule) -class DrmModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class DrmModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! /// In-memory mapping from `nativeId`s to `FairplayConfig` instances. private var drmConfigs: Registry = [:] - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "DrmModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - - /// Use `UIManager.addBlock` to enqueue module methods on UI thread. - var methodQueue: DispatchQueue! { + + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } - + /** Creates a new `FairplayConfig` instance inside the internal drmConfigs using the provided `config` object. - Parameter nativeId: ID to associate with the `FairplayConfig` instance. - Returns: The associated `FairplayConfig` instance or `nil`. */ - @objc func retrieve(_ nativeId: NativeId) -> FairplayConfig? { + @objc + func retrieve(_ nativeId: NativeId) -> FairplayConfig? { drmConfigs[nativeId] } @@ -52,7 +52,8 @@ class DrmModule: NSObject, RCTBridgeModule { } /** - Removes the `FairplayConfig` instance associated with `nativeId` from `drmConfigs` and all data produced during preparation hooks. + Removes the `FairplayConfig` instance associated with `nativeId` from `drmConfigs` + and all data produced during preparation hooks. - Parameter nativeId Instance to be disposed. */ @objc(destroy:) @@ -78,7 +79,8 @@ class DrmModule: NSObject, RCTBridgeModule { var preparedSyncMessages: Registry = [:] /// Mapping between an object's `nativeId` and the value that'll be returned by its `prepareLicense` callback. var preparedLicenses: Registry = [:] - /// Mapping between an object's `nativeId` and the value that'll be returned by its `prepareLicenseServerUrl` callback. + /// Mapping between an object's `nativeId` and the value that'll be returned + /// by its `prepareLicenseServerUrl` callback. var preparedLicenseServerUrls: Registry = [:] /// Mapping between an object's `nativeId` and the value that'll be returned by its `prepareContentId` callback. var preparedContentIds: Registry = [:] @@ -86,11 +88,14 @@ class DrmModule: NSObject, RCTBridgeModule { /** Function called from JS to store the computed `prepareCertificate` return value for `nativeId`. - Note this function is **synchronous** and **blocks** the JS thread. It's important that it stays this way, otherwise we wouldn't be able to return + Note this function is **synchronous** and **blocks** the JS thread. + It's important that it stays this way, otherwise we wouldn't be able to return the computed JS message from inside the `fairplayConfig.prepareCertificate` Swift closure. - Also, since RN has some limitations regarding the definition of sync JS methods from Swift, it's necessary to add a return type and a return - value (even if it's a void method like in this case) or a crash happens. So the type `Any?` and return value `nil` were used here (it could be any value). + Also, since RN has some limitations regarding the definition of sync JS methods from Swift, + it's necessary to add a return type and a return + value (even if it's a void method like in this case) or a crash happens. + So the type `Any?` and return value `nil` were used here (it could be any value). */ @objc(setPreparedCertificate:certificate:) func setPreparedCertificate(_ nativeId: NativeId, certificate: String) -> Any? { @@ -101,11 +106,14 @@ class DrmModule: NSObject, RCTBridgeModule { /** Function called from JS to store the computed `prepareMessage` return value for `nativeId`. - Note this function is **synchronous** and **blocks** the JS thread. It's important that it stays this way, otherwise we wouldn't be able to return + Note this function is **synchronous** and **blocks** the JS thread. + It's important that it stays this way, otherwise we wouldn't be able to return the computed JS message from inside the `fairplayConfig.prepareMessage` Swift closure. - Also, since RN has some limitations regarding the definition of sync JS methods from Swift, it's necessary to add a return type and a return - value (even if it's a void method like in this case) or a crash happens. So the type `Any?` and return value `nil` were used here (it could be any value). + Also, since RN has some limitations regarding the definition of sync JS methods from Swift, + it's necessary to add a return type and a return + value (even if it's a void method like in this case) or a crash happens. + So the type `Any?` and return value `nil` were used here (it could be any value). */ @objc(setPreparedMessage:message:) func setPreparedMessage(_ nativeId: NativeId, message: String) -> Any? { @@ -116,26 +124,32 @@ class DrmModule: NSObject, RCTBridgeModule { /** Function called from JS to store the computed `prepareSyncMessage` return value for `nativeId`. - Note this function is **synchronous** and **blocks** the JS thread. It's important that it stays this way, otherwise we wouldn't be able to return + Note this function is **synchronous** and **blocks** the JS thread. + It's important that it stays this way, otherwise we wouldn't be able to return the computed JS message from inside the `fairplayConfig.prepareSyncMessage` Swift closure. - Also, since RN has some limitations regarding the definition of sync JS methods from Swift, it's necessary to add a return type and a return - value (even if it's a void method like in this case) or a crash happens. So the type `Any?` and return value `nil` were used here (it could be any value). + Also, since RN has some limitations regarding the definition of sync JS methods from Swift, + it's necessary to add a return type and a return + value (even if it's a void method like in this case) or a crash happens. + So the type `Any?` and return value `nil` were used here (it could be any value). */ @objc(setPreparedSyncMessage:syncMessage:) func setPreparedSyncMessage(_ nativeId: NativeId, syncMessage: String) -> Any? { preparedSyncMessages[nativeId] = syncMessage return nil } - + /** Function called from JS to store the computed `prepareLicense` return value for `nativeId`. - Note this function is **synchronous** and **blocks** the JS thread. It's important that it stays this way, otherwise we wouldn't be able to return + Note this function is **synchronous** and **blocks** the JS thread. + It's important that it stays this way, otherwise we wouldn't be able to return the computed JS message from inside the `fairplayConfig.prepareLicense` Swift closure. - Also, since RN has some limitations regarding the definition of sync JS methods from Swift, it's necessary to add a return type and a return value - (even if it's a void method like in this case) or a crash happens. So the type `Any?` and return value `nil` were used here (it could be any value). + Also, since RN has some limitations regarding the definition of sync JS methods from Swift, + it's necessary to add a return type and a return value + (even if it's a void method like in this case) or a crash happens. + So the type `Any?` and return value `nil` were used here (it could be any value). */ @objc(setPreparedLicense:license:) func setPreparedLicense(_ nativeId: NativeId, license: String) -> Any? { @@ -146,11 +160,14 @@ class DrmModule: NSObject, RCTBridgeModule { /** Function called from JS to store the computed `prepareLicenseServerUrl` return value for `nativeId`. - Note this function is **synchronous** and **blocks** the JS thread. It's important that it stays this way, otherwise we wouldn't be able to return + Note this function is **synchronous** and **blocks** the JS thread. + It's important that it stays this way, otherwise we wouldn't be able to return the computed JS message from inside the `fairplayConfig.prepareLicenseServerUrl` Swift closure. - Also, since RN has some limitations regarding the definition of sync JS methods from Swift, it's necessary to add a return type and a return value - (even if it's a void method like in this case) or a crash happens. So the type `Any?` and return value `nil` were used here (it could be any value). + Also, since RN has some limitations regarding the definition of sync JS methods from Swift, + it's necessary to add a return type and a return value + (even if it's a void method like in this case) or a crash happens. + So the type `Any?` and return value `nil` were used here (it could be any value). */ @objc(setPreparedLicenseServerUrl:url:) func setPreparedLicenseServerUrl(_ nativeId: NativeId, url: String) -> Any? { @@ -161,11 +178,14 @@ class DrmModule: NSObject, RCTBridgeModule { /** Function called from JS to store the computed `prepareContentId` return value for `nativeId`. - Note this function is **synchronous** and **blocks** the JS thread. It's important that it stays this way, otherwise we wouldn't be able to return + Note this function is **synchronous** and **blocks** the JS thread. + It's important that it stays this way, otherwise we wouldn't be able to return the computed JS message from inside the `fairplayConfig.prepareContentId` Swift closure. - Also, since RN has some limitations regarding the definition of sync JS methods from Swift, it's necessary to add a return type and a return value - (even if it's a void method like in this case) or a crash happens. So the type `Any?` and return value `nil` were used here (it could be any value). + Also, since RN has some limitations regarding the definition of sync JS methods from Swift, + it's necessary to add a return type and a return value + (even if it's a void method like in this case) or a crash happens. + So the type `Any?` and return value `nil` were used here (it could be any value). */ @objc(setPreparedContentId:contentId:) func setPreparedContentId(_ nativeId: NativeId, contentId: String) -> Any? { @@ -174,7 +194,8 @@ class DrmModule: NSObject, RCTBridgeModule { } /** - Initialize all configuration blocks in `FairplayConfig` applying the designated JS functions according to it's JS instance config. + Initialize all configuration blocks in `FairplayConfig` applying the designated + JS functions according to it's JS instance config. - Parameter nativeId: Instance nativeId. - Parameter config: FairPlay config object sent from JS. @@ -189,7 +210,7 @@ class DrmModule: NSObject, RCTBridgeModule { initPrepareContentId(nativeId, fairplayJson: fairplayJson) } } - + /** Initialize the `prepareCertificate` block in the `FairplayConfig` associated with `nativeId`. @@ -274,7 +295,7 @@ class DrmModule: NSObject, RCTBridgeModule { } } } - + /** Initialize the `prepareContentId` block in the `FairplayConfig` associated with `nativeId`. diff --git a/ios/Event+JSON.swift b/ios/Event+JSON.swift index 8dfc82b0..7230c2e7 100644 --- a/ios/Event+JSON.swift +++ b/ios/Event+JSON.swift @@ -8,7 +8,7 @@ extension Source { "loadingState": loadingState, "isAttachedToPlayer": isAttachedToPlayer ] - if let metadata = metadata { + if let metadata { json["metadata"] = metadata } return json @@ -69,14 +69,14 @@ extension NSError { extension DeficiencyData { func toJSON() -> [AnyHashable: Any] { var json: [AnyHashable: Any] = ["code": code, "message": message] - if let underlyingError = underlyingError { + if let underlyingError { json["underlyingError"] = underlyingError.toJSON() } return json } } -protocol ErrorEventType: Event { +private protocol ErrorEventType: Event { associatedtype Code var code: Code { get } var data: DeficiencyData? { get } @@ -91,7 +91,7 @@ extension ErrorEventType { "code": code, "message": message ] - if let data = data { + if let data { json["data"] = data.toJSON() } return json @@ -114,7 +114,7 @@ extension SourceWarningEvent: ErrorEventType { typealias Code = SourceWarning.Code } -protocol SourceEventType: Event { +private protocol SourceEventType: Event { var source: Source { get } } @@ -128,7 +128,7 @@ extension SourceLoadEvent: SourceEventType {} extension SourceLoadedEvent: SourceEventType {} extension SourceUnloadedEvent: SourceEventType {} -protocol TimedEventType: Event { +private protocol TimedEventType: Event { var time: TimeInterval { get } } @@ -175,7 +175,6 @@ extension AudioChangedEvent { } } - extension SubtitleAddedEvent { func toJSON() -> [AnyHashable: Any] { [ diff --git a/ios/FullscreenHandlerBridge.swift b/ios/FullscreenHandlerBridge.swift index 2a26cca3..d2b817a1 100644 --- a/ios/FullscreenHandlerBridge.swift +++ b/ios/FullscreenHandlerBridge.swift @@ -1,6 +1,6 @@ import BitmovinPlayer -class FullscreenHandlerBridge: NSObject, FullscreenHandler { +internal class FullscreenHandlerBridge: NSObject, FullscreenHandler { var isFullscreen = false private let nativeId: NativeId diff --git a/ios/FullscreenHandlerModule.swift b/ios/FullscreenHandlerModule.swift index 488c5929..963b0cbd 100644 --- a/ios/FullscreenHandlerModule.swift +++ b/ios/FullscreenHandlerModule.swift @@ -1,22 +1,21 @@ import BitmovinPlayer @objc(FullscreenHandlerModule) -class FullscreenHandlerModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class FullscreenHandlerModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "FullscreenHandlerModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Use `UIManager.addBlock` to enqueue module methods on UI thread. - var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } @@ -31,7 +30,8 @@ class FullscreenHandlerModule: NSObject, RCTBridgeModule { - Parameter nativeId: `FullscreenHandlerBridge` instance ID. - Returns: The associated `FullscreenHandlerBridge` instance or `nil`. */ - @objc func retrieve(_ nativeId: NativeId) -> FullscreenHandlerBridge? { + @objc + func retrieve(_ nativeId: NativeId) -> FullscreenHandlerBridge? { fullscreenHandlers[nativeId] } diff --git a/ios/OfflineContentManagerBridge.swift b/ios/OfflineContentManagerBridge.swift index 161b79a8..4937ace2 100644 --- a/ios/OfflineContentManagerBridge.swift +++ b/ios/OfflineContentManagerBridge.swift @@ -1,25 +1,25 @@ #if os(iOS) -import Foundation import BitmovinPlayer +import Foundation -class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { +internal class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { enum EventType: String { - case onCompleted = "onCompleted" - case onError = "onError" - case onProgress = "onProgress" - case onOptionsAvailable = "onOptionsAvailable" - case onDrmLicenseUpdated = "onDrmLicenseUpdated" - case onSuspended = "onSuspended" - case onResumed = "onResumed" - case onCanceled = "onCanceled" - case onDrmLicenseExpired = "onDrmLicenseExpired" + case onCompleted + case onError + case onProgress + case onOptionsAvailable + case onDrmLicenseUpdated + case onSuspended + case onResumed + case onCanceled + case onDrmLicenseExpired } let offlineContentManager: OfflineContentManager let eventEmitter: RCTEventEmitter? let nativeId: NativeId let identifier: String - var currentTrackSelection: OfflineTrackSelection? = nil + var currentTrackSelection: OfflineTrackSelection? init( forManager offlineContentManager: OfflineContentManager, @@ -50,7 +50,10 @@ class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { /** Called when an error occurs. */ - func onOfflineError(_ event: OfflineErrorEvent, offlineContentManager: OfflineContentManager) { + func onOfflineError( + _ event: OfflineErrorEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onError, body: [ "code": event.code, "message": event.message @@ -60,7 +63,10 @@ class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { /** Called after a getOptions or when am OfflineOptionEntry has been updated during a process call. */ - func onAvailableTracksFetched(_ event: AvailableTracksFetchedEvent, offlineContentManager: OfflineContentManager) { + func onAvailableTracksFetched( + _ event: AvailableTracksFetchedEvent, + offlineContentManager: OfflineContentManager + ) { currentTrackSelection = event.tracks sendOfflineEvent(eventType: .onOptionsAvailable, body: [ @@ -71,7 +77,10 @@ class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { /** Called when a process call has completed. */ - func onContentDownloadFinished(_ event: ContentDownloadFinishedEvent, offlineContentManager: OfflineContentManager) { + func onContentDownloadFinished( + _ event: ContentDownloadFinishedEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onCompleted, body: [ "options": RCTConvert.toJson(offlineTracks: currentTrackSelection) ]) @@ -80,7 +89,10 @@ class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { /** Called when the progress for a process call changes. */ - func onContentDownloadProgressChanged(_ event: ContentDownloadProgressChangedEvent, offlineContentManager: OfflineContentManager) { + func onContentDownloadProgressChanged( + _ event: ContentDownloadProgressChangedEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onProgress, body: [ "progress": event.progress ]) @@ -89,35 +101,52 @@ class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { /** Called when all actions have been suspended. */ - func onContentDownloadSuspended(_ event: ContentDownloadSuspendedEvent, offlineContentManager: OfflineContentManager) { + func onContentDownloadSuspended( + _ event: ContentDownloadSuspendedEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onSuspended) } /** Called when all actions have been resumed. */ - func onContentDownloadResumed(_ event: ContentDownloadResumedEvent, offlineContentManager: OfflineContentManager) { + func onContentDownloadResumed( + _ event: ContentDownloadResumedEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onResumed) } /** - Called when the download of the media content was canceled by the user and all partially downloaded content has been deleted from disk. + Called when the download of the media content was canceled by the user + and all partially downloaded content has been deleted from disk. */ - func onContentDownloadCanceled(_ event: ContentDownloadCanceledEvent, offlineContentManager: OfflineContentManager) { + func onContentDownloadCanceled( + _ event: ContentDownloadCanceledEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onCanceled) } /** Called when the DRM license was renewed. */ - func onOfflineContentLicenseRenewed(_ event: OfflineContentLicenseRenewedEvent, offlineContentManager: OfflineContentManager) { + func onOfflineContentLicenseRenewed( + _ event: OfflineContentLicenseRenewedEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onDrmLicenseUpdated) } /** - Called on every call to OfflineContentManager.createOfflineSourceConfig(restrictedToAssetCache:) if it is DRM protected and the offline DRM license has expired. + Called on every call to OfflineContentManager.createOfflineSourceConfig(restrictedToAssetCache:) + if it is DRM protected and the offline DRM license has expired. */ - func onOfflineContentLicenseExpired(_ event: OfflineContentLicenseExpiredEvent, offlineContentManager: OfflineContentManager) { + func onOfflineContentLicenseExpired( + _ event: OfflineContentLicenseExpiredEvent, + offlineContentManager: OfflineContentManager + ) { sendOfflineEvent(eventType: .onDrmLicenseExpired) } @@ -129,7 +158,7 @@ class OfflineContentManagerBridge: NSObject, OfflineContentManagerListener { "state": RCTConvert.toJson(offlineState: offlineContentManager.offlineState) ] - var eventBody = baseEvent.merging(body) { (current, _) in current } + var eventBody = baseEvent.merging(body) { current, _ in current } do { try eventEmitter?.sendEvent(withName: "BitmovinOfflineEvent", body: eventBody) diff --git a/ios/OfflineModule.swift b/ios/OfflineModule.swift index b9b70321..b74aef7a 100644 --- a/ios/OfflineModule.swift +++ b/ios/OfflineModule.swift @@ -1,25 +1,24 @@ - -import Foundation import BitmovinPlayer +import Foundation @objc(OfflineModule) -class OfflineModule: RCTEventEmitter { - /// JS module name. - override static func moduleName() -> String! { +public class OfflineModule: RCTEventEmitter { // swiftlint:disable:this type_body_length + // swiftlint:disable:next implicitly_unwrapped_optional + override public static func moduleName() -> String! { "BitmovinOfflineModule" } - /// Module requires main thread initialization. - override static func requiresMainQueueSetup() -> Bool { + override public static func requiresMainQueueSetup() -> Bool { true } - override func supportedEvents() -> [String]! { - return ["BitmovinOfflineEvent"] + // swiftlint:disable:next implicitly_unwrapped_optional + override public func supportedEvents() -> [String]! { + ["BitmovinOfflineEvent"] } - /// Since most `OfflineModule` operations are UI related and need to be executed on the main thread, they are scheduled with `UIManager.addBlock`. - override var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + override public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } @@ -37,8 +36,9 @@ class OfflineModule: RCTEventEmitter { #endif /** - Creates a new `OfflineContentManager` instance inside the internal offline managers using the provided config object. - - @param config Config object received from JS. Should contain `sourceConfig` and `identifier`. + Creates a new `OfflineContentManager` instance inside the internal offline managers using + the provided config object. + - Parameter config: Config object received from JS. Should contain `sourceConfig` and `identifier`. */ @objc(initWithConfig:config:drmNativeId:resolver:rejecter:) func initWithConfig( @@ -51,7 +51,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, self.offlineContentManagerBridges[nativeId] == nil, let config = config as? [String: Any?], let identifier = config["identifier"] as? String @@ -94,7 +94,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -108,7 +108,8 @@ class OfflineModule: RCTEventEmitter { /** Starts the `OfflineContentManager`'s asynchronous process of fetching the `OfflineContentOptions`. - When the options are loaded a device event will be fired where the event type is `BitmovinOfflineEvent` and the data has an event type of `onOptionsAvailable`. + When the options are loaded a device event will be fired where the event type is `BitmovinOfflineEvent` + and the data has an event type of `onOptionsAvailable`. - Parameter nativeId: Target offline module Id. - Parameter resolver: JS promise resolver. - Parameter rejecter: JS promise rejecter. @@ -117,11 +118,12 @@ class OfflineModule: RCTEventEmitter { func getOptions( _ nativeId: NativeId, resolver resolve: @escaping RCTPromiseResolveBlock, - rejecter reject: @escaping RCTPromiseRejectBlock) { + rejecter reject: @escaping RCTPromiseRejectBlock + ) { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -138,12 +140,13 @@ class OfflineModule: RCTEventEmitter { Enqueues downloads according to the `OfflineDownloadRequest`. * The promise will reject in the event of null or invalid request parameters. - Parameter nativeId: Target offline module Id - - Parameter request: The download request js object containing the requested bitrate and track option ids to download. + - Parameter request: The download request js object containing the requested bitrate + and track option ids to download. - Parameter resolver: JS promise resolver. - Parameter rejecter: JS promise rejecter. */ @objc(download:request:resolver:rejecter:) - func download( + func download( // swiftlint:disable:this cyclomatic_complexity function_body_length _ nativeId: NativeId, request: Any?, resolver resolve: @escaping RCTPromiseResolveBlock, @@ -152,7 +155,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -213,7 +216,10 @@ class OfflineModule: RCTEventEmitter { config.minimumBitrate = minimumBitrate } - offlineContentManagerBridge.offlineContentManager.download(tracks: currentTrackSelection, downloadConfig: config) + offlineContentManagerBridge.offlineContentManager.download( + tracks: currentTrackSelection, + downloadConfig: config + ) resolve(nil) } #endif @@ -229,11 +235,12 @@ class OfflineModule: RCTEventEmitter { func resume( _ nativeId: NativeId, resolver resolve: @escaping RCTPromiseResolveBlock, - rejecter reject: @escaping RCTPromiseRejectBlock) { + rejecter reject: @escaping RCTPromiseRejectBlock + ) { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -261,7 +268,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -289,7 +296,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -317,7 +324,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -344,7 +351,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -359,8 +366,10 @@ class OfflineModule: RCTEventEmitter { /** Downloads the offline license. - When finished successfully a device event will be fired where the event type is `BitmovinOfflineEvent` and the data has an event type of `onDrmLicenseUpdated`. - Errors are transmitted by a device event will be fired where the event type is `BitmovinOfflineEvent` and the data has an event type of `onError`. + When finished successfully a device event will be fired where the event type is `BitmovinOfflineEvent` + and the data has an event type of `onDrmLicenseUpdated`. + Errors are transmitted by a device event will be fired where the event type is `BitmovinOfflineEvent` + and the data has an event type of `onError`. - Parameter nativeId: Target offline module Id - Parameter resolver: JS promise resolver. - Parameter rejecter: JS promise rejecter. @@ -374,7 +383,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -389,8 +398,10 @@ class OfflineModule: RCTEventEmitter { /** Renews the already downloaded DRM license. - When finished successfully a device event will be fired where the event type is `BitmovinOfflineEvent` and the data has an event type of `onDrmLicenseUpdated`. - Errors are transmitted by a device event will be fired where the event type is `BitmovinOfflineEvent` and the data has an event type of `onError`. + When finished successfully a device event will be fired where the event type is `BitmovinOfflineEvent` + and the data has an event type of `onDrmLicenseUpdated`. + Errors are transmitted by a device event will be fired where the event type is `BitmovinOfflineEvent` + and the data has an event type of `onError`. - Parameter nativeId: Target offline module Id - Parameter resolver: JS promise resolver. - Parameter rejecter: JS promise rejecter. @@ -404,7 +415,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) @@ -434,7 +445,7 @@ class OfflineModule: RCTEventEmitter { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in guard - let self = self, + let self, let offlineContentManagerBridge = self.offlineContentManagerBridges[nativeId] else { reject("BitmovinOfflineModule", "Could not find the offline module instance", nil) diff --git a/ios/PlayerAnalyticsModule.swift b/ios/PlayerAnalyticsModule.swift index 34960e76..e64bdf61 100644 --- a/ios/PlayerAnalyticsModule.swift +++ b/ios/PlayerAnalyticsModule.swift @@ -1,28 +1,26 @@ -import BitmovinPlayer import BitmovinCollector +import BitmovinPlayer @objc(PlayerAnalyticsModule) -class PlayerAnalyticsModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class PlayerAnalyticsModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! - /// PlayerModule instance fetched from the bridge's registry @objc var playerModule: PlayerModule? { bridge.module(for: PlayerModule.self) as? PlayerModule } - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "PlayerAnalyticsModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Use `UIManager.addBlock` to enqueue module methods on UI thread. - var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } diff --git a/ios/PlayerModule.swift b/ios/PlayerModule.swift index 725e330e..bb266688 100644 --- a/ios/PlayerModule.swift +++ b/ios/PlayerModule.swift @@ -1,25 +1,25 @@ +// swiftlint:disable file_length import BitmovinPlayer @objc(PlayerModule) -class PlayerModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class PlayerModule: NSObject, RCTBridgeModule { // swiftlint:disable:this type_body_length + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! /// In-memory mapping from `nativeId`s to `Player` instances. private var players: Registry = [:] - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "PlayerModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Since most `PlayerModule` operations are UI related and need to be executed on the main thread, they are scheduled with `UIManager.addBlock`. - var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } @@ -28,7 +28,8 @@ class PlayerModule: NSObject, RCTBridgeModule { - Parameter nativeId: `Player` instance ID. - Returns: The associated `Player` instance or `nil`. */ - @objc func retrieve(_ nativeId: NativeId) -> Player? { + @objc + func retrieve(_ nativeId: NativeId) -> Player? { players[nativeId] } @@ -53,7 +54,8 @@ class PlayerModule: NSObject, RCTBridgeModule { } /** - Creates a new analytics enabled `Player` instance inside the internal players using the provided `config` and `analyticsConfig` object. + Creates a new analytics enabled `Player` instance inside the internal players using the provided `config` + and `analyticsConfig` object. - Parameter config: `PlayerConfig` object received from JS. - Parameter analyticsConfig: `AnalyticsConfig` object received from JS. */ @@ -107,17 +109,18 @@ class PlayerModule: NSObject, RCTBridgeModule { func loadOfflineContent(_ nativeId: NativeId, offlineContentManagerBridgeId: NativeId, options: Any?) { #if os(iOS) bridge.uiManager.addUIBlock { [weak self] _, _ in - guard - let player = self?.players[nativeId], - let offlineContentManagerBridge = self?.bridge[OfflineModule.self]?.retrieve(offlineContentManagerBridgeId) - else { + guard let player = self?.players[nativeId], + let offlineContentManagerBridge = self?.bridge[OfflineModule.self]? + .retrieve(offlineContentManagerBridgeId) else { return } let optionsDictionary = options as? [String: Any?] ?? [:] let restrictedToAssetCache = optionsDictionary["restrictedToAssetCache"] as? Bool ?? true - let offlineSourceConfig = offlineContentManagerBridge.offlineContentManager.createOfflineSourceConfig(restrictedToAssetCache: restrictedToAssetCache) + let offlineSourceConfig = offlineContentManagerBridge + .offlineContentManager + .createOfflineSourceConfig(restrictedToAssetCache: restrictedToAssetCache) - guard let offlineSourceConfig = offlineSourceConfig else { return } + guard let offlineSourceConfig else { return } player.load(sourceConfig: offlineSourceConfig) } #endif @@ -262,7 +265,7 @@ class PlayerModule: NSObject, RCTBridgeModule { ) { bridge.uiManager.addUIBlock { [weak self] _, _ in let player = self?.players[nativeId] - if let mode = mode { + if let mode { resolve(player?.currentTime(RCTConvert.timeMode(mode))) } else { resolve(player?.currentTime) @@ -592,7 +595,8 @@ class PlayerModule: NSObject, RCTBridgeModule { func setMaxSelectableBitrate(_ nativeId: NativeId, maxSelectableBitrate: NSNumber) { let maxSelectableBitrateValue = maxSelectableBitrate.uintValue bridge.uiManager.addUIBlock { [weak self] _, _ in - self?.players[nativeId]?.maxSelectableBitrate = maxSelectableBitrateValue != -1 ? maxSelectableBitrateValue : 0 + let maxSelectableBitrate = maxSelectableBitrateValue != -1 ? maxSelectableBitrateValue : 0 + self?.players[nativeId]?.maxSelectableBitrate = maxSelectableBitrate } } @@ -632,7 +636,8 @@ class PlayerModule: NSObject, RCTBridgeModule { } /** - Returns `true` if the video is currently casted to a device and not played locally, or `false` if the video is played locally. + Returns `true` if the video is currently casted to a device and not played locally, + or `false` if the video is played locally. - Parameter nativeId: Target player id. - Parameter resolver: JS promise resolver. - Parameter rejecter: JS promise rejecter. @@ -649,7 +654,8 @@ class PlayerModule: NSObject, RCTBridgeModule { } /** - Initiates casting the current video to a cast-compatible device. The user has to choose to which device it should be sent. + Initiates casting the current video to a cast-compatible device. + The user has to choose to which device it should be sent. */ @objc(castVideo:) func castVideo(_ nativeId: NativeId) { @@ -670,7 +676,7 @@ class PlayerModule: NSObject, RCTBridgeModule { } private func setupRemoteControlConfig(_ remoteControlConfig: RemoteControlConfig) { - remoteControlConfig.prepareSource = { [weak self] type, sourceConfig in + remoteControlConfig.prepareSource = { [weak self] _, sourceConfig in guard let sourceModule = self?.bridge[SourceModule.self], let sourceNativeId = sourceModule.nativeId(where: { $0.sourceConfig === sourceConfig }), let castSourceConfig = sourceModule.retrieveCastSourceConfig(sourceNativeId) else { diff --git a/ios/RCTConvert+BitmovinPlayer.swift b/ios/RCTConvert+BitmovinPlayer.swift index 5e763c79..6eec7c88 100644 --- a/ios/RCTConvert+BitmovinPlayer.swift +++ b/ios/RCTConvert+BitmovinPlayer.swift @@ -1,6 +1,8 @@ -import Foundation -import BitmovinPlayer +// swiftlint:disable file_length + import BitmovinCollector +import BitmovinPlayer +import Foundation extension RCTConvert { /** @@ -72,7 +74,7 @@ extension RCTConvert { - Parameter json: JS object. - Returns: The produced `StyleConfig` object. */ - static func styleConfig(_ json: Any?) -> StyleConfig? { + static func styleConfig(_ json: Any?) -> StyleConfig? { // swiftlint:disable:this cyclomatic_complexity guard let json = json as? [String: Any?] else { return nil } @@ -104,7 +106,6 @@ extension RCTConvert { styleConfig.scalingMode = .zoom default: styleConfig.scalingMode = .fit - break } } return styleConfig @@ -115,7 +116,7 @@ extension RCTConvert { - Parameter json: JS object. - Returns: The produced `TweaksConfig` object. */ - static func tweaksConfig(_ json: Any?) -> TweaksConfig? { + static func tweaksConfig(_ json: Any?) -> TweaksConfig? { // swiftlint:disable:this cyclomatic_complexity guard let json = json as? [String: Any?] else { return nil } @@ -230,7 +231,7 @@ extension RCTConvert { - Parameter json: JS object - Returns: The produced `SourceConfig` object */ - static func sourceConfig(_ json: Any?, drmConfig: DrmConfig? = nil) -> SourceConfig? { + static func sourceConfig(_ json: Any?, drmConfig: DrmConfig? = nil) -> SourceConfig? { // swiftlint:disable:this cyclomatic_complexity line_length guard let json = json as? [String: Any?] else { return nil } @@ -238,7 +239,7 @@ extension RCTConvert { url: RCTConvert.nsurl(json["url"]), type: RCTConvert.sourceType(json["type"]) ) - if let drmConfig = drmConfig { + if let drmConfig { sourceConfig.drmConfig = drmConfig } if let title = json["title"] as? String { @@ -285,7 +286,8 @@ extension RCTConvert { if let startOffset = json["startOffset"] as? NSNumber { sourceOptions.startOffset = startOffset.doubleValue } - sourceOptions.startOffsetTimelineReference = RCTConvert.timelineReferencePoint(json["startOffsetTimelineReference"]) + sourceOptions.startOffsetTimelineReference = RCTConvert + .timelineReferencePoint(json["startOffsetTimelineReference"]) return sourceOptions } @@ -297,9 +299,12 @@ extension RCTConvert { static func timelineReferencePoint(_ json: Any?) -> TimelineReferencePoint { guard let stringValue = json as? String else { return .auto } switch stringValue { - case "start": return .start - case "end": return .end - default: return .auto + case "start": + return .start + case "end": + return .end + default: + return .auto } } @@ -313,11 +318,16 @@ extension RCTConvert { return .none } switch json { - case "none": return .none - case "hls": return .hls - case "dash": return .dash - case "progressive": return .progressive - default: return .none + case "none": + return .none + case "hls": + return .hls + case "dash": + return .dash + case "progressive": + return .progressive + default: + return .none } } @@ -331,9 +341,12 @@ extension RCTConvert { return .absoluteTime } switch json { - case "absolute": return .absoluteTime - case "relative": return .relativeTime - default: return .absoluteTime + case "absolute": + return .absoluteTime + case "relative": + return .relativeTime + default: + return .absoluteTime } } @@ -359,13 +372,14 @@ extension RCTConvert { */ static func fairplayConfig(_ json: Any?) -> FairplayConfig? { guard let json = json as? [String: Any?], - let licenseURL = json["licenseUrl"] as? String, - let certificateURL = json["certificateUrl"] as? String else { + let licenseURLString = json["licenseUrl"] as? String, + let certificateURLString = json["certificateUrl"] as? String, + let certificateURL = URL(string: certificateURLString) else { return nil } let fairplayConfig = FairplayConfig( - license: URL(string: licenseURL), - certificateURL: URL(string: certificateURL)! + license: URL(string: licenseURLString), + certificateURL: certificateURL ) if let licenseRequestHeaders = json["licenseRequestHeaders"] as? [String: String] { fairplayConfig.licenseRequestHeaders = licenseRequestHeaders @@ -418,7 +432,7 @@ extension RCTConvert { - Returns: The generated json dictionary. */ static func audioTrackJson(_ audioTrack: AudioTrack?) -> [AnyHashable: Any]? { - guard let audioTrack = audioTrack else { + guard let audioTrack else { return nil } return [ @@ -479,10 +493,14 @@ extension RCTConvert { return nil } switch json { - case "cea": return .cea - case "vtt": return .webVtt - case "ttml": return .ttml - default: return nil + case "cea": + return .cea + case "vtt": + return .webVtt + case "ttml": + return .ttml + default: + return nil } } @@ -492,7 +510,7 @@ extension RCTConvert { - Returns: The generated json dictionary. */ static func subtitleTrackJson(_ subtitleTrack: SubtitleTrack?) -> [AnyHashable: Any]? { - guard let subtitleTrack = subtitleTrack else { + guard let subtitleTrack else { return nil } return [ @@ -504,9 +522,12 @@ extension RCTConvert { "isForced": subtitleTrack.isForced, "format": { switch subtitleTrack.format { - case .cea: return "cea" - case .webVtt: return "vtt" - case .ttml: return "ttml" + case .cea: + return "cea" + case .webVtt: + return "vtt" + case .ttml: + return "ttml" } }(), ] @@ -518,7 +539,7 @@ extension RCTConvert { - Returns: The generated json dictionary. */ static func toJson(thumbnailTrack: ThumbnailTrack?) -> [AnyHashable: Any]? { - guard let thumbnailTrack = thumbnailTrack else { + guard let thumbnailTrack else { return nil } @@ -536,7 +557,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(adItem: AdItem?) -> [String: Any?]? { - guard let adItem = adItem else { + guard let adItem else { return nil } return [ @@ -551,7 +572,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(adSource: AdSource?) -> [String: Any?]? { - guard let adSource = adSource else { + guard let adSource else { return nil } return [ @@ -566,7 +587,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(adSourceType: AdSourceType?) -> String? { - guard let adSourceType = adSourceType else { + guard let adSourceType else { return nil } switch adSourceType { @@ -587,7 +608,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(adConfig: AdConfig?) -> [String: Any?]? { - guard let adConfig = adConfig else { + guard let adConfig else { return nil } return ["replaceContentDuration": adConfig.replaceContentDuration] @@ -599,7 +620,7 @@ extension RCTConvert { - Returns: The produced JS string. */ static func toJson(adQuartile: AdQuartile?) -> String? { - guard let adQuartile = adQuartile else { + guard let adQuartile else { return nil } switch adQuartile { @@ -618,7 +639,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(adBreak: AdBreak?) -> [String: Any?]? { - guard let adBreak = adBreak else { + guard let adBreak else { return nil } return [ @@ -634,7 +655,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(ad: Ad?) -> [String: Any?]? { - guard let ad = ad else { + guard let ad else { return nil } return [ @@ -654,7 +675,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(adData: AdData?) -> [String: Any?]? { - guard let adData = adData else { + guard let adData else { return nil } return [ @@ -756,7 +777,7 @@ extension RCTConvert { - Returns: The JS value representing the given object. */ static func toJson(analyticsCustomData: CustomData?) -> [String: Any?]? { - guard let analyticsCustomData = analyticsCustomData else { + guard let analyticsCustomData else { return nil } var json: [String: Any?] = [:] @@ -822,7 +843,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(videoQuality: VideoQuality?) -> [String: Any?]? { - guard let videoQuality = videoQuality else { + guard let videoQuality else { return nil } return [ @@ -846,11 +867,15 @@ extension RCTConvert { } switch json { #if os(iOS) - case "Bitmovin": return .bitmovin + case "Bitmovin": + return .bitmovin #endif - case "System": return .system - case "Subtitle": return .subtitle - default: return nil + case "System": + return .system + case "Subtitle": + return .subtitle + default: + return nil } } @@ -862,15 +887,19 @@ extension RCTConvert { */ static func toJson(offlineState: OfflineState?) -> String { var notDownloaded = "NotDownloaded" - guard let offlineState = offlineState else { + guard let offlineState else { return notDownloaded } switch offlineState { - case .downloading: return "Downloading" - case .downloaded: return "Downloaded" - case .suspended: return "Suspended" - default: return notDownloaded + case .downloading: + return "Downloading" + case .downloaded: + return "Downloaded" + case .suspended: + return "Suspended" + default: + return notDownloaded } } @@ -880,7 +909,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(offlineTrack: OfflineTextTrack) -> [String: Any?] { - return [ + [ "id": offlineTrack.label, "language": offlineTrack.language, ] @@ -892,7 +921,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(offlineTrack: OfflineAudioTrack) -> [String: Any?] { - return [ + [ "id": offlineTrack.label, "language": offlineTrack.language, ] @@ -904,7 +933,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(offlineTracks: OfflineTrackSelection?) -> [String: Any?]? { - guard let offlineTracks = offlineTracks else { + guard let offlineTracks else { return nil } @@ -938,7 +967,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(thumbnail: Thumbnail?) -> [String: Any?]? { - guard let thumbnail = thumbnail else { + guard let thumbnail else { return nil } @@ -1008,7 +1037,7 @@ extension RCTConvert { - Returns: The produced JS object. */ static func toJson(castPayload: CastPayload) -> [String: Any?] { - return [ + [ "currentTime": castPayload.currentTime, "deviceName": castPayload.deviceName, "type": castPayload.type, diff --git a/ios/RNPlayerView+PlayerListener.swift b/ios/RNPlayerView+PlayerListener.swift index 0918a05b..9f5a48f4 100644 --- a/ios/RNPlayerView+PlayerListener.swift +++ b/ios/RNPlayerView+PlayerListener.swift @@ -1,207 +1,207 @@ import BitmovinPlayer extension RNPlayerView: PlayerListener { - func onEvent(_ event: Event, player: Player) { + public func onEvent(_ event: Event, player: Player) { onEvent?(event.toJSON()) } - func onPlayerActive(_ event: PlayerActiveEvent, player: Player) { + public func onPlayerActive(_ event: PlayerActiveEvent, player: Player) { onPlayerActive?(event.toJSON()) } - func onPlayerError(_ event: PlayerErrorEvent, player: Player) { + public func onPlayerError(_ event: PlayerErrorEvent, player: Player) { onPlayerError?(event.toJSON()) } - func onPlayerWarning(_ event: PlayerWarningEvent, player: Player) { + public func onPlayerWarning(_ event: PlayerWarningEvent, player: Player) { onPlayerWarning?(event.toJSON()) } - func onDestroy(_ event: DestroyEvent, player: Player) { + public func onDestroy(_ event: DestroyEvent, player: Player) { onDestroy?(event.toJSON()) } - func onMuted(_ event: MutedEvent, player: Player) { + public func onMuted(_ event: MutedEvent, player: Player) { onMuted?(event.toJSON()) } - func onUnmuted(_ event: UnmutedEvent, player: Player) { + public func onUnmuted(_ event: UnmutedEvent, player: Player) { onUnmuted?(event.toJSON()) } - func onReady(_ event: ReadyEvent, player: Player) { + public func onReady(_ event: ReadyEvent, player: Player) { onReady?(event.toJSON()) } - func onPaused(_ event: PausedEvent, player: Player) { + public func onPaused(_ event: PausedEvent, player: Player) { onPaused?(event.toJSON()) } - func onPlay(_ event: PlayEvent, player: Player) { + public func onPlay(_ event: PlayEvent, player: Player) { onPlay?(event.toJSON()) } - func onPlaying(_ event: PlayingEvent, player: Player) { + public func onPlaying(_ event: PlayingEvent, player: Player) { onPlaying?(event.toJSON()) } - func onPlaybackFinished(_ event: PlaybackFinishedEvent, player: Player) { + public func onPlaybackFinished(_ event: PlaybackFinishedEvent, player: Player) { onPlaybackFinished?(event.toJSON()) } - func onSeek(_ event: SeekEvent, player: Player) { + public func onSeek(_ event: SeekEvent, player: Player) { onSeek?(event.toJSON()) } - func onSeeked(_ event: SeekedEvent, player: Player) { + public func onSeeked(_ event: SeekedEvent, player: Player) { onSeeked?(event.toJSON()) } - func onTimeShift(_ event: TimeShiftEvent, player: Player) { + public func onTimeShift(_ event: TimeShiftEvent, player: Player) { onTimeShift?(event.toJSON()) } - func onTimeShifted(_ event: TimeShiftedEvent, player: Player) { + public func onTimeShifted(_ event: TimeShiftedEvent, player: Player) { onTimeShifted?(event.toJSON()) } - func onStallStarted(_ event: StallStartedEvent, player: Player) { + public func onStallStarted(_ event: StallStartedEvent, player: Player) { onStallStarted?(event.toJSON()) } - func onStallEnded(_ event: StallEndedEvent, player: Player) { + public func onStallEnded(_ event: StallEndedEvent, player: Player) { onStallEnded?(event.toJSON()) } - func onTimeChanged(_ event: TimeChangedEvent, player: Player) { + public func onTimeChanged(_ event: TimeChangedEvent, player: Player) { onTimeChanged?(event.toJSON()) } - func onSourceLoad(_ event: SourceLoadEvent, player: Player) { + public func onSourceLoad(_ event: SourceLoadEvent, player: Player) { onSourceLoad?(event.toJSON()) } - func onSourceLoaded(_ event: SourceLoadedEvent, player: Player) { + public func onSourceLoaded(_ event: SourceLoadedEvent, player: Player) { onSourceLoaded?(event.toJSON()) } - func onSourceUnloaded(_ event: SourceUnloadedEvent, player: Player) { + public func onSourceUnloaded(_ event: SourceUnloadedEvent, player: Player) { onSourceUnloaded?(event.toJSON()) } - func onSourceError(_ event: SourceErrorEvent, player: Player) { + public func onSourceError(_ event: SourceErrorEvent, player: Player) { onSourceError?(event.toJSON()) } - func onSourceWarning(_ event: SourceWarningEvent, player: Player) { + public func onSourceWarning(_ event: SourceWarningEvent, player: Player) { onSourceWarning?(event.toJSON()) } - - func onAudioAdded(_ event: AudioAddedEvent, player: Player) { + + public func onAudioAdded(_ event: AudioAddedEvent, player: Player) { onAudioAdded?(event.toJSON()) } - func onAudioRemoved(_ event: AudioRemovedEvent, player: Player) { + public func onAudioRemoved(_ event: AudioRemovedEvent, player: Player) { onAudioRemoved?(event.toJSON()) } - func onAudioChanged(_ event: AudioChangedEvent, player: Player) { + public func onAudioChanged(_ event: AudioChangedEvent, player: Player) { onAudioChanged?(event.toJSON()) } - func onSubtitleAdded(_ event: SubtitleAddedEvent, player: Player) { + public func onSubtitleAdded(_ event: SubtitleAddedEvent, player: Player) { onSubtitleAdded?(event.toJSON()) } - func onSubtitleRemoved(_ event: SubtitleRemovedEvent, player: Player) { + public func onSubtitleRemoved(_ event: SubtitleRemovedEvent, player: Player) { onSubtitleRemoved?(event.toJSON()) } - func onSubtitleChanged(_ event: SubtitleChangedEvent, player: Player) { + public func onSubtitleChanged(_ event: SubtitleChangedEvent, player: Player) { onSubtitleChanged?(event.toJSON()) } - func onAdBreakFinished(_ event: AdBreakFinishedEvent, player: Player) { + public func onAdBreakFinished(_ event: AdBreakFinishedEvent, player: Player) { onAdBreakFinished?(event.toJSON()) } - func onAdBreakStarted(_ event: AdBreakStartedEvent, player: Player) { + public func onAdBreakStarted(_ event: AdBreakStartedEvent, player: Player) { onAdBreakStarted?(event.toJSON()) } - func onAdClicked(_ event: AdClickedEvent, player: Player) { + public func onAdClicked(_ event: AdClickedEvent, player: Player) { onAdClicked?(event.toJSON()) } - func onAdError(_ event: AdErrorEvent, player: Player) { + public func onAdError(_ event: AdErrorEvent, player: Player) { onAdError?(event.toJSON()) } - func onAdFinished(_ event: AdFinishedEvent, player: Player) { + public func onAdFinished(_ event: AdFinishedEvent, player: Player) { onAdFinished?(event.toJSON()) } - func onAdManifestLoad(_ event: AdManifestLoadEvent, player: Player) { + public func onAdManifestLoad(_ event: AdManifestLoadEvent, player: Player) { onAdManifestLoad?(event.toJSON()) } - func onAdManifestLoaded(_ event: AdManifestLoadedEvent, player: Player) { + public func onAdManifestLoaded(_ event: AdManifestLoadedEvent, player: Player) { onAdManifestLoaded?(event.toJSON()) } - func onAdQuartile(_ event: AdQuartileEvent, player: Player) { + public func onAdQuartile(_ event: AdQuartileEvent, player: Player) { onAdQuartile?(event.toJSON()) } - func onAdScheduled(_ event: AdScheduledEvent, player: Player) { + public func onAdScheduled(_ event: AdScheduledEvent, player: Player) { onAdScheduled?(event.toJSON()) } - func onAdSkipped(_ event: AdSkippedEvent, player: Player) { + public func onAdSkipped(_ event: AdSkippedEvent, player: Player) { onAdSkipped?(event.toJSON()) } - func onAdStarted(_ event: AdStartedEvent, player: Player) { + public func onAdStarted(_ event: AdStartedEvent, player: Player) { onAdStarted?(event.toJSON()) } - func onVideoPlaybackQualityChanged(_ event: VideoDownloadQualityChangedEvent, player: Player) { + public func onVideoPlaybackQualityChanged(_ event: VideoDownloadQualityChangedEvent, player: Player) { onVideoPlaybackQualityChanged?(event.toJSON()) } #if os(iOS) - func onCastAvailable(_ event: CastAvailableEvent, player: Player) { + public func onCastAvailable(_ event: CastAvailableEvent, player: Player) { onCastAvailable?(event.toJSON()) } - func onCastPaused(_ event: CastPausedEvent, player: Player) { + public func onCastPaused(_ event: CastPausedEvent, player: Player) { onCastPaused?(event.toJSON()) } - func onCastPlaybackFinished(_ event: CastPlaybackFinishedEvent, player: Player) { + public func onCastPlaybackFinished(_ event: CastPlaybackFinishedEvent, player: Player) { onCastPlaybackFinished?(event.toJSON()) } - func onCastPlaying(_ event: CastPlayingEvent, player: Player) { + public func onCastPlaying(_ event: CastPlayingEvent, player: Player) { onCastPlaying?(event.toJSON()) } - func onCastStarted(_ event: CastStartedEvent, player: Player) { + public func onCastStarted(_ event: CastStartedEvent, player: Player) { onCastStarted?(event.toJSON()) } - func onCastStart(_ event: CastStartEvent, player: Player) { + public func onCastStart(_ event: CastStartEvent, player: Player) { onCastStart?(event.toJSON()) } - func onCastStopped(_ event: CastStoppedEvent, player: Player) { + public func onCastStopped(_ event: CastStoppedEvent, player: Player) { onCastStopped?(event.toJSON()) } - func onCastTimeUpdated(_ event: CastTimeUpdatedEvent, player: Player) { + public func onCastTimeUpdated(_ event: CastTimeUpdatedEvent, player: Player) { onCastTimeUpdated?(event.toJSON()) } - func onCastWaitingForDevice(_ event: CastWaitingForDeviceEvent, player: Player) { + public func onCastWaitingForDevice(_ event: CastWaitingForDeviceEvent, player: Player) { onCastWaitingForDevice?(event.toJSON()) } #endif diff --git a/ios/RNPlayerView+UserInterfaceListener.swift b/ios/RNPlayerView+UserInterfaceListener.swift index a7d62b48..0059c580 100644 --- a/ios/RNPlayerView+UserInterfaceListener.swift +++ b/ios/RNPlayerView+UserInterfaceListener.swift @@ -1,35 +1,35 @@ import BitmovinPlayer extension RNPlayerView: UserInterfaceListener { - func onPictureInPictureEnter(_ event: PictureInPictureEnterEvent, view: PlayerView) { + public func onPictureInPictureEnter(_ event: PictureInPictureEnterEvent, view: PlayerView) { onPictureInPictureEnter?(event.toJSON()) } - func onPictureInPictureEntered(_ event: PictureInPictureEnteredEvent, view: PlayerView) { + public func onPictureInPictureEntered(_ event: PictureInPictureEnteredEvent, view: PlayerView) { onPictureInPictureEntered?(event.toJSON()) } - func onPictureInPictureExit(_ event: PictureInPictureExitEvent, view: PlayerView) { + public func onPictureInPictureExit(_ event: PictureInPictureExitEvent, view: PlayerView) { onPictureInPictureExit?(event.toJSON()) } - func onPictureInPictureExited(_ event: PictureInPictureExitedEvent, view: PlayerView) { + public func onPictureInPictureExited(_ event: PictureInPictureExitedEvent, view: PlayerView) { onPictureInPictureExited?(event.toJSON()) } - func onFullscreenEnter(_ event: FullscreenEnterEvent, view: PlayerView) { + public func onFullscreenEnter(_ event: FullscreenEnterEvent, view: PlayerView) { onFullscreenEnter?(event.toJSON()) } - func onFullscreenExit(_ event: FullscreenExitEvent, view: PlayerView) { + public func onFullscreenExit(_ event: FullscreenExitEvent, view: PlayerView) { onFullscreenExit?(event.toJSON()) } - func onFullscreenEnabled(_ event: FullscreenEnabledEvent, view: PlayerView) { + public func onFullscreenEnabled(_ event: FullscreenEnabledEvent, view: PlayerView) { onFullscreenEnabled?(event.toJSON()) } - func onFullscreenDisabled(_ event: FullscreenDisabledEvent, view: PlayerView) { + public func onFullscreenDisabled(_ event: FullscreenDisabledEvent, view: PlayerView) { onFullscreenDisabled?(event.toJSON()) } } diff --git a/ios/RNPlayerView.swift b/ios/RNPlayerView.swift index f03a1948..d67daccd 100644 --- a/ios/RNPlayerView.swift +++ b/ios/RNPlayerView.swift @@ -1,7 +1,7 @@ import BitmovinPlayer @objc(RNPlayerView) -class RNPlayerView: UIView { +public class RNPlayerView: UIView { /// React component events. Directly mapped to props in `NativePlayerView`. @objc var onEvent: RCTBubblingEventBlock? @objc var onPlayerActive: RCTBubblingEventBlock? @@ -74,7 +74,7 @@ class RNPlayerView: UIView { ] } didSet { - if let playerView = playerView { + if let playerView { addSubview(playerView) } } diff --git a/ios/RNPlayerViewManager.swift b/ios/RNPlayerViewManager.swift index 1fd26dc6..1e00574f 100644 --- a/ios/RNPlayerViewManager.swift +++ b/ios/RNPlayerViewManager.swift @@ -2,15 +2,15 @@ import BitmovinPlayer import Foundation @objc(RNPlayerViewManager) -class RNPlayerViewManager: RCTViewManager { +public class RNPlayerViewManager: RCTViewManager { /// Initialize module on main thread. - override static func requiresMainQueueSetup() -> Bool { + override public static func requiresMainQueueSetup() -> Bool { true } /// `UIView` factory function. It gets called for each `` component /// from React. - override func view() -> UIView! { + override public func view() -> UIView! { // swiftlint:disable:this implicitly_unwrapped_optional RNPlayerView() } @@ -21,7 +21,8 @@ class RNPlayerViewManager: RCTViewManager { - Parameter viewId: `RNPlayerView` id inside `UIManager`'s registry. - Parameter playerId: `Player` instance id inside `PlayerModule`'s registry. */ - @objc func attachPlayer(_ viewId: NSNumber, playerId: NativeId, playerConfig: NSDictionary?) { + @objc + func attachPlayer(_ viewId: NSNumber, playerId: NativeId, playerConfig: NSDictionary?) { bridge.uiManager.addUIBlock { [weak self] _, views in guard let self, @@ -32,9 +33,13 @@ class RNPlayerViewManager: RCTViewManager { } #if os(iOS) if let customMessageHandlerBridgeId = self.customMessageHandlerBridgeId, - let customMessageHandlerBridge = self.bridge[CustomMessageHandlerModule.self]?.retrieve(customMessageHandlerBridgeId), + let customMessageHandlerBridge = self.bridge[CustomMessageHandlerModule.self]? + .retrieve(customMessageHandlerBridgeId), player.config.styleConfig.userInterfaceType == .bitmovin { - let bitmovinUserInterfaceConfig = player.config.styleConfig.userInterfaceConfig as? BitmovinUserInterfaceConfig ?? BitmovinUserInterfaceConfig() + let bitmovinUserInterfaceConfig = player + .config + .styleConfig + .userInterfaceConfig as? BitmovinUserInterfaceConfig ?? BitmovinUserInterfaceConfig() player.config.styleConfig.userInterfaceConfig = bitmovinUserInterfaceConfig bitmovinUserInterfaceConfig.customMessageHandler = customMessageHandlerBridge.customMessageHandler } @@ -59,11 +64,15 @@ class RNPlayerViewManager: RCTViewManager { player.add(listener: view) view.playerView?.add(listener: view) - self.maybeEmitPictureInPictureAvailabilityEvent(for: view, previousState: previousPictureInPictureAvailableValue) + self.maybeEmitPictureInPictureAvailabilityEvent( + for: view, + previousState: previousPictureInPictureAvailableValue + ) } } - @objc func attachFullscreenBridge(_ viewId: NSNumber, fullscreenBridgeId: NativeId) { + @objc + func attachFullscreenBridge(_ viewId: NSNumber, fullscreenBridgeId: NativeId) { bridge.uiManager.addUIBlock { [weak self] _, views in guard let view = views?[viewId] as? RNPlayerView, @@ -79,11 +88,13 @@ class RNPlayerViewManager: RCTViewManager { } } - @objc func setCustomMessageHandlerBridgeId(_ viewId: NSNumber, customMessageHandlerBridgeId: NativeId) { + @objc + func setCustomMessageHandlerBridgeId(_ viewId: NSNumber, customMessageHandlerBridgeId: NativeId) { self.customMessageHandlerBridgeId = customMessageHandlerBridgeId } - @objc func setFullscreen(_ viewId: NSNumber, isFullscreen: Bool) { + @objc + func setFullscreen(_ viewId: NSNumber, isFullscreen: Bool) { bridge.uiManager.addUIBlock { [weak self] _, views in guard let self, diff --git a/ios/Registry.swift b/ios/Registry.swift index 05391a68..ddc33df2 100644 --- a/ios/Registry.swift +++ b/ios/Registry.swift @@ -1,5 +1,5 @@ /// Represents the `UUID` string used as index for a certain registry object. -typealias NativeId = String +internal typealias NativeId = String /// Represents an in memory storage facility that associates an object of type `T` with a certain `NativeId`. -typealias Registry = [NativeId: T] +internal typealias Registry = [NativeId: T] diff --git a/ios/SourceModule.swift b/ios/SourceModule.swift index d09d900d..52003193 100644 --- a/ios/SourceModule.swift +++ b/ios/SourceModule.swift @@ -1,9 +1,9 @@ import BitmovinPlayer @objc(SourceModule) -class SourceModule: NSObject, RCTBridgeModule { - /// React bridge reference. - @objc var bridge: RCTBridge! +public class SourceModule: NSObject, RCTBridgeModule { + // swiftlint:disable:next implicitly_unwrapped_optional + @objc public var bridge: RCTBridge! /// In-memory mapping from `nativeId`s to `Source` instances. private var sources: Registry = [:] @@ -11,18 +11,17 @@ class SourceModule: NSObject, RCTBridgeModule { /// In-memory mapping from `nativeId`s to `SourceConfig` instances for casting. private var castSourceConfigs: Registry = [:] - /// JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "SourceModule" } - /// Module requires main thread initialization. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Use `UIManager.addBlock` to enqueue module methods on UI thread. - var methodQueue: DispatchQueue! { + // swiftlint:disable:next implicitly_unwrapped_optional + public var methodQueue: DispatchQueue! { bridge.uiManager.methodQueue } @@ -31,7 +30,8 @@ class SourceModule: NSObject, RCTBridgeModule { - Parameter nativeId: `Source` instance ID. - Returns: The associated `Source` instance or `nil`. */ - @objc func retrieve(_ nativeId: NativeId) -> Source? { + @objc + func retrieve(_ nativeId: NativeId) -> Source? { sources[nativeId] } @@ -48,7 +48,8 @@ class SourceModule: NSObject, RCTBridgeModule { } /** - Creates a new `Source` instance inside the internal sources using the provided `config` and `analyticsSourceMetadata` object and an optionally initialized DRM configuration ID. + Creates a new `Source` instance inside the internal sources using the provided `config` + and `analyticsSourceMetadata` object and an optionally initialized DRM configuration ID. - Parameter nativeId: ID to be associated with the `Source` instance. - Parameter drmNativeId: ID of the DRM config object to use. - Parameter config: `SourceConfig` object received from JS. @@ -65,7 +66,7 @@ class SourceModule: NSObject, RCTBridgeModule { ) { bridge.uiManager.addUIBlock { [weak self] _, _ in let drmConfig: DrmConfig? - if let drmNativeId = drmNativeId { + if let drmNativeId { drmConfig = self?.getDrmModule()?.retrieve(drmNativeId) } else { drmConfig = nil @@ -80,7 +81,7 @@ class SourceModule: NSObject, RCTBridgeModule { } self?.sources[nativeId] = SourceFactory.create(from: sourceConfig, sourceMetadata: sourceMetadata) #if os(iOS) - if let remoteConfig = RCTConvert.sourceRemoteControlConfig(sourceRemoteControlConfig){ + if let remoteConfig = RCTConvert.sourceRemoteControlConfig(sourceRemoteControlConfig) { self?.castSourceConfigs[nativeId] = remoteConfig.castSourceConfig } #endif @@ -88,7 +89,8 @@ class SourceModule: NSObject, RCTBridgeModule { } /** - Creates a new `Source` instance inside the internal sources using the provided `config` object and an initialized DRM configuration ID. + Creates a new `Source` instance inside the internal sources using + the provided `config` object and an initialized DRM configuration ID. - Parameter nativeId: ID to be associated with the `Source` instance. - Parameter drmNativeId: ID of the DRM config object to use. - Parameter config: `SourceConfig` object received from JS. @@ -103,7 +105,7 @@ class SourceModule: NSObject, RCTBridgeModule { ) { bridge.uiManager.addUIBlock { [weak self] _, _ in let drmConfig: DrmConfig? - if let drmNativeId = drmNativeId { + if let drmNativeId { drmConfig = self?.getDrmModule()?.retrieve(drmNativeId) } else { drmConfig = nil diff --git a/ios/UuidModule.swift b/ios/UuidModule.swift index b3fe13f6..d4e33fd0 100644 --- a/ios/UuidModule.swift +++ b/ios/UuidModule.swift @@ -2,14 +2,14 @@ Native module for easy and fast unique ID generation on JS side. Used to generate native instance IDs. */ @objc(UuidModule) -class UuidModule: NSObject, RCTBridgeModule { +public class UuidModule: NSObject, RCTBridgeModule { /// Initialize this module on main thread. - static func requiresMainQueueSetup() -> Bool { + public static func requiresMainQueueSetup() -> Bool { true } - /// Exported JS module name. - static func moduleName() -> String! { + // swiftlint:disable:next implicitly_unwrapped_optional + public static func moduleName() -> String! { "UuidModule" } @@ -17,7 +17,8 @@ class UuidModule: NSObject, RCTBridgeModule { Synchronously generate a random UUIDv4. - Returns: Random UUID RFC 4122 version 4. */ - @objc func generate() -> String { + @objc + public func generate() -> String { UUID().uuidString } } From 25fdf63f323f540637b1ddbe1716e451b6a23048 Mon Sep 17 00:00:00 2001 From: Roland Kakonyi Date: Tue, 17 Oct 2023 11:19:58 +0200 Subject: [PATCH 2/2] feat(swiftlint-warnings): fix SwiftLint warnings --- ios/RNPlayerViewManager.swift | 47 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/ios/RNPlayerViewManager.swift b/ios/RNPlayerViewManager.swift index 75811810..58891c51 100644 --- a/ios/RNPlayerViewManager.swift +++ b/ios/RNPlayerViewManager.swift @@ -116,29 +116,30 @@ public class RNPlayerViewManager: RCTViewManager { } } - @objc func setScalingMode(_ viewId: NSNumber, scalingMode: String) { - bridge.uiManager.addUIBlock { [weak self] _, views in - guard - let self, - let view = views?[viewId] as? RNPlayerView - else { - return - } - guard let playerView = view.playerView else { - return - } - switch scalingMode { - case "Zoom": - playerView.scalingMode = .zoom - case "Stretch": - playerView.scalingMode = .stretch - case "Fit": - playerView.scalingMode = .fit - default: - break - } - } - } + @objc + func setScalingMode(_ viewId: NSNumber, scalingMode: String) { + bridge.uiManager.addUIBlock { [weak self] _, views in + guard + let self, + let view = views?[viewId] as? RNPlayerView + else { + return + } + guard let playerView = view.playerView else { + return + } + switch scalingMode { + case "Zoom": + playerView.scalingMode = .zoom + case "Stretch": + playerView.scalingMode = .stretch + case "Fit": + playerView.scalingMode = .fit + default: + break + } + } + } /// Fetches the initialized `PlayerModule` instance on RN's bridge object. private func getPlayerModule() -> PlayerModule? {