-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore(android): refactor drm props (#3846)
- Loading branch information
Showing
3 changed files
with
84 additions
and
43 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
android/src/main/java/com/brentvatne/common/api/DRMProps.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.brentvatne.common.api | ||
|
||
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetArray | ||
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetString | ||
import com.facebook.react.bridge.ReadableMap | ||
import java.util.UUID | ||
|
||
/** | ||
* Class representing DRM props for host. | ||
* Only generic code here, no reference to the player. | ||
*/ | ||
class DRMProps { | ||
/** | ||
* string version of configured UUID for drm prop | ||
*/ | ||
var drmType: String? = null | ||
|
||
/** | ||
* Configured UUID for drm prop | ||
*/ | ||
var drmUUID: UUID? = null | ||
|
||
/** | ||
* DRM license server to be used | ||
*/ | ||
var drmLicenseServer: String? = null | ||
|
||
/** | ||
* DRM Http Header to access to license server | ||
*/ | ||
var drmLicenseHeader: Array<String> = emptyArray<String>() | ||
companion object { | ||
private const val PROP_DRM_TYPE = "type" | ||
private const val PROP_DRM_LICENSE_SERVER = "licenseServer" | ||
private const val PROP_DRM_HEADERS = "headers" | ||
private const val PROP_DRM_HEADERS_KEY = "key" | ||
private const val PROP_DRM_HEADERS_VALUE = "value" | ||
|
||
/** parse the source ReadableMap received from app */ | ||
@JvmStatic | ||
fun parse(src: ReadableMap?): DRMProps? { | ||
var drm: DRMProps? = null | ||
if (src != null && src.hasKey(PROP_DRM_TYPE)) { | ||
drm = DRMProps() | ||
drm.drmType = safeGetString(src, PROP_DRM_TYPE) | ||
drm.drmLicenseServer = safeGetString(src, PROP_DRM_LICENSE_SERVER) | ||
val drmHeadersArray = safeGetArray(src, PROP_DRM_HEADERS) | ||
if (drm.drmType != null && drm.drmLicenseServer != null) { | ||
if (drmHeadersArray != null) { | ||
val drmKeyRequestPropertiesList = ArrayList<String?>() | ||
for (i in 0 until drmHeadersArray.size()) { | ||
val current = drmHeadersArray.getMap(i) | ||
drmKeyRequestPropertiesList.add(safeGetString(current, PROP_DRM_HEADERS_KEY)) | ||
drmKeyRequestPropertiesList.add(safeGetString(current, PROP_DRM_HEADERS_VALUE)) | ||
} | ||
val array = emptyArray<String>() | ||
drm.drmLicenseHeader = drmKeyRequestPropertiesList.toArray(array) | ||
} | ||
} else { | ||
return null | ||
} | ||
} | ||
return drm | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters