@granite-js/video 1.0.29 → 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
@@ -1,5 +1,11 @@
1
1
  # @granite-js/video
2
2
 
3
+ ## 1.0.30
4
+
5
+ ### Patch Changes
6
+
7
+ - 4b2e737: Fix Android video source headers parsing for React Native codegen header entries.
8
+
3
9
  ## 1.0.29
4
10
 
5
11
  ## 1.0.28
@@ -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"] as? Map<String, String>
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"] as? Map<String, String>
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(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@granite-js/video",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "Pluggable video component for React Native with provider selection",
5
5
  "type": "module",
6
6
  "main": "./dist/module/index.js",