react-native-theoplayer 11.8.0 → 11.10.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 (90) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/README.md +0 -67
  3. package/android/build.gradle +2 -0
  4. package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +1 -0
  5. package/android/src/main/java/com/theoplayer/ads/AdAdapter.kt +33 -7
  6. package/android/src/main/java/com/theoplayer/ads/AdEventAdapter.kt +8 -1
  7. package/android/src/main/java/com/theoplayer/drm/ContentProtectionAdapter.kt +7 -0
  8. package/android/src/main/java/com/theoplayer/drm/KeySystemAdapter.kt +5 -5
  9. package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAds.kt +3 -6
  10. package/android/src/main/java/com/theoplayer/source/SourceAdapter.kt +23 -0
  11. package/android/src/main/java/com/theoplayer/util/BridgeUtils.kt +4 -4
  12. package/android/src/test/java/com/theoplayer/ads/AdAdapterCustomDataTest.kt +144 -0
  13. package/android/src/test/java/com/theoplayer/drm/KeySystemAdapterTest.kt +30 -0
  14. package/android/src/test/java/com/theoplayer/integration/PlayerFacadeTest.kt +18 -0
  15. package/android/src/test/java/com/theoplayer/integration/PlayerFacadeTestHost.kt +1 -1
  16. package/ios/THEOplayerRCTBridge.m +7 -0
  17. package/ios/THEOplayerRCTMainEventHandler.swift +27 -1
  18. package/ios/THEOplayerRCTPlayerAPI.swift +20 -0
  19. package/ios/ads/THEOplayerRCTAdAdapter.swift +14 -3
  20. package/ios/ads/THEOplayerRCTAdsNative.swift +4 -0
  21. package/lib/commonjs/api/source/abr/SourceAbrConfiguration.js +2 -0
  22. package/lib/commonjs/api/source/abr/SourceAbrConfiguration.js.map +1 -0
  23. package/lib/commonjs/api/source/abr/barrel.js +17 -0
  24. package/lib/commonjs/api/source/abr/barrel.js.map +1 -0
  25. package/lib/commonjs/api/source/barrel.js +18 -7
  26. package/lib/commonjs/api/source/barrel.js.map +1 -1
  27. package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js +1 -0
  28. package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js.map +1 -1
  29. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +9 -0
  30. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
  31. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +13 -1
  32. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  33. package/lib/commonjs/internal/adapter/event/native/NativeTheoLiveEvent.js +2 -2
  34. package/lib/commonjs/internal/adapter/event/native/NativeTheoLiveEvent.js.map +1 -1
  35. package/lib/commonjs/manifest.json +1 -1
  36. package/lib/module/api/source/abr/SourceAbrConfiguration.js +2 -0
  37. package/lib/module/api/source/abr/SourceAbrConfiguration.js.map +1 -0
  38. package/lib/module/api/source/abr/barrel.js +4 -0
  39. package/lib/module/api/source/abr/barrel.js.map +1 -0
  40. package/lib/module/api/source/barrel.js +1 -0
  41. package/lib/module/api/source/barrel.js.map +1 -1
  42. package/lib/module/internal/adapter/DefaultNativePlayerState.js +1 -0
  43. package/lib/module/internal/adapter/DefaultNativePlayerState.js.map +1 -1
  44. package/lib/module/internal/adapter/THEOplayerAdapter.js +9 -0
  45. package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
  46. package/lib/module/internal/adapter/THEOplayerWebAdapter.js +13 -1
  47. package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  48. package/lib/module/internal/adapter/event/native/NativeTheoLiveEvent.js +2 -2
  49. package/lib/module/internal/adapter/event/native/NativeTheoLiveEvent.js.map +1 -1
  50. package/lib/module/manifest.json +1 -1
  51. package/lib/typescript/__tests__/NativeTheoLiveEvent.test.d.ts +2 -0
  52. package/lib/typescript/__tests__/NativeTheoLiveEvent.test.d.ts.map +1 -0
  53. package/lib/typescript/api/ads/Ad.d.ts +9 -0
  54. package/lib/typescript/api/ads/Ad.d.ts.map +1 -1
  55. package/lib/typescript/api/ads/AdBreak.d.ts +9 -0
  56. package/lib/typescript/api/ads/AdBreak.d.ts.map +1 -1
  57. package/lib/typescript/api/player/THEOplayer.d.ts +11 -0
  58. package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
  59. package/lib/typescript/api/source/SourceDescription.d.ts +7 -0
  60. package/lib/typescript/api/source/SourceDescription.d.ts.map +1 -1
  61. package/lib/typescript/api/source/abr/SourceAbrConfiguration.d.ts +27 -0
  62. package/lib/typescript/api/source/abr/SourceAbrConfiguration.d.ts.map +1 -0
  63. package/lib/typescript/api/source/abr/barrel.d.ts +2 -0
  64. package/lib/typescript/api/source/abr/barrel.d.ts.map +1 -0
  65. package/lib/typescript/api/source/barrel.d.ts +1 -0
  66. package/lib/typescript/api/source/barrel.d.ts.map +1 -1
  67. package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts +1 -0
  68. package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts.map +1 -1
  69. package/lib/typescript/internal/adapter/NativePlayerState.d.ts +1 -0
  70. package/lib/typescript/internal/adapter/NativePlayerState.d.ts.map +1 -1
  71. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +2 -0
  72. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
  73. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +2 -0
  74. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/src/__tests__/NativeTheoLiveEvent.test.ts +82 -0
  77. package/src/__tests__/PlayerFacadeWebAdapter.test.ts +13 -0
  78. package/src/api/ads/Ad.ts +10 -0
  79. package/src/api/ads/AdBreak.ts +10 -0
  80. package/src/api/player/THEOplayer.ts +12 -0
  81. package/src/api/source/SourceDescription.ts +8 -0
  82. package/src/api/source/abr/SourceAbrConfiguration.ts +27 -0
  83. package/src/api/source/abr/barrel.ts +1 -0
  84. package/src/api/source/barrel.ts +1 -0
  85. package/src/internal/adapter/DefaultNativePlayerState.ts +1 -0
  86. package/src/internal/adapter/NativePlayerState.ts +1 -0
  87. package/src/internal/adapter/THEOplayerAdapter.ts +11 -0
  88. package/src/internal/adapter/THEOplayerWebAdapter.ts +15 -1
  89. package/src/internal/adapter/event/native/NativeTheoLiveEvent.ts +2 -2
  90. package/src/manifest.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,7 +5,38 @@ 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.10.0] - 19-11-26
9
+
10
+ ### Added
11
+
12
+ - Added support for registering client-side ad integrations through the player facade's Ads API on Android.
13
+
14
+ ### Changed
15
+
16
+ - Ad integrations registered through the player facade's Ads API on Android now always register on the player, also while a player integration supplies the Ads API.
17
+
18
+ ### Fixed
19
+
20
+ - Fixed a memory leak on Android where a player destroyed during playback stayed in memory.
21
+
22
+ ## [11.9.0] - 13-11-26
23
+
24
+ ### Added
25
+
26
+ - Added `THEOplayer.allowsExternalPlayback` to enable or disable AirPlay playback on iOS.
27
+ - Added `abr` property to `TypedSource`, supporting `preferredVideoCodecs` and `preferredAudioCodecs` on Android and Web.
28
+ - Added `contentprotectionerror` event bridging on iOS.
29
+ - Added `customData` to `Ad` and `AdBreak`, including bidirectional event bridging on Android, iOS and tvOS.
30
+
31
+ ### Fixed
32
+
33
+ - Fixed an issue on Web where player facade listeners, such as analytics connectors, did not receive the player's `destroy` event.
34
+ - Fixed THEOlive events not being forwarded correctly on React Native v0.88.0+.
35
+ - Fixed an issue on Android where `preferredKeySystems` in the content protection configuration was ignored.
36
+ - Fixed ad-break integration identifiers being forwarded incorrectly on iOS and tvOS.
37
+ - Fixed an issue on Android where key system URNs in `preferredKeySystems` were ignored.
38
+
39
+ ## [11.8.0] - 18-10-26
9
40
 
10
41
  ### Added
11
42
 
package/README.md CHANGED
@@ -33,73 +33,6 @@ by the `@theoplayer/react-native-ui` package.
33
33
  It also gives a description of the properties of the `THEOplayerView` component, and
34
34
  a list of features and known limitations.
35
35
 
36
- ### Player facade (Web and Android)
37
-
38
- Set `usePlayerFacade: true` in the player configuration at creation to enable the facade.
39
- The default is `false`; iOS and tvOS do not support this option.
40
- On Web, the facade is available at `player.nativeHandle`.
41
- Integrations can register through `registerIntegration`, dispatch THEOplayer player
42
- and ad events (including `adclicked`), and supply a clock through `getCurrentTime()` in
43
- seconds. The wrapper forwards `adclicked` to React Native's ad-event stream.
44
- Close the registration before replacing an integration. Playback engines and ad
45
- schedulers should use `facade.contentPlayer`, not the facade's overridden ad clock.
46
-
47
- Integrations can provide an `ads` object implementing the Ads API and its event
48
- subscriptions. The stable public `player.ads` delegates to that object, including
49
- scheduling queries and controls. Existing listeners migrate when an integration
50
- registers or closes; native Ads behavior returns after removal. The earlier
51
- `getAdState()` and `shouldConsumeAdEvent(event)` hooks remain available for
52
- integrations without an Ads object. The facade never reconstructs ad lifecycle.
53
-
54
- `getMuted()` / `setMuted(value)` and `getVolume()` / `setVolume(value)` route audio
55
- through an integration. Setters return `true` when handled; otherwise the facade
56
- falls back to content. Nullish getter results also fall back to content.
57
- `registration.dispatchEvent(event)` accepts typed THEOplayer player and ad events.
58
- Ad events route to `player.ads` listeners; player events such as `playing`, `waiting`,
59
- and `volumechange` route to `player` listeners. Dispatch does not emit on the content
60
- player or pass through backing-event interceptors. Closed registrations cannot emit.
61
- `registration.dispatchPlayerEvent(event)` remains a compatible player-event entry point.
62
- Playback ownership and audio synchronization remain integration responsibilities.
63
-
64
- `registration.interceptPlayerEvent(type, callback)` lets an integration inspect a
65
- backing player event once before facade listeners receive it. Return `true` to
66
- consume the event, or `false` to forward it. Raw player listeners are unaffected.
67
- The returned disposer removes the interceptor. Existing interceptors remain until
68
- disposed or the facade is destroyed, allowing an integration to drain already-queued
69
- events after unregistering; a closed registration cannot install new interceptors.
70
- `registration.interceptPlayerEvents(callback)` applies the same policy to every
71
- subscribed backing-player event, including subscriptions added later. Type-specific
72
- interceptors run first; integration-dispatched events bypass both kinds. Use a
73
- type-specific interceptor when an event must be observed even without consumers.
74
- An optional `isSeeking()` integration hook overrides the public seeking state;
75
- nullish results fall back to the backing player.
76
- Pause/seek ownership, pending transitions, lifecycle exceptions and ad lifecycle
77
- decisions belong to the integration, not the facade.
78
-
79
- On Android, implement `com.theoplayer.integration.Integration` and call
80
- `ReactTHEOplayerView.registerIntegration(integration)` after the view is initialized.
81
- The returned `IntegrationRegistration` supports the same dispatch and interception
82
- semantics using native Android SDK events. Interceptor disposers implement `Closeable`;
83
- call `close()` to remove them. Access the raw engine through
84
- `(view.player as PlayerFacade).contentPlayer`. Time values are in seconds on both platforms.
85
- Android's `getAdState()` returns a `PlayerFacadeAdState`; its nullable result delegates
86
- to native Ads. The facade permits registration during native ads and does not infer
87
- state or suppress native ad events merely because an integration is registered.
88
- Native SDK extensions (`theoAds`, `ima`, `dai`) resolve against the raw player or Ads
89
- object through the facade-aware extensions in `com.theoplayer.integration`.
90
-
91
- Custom advertising must not overlap ongoing native IMA/DAI playback on Android.
92
- Finish or reset native advertising before taking over. Replacing/filtering native
93
- ad events can suspend the RN bridge's native DAI bookkeeping, so fresh native state
94
- after hidden native playback is not guaranteed. `ReactTHEOplayerView.adsApi` remains
95
- the native source-specific adapter/event sink; use `view.player.ads` for facade state.
96
- React Native Ads queries and controls use a facade-aware bridge with native fallback.
97
-
98
- Focused facade regression tests (Node 22.18+):
99
- `node --test src/__tests__/PlayerFacade.test.ts`.
100
- Android tests, from `example/android`:
101
- `./gradlew :react-native-theoplayer:testDebugUnitTest --tests 'com.theoplayer.integration.PlayerFacade*Test' --console=plain`.
102
-
103
36
  ## Prerequisites
104
37
 
105
38
  For each platform, a dependency to the corresponding THEOplayer SDK is included through a dependency manager:
@@ -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')
@@ -492,6 +492,7 @@ class ReactTHEOplayerContext private constructor(
492
492
  fun destroy() {
493
493
  isDestroyed = true
494
494
  removeListeners()
495
+ audioBecomingNoisyManager.setEnabled(false)
495
496
 
496
497
  // The media session can be shared with other player contexts through the playback service.
497
498
  // Determine ownership before unbinding, as that clears the binder needed to check it.
@@ -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,11 +8,11 @@ private const val ERROR_INVALID_KEYSYSTEM_ID = "Invalid KeySystemId"
8
8
 
9
9
  object KeySystemAdapter {
10
10
  fun fromString(keySystemStr: String): KeySystemId? {
11
- return when (keySystemStr) {
12
- "widevine" -> KeySystemId.WIDEVINE
13
- "playready" -> KeySystemId.PLAYREADY
14
- "fairplay" -> KeySystemId.FAIRPLAY
15
- "clearkey" -> KeySystemId.CLEAR_KEY
11
+ return when (keySystemStr.lowercase()) {
12
+ "widevine", "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed" -> KeySystemId.WIDEVINE
13
+ "playready", "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95" -> KeySystemId.PLAYREADY
14
+ "fairplay", "urn:uuid:94ce86fb-07bb-4b43-adb8-93d2fa968ca2" -> KeySystemId.FAIRPLAY
15
+ "clearkey", "urn:uuid:e2719d58-a985-b3c9-781a-b030af78d30e" -> KeySystemId.CLEAR_KEY
16
16
  else -> null
17
17
  }
18
18
  }
@@ -5,7 +5,6 @@ import com.theoplayer.android.api.ads.Ad
5
5
  import com.theoplayer.android.api.ads.AdBreak
6
6
  import com.theoplayer.android.api.ads.Ads
7
7
  import com.theoplayer.android.api.ads.Omid
8
- import com.theoplayer.android.api.ads.ServerSideAdIntegrationFactory
9
8
  import com.theoplayer.android.api.ads.dai.GoogleDaiIntegration
10
9
  import com.theoplayer.android.api.ads.dai.dai as sdkDai
11
10
  import com.theoplayer.android.api.ads.ima.GoogleImaIntegration
@@ -18,6 +17,8 @@ import com.theoplayer.android.api.source.addescription.AdDescription
18
17
  /**
19
18
  * Stable advertising API whose state, controls, and event source follow the current [Integration].
20
19
  * Advertising lifecycle is owned by the integration, never inferred from dispatched events.
20
+ * Members not overridden here, including ad integration registrations, delegate to the native Ads
21
+ * API, also while an integration supplies `ads`.
21
22
  *
22
23
  * Experimental API: subject to change or removal without notice.
23
24
  */
@@ -26,7 +27,7 @@ class PlayerFacadeAds internal constructor(
26
27
  private val nativeAds: Ads,
27
28
  private val integration: () -> Integration?,
28
29
  private val events: PlayerFacadeEvents<AdEvent<*>>,
29
- ) : Ads {
30
+ ) : Ads by nativeAds {
30
31
  private val backing: Ads get() = integration()?.ads ?: nativeAds
31
32
 
32
33
  /** Native IMA integration, resolved on the raw Ads API rather than this facade. */
@@ -61,10 +62,6 @@ class PlayerFacadeAds internal constructor(
61
62
  /** Returns the Open Measurement API of the currently delegated Ads API. */
62
63
  override fun getOmid(): Omid = backing.omid
63
64
 
64
- /** Registers [factory] for [integrationId] on the currently delegated Ads API. */
65
- override fun registerServerSideIntegration(integrationId: String, factory: ServerSideAdIntegrationFactory) =
66
- backing.registerServerSideIntegration(integrationId, factory)
67
-
68
65
  /** Adds [listener] for [type], preserving the subscription across integration changes. Duplicate listeners are ignored. */
69
66
  override fun <T : AdEvent<*>> addEventListener(type: EventType<T>, listener: EventListener<in T>) = events.addEventListener(type, listener)
70
67
 
@@ -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
+ }
@@ -0,0 +1,30 @@
1
+ package com.theoplayer.drm
2
+
3
+ import com.theoplayer.android.api.contentprotection.KeySystemId
4
+ import org.junit.Assert.*
5
+ import org.junit.Test
6
+
7
+ class KeySystemAdapterTest {
8
+ @Test fun parsesKeySystemAliases() {
9
+ assertEquals(KeySystemId.WIDEVINE, KeySystemAdapter.fromString("widevine"))
10
+ assertEquals(KeySystemId.PLAYREADY, KeySystemAdapter.fromString("playready"))
11
+ assertEquals(KeySystemId.FAIRPLAY, KeySystemAdapter.fromString("fairplay"))
12
+ assertEquals(KeySystemId.CLEAR_KEY, KeySystemAdapter.fromString("clearkey"))
13
+ }
14
+
15
+ @Test fun parsesDashIfKeySystemUrns() {
16
+ assertEquals(KeySystemId.WIDEVINE, KeySystemAdapter.fromString("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"))
17
+ assertEquals(KeySystemId.PLAYREADY, KeySystemAdapter.fromString("urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95"))
18
+ assertEquals(KeySystemId.FAIRPLAY, KeySystemAdapter.fromString("urn:uuid:94ce86fb-07bb-4b43-adb8-93d2fa968ca2"))
19
+ assertEquals(KeySystemId.CLEAR_KEY, KeySystemAdapter.fromString("urn:uuid:e2719d58-a985-b3c9-781a-b030af78d30e"))
20
+ }
21
+
22
+ @Test fun parsesKeySystemUrnsCaseInsensitively() {
23
+ assertEquals(KeySystemId.PLAYREADY, KeySystemAdapter.fromString("URN:UUID:9A04F079-9840-4286-AB92-E65BE0885F95"))
24
+ }
25
+
26
+ @Test fun rejectsUnknownKeySystems() {
27
+ assertNull(KeySystemAdapter.fromString("urn:uuid:00000000-0000-0000-0000-000000000000"))
28
+ assertNull(KeySystemAdapter.fromString(""))
29
+ }
30
+ }
@@ -2,6 +2,7 @@ package com.theoplayer.integration
2
2
 
3
3
  import com.theoplayer.android.api.ads.Ad
4
4
  import com.theoplayer.android.api.ads.AdBreak
5
+ import com.theoplayer.android.api.ads.ServerSideAdIntegrationFactory
5
6
  import com.theoplayer.android.api.event.EventListener
6
7
  import com.theoplayer.android.api.event.ads.*
7
8
  import com.theoplayer.android.api.event.player.*
@@ -234,6 +235,23 @@ class PlayerFacadeTest {
234
235
  facade.close()
235
236
  }
236
237
 
238
+ @Test fun stableAdsRegistersAdIntegrationsOnNativeAds() {
239
+ val host = PlayerFacadeTestHost()
240
+ val integrated = PlayerFacadeTestHost()
241
+ val facade = PlayerFacade(host.player)
242
+ val factory = ServerSideAdIntegrationFactory { throw AssertionError("not built") }
243
+ facade.ads.registerServerSideIntegration("server", factory)
244
+ assertEquals(listOf("registerServerSideIntegration"), host.commands)
245
+ val registration = facade.registerIntegration(object : Integration {
246
+ override val ads = integrated.ads
247
+ })
248
+ facade.ads.registerServerSideIntegration("server", factory)
249
+ assertEquals(listOf("registerServerSideIntegration", "registerServerSideIntegration"), host.commands)
250
+ assertTrue(integrated.commands.isEmpty())
251
+ registration.close()
252
+ facade.close()
253
+ }
254
+
237
255
  @Test fun nativeAdFilteringDecidesOnceForAllListenersAndSyntheticEventsBypassIt() {
238
256
  val host = PlayerFacadeTestHost()
239
257
  val facade = PlayerFacade(host.player)
@@ -38,7 +38,7 @@ internal class PlayerFacadeTestHost {
38
38
  null
39
39
  }
40
40
  "removeEventListener" -> remove(adListeners, args)
41
- "skip", "schedule", "registerServerSideIntegration" -> { commands.add(method); null }
41
+ "skip", "schedule", "registerServerSideIntegration", "registerClientSideIntegration" -> { commands.add(method); null }
42
42
  else -> null
43
43
  }
44
44
  }
@@ -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