react-native-theoplayer 11.8.0 → 11.9.0

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/android/build.gradle +2 -0
  3. package/android/src/main/java/com/theoplayer/ads/AdAdapter.kt +33 -7
  4. package/android/src/main/java/com/theoplayer/ads/AdEventAdapter.kt +8 -1
  5. package/android/src/main/java/com/theoplayer/drm/ContentProtectionAdapter.kt +7 -0
  6. package/android/src/main/java/com/theoplayer/source/SourceAdapter.kt +23 -0
  7. package/android/src/main/java/com/theoplayer/util/BridgeUtils.kt +4 -4
  8. package/android/src/test/java/com/theoplayer/ads/AdAdapterCustomDataTest.kt +144 -0
  9. package/ios/THEOplayerRCTBridge.m +7 -0
  10. package/ios/THEOplayerRCTMainEventHandler.swift +27 -1
  11. package/ios/THEOplayerRCTPlayerAPI.swift +20 -0
  12. package/ios/ads/THEOplayerRCTAdAdapter.swift +14 -3
  13. package/ios/ads/THEOplayerRCTAdsNative.swift +4 -0
  14. package/lib/commonjs/api/source/abr/SourceAbrConfiguration.js +2 -0
  15. package/lib/commonjs/api/source/abr/SourceAbrConfiguration.js.map +1 -0
  16. package/lib/commonjs/api/source/abr/barrel.js +17 -0
  17. package/lib/commonjs/api/source/abr/barrel.js.map +1 -0
  18. package/lib/commonjs/api/source/barrel.js +18 -7
  19. package/lib/commonjs/api/source/barrel.js.map +1 -1
  20. package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js +1 -0
  21. package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js.map +1 -1
  22. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +9 -0
  23. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
  24. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +13 -1
  25. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  26. package/lib/commonjs/internal/adapter/event/native/NativeTheoLiveEvent.js +2 -2
  27. package/lib/commonjs/internal/adapter/event/native/NativeTheoLiveEvent.js.map +1 -1
  28. package/lib/commonjs/manifest.json +1 -1
  29. package/lib/module/api/source/abr/SourceAbrConfiguration.js +2 -0
  30. package/lib/module/api/source/abr/SourceAbrConfiguration.js.map +1 -0
  31. package/lib/module/api/source/abr/barrel.js +4 -0
  32. package/lib/module/api/source/abr/barrel.js.map +1 -0
  33. package/lib/module/api/source/barrel.js +1 -0
  34. package/lib/module/api/source/barrel.js.map +1 -1
  35. package/lib/module/internal/adapter/DefaultNativePlayerState.js +1 -0
  36. package/lib/module/internal/adapter/DefaultNativePlayerState.js.map +1 -1
  37. package/lib/module/internal/adapter/THEOplayerAdapter.js +9 -0
  38. package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
  39. package/lib/module/internal/adapter/THEOplayerWebAdapter.js +13 -1
  40. package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  41. package/lib/module/internal/adapter/event/native/NativeTheoLiveEvent.js +2 -2
  42. package/lib/module/internal/adapter/event/native/NativeTheoLiveEvent.js.map +1 -1
  43. package/lib/module/manifest.json +1 -1
  44. package/lib/typescript/__tests__/NativeTheoLiveEvent.test.d.ts +2 -0
  45. package/lib/typescript/__tests__/NativeTheoLiveEvent.test.d.ts.map +1 -0
  46. package/lib/typescript/api/ads/Ad.d.ts +9 -0
  47. package/lib/typescript/api/ads/Ad.d.ts.map +1 -1
  48. package/lib/typescript/api/ads/AdBreak.d.ts +9 -0
  49. package/lib/typescript/api/ads/AdBreak.d.ts.map +1 -1
  50. package/lib/typescript/api/player/THEOplayer.d.ts +11 -0
  51. package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
  52. package/lib/typescript/api/source/SourceDescription.d.ts +7 -0
  53. package/lib/typescript/api/source/SourceDescription.d.ts.map +1 -1
  54. package/lib/typescript/api/source/abr/SourceAbrConfiguration.d.ts +27 -0
  55. package/lib/typescript/api/source/abr/SourceAbrConfiguration.d.ts.map +1 -0
  56. package/lib/typescript/api/source/abr/barrel.d.ts +2 -0
  57. package/lib/typescript/api/source/abr/barrel.d.ts.map +1 -0
  58. package/lib/typescript/api/source/barrel.d.ts +1 -0
  59. package/lib/typescript/api/source/barrel.d.ts.map +1 -1
  60. package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts +1 -0
  61. package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts.map +1 -1
  62. package/lib/typescript/internal/adapter/NativePlayerState.d.ts +1 -0
  63. package/lib/typescript/internal/adapter/NativePlayerState.d.ts.map +1 -1
  64. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +2 -0
  65. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
  66. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +2 -0
  67. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
  68. package/package.json +1 -1
  69. package/src/__tests__/NativeTheoLiveEvent.test.ts +82 -0
  70. package/src/__tests__/PlayerFacadeWebAdapter.test.ts +13 -0
  71. package/src/api/ads/Ad.ts +10 -0
  72. package/src/api/ads/AdBreak.ts +10 -0
  73. package/src/api/player/THEOplayer.ts +12 -0
  74. package/src/api/source/SourceDescription.ts +8 -0
  75. package/src/api/source/abr/SourceAbrConfiguration.ts +27 -0
  76. package/src/api/source/abr/barrel.ts +1 -0
  77. package/src/api/source/barrel.ts +1 -0
  78. package/src/internal/adapter/DefaultNativePlayerState.ts +1 -0
  79. package/src/internal/adapter/NativePlayerState.ts +1 -0
  80. package/src/internal/adapter/THEOplayerAdapter.ts +11 -0
  81. package/src/internal/adapter/THEOplayerWebAdapter.ts +15 -1
  82. package/src/internal/adapter/event/native/NativeTheoLiveEvent.ts +2 -2
  83. package/src/manifest.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,7 +5,23 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [11.8.0] - 18-10-21
8
+ ## [11.9.0] - 13-11-26
9
+
10
+ ### Added
11
+
12
+ - Added `THEOplayer.allowsExternalPlayback` to enable or disable AirPlay playback on iOS.
13
+ - Added `abr` property to `TypedSource`, supporting `preferredVideoCodecs` and `preferredAudioCodecs` on Android and Web.
14
+ - Added `contentprotectionerror` event bridging on iOS.
15
+ - Added `customData` to `Ad` and `AdBreak`, including bidirectional event bridging on Android, iOS and tvOS.
16
+
17
+ ### Fixed
18
+
19
+ - Fixed an issue on Web where player facade listeners, such as analytics connectors, did not receive the player's `destroy` event.
20
+ - Fixed THEOlive events not being forwarded correctly on React Native v0.88.0+.
21
+ - Fixed an issue on Android where `preferredKeySystems` in the content protection configuration was ignored.
22
+ - Fixed ad-break integration identifiers being forwarded incorrectly on iOS and tvOS.
23
+
24
+ ## [11.8.0] - 18-10-26
9
25
 
10
26
  ### Added
11
27
 
@@ -168,6 +168,8 @@ dependencies {
168
168
  implementation("com.theoplayer.theoplayer-sdk-android:ads-wrapper:$theoAdsWrapperVersion")
169
169
  implementation("com.theoplayer.android-connector:mediasession:$theoMediaSessionVersion")
170
170
  testImplementation("junit:junit:4.13.2")
171
+ testImplementation("com.vaadin.external.google:android-json:0.0.20131108.vaadin1")
172
+ testImplementation("org.mockito:mockito-core:5.20.0")
171
173
 
172
174
  addOptiViewIntegration(enabledGoogleIMA || enabledGoogleDAI || enabledTHEOads, 'integration-ads-ima')
173
175
  addOptiViewIntegration(enabledGoogleDAI || enabledTHEOads, 'integration-ads-dai')
@@ -2,6 +2,7 @@ package com.theoplayer.ads
2
2
 
3
3
  import com.facebook.react.bridge.Arguments
4
4
  import com.facebook.react.bridge.ReadableMap
5
+ import com.facebook.react.bridge.ReadableType
5
6
  import com.facebook.react.bridge.WritableMap
6
7
  import com.facebook.react.bridge.WritableArray
7
8
  import com.google.ads.interactivemedia.v3.api.AdPodInfo
@@ -12,6 +13,8 @@ import com.theoplayer.android.api.ads.CompanionAd
12
13
  import com.theoplayer.android.api.ads.ima.GoogleImaAd
13
14
  import com.theoplayer.android.api.ads.UniversalAdId
14
15
  import com.theoplayer.android.api.event.ads.AdIntegrationKind
16
+ import com.theoplayer.util.BridgeUtils
17
+ import org.json.JSONObject
15
18
  import java.lang.Exception
16
19
 
17
20
  private const val PROP_AD_SYSTEM = "adSystem"
@@ -49,6 +52,7 @@ private const val PROP_COMPANION_HEIGHT = "height"
49
52
  private const val PROP_COMPANION_RESOURCEURI = "resourceURI"
50
53
  private const val PROP_UNIVERSAL_AD_ID_REGISTRY = "adIdRegistry"
51
54
  private const val PROP_UNIVERSAL_AD_ID_VALUE = "adIdValue"
55
+ private const val PROP_CUSTOM_DATA = "customData"
52
56
 
53
57
  private const val INVALID_DOUBLE = -1.0
54
58
  private const val INVALID_INT = -1
@@ -130,6 +134,9 @@ object AdAdapter {
130
134
  }
131
135
  adPayload.putArray(PROP_AD_WRAPPER_CREATIVE_IDS, wrapperCreativeIdsPayload)
132
136
  }
137
+ fromCustomData(ad.customData)?.let {
138
+ adPayload.putMap(PROP_CUSTOM_DATA, it)
139
+ }
133
140
  return adPayload
134
141
  }
135
142
 
@@ -146,6 +153,9 @@ object AdAdapter {
146
153
  adbreakPayload.putInt(PROP_ADBREAK_MAXDURATION,adbreak.maxDuration)
147
154
  adbreakPayload.putInt(PROP_ADBREAK_TIMEOFFSET, adbreak.timeOffset)
148
155
  adbreakPayload.putDouble(PROP_ADBREAK_MAXREMAININGDURATION, adbreak.maxRemainingDuration)
156
+ fromCustomData(adbreak.customData)?.let {
157
+ adbreakPayload.putMap(PROP_CUSTOM_DATA, it)
158
+ }
149
159
  val adsPayload = Arguments.createArray()
150
160
  for (ad in adbreak.ads) {
151
161
  // Some ads in the ad break are possibly not loaded yet.
@@ -180,10 +190,27 @@ object AdAdapter {
180
190
  return companionsPayload
181
191
  }
182
192
 
193
+ private fun fromCustomData(customData: Any?): WritableMap? = when (customData) {
194
+ is JSONObject -> BridgeUtils.fromJSONObjectToBridge(customData)
195
+ is Map<*, *> -> BridgeUtils.fromJSONObjectToBridge(JSONObject(customData.filterKeys { it is String }))
196
+ else -> null
197
+ }
198
+
199
+ private fun parseCustomData(data: ReadableMap): Map<String, Any?>? =
200
+ if (data.hasKey(PROP_CUSTOM_DATA) && data.getType(PROP_CUSTOM_DATA) == ReadableType.Map) {
201
+ data.getMap(PROP_CUSTOM_DATA)?.toHashMap()
202
+ } else {
203
+ null
204
+ }
205
+
183
206
  /**
184
207
  * Convert a ReactNative Ad to a native Ad.
208
+ *
209
+ * @param ad The bridged ad, or null.
210
+ * @param parentAdBreak The owning break when parsing an ad nested in a break.
211
+ * @return The native ad, or null when the input is null.
185
212
  */
186
- fun parseAd(ad: ReadableMap?): GoogleImaAd? {
213
+ fun parseAd(ad: ReadableMap?, parentAdBreak: AdBreak? = null): GoogleImaAd? {
187
214
  if (ad == null) {
188
215
  return null
189
216
  }
@@ -201,7 +228,7 @@ object AdAdapter {
201
228
  }
202
229
 
203
230
  override fun getAdBreak(): AdBreak? {
204
- return parseAdBreak(ad.getMap(PROP_AD_BREAK))
231
+ return parentAdBreak ?: if (ad.hasKey(PROP_AD_BREAK)) parseAdBreak(ad.getMap(PROP_AD_BREAK)) else null
205
232
  }
206
233
 
207
234
  override fun getSkipOffset(): Int {
@@ -217,8 +244,7 @@ object AdAdapter {
217
244
  }
218
245
 
219
246
  override fun getCustomData(): Any? {
220
- // Not supported yet
221
- return null
247
+ return parseCustomData(ad)
222
248
  }
223
249
 
224
250
  override val imaAd: com.google.ads.interactivemedia.v3.api.Ad
@@ -256,7 +282,8 @@ object AdAdapter {
256
282
  }
257
283
  return object: AdBreak {
258
284
  override fun getAds(): List<Ad> {
259
- return emptyList()
285
+ val ads = if (adBreak.hasKey(PROP_ADBREAK_ADS)) adBreak.getArray(PROP_ADBREAK_ADS) else null
286
+ return (0 until (ads?.size() ?: 0)).mapNotNull { parseAd(ads?.getMap(it), this) }
260
287
  }
261
288
 
262
289
  override fun getMaxDuration(): Int {
@@ -298,8 +325,7 @@ object AdAdapter {
298
325
  }
299
326
 
300
327
  override fun getCustomData(): Any? {
301
- // Not supported yet
302
- return null
328
+ return parseCustomData(adBreak)
303
329
  }
304
330
  }
305
331
  }
@@ -65,7 +65,14 @@ class AdEventAdapter(private val adsApi: AdsApiWrapper, eventEmitter: AdEventEmi
65
65
  return if (event != null && eventType != null) {
66
66
  object : GoogleImaAdEvent {
67
67
  override val ad: GoogleImaAd?
68
- get() = AdAdapter.parseAd(event.getMap(EVENT_PROP_AD))
68
+ get() {
69
+ val payload = event.getMap(EVENT_PROP_AD)
70
+ val adBreak = when (eventType) {
71
+ GoogleImaAdEventType.AD_BREAK_STARTED, GoogleImaAdEventType.AD_BREAK_ENDED -> AdAdapter.parseAdBreak(payload)
72
+ else -> null
73
+ }
74
+ return AdAdapter.parseAd(payload, adBreak)
75
+ }
69
76
  override val adData: Map<String, String>
70
77
  get() = mapOf()
71
78
  override fun getDate(): Date {
@@ -49,6 +49,7 @@ const val PROP_MULTISESSION: String = "multiSession"
49
49
  const val PROP_KEYS: String = "keys"
50
50
  const val PROP_ID: String = "id"
51
51
  const val PROP_VALUE: String = "value"
52
+ const val PROP_PREFERRED_KEY_SYSTEMS: String = "preferredKeySystems"
52
53
 
53
54
  object ContentProtectionAdapter {
54
55
 
@@ -114,6 +115,12 @@ object ContentProtectionAdapter {
114
115
  if (jsonConfig.has(PROP_MULTISESSION)) {
115
116
  multiSession(jsonConfig.getBoolean(PROP_MULTISESSION))
116
117
  }
118
+ if (jsonConfig.has(PROP_PREFERRED_KEY_SYSTEMS)) {
119
+ val jsonKeySystems = jsonConfig.getJSONArray(PROP_PREFERRED_KEY_SYSTEMS)
120
+ preferredKeySystems((0 until jsonKeySystems.length()).mapNotNull {
121
+ KeySystemAdapter.fromString(jsonKeySystems.getString(it))
122
+ })
123
+ }
117
124
  queryParameters(fromJSONObjectToMap(jsonConfig.optJSONObject(PROP_QUERY_PARAMETERS)))
118
125
  }.build()
119
126
  }
@@ -8,6 +8,7 @@ import com.theoplayer.android.api.ads.theoads.TheoAdDescription
8
8
  import com.theoplayer.android.api.error.THEOplayerException
9
9
  import com.facebook.react.bridge.ReadableMap
10
10
  import com.facebook.react.bridge.WritableMap
11
+ import com.theoplayer.android.api.source.SourceAbrConfiguration
11
12
  import com.theoplayer.android.api.source.SourceDescription
12
13
  import com.theoplayer.android.api.source.TypedSource
13
14
  import com.theoplayer.android.api.source.metadata.MetadataDescription
@@ -41,6 +42,9 @@ import java.util.ArrayList
41
42
  import java.util.HashMap
42
43
 
43
44
  private const val TAG = "SourceAdapter"
45
+ private const val PROP_ABR = "abr"
46
+ private const val PROP_PREFERRED_VIDEO_CODECS = "preferredVideoCodecs"
47
+ private const val PROP_PREFERRED_AUDIO_CODECS = "preferredAudioCodecs"
44
48
  private const val PROP_CONTENT_PROTECTION = "contentProtection"
45
49
  private const val PROP_LIVE_OFFSET = "liveOffset"
46
50
  private const val PROP_HLS_DATERANGE = "hlsDateRange"
@@ -179,6 +183,9 @@ class SourceAdapter {
179
183
  .poster(poster)
180
184
  .ads(*ads.toTypedArray())
181
185
  .textTracks(*sideLoadedTextTracks.toTypedArray())
186
+ parseAbrConfigurationFromSources(jsonSources, jsonSourceObject.optJSONObject(PROP_SOURCES))?.let {
187
+ builder.abr(it)
188
+ }
182
189
  if (metadataDescription != null) {
183
190
  builder.metadata(metadataDescription)
184
191
  }
@@ -194,6 +201,22 @@ class SourceAdapter {
194
201
  return null
195
202
  }
196
203
 
204
+ private fun parseAbrConfigurationFromSources(jsonSources: JSONArray?, jsonSource: JSONObject?): SourceAbrConfiguration? {
205
+ // The SDK applies the ABR configuration per source description: take it from the first typed source specifying one.
206
+ val jsonAbr = if (jsonSources != null) {
207
+ (0 until jsonSources.length()).firstNotNullOfOrNull { (jsonSources[it] as JSONObject).optJSONObject(PROP_ABR) }
208
+ } else {
209
+ jsonSource?.optJSONObject(PROP_ABR)
210
+ } ?: return null
211
+ return SourceAbrConfiguration(
212
+ maxBitrate = null,
213
+ preferredVideoCodecs = jsonAbr.optJSONArray(PROP_PREFERRED_VIDEO_CODECS)?.toStringList(),
214
+ preferredAudioCodecs = jsonAbr.optJSONArray(PROP_PREFERRED_AUDIO_CODECS)?.toStringList()
215
+ )
216
+ }
217
+
218
+ private fun JSONArray.toStringList(): List<String> = (0 until length()).map { getString(it) }
219
+
197
220
  private fun parseTheoLiveSource(jsonTypedSource: JSONObject): TheoLiveSource {
198
221
  return TheoLiveSource(
199
222
  src=jsonTypedSource.optString(PROP_SRC),
@@ -26,10 +26,10 @@ object BridgeUtils {
26
26
  while (iterator.hasNext()) {
27
27
  val key = iterator.next()
28
28
  when (val value = json.opt(key)) {
29
- // null -> putNull(key)
29
+ null, JSONObject.NULL -> putNull(key)
30
30
  is Boolean -> putBoolean(key, value)
31
31
  is Int -> putInt(key, value)
32
- is Double -> putDouble(key, value)
32
+ is Number -> putDouble(key, value.toDouble())
33
33
  is String -> putString(key, value)
34
34
  is JSONObject -> putMap(key, fromJSONObjectToBridge(value))
35
35
  is JSONArray -> putArray(key, fromJSONArrayToBridge(value))
@@ -50,10 +50,10 @@ object BridgeUtils {
50
50
  try {
51
51
  for (i in 0 until jsonArray.length()) {
52
52
  when (val value = jsonArray.opt(i)) {
53
- // null -> writableArray.pushNull()
53
+ null, JSONObject.NULL -> pushNull()
54
54
  is Boolean -> pushBoolean(value)
55
55
  is Int -> pushInt(value)
56
- is Double -> pushDouble(value)
56
+ is Number -> pushDouble(value.toDouble())
57
57
  is String -> pushString(value)
58
58
  is JSONObject -> pushMap(fromJSONObjectToBridge(value))
59
59
  is JSONArray -> pushArray(fromJSONArrayToBridge(value))
@@ -0,0 +1,144 @@
1
+ package com.theoplayer.ads
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.JavaOnlyArray
5
+ import com.facebook.react.bridge.JavaOnlyMap
6
+ import com.facebook.react.bridge.WritableArray
7
+ import com.facebook.react.bridge.WritableMap
8
+ import com.theoplayer.android.api.ads.Ad
9
+ import com.theoplayer.android.api.ads.AdBreak
10
+ import com.theoplayer.android.api.event.ads.AdIntegrationKind
11
+ import com.theoplayer.integration.facadeStub
12
+ import org.json.JSONObject
13
+ import org.junit.After
14
+ import org.junit.Assert.*
15
+ import org.junit.Before
16
+ import org.junit.Test
17
+ import org.mockito.MockedStatic
18
+ import org.mockito.Mockito.mockStatic
19
+
20
+ class AdAdapterCustomDataTest {
21
+ private var factories: MockedStatic<Arguments>? = null
22
+
23
+ @Before fun useJavaBridgeContainers() {
24
+ factories = mockStatic(Arguments::class.java).apply {
25
+ `when`<WritableMap> { Arguments.createMap() }.thenAnswer { JavaOnlyMap() }
26
+ `when`<WritableArray> { Arguments.createArray() }.thenAnswer { JavaOnlyArray() }
27
+ }
28
+ }
29
+
30
+ @After fun restoreBridgeFactories() {
31
+ factories?.close()
32
+ }
33
+
34
+ @Test fun parsesAdAndAdBreakCustomDataFromJavascript() {
35
+ val metadata = JavaOnlyMap.of(
36
+ "campaign", "example",
37
+ "optional", null,
38
+ "nested", mapOf("enabled" to true),
39
+ "values", listOf(1.5, null, 2.0),
40
+ )
41
+ val payload = JavaOnlyMap.of("customData", metadata)
42
+ assertEquals(metadata.toHashMap(), AdAdapter.parseAd(payload)?.customData)
43
+ assertEquals(metadata.toHashMap(), AdAdapter.parseAdBreak(payload)?.customData)
44
+ }
45
+
46
+ @Test fun missingAndNullCustomDataRemainAbsent() {
47
+ for (payload in listOf(JavaOnlyMap(), JavaOnlyMap.of("customData", null))) {
48
+ assertNull(AdAdapter.parseAd(payload)?.customData)
49
+ assertNull(AdAdapter.parseAdBreak(payload)?.customData)
50
+ }
51
+ assertFalse(AdAdapter.fromAd(ad(null)).hasKey("customData"))
52
+ assertFalse(AdAdapter.fromAdBreak(adBreak(null)).hasKey("customData"))
53
+ }
54
+
55
+ @Test fun emptyCustomDataIsNotTreatedAsAbsent() {
56
+ val payload = JavaOnlyMap.of("customData", JavaOnlyMap())
57
+ assertEquals(emptyMap<String, Any?>(), AdAdapter.parseAd(payload)?.customData)
58
+ assertEquals(emptyMap<String, Any?>(), AdAdapter.parseAdBreak(payload)?.customData)
59
+ assertEquals(emptyMap<String, Any?>(), AdAdapter.fromAd(ad(emptyMap<String, Any?>())).getMap("customData")?.toHashMap())
60
+ }
61
+
62
+ @Test fun preservesNestedValuesNullsAndNumericTypesInBothNativeModels() {
63
+ val metadata = linkedMapOf(
64
+ "nested" to mapOf("enabled" to true),
65
+ "values" to listOf(1.5f, null, 2.toShort(), 3.toByte()),
66
+ "optional" to null,
67
+ "long" to 4_000_000_000L,
68
+ )
69
+ for (payload in listOf(AdAdapter.fromAd(ad(metadata)), AdAdapter.fromAdBreak(adBreak(JSONObject(metadata))))) {
70
+ val result = requireNotNull(payload.getMap("customData"))
71
+ assertTrue(requireNotNull(result.getMap("nested")).getBoolean("enabled"))
72
+ assertTrue(result.hasKey("optional"))
73
+ assertTrue(result.isNull("optional"))
74
+ assertEquals(listOf(1.5, null, 2.0, 3.0), result.getArray("values")?.toArrayList())
75
+ assertEquals(4_000_000_000.0, result.getDouble("long"), 0.0)
76
+ }
77
+ }
78
+
79
+ @Test fun invalidMapKeysCannotAbortAdOrAdBreakSerialization() {
80
+ val metadata = linkedMapOf<Any?, Any?>(null to "invalid", 1 to "invalid", "campaign" to "example")
81
+ for (payload in listOf(AdAdapter.fromAd(ad(metadata)), AdAdapter.fromAdBreak(adBreak(metadata)))) {
82
+ assertEquals(mapOf("campaign" to "example"), payload.getMap("customData")?.toHashMap())
83
+ }
84
+ }
85
+
86
+ @Test fun nestedAdsKeepIndependentCustomDataWithoutRecursiveAdBreaks() {
87
+ val nativeBreak = adBreak(mapOf("break" to "metadata"))
88
+ val nativeAd = ad(mapOf("ad" to "metadata"), nativeBreak)
89
+ val breakWithAds = adBreak(mapOf("break" to "metadata"), listOf(nativeAd))
90
+ val payload = AdAdapter.fromAdBreak(breakWithAds)
91
+ val nestedAd = requireNotNull(payload.getArray("ads")?.getMap(0))
92
+ assertEquals("metadata", payload.getMap("customData")?.getString("break"))
93
+ assertEquals("metadata", nestedAd.getMap("customData")?.getString("ad"))
94
+ assertFalse(nestedAd.hasKey("adBreak"))
95
+ }
96
+
97
+ @Test fun broadcastAdEventsExposeCustomDataToNativeListeners() {
98
+ val payload = JavaOnlyMap.of(
99
+ "subType", "adbegin",
100
+ "ad", JavaOnlyMap.of("customData", JavaOnlyMap.of("campaign", "example")),
101
+ )
102
+ assertEquals(mapOf("campaign" to "example"), AdEventAdapter.parseEvent(payload)?.ad?.customData)
103
+ }
104
+
105
+ @Test fun broadcastAdBreakEventsExposeBreakAndNestedAdCustomData() {
106
+ for (subType in listOf("adbreakbegin", "adbreakend")) {
107
+ val payload = JavaOnlyMap.of(
108
+ "subType", subType,
109
+ "ad", JavaOnlyMap.of(
110
+ "customData", JavaOnlyMap.of("break", "metadata"),
111
+ "ads", JavaOnlyArray.of(JavaOnlyMap.of("customData", JavaOnlyMap.of("ad", "metadata"))),
112
+ ),
113
+ )
114
+ val adBreak = requireNotNull(AdEventAdapter.parseEvent(payload)?.ad?.adBreak)
115
+ assertEquals(mapOf("break" to "metadata"), adBreak.customData)
116
+ assertEquals(mapOf("ad" to "metadata"), adBreak.ads.single().customData)
117
+ assertSame(adBreak, adBreak.ads.single().adBreak)
118
+ }
119
+ }
120
+
121
+ private fun ad(metadata: Any?, adBreak: AdBreak? = null): Ad = facadeStub { method, _ ->
122
+ when (method) {
123
+ "getIntegration" -> AdIntegrationKind.CUSTOM
124
+ "getType" -> "linear"
125
+ "getCompanions" -> emptyList<Any>()
126
+ "getSkipOffset" -> -1
127
+ "getAdBreak" -> adBreak
128
+ "getCustomData" -> metadata
129
+ else -> null
130
+ }
131
+ }
132
+
133
+ private fun adBreak(metadata: Any?, ads: List<Ad> = emptyList()): AdBreak = facadeStub { method, _ ->
134
+ when (method) {
135
+ "getIntegration" -> AdIntegrationKind.CUSTOM
136
+ "getAds" -> ads
137
+ "getMaxDuration" -> -1
138
+ "getMaxRemainingDuration" -> -1.0
139
+ "getTimeOffset" -> 0
140
+ "getCustomData" -> metadata
141
+ else -> null
142
+ }
143
+ }
144
+ }
@@ -106,6 +106,13 @@ RCT_EXTERN_METHOD(getManageContentMatching:(nonnull NSNumber *)node
106
106
  resolver:(RCTPromiseResolveBlock)resolve
107
107
  rejecter:(RCTPromiseRejectBlock)reject)
108
108
 
109
+ RCT_EXTERN_METHOD(setAllowsExternalPlayback:(nonnull NSNumber *)node
110
+ enable:(BOOL)enable)
111
+
112
+ RCT_EXTERN_METHOD(getAllowsExternalPlayback:(nonnull NSNumber *)node
113
+ resolver:(RCTPromiseResolveBlock)resolve
114
+ rejecter:(RCTPromiseRejectBlock)reject)
115
+
109
116
  RCT_EXTERN_METHOD(setPipConfig:(nonnull NSNumber *)node
110
117
  pipConfig:(NSDictionary)pipConfig)
111
118
 
@@ -58,6 +58,7 @@ public class THEOplayerRCTMainEventHandler {
58
58
  private var canPlayListener: EventListener?
59
59
  private var contentProtectionSuccessListener: EventListener?
60
60
  private var videoResizeListener: EventListener?
61
+ private var contentProtectionErrorListener: EventListener?
61
62
 
62
63
  // MARK: player observer
63
64
  private var dimensionChangeObserver: NSKeyValueObservation?
@@ -338,6 +339,25 @@ public class THEOplayerRCTMainEventHandler {
338
339
  }
339
340
  if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] CanPlay listener attached to THEOplayer") }
340
341
 
342
+ // CONTENT_PROTECTION_ERROR
343
+ self.contentProtectionErrorListener = player.addEventListener(type: PlayerEventTypes.CONTENT_PROTECTION_ERROR) { [weak self] event in
344
+ if DEBUG_THEOPLAYER_EVENTS { PrintUtils.printLog(logText: "[NATIVE] Received CONTENT_PROTECTION_ERROR event from THEOplayer") }
345
+ if let forwardedContentProtectionErrorEvent = self?.onNativeContentProtectionError {
346
+ let errorObject = event.errorObject
347
+ let errorCodeString = String(errorObject.code.rawValue)
348
+ let errorCodeMessage = errorObject.message
349
+ forwardedContentProtectionErrorEvent(
350
+ [
351
+ "error": [
352
+ "errorCode": errorCodeString,
353
+ "errorMessage": errorCodeMessage
354
+ ]
355
+ ]
356
+ )
357
+ }
358
+ }
359
+ if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] ContentProtectionError listener attached to THEOplayer") }
360
+
341
361
  // RESIZE
342
362
  self.videoResizeListener = player.addEventListener(type: PlayerEventTypes.RESIZE) { [weak self, weak player] event in
343
363
  if DEBUG_THEOPLAYER_EVENTS { PrintUtils.printLog(logText: "[NATIVE] Received RESIZE event from THEOplayer") }
@@ -503,7 +523,13 @@ public class THEOplayerRCTMainEventHandler {
503
523
  if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] Invalidate dimensionChangeObserver from THEOplayer") }
504
524
  self.dimensionChangeObserver?.invalidate()
505
525
  self.dimensionChangeObserver = nil
506
-
526
+
527
+ // CONTENT_PROTECTION_ERROR
528
+ if let contentProtectionErrorListener = self.contentProtectionErrorListener {
529
+ player.removeEventListener(type: PlayerEventTypes.CONTENT_PROTECTION_ERROR, listener: contentProtectionErrorListener)
530
+ if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] ContentProtectionError listener dettached from THEOplayer") }
531
+ }
532
+
507
533
  // RESIZE
508
534
  if let videoResizeListener = self.videoResizeListener {
509
535
  player.removeEventListener(type: PlayerEventTypes.RESIZE, listener: videoResizeListener)
@@ -234,6 +234,26 @@ class THEOplayerRCTPlayerAPI: NSObject, RCTBridgeModule {
234
234
  #endif
235
235
  }
236
236
 
237
+ @objc(setAllowsExternalPlayback:enable:)
238
+ func setAllowsExternalPlayback(_ node: NSNumber, enable: Bool) -> Void {
239
+ withViewAndPlayer(node) { _, player in
240
+ if player.allowsExternalPlayback != enable {
241
+ if DEBUG_PLAYER_API { PrintUtils.printLog(logText: "[NATIVE] Changing TheoPlayer's allowsExternalPlayback to \(enable)") }
242
+ player.allowsExternalPlayback = enable
243
+ }
244
+ }
245
+ }
246
+
247
+ // Used by the e2e test app to verify the native value rather than the adapter's cached state.
248
+ @objc(getAllowsExternalPlayback:resolver:rejecter:)
249
+ func getAllowsExternalPlayback(_ node: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
250
+ withViewAndPlayer(node) { _, player in
251
+ resolve(player.allowsExternalPlayback)
252
+ } onFailure: {
253
+ reject(ERROR_CODE_PLAYER_ACCESS_FAILURE, ERROR_MESSAGE_PLAYER_ACCESS_FAILURE, nil)
254
+ }
255
+ }
256
+
237
257
  @objc(setPipConfig:pipConfig:)
238
258
  func setPipConfig(_ node: NSNumber, pipConfig: NSDictionary) -> Void {
239
259
  withView(node) { theView in
@@ -34,6 +34,7 @@ let PROP_ADBREAK_MAX_REMAINING_DURATION: String = "maxRemainingDuration"
34
34
  let PROP_ADBREAK_ADS: String = "ads"
35
35
  let PROP_ADBREAK_INTEGRATION: String = "integration"
36
36
  let PROP_ADBREAK_CUSTOM_INTEGRATION: String = "customIntegration"
37
+ let PROP_CUSTOM_DATA: String = "customData"
37
38
  let PROP_COMPANION_AD_SLOT_ID: String = "adSlotId"
38
39
  let PROP_COMPANION_ALT_TEXT: String = "altText"
39
40
  let PROP_COMPANION_CLICK_THROUGH: String = "clickThrough"
@@ -49,6 +50,9 @@ class THEOplayerRCTAdAdapter {
49
50
  if let customIntegration = ad.customIntegration {
50
51
  adData[PROP_AD_CUSTOM_INTEGRATION] = customIntegration
51
52
  }
53
+ if let customData = ad.customData {
54
+ adData[PROP_CUSTOM_DATA] = customData
55
+ }
52
56
  adData[PROP_AD_TYPE] = ad.type
53
57
  if let adId = ad.id {
54
58
  adData[PROP_AD_ID] = adId
@@ -134,7 +138,7 @@ class THEOplayerRCTAdAdapter {
134
138
  return nil
135
139
  }
136
140
 
137
- return NativeLinearGoogleImaAd(adBreak: THEOplayerRCTAdAdapter.toAdBreak(adBreakData: adData[PROP_AD_BREAK] as? [String:Any]),
141
+ let ad = NativeLinearGoogleImaAd(adBreak: THEOplayerRCTAdAdapter.toAdBreak(adBreakData: adData[PROP_AD_BREAK] as? [String:Any]),
138
142
  companions: THEOplayerRCTAdAdapter.toCompanionAds(companiondAdsData: adData[PROP_AD_COMPANIONS] as? [[String : Any]]),
139
143
  type: (adData[PROP_AD_TYPE] as? String) ?? "",
140
144
  id: adData[PROP_AD_ID] as? String,
@@ -155,6 +159,8 @@ class THEOplayerRCTAdAdapter {
155
159
  vastMediaBitrate: (adData[PROP_GOOGLE_AD_BITRATE] as? Int) ?? 0,
156
160
  universalAdIds: THEOplayerRCTAdAdapter.toUniversalAdIds(universalAdIdsData: adData[PROP_AD_UNIVERSAL_AD_IDS] as? [[String:Any]]),
157
161
  traffickingParameters: "") // TODO
162
+ ad.customData = adData[PROP_CUSTOM_DATA] as? [String: Any]
163
+ return ad
158
164
  }
159
165
 
160
166
  private class func toUniversalAdIds(universalAdIdsData: [[String:Any]]?) -> [THEOplayerSDK.UniversalAdId] {
@@ -178,8 +184,11 @@ class THEOplayerRCTAdAdapter {
178
184
  adBreakData[PROP_ADBREAK_MAX_DURATION] = adBreak.maxDuration
179
185
  adBreakData[PROP_ADBREAK_TIME_OFFSET] = adBreak.timeOffset
180
186
  adBreakData[PROP_ADBREAK_MAX_REMAINING_DURATION] = adBreak.maxRemainingDuration
181
- adBreakData[PROP_ADBREAK_INTEGRATION] = adBreak.integration
187
+ adBreakData[PROP_ADBREAK_INTEGRATION] = adBreak.integration._rawValue
182
188
  adBreakData[PROP_ADBREAK_CUSTOM_INTEGRATION] = adBreak.customIntegration
189
+ if let customData = adBreak.customData {
190
+ adBreakData[PROP_CUSTOM_DATA] = customData
191
+ }
183
192
  // process adds when adbreak contains them
184
193
  if !adBreak.ads.isEmpty {
185
194
  var adList: [[String:Any]] = []
@@ -205,13 +214,15 @@ class THEOplayerRCTAdAdapter {
205
214
  }
206
215
  }
207
216
 
208
- return NativeAdBreak(ads: ads,
217
+ let adBreak = NativeAdBreak(ads: ads,
209
218
  id: adBreakData[PROP_ADBREAK_ID] as? String,
210
219
  maxDuration: lround((adBreakData[PROP_ADBREAK_MAX_DURATION] as? Double) ?? 0),
211
220
  maxRemainingDuration: (adBreakData[PROP_ADBREAK_MAX_REMAINING_DURATION] as? Double) ?? 0,
212
221
  timeOffset: lround((adBreakData[PROP_ADBREAK_TIME_OFFSET] as? Double) ?? 0),
213
222
  integration: THEOplayerRCTTypeUtils.adIntegrationKind((adBreakData[PROP_ADBREAK_INTEGRATION] as? String) ?? ""),
214
223
  customIntegration: adBreakData[PROP_ADBREAK_CUSTOM_INTEGRATION] as? String)
224
+ adBreak.customData = adBreakData[PROP_CUSTOM_DATA] as? [String: Any]
225
+ return adBreak
215
226
  }
216
227
 
217
228
  class func defaultAdBreak() -> NativeAdBreak {
@@ -30,6 +30,8 @@ class NativeAd: THEOplayerSDK.Ad {
30
30
  var clickThrough: String? = nil
31
31
  /**The type of custom ad integration.*/
32
32
  var customIntegration: String? = nil
33
+ /** Additional integration-specific data associated with this ad.*/
34
+ var customData: [String: Any]? = nil
33
35
 
34
36
  init(adBreak: AdBreak, companions: [THEOplayerSDK.CompanionAd], type: String, id: String? = nil, skipOffset: Int? = nil, resourceURI: String? = nil, width: Int? = nil, height: Int? = nil, isSlate: Bool = false, integration: THEOplayerSDK.AdIntegrationKind, duration: Int? = 0, clickThrough: String?, customIntegration: String?) {
35
37
  self.adBreak = adBreak
@@ -134,6 +136,8 @@ class NativeAdBreak: THEOplayerSDK.AdBreak {
134
136
  - For other integrations, this may be `nil`.
135
137
  */
136
138
  var id: String? = nil
139
+ /** Additional integration-specific data associated with this ad break.*/
140
+ var customData: [String: Any]? = nil
137
141
 
138
142
  init(ads: [Ad], id: String? = nil, maxDuration: Int, maxRemainingDuration: Double, timeOffset: Int, integration: THEOplayerSDK.AdIntegrationKind, customIntegration: String? = nil) {
139
143
  self.ads = ads
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=SourceAbrConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["api/source/abr/SourceAbrConfiguration.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _SourceAbrConfiguration = require("./SourceAbrConfiguration");
7
+ Object.keys(_SourceAbrConfiguration).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _SourceAbrConfiguration[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _SourceAbrConfiguration[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=barrel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_SourceAbrConfiguration","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../../../../src","sources":["api/source/abr/barrel.ts"],"mappings":";;;;;AAAA,IAAAA,uBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,uBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,uBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,uBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}