@granite-js/video 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -66,11 +66,10 @@ class GraniteVideoView @JvmOverloads constructor(
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Source
|
|
69
|
-
@Suppress("UNCHECKED_CAST")
|
|
70
69
|
fun setSource(source: Map<String, Any>?) {
|
|
71
70
|
source ?: return
|
|
72
71
|
|
|
73
|
-
val headers = source["headers"]
|
|
72
|
+
val headers = parseHeaders(source["headers"])
|
|
74
73
|
|
|
75
74
|
val videoSource = GraniteVideoSource(
|
|
76
75
|
uri = source["uri"] as? String,
|
|
@@ -113,7 +112,7 @@ class GraniteVideoView @JvmOverloads constructor(
|
|
|
113
112
|
"clearkey" -> GraniteVideoDrmType.CLEARKEY
|
|
114
113
|
else -> GraniteVideoDrmType.NONE
|
|
115
114
|
}
|
|
116
|
-
val headers = map["headers"]
|
|
115
|
+
val headers = parseHeaders(map["headers"])
|
|
117
116
|
return GraniteVideoDrmConfig(
|
|
118
117
|
type = drmType,
|
|
119
118
|
licenseServer = map["licenseServer"] as? String,
|
|
@@ -122,6 +121,25 @@ class GraniteVideoView @JvmOverloads constructor(
|
|
|
122
121
|
)
|
|
123
122
|
}
|
|
124
123
|
|
|
124
|
+
private fun parseHeaders(value: Any?): Map<String, String>? {
|
|
125
|
+
return when (value) {
|
|
126
|
+
is Map<*, *> -> value.entries.mapNotNull { (name, headerValue) ->
|
|
127
|
+
val headerName = name as? String ?: return@mapNotNull null
|
|
128
|
+
val headerStringValue = headerValue as? String ?: return@mapNotNull null
|
|
129
|
+
headerName to headerStringValue
|
|
130
|
+
}.toMap().ifEmpty { null }
|
|
131
|
+
|
|
132
|
+
is List<*> -> value.mapNotNull { entry ->
|
|
133
|
+
val header = entry as? Map<*, *> ?: return@mapNotNull null
|
|
134
|
+
val headerName = header["name"] as? String ?: return@mapNotNull null
|
|
135
|
+
val headerValue = header["value"] as? String ?: return@mapNotNull null
|
|
136
|
+
headerName to headerValue
|
|
137
|
+
}.toMap().ifEmpty { null }
|
|
138
|
+
|
|
139
|
+
else -> null
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
125
143
|
private fun parseMetadata(map: Map<String, Any>?): GraniteVideoMetadata? {
|
|
126
144
|
map ?: return null
|
|
127
145
|
return GraniteVideoMetadata(
|
|
@@ -124,6 +124,31 @@ class GraniteVideoViewRobolectricTest {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
@Test
|
|
128
|
+
fun `setSource with codegen header entries should restore headers map`() {
|
|
129
|
+
val view = GraniteVideoView(
|
|
130
|
+
context = context,
|
|
131
|
+
providerFactory = { mockProvider }
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
val source = mapOf(
|
|
135
|
+
"uri" to "https://example.com/protected.m3u8",
|
|
136
|
+
"headers" to listOf(
|
|
137
|
+
mapOf(
|
|
138
|
+
"name" to "X-Auth-Token",
|
|
139
|
+
"value" to "test-secret"
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
view.setSource(source)
|
|
144
|
+
|
|
145
|
+
verify {
|
|
146
|
+
mockProvider.loadSource(match<GraniteVideoSource> {
|
|
147
|
+
it.headers == mapOf("X-Auth-Token" to "test-secret")
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
127
152
|
@Test
|
|
128
153
|
fun `setSource with null source should not call loadSource`() {
|
|
129
154
|
val view = GraniteVideoView(
|