Skip to content

Commit

Permalink
Merge pull request #292 from bitmovin/fix-swiftlint-warnings
Browse files Browse the repository at this point in the history
Fix SwiftLint warnings
  • Loading branch information
rolandkakonyi authored Oct 17, 2023
2 parents 5ad192c + 25fdf63 commit 7b8c7bc
Show file tree
Hide file tree
Showing 20 changed files with 477 additions and 354 deletions.
18 changes: 9 additions & 9 deletions ios/AudioSessionModule.swift
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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
Expand All @@ -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":
Expand Down
19 changes: 9 additions & 10 deletions ios/BitmovinCastManagerModule.swift
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions ios/CustomMessageHandlerBridge.swift
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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?) {
Expand Down
32 changes: 20 additions & 12 deletions ios/CustomMessageHandlerModule.swift
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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]
}

Expand Down Expand Up @@ -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()
}
Expand All @@ -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]
) {}
}
}
93 changes: 57 additions & 36 deletions ios/DrmModule.swift
Original file line number Diff line number Diff line change
@@ -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<FairplayConfig> = [:]

/// 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]
}

Expand All @@ -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:)
Expand All @@ -78,19 +79,23 @@ class DrmModule: NSObject, RCTBridgeModule {
var preparedSyncMessages: Registry<String> = [:]
/// Mapping between an object's `nativeId` and the value that'll be returned by its `prepareLicense` callback.
var preparedLicenses: Registry<String> = [:]
/// 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<String> = [:]
/// Mapping between an object's `nativeId` and the value that'll be returned by its `prepareContentId` callback.
var preparedContentIds: Registry<String> = [:]

/**
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? {
Expand All @@ -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? {
Expand All @@ -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? {
Expand All @@ -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? {
Expand All @@ -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? {
Expand All @@ -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.
Expand All @@ -189,7 +210,7 @@ class DrmModule: NSObject, RCTBridgeModule {
initPrepareContentId(nativeId, fairplayJson: fairplayJson)
}
}

/**
Initialize the `prepareCertificate` block in the `FairplayConfig` associated with `nativeId`.

Expand Down Expand Up @@ -274,7 +295,7 @@ class DrmModule: NSObject, RCTBridgeModule {
}
}
}

/**
Initialize the `prepareContentId` block in the `FairplayConfig` associated with `nativeId`.

Expand Down
Loading

0 comments on commit 7b8c7bc

Please sign in to comment.