react-native-theoplayer 11.7.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.
- package/CHANGELOG.md +34 -0
- package/android/build.gradle +4 -2
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/gradlew +176 -110
- package/android/gradlew.bat +23 -18
- package/android/src/main/java/com/theoplayer/ads/AdAdapter.kt +33 -7
- package/android/src/main/java/com/theoplayer/ads/AdEventAdapter.kt +8 -1
- package/android/src/main/java/com/theoplayer/drm/ContentProtectionAdapter.kt +24 -5
- package/android/src/main/java/com/theoplayer/drm/ContentProtectionModule.kt +61 -7
- package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegration.kt +12 -5
- package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegrationFactory.kt +3 -1
- package/android/src/main/java/com/theoplayer/source/SourceAdapter.kt +23 -0
- package/android/src/main/java/com/theoplayer/theolive/EndpointAdapter.kt +33 -0
- package/android/src/main/java/com/theoplayer/util/BridgeUtils.kt +4 -4
- package/android/src/test/java/com/theoplayer/ads/AdAdapterCustomDataTest.kt +144 -0
- package/ios/THEOplayerRCTBridge.m +7 -0
- package/ios/THEOplayerRCTMainEventHandler.swift +27 -1
- package/ios/THEOplayerRCTPlayerAPI.swift +20 -0
- package/ios/ads/THEOplayerRCTAdAdapter.swift +14 -3
- package/ios/ads/THEOplayerRCTAdsNative.swift +4 -0
- package/ios/contentprotection/THEOplayerRCTContentProtectionAPI.swift +39 -9
- package/ios/contentprotection/THEOplayerRCTContentProtectionAggregator.swift +15 -11
- package/ios/contentprotection/THEOplayerRCTProxyContentProtectionIntegration.swift +12 -7
- package/ios/theolive/THEOplayerRCTTHEOliveEventAdapter.swift +21 -0
- package/lib/commonjs/api/player/PlayerEventMap.js +1 -1
- package/lib/commonjs/api/source/abr/SourceAbrConfiguration.js +2 -0
- package/lib/commonjs/api/source/abr/SourceAbrConfiguration.js.map +1 -0
- package/lib/commonjs/api/source/abr/barrel.js +17 -0
- package/lib/commonjs/api/source/abr/barrel.js.map +1 -0
- package/lib/commonjs/api/source/barrel.js +18 -7
- package/lib/commonjs/api/source/barrel.js.map +1 -1
- package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js +1 -0
- package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js.map +1 -1
- package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +9 -0
- package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
- package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +13 -1
- package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
- package/lib/commonjs/internal/adapter/WebEventForwarder.js +61 -10
- package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/commonjs/internal/adapter/event/native/NativeTheoLiveEvent.js +2 -2
- package/lib/commonjs/internal/adapter/event/native/NativeTheoLiveEvent.js.map +1 -1
- package/lib/commonjs/internal/drm/ContentProtectionRegistry.js +38 -12
- package/lib/commonjs/internal/drm/ContentProtectionRegistry.js.map +1 -1
- package/lib/commonjs/manifest.json +1 -1
- package/lib/commonjs/plugins/typedoc-platform-icons/package-lock.json +200 -58
- package/lib/commonjs/plugins/typedoc-platform-icons/package.json +1 -1
- package/lib/commonjs/plugins/typedoc-platform-icons/tsconfig.json +2 -1
- package/lib/module/api/player/PlayerEventMap.js +1 -1
- package/lib/module/api/source/abr/SourceAbrConfiguration.js +2 -0
- package/lib/module/api/source/abr/SourceAbrConfiguration.js.map +1 -0
- package/lib/module/api/source/abr/barrel.js +4 -0
- package/lib/module/api/source/abr/barrel.js.map +1 -0
- package/lib/module/api/source/barrel.js +1 -0
- package/lib/module/api/source/barrel.js.map +1 -1
- package/lib/module/internal/adapter/DefaultNativePlayerState.js +1 -0
- package/lib/module/internal/adapter/DefaultNativePlayerState.js.map +1 -1
- package/lib/module/internal/adapter/THEOplayerAdapter.js +9 -0
- package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
- package/lib/module/internal/adapter/THEOplayerWebAdapter.js +13 -1
- package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
- package/lib/module/internal/adapter/WebEventForwarder.js +61 -10
- package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/module/internal/adapter/event/native/NativeTheoLiveEvent.js +2 -2
- package/lib/module/internal/adapter/event/native/NativeTheoLiveEvent.js.map +1 -1
- package/lib/module/internal/drm/ContentProtectionRegistry.js +38 -12
- package/lib/module/internal/drm/ContentProtectionRegistry.js.map +1 -1
- package/lib/module/manifest.json +1 -1
- package/lib/module/plugins/typedoc-platform-icons/package-lock.json +200 -58
- package/lib/module/plugins/typedoc-platform-icons/package.json +1 -1
- package/lib/module/plugins/typedoc-platform-icons/tsconfig.json +2 -1
- package/lib/typescript/__tests__/ContentProtectionRegistry.test.d.ts +2 -0
- package/lib/typescript/__tests__/ContentProtectionRegistry.test.d.ts.map +1 -0
- package/lib/typescript/__tests__/NativeTheoLiveEvent.test.d.ts +2 -0
- package/lib/typescript/__tests__/NativeTheoLiveEvent.test.d.ts.map +1 -0
- package/lib/typescript/api/ads/Ad.d.ts +9 -0
- package/lib/typescript/api/ads/Ad.d.ts.map +1 -1
- package/lib/typescript/api/ads/AdBreak.d.ts +9 -0
- package/lib/typescript/api/ads/AdBreak.d.ts.map +1 -1
- package/lib/typescript/api/error/ChromecastError.d.ts +2 -2
- package/lib/typescript/api/player/PlayerEventMap.d.ts +1 -1
- package/lib/typescript/api/player/THEOplayer.d.ts +11 -0
- package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
- package/lib/typescript/api/source/SourceDescription.d.ts +7 -0
- package/lib/typescript/api/source/SourceDescription.d.ts.map +1 -1
- package/lib/typescript/api/source/abr/SourceAbrConfiguration.d.ts +27 -0
- package/lib/typescript/api/source/abr/SourceAbrConfiguration.d.ts.map +1 -0
- package/lib/typescript/api/source/abr/barrel.d.ts +2 -0
- package/lib/typescript/api/source/abr/barrel.d.ts.map +1 -0
- package/lib/typescript/api/source/barrel.d.ts +1 -0
- package/lib/typescript/api/source/barrel.d.ts.map +1 -1
- package/lib/typescript/api/theoads/interstitial/Interstitial.d.ts +1 -1
- package/lib/typescript/api/theolive/TheoLiveEndpoint.d.ts +23 -5
- package/lib/typescript/api/theolive/TheoLiveEndpoint.d.ts.map +1 -1
- package/lib/typescript/api/theolive/WebrtcOptions.d.ts +1 -1
- package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts +1 -0
- package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/NativePlayerState.d.ts +1 -0
- package/lib/typescript/internal/adapter/NativePlayerState.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +2 -0
- package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +2 -0
- package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +3 -0
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/web/PlayerFacadeAdsEvents.d.ts +2 -2
- package/lib/typescript/internal/adapter/web/PlayerFacadeAdsEvents.d.ts.map +1 -1
- package/lib/typescript/internal/drm/ContentProtectionRegistry.d.ts +3 -1
- package/lib/typescript/internal/drm/ContentProtectionRegistry.d.ts.map +1 -1
- package/lib/typescript/internal/drm/NativeContentProtectionEvent.d.ts +5 -0
- package/lib/typescript/internal/drm/NativeContentProtectionEvent.d.ts.map +1 -1
- package/package.json +5 -6
- package/react-native-theoplayer.podspec +6 -6
- package/src/__tests__/ContentProtectionRegistry.test.ts +239 -0
- package/src/__tests__/NativeTheoLiveEvent.test.ts +82 -0
- package/src/__tests__/PlayerFacadeWebAdapter.test.ts +13 -0
- package/src/api/ads/Ad.ts +10 -0
- package/src/api/ads/AdBreak.ts +10 -0
- package/src/api/error/ChromecastError.ts +2 -2
- package/src/api/player/PlayerEventMap.ts +1 -1
- package/src/api/player/THEOplayer.ts +12 -0
- package/src/api/source/SourceDescription.ts +8 -0
- package/src/api/source/abr/SourceAbrConfiguration.ts +27 -0
- package/src/api/source/abr/barrel.ts +1 -0
- package/src/api/source/barrel.ts +1 -0
- package/src/api/theoads/interstitial/Interstitial.ts +1 -1
- package/src/api/theolive/TheoLiveEndpoint.ts +24 -5
- package/src/api/theolive/WebrtcOptions.ts +1 -1
- package/src/internal/adapter/DefaultNativePlayerState.ts +1 -0
- package/src/internal/adapter/NativePlayerState.ts +1 -0
- package/src/internal/adapter/THEOplayerAdapter.ts +11 -0
- package/src/internal/adapter/THEOplayerWebAdapter.ts +15 -1
- package/src/internal/adapter/WebEventForwarder.ts +69 -10
- package/src/internal/adapter/event/native/NativeTheoLiveEvent.ts +2 -2
- package/src/internal/drm/ContentProtectionRegistry.ts +35 -17
- package/src/internal/drm/NativeContentProtectionEvent.ts +5 -0
- package/src/manifest.json +1 -1
- package/src/plugins/typedoc-platform-icons/package-lock.json +200 -58
- package/src/plugins/typedoc-platform-icons/package.json +1 -1
- package/src/plugins/typedoc-platform-icons/tsconfig.json +2 -1
- package/lib/typescript/plugins/expo/Common.d.ts +0 -13
- package/lib/typescript/plugins/expo/Common.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withCustomPod.d.ts +0 -2
- package/lib/typescript/plugins/expo/withCustomPod.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withTHEOplayer.d.ts +0 -4
- package/lib/typescript/plugins/expo/withTHEOplayer.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withTHEOplayerAndroid.d.ts +0 -4
- package/lib/typescript/plugins/expo/withTHEOplayerAndroid.d.ts.map +0 -1
- package/lib/typescript/plugins/expo/withTHEOplayerIOS.d.ts +0 -4
- package/lib/typescript/plugins/expo/withTHEOplayerIOS.d.ts.map +0 -1
- package/lib/typescript/plugins/typedoc-platform-icons/src/index.d.ts +0 -3
- package/lib/typescript/plugins/typedoc-platform-icons/src/index.d.ts.map +0 -1
|
@@ -22,6 +22,7 @@ private const val TAG = "ContentProtection"
|
|
|
22
22
|
|
|
23
23
|
const val PROP_INTEGRATION: String = "integration"
|
|
24
24
|
const val PROP_INTEGRATION_ID: String = "integrationId"
|
|
25
|
+
const val PROP_INTEGRATION_INSTANCE_ID: String = "integrationInstanceId"
|
|
25
26
|
const val PROP_INTEGRATION_PARAMETERS: String = "integrationParameters"
|
|
26
27
|
const val PROP_REQUEST: String = "request"
|
|
27
28
|
const val PROP_KEYSYSTEM_ID: String = "keySystemId"
|
|
@@ -48,12 +49,18 @@ const val PROP_MULTISESSION: String = "multiSession"
|
|
|
48
49
|
const val PROP_KEYS: String = "keys"
|
|
49
50
|
const val PROP_ID: String = "id"
|
|
50
51
|
const val PROP_VALUE: String = "value"
|
|
52
|
+
const val PROP_PREFERRED_KEY_SYSTEMS: String = "preferredKeySystems"
|
|
51
53
|
|
|
52
54
|
object ContentProtectionAdapter {
|
|
53
55
|
|
|
54
|
-
private fun createBridgeData(
|
|
56
|
+
private fun createBridgeData(
|
|
57
|
+
integrationId: String,
|
|
58
|
+
keySystemId: KeySystemId,
|
|
59
|
+
integrationInstanceId: String
|
|
60
|
+
): WritableMap {
|
|
55
61
|
return Arguments.createMap().apply {
|
|
56
62
|
putString(PROP_INTEGRATION_ID, integrationId)
|
|
63
|
+
putString(PROP_INTEGRATION_INSTANCE_ID, integrationInstanceId)
|
|
57
64
|
putString(PROP_KEYSYSTEM_ID, KeySystemAdapter.toString(keySystemId))
|
|
58
65
|
}
|
|
59
66
|
}
|
|
@@ -108,6 +115,12 @@ object ContentProtectionAdapter {
|
|
|
108
115
|
if (jsonConfig.has(PROP_MULTISESSION)) {
|
|
109
116
|
multiSession(jsonConfig.getBoolean(PROP_MULTISESSION))
|
|
110
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
|
+
}
|
|
111
124
|
queryParameters(fromJSONObjectToMap(jsonConfig.optJSONObject(PROP_QUERY_PARAMETERS)))
|
|
112
125
|
}.build()
|
|
113
126
|
}
|
|
@@ -176,8 +189,13 @@ object ContentProtectionAdapter {
|
|
|
176
189
|
}
|
|
177
190
|
}
|
|
178
191
|
|
|
179
|
-
fun fromRequest(
|
|
180
|
-
|
|
192
|
+
fun fromRequest(
|
|
193
|
+
integrationId: String,
|
|
194
|
+
keySystemId: KeySystemId,
|
|
195
|
+
integrationInstanceId: String,
|
|
196
|
+
request: Request
|
|
197
|
+
): WritableMap {
|
|
198
|
+
val payload = createBridgeData(integrationId, keySystemId, integrationInstanceId)
|
|
181
199
|
payload.putString(PROP_URL, request.url)
|
|
182
200
|
payload.putString(PROP_METHOD, RequestMethodAdapter.toString(request.method))
|
|
183
201
|
val headers = Arguments.createMap()
|
|
@@ -192,9 +210,10 @@ object ContentProtectionAdapter {
|
|
|
192
210
|
fun fromResponse(
|
|
193
211
|
integrationId: String,
|
|
194
212
|
keySystemId: KeySystemId,
|
|
213
|
+
integrationInstanceId: String,
|
|
195
214
|
response: Response
|
|
196
215
|
): WritableMap {
|
|
197
|
-
val payload = createBridgeData(integrationId, keySystemId)
|
|
216
|
+
val payload = createBridgeData(integrationId, keySystemId, integrationInstanceId)
|
|
198
217
|
payload.putString(PROP_URL, response.url)
|
|
199
218
|
payload.putInt(PROP_STATUS, response.status)
|
|
200
219
|
payload.putString(PROP_STATUS_TEXT, response.statusText)
|
|
@@ -205,7 +224,7 @@ object ContentProtectionAdapter {
|
|
|
205
224
|
}
|
|
206
225
|
}
|
|
207
226
|
payload.putMap(PROP_HEADERS, headers)
|
|
208
|
-
payload.putMap(PROP_REQUEST, fromRequest(integrationId, keySystemId, response.request))
|
|
227
|
+
payload.putMap(PROP_REQUEST, fromRequest(integrationId, keySystemId, integrationInstanceId, response.request))
|
|
209
228
|
payload.putString(PROP_BASE64_BODY, Base64.encodeToString(response.body, Base64.DEFAULT))
|
|
210
229
|
return payload
|
|
211
230
|
}
|
|
@@ -14,6 +14,7 @@ import com.theoplayer.android.api.contentprotection.*
|
|
|
14
14
|
import com.theoplayer.android.api.error.ErrorCode
|
|
15
15
|
import com.theoplayer.android.api.error.THEOplayerException
|
|
16
16
|
import com.theoplayer.android.api.source.drm.DRMConfiguration
|
|
17
|
+
import java.lang.ref.WeakReference
|
|
17
18
|
|
|
18
19
|
data class BridgeRequest(
|
|
19
20
|
val onResult: HashMap<String, (result: ReadableMap) -> Unit>,
|
|
@@ -35,6 +36,7 @@ private const val EVENT_LICENSE_REQUEST_PROCESSED_AS_REQUEST = "onLicenseRequest
|
|
|
35
36
|
private const val EVENT_LICENSE_REQUEST_PROCESSED_AS_LICENSE = "onLicenseRequestProcessedAsLicense"
|
|
36
37
|
private const val EVENT_LICENSE_RESPONSE = "onLicenseResponse"
|
|
37
38
|
private const val EVENT_LICENSE_RESPONSE_PROCESSED = "onLicenseResponseProcessed"
|
|
39
|
+
private const val EVENT_INTEGRATION_DISPOSED = "onIntegrationDisposed"
|
|
38
40
|
|
|
39
41
|
@Suppress("unused")
|
|
40
42
|
@ReactModule(name = ContentProtectionModule.NAME)
|
|
@@ -52,6 +54,7 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
52
54
|
isTurboModule = false,
|
|
53
55
|
)
|
|
54
56
|
const val REQUEST_TIMEOUT_MS = 10000L
|
|
57
|
+
const val PRUNE_INTERVAL_MS = 30000L
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
private val handler = Handler(Looper.getMainLooper())
|
|
@@ -60,6 +63,47 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
60
63
|
|
|
61
64
|
private val requestQueue: HashMap<String, BridgeRequest> = HashMap()
|
|
62
65
|
|
|
66
|
+
// Weak references to every proxy integration instance built by the native SDK.
|
|
67
|
+
// The Android content protection API has no disposal callback, so instance
|
|
68
|
+
// cleanup is detected through garbage collection and reported to JavaScript.
|
|
69
|
+
private val integrationRefs: HashMap<String, WeakReference<ProxyContentProtectionIntegration>> = HashMap()
|
|
70
|
+
|
|
71
|
+
// Periodically reports collected proxy instances to JavaScript, so cleanup also
|
|
72
|
+
// happens when no further DRM events trigger it.
|
|
73
|
+
private val pruneRunnable = object : Runnable {
|
|
74
|
+
override fun run() {
|
|
75
|
+
pruneDisposedIntegrations()
|
|
76
|
+
if (integrationRefs.isNotEmpty()) {
|
|
77
|
+
handler.postDelayed(this, PRUNE_INTERVAL_MS)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fun trackIntegration(integration: ProxyContentProtectionIntegration) {
|
|
83
|
+
integrationRefs[integration.integrationInstanceId] = WeakReference(integration)
|
|
84
|
+
if (integrationRefs.size == 1) {
|
|
85
|
+
handler.postDelayed(pruneRunnable, PRUNE_INTERVAL_MS)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
override fun invalidate() {
|
|
90
|
+
handler.removeCallbacks(pruneRunnable)
|
|
91
|
+
super.invalidate()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private fun pruneDisposedIntegrations() {
|
|
95
|
+
val disposed = integrationRefs.filterValues { it.get() == null }.keys
|
|
96
|
+
disposed.forEach { integrationInstanceId ->
|
|
97
|
+
integrationRefs.remove(integrationInstanceId)
|
|
98
|
+
context.getJSModule(RCTDeviceEventEmitter::class.java).emit(
|
|
99
|
+
EVENT_INTEGRATION_DISPOSED,
|
|
100
|
+
Arguments.createMap().apply {
|
|
101
|
+
putString(PROP_INTEGRATION_INSTANCE_ID, integrationInstanceId)
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
63
107
|
override fun getName(): String {
|
|
64
108
|
return NAME
|
|
65
109
|
}
|
|
@@ -117,8 +161,8 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
117
161
|
receive(EVENT_LICENSE_RESPONSE_PROCESSED, payload)
|
|
118
162
|
}
|
|
119
163
|
|
|
120
|
-
fun onBuild(integrationId: String, keySystemId: KeySystemId, config: DRMConfiguration?) {
|
|
121
|
-
val payload = createBridgeData(integrationId, keySystemId)
|
|
164
|
+
fun onBuild(integrationId: String, keySystemId: KeySystemId, integrationInstanceId: String, config: DRMConfiguration?) {
|
|
165
|
+
val payload = createBridgeData(integrationId, keySystemId, integrationInstanceId)
|
|
122
166
|
if (config != null) {
|
|
123
167
|
payload.putMap(PROP_DRM_CONFIG, ContentProtectionAdapter.fromDRMConfiguration(config))
|
|
124
168
|
}
|
|
@@ -132,10 +176,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
132
176
|
fun onCertificateRequest(
|
|
133
177
|
integrationId: String,
|
|
134
178
|
keySystemId: KeySystemId,
|
|
179
|
+
integrationInstanceId: String,
|
|
135
180
|
request: Request,
|
|
136
181
|
callback: CertificateRequestCallback
|
|
137
182
|
) {
|
|
138
|
-
val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, request)
|
|
183
|
+
val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, integrationInstanceId, request)
|
|
139
184
|
emit(
|
|
140
185
|
EVENT_CERTIFICATE_REQUEST, payload,
|
|
141
186
|
onResult = hashMapOf(
|
|
@@ -163,10 +208,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
163
208
|
fun onCertificateResponse(
|
|
164
209
|
integrationId: String,
|
|
165
210
|
keySystemId: KeySystemId,
|
|
211
|
+
integrationInstanceId: String,
|
|
166
212
|
response: Response,
|
|
167
213
|
callback: CertificateResponseCallback
|
|
168
214
|
) {
|
|
169
|
-
val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, response)
|
|
215
|
+
val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, integrationInstanceId, response)
|
|
170
216
|
emit(
|
|
171
217
|
EVENT_CERTIFICATE_RESPONSE, payload,
|
|
172
218
|
onResult = hashMapOf(
|
|
@@ -182,10 +228,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
182
228
|
fun onLicenseRequest(
|
|
183
229
|
integrationId: String,
|
|
184
230
|
keySystemId: KeySystemId,
|
|
231
|
+
integrationInstanceId: String,
|
|
185
232
|
request: Request,
|
|
186
233
|
callback: LicenseRequestCallback
|
|
187
234
|
) {
|
|
188
|
-
val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, request)
|
|
235
|
+
val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, integrationInstanceId, request)
|
|
189
236
|
emit(
|
|
190
237
|
EVENT_LICENSE_REQUEST, payload,
|
|
191
238
|
onResult = hashMapOf(
|
|
@@ -213,10 +260,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
213
260
|
fun onLicenseResponse(
|
|
214
261
|
integrationId: String,
|
|
215
262
|
keySystemId: KeySystemId,
|
|
263
|
+
integrationInstanceId: String,
|
|
216
264
|
response: Response,
|
|
217
265
|
callback: LicenseResponseCallback
|
|
218
266
|
) {
|
|
219
|
-
val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, response)
|
|
267
|
+
val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, integrationInstanceId, response)
|
|
220
268
|
emit(
|
|
221
269
|
EVENT_LICENSE_RESPONSE, payload,
|
|
222
270
|
onResult = hashMapOf(
|
|
@@ -246,6 +294,7 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
246
294
|
onResult: HashMap<String, (result: ReadableMap) -> Unit>,
|
|
247
295
|
onError: (error: THEOplayerException) -> Unit
|
|
248
296
|
) {
|
|
297
|
+
pruneDisposedIntegrations()
|
|
249
298
|
val requestId = createRequestId()
|
|
250
299
|
if (BuildConfig.DEBUG) {
|
|
251
300
|
Log.d(NAME, "emit $eventName ($requestId)")
|
|
@@ -289,9 +338,14 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
|
|
|
289
338
|
return (requestId++).toString()
|
|
290
339
|
}
|
|
291
340
|
|
|
292
|
-
private fun createBridgeData(
|
|
341
|
+
private fun createBridgeData(
|
|
342
|
+
integrationId: String,
|
|
343
|
+
keySystemId: KeySystemId,
|
|
344
|
+
integrationInstanceId: String
|
|
345
|
+
): WritableMap {
|
|
293
346
|
return Arguments.createMap().apply {
|
|
294
347
|
putString(PROP_INTEGRATION_ID, integrationId)
|
|
348
|
+
putString(PROP_INTEGRATION_INSTANCE_ID, integrationInstanceId)
|
|
295
349
|
putString(PROP_KEYSYSTEM_ID, KeySystemAdapter.toString(keySystemId))
|
|
296
350
|
}
|
|
297
351
|
}
|
|
@@ -2,6 +2,7 @@ package com.theoplayer.drm
|
|
|
2
2
|
|
|
3
3
|
import com.theoplayer.android.api.contentprotection.*
|
|
4
4
|
import com.theoplayer.android.api.source.drm.DRMConfiguration
|
|
5
|
+
import java.util.UUID
|
|
5
6
|
|
|
6
7
|
class ProxyContentProtectionIntegration(
|
|
7
8
|
private val integrationId: String,
|
|
@@ -10,23 +11,29 @@ class ProxyContentProtectionIntegration(
|
|
|
10
11
|
private val module: ContentProtectionModule
|
|
11
12
|
) : ContentProtectionIntegration() {
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Unique identifier for this integration instance, shared with the JavaScript
|
|
16
|
+
* content protection registry to route callbacks to the matching integration.
|
|
17
|
+
*/
|
|
18
|
+
val integrationInstanceId: String = UUID.randomUUID().toString()
|
|
19
|
+
|
|
13
20
|
init {
|
|
14
|
-
module.onBuild(integrationId, keySystemId, config)
|
|
21
|
+
module.onBuild(integrationId, keySystemId, integrationInstanceId, config)
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
override fun onCertificateRequest(request: Request, callback: CertificateRequestCallback) {
|
|
18
|
-
module.onCertificateRequest(integrationId, keySystemId, request, callback)
|
|
25
|
+
module.onCertificateRequest(integrationId, keySystemId, integrationInstanceId, request, callback)
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
override fun onCertificateResponse(response: Response, callback: CertificateResponseCallback) {
|
|
22
|
-
module.onCertificateResponse(integrationId, keySystemId, response, callback)
|
|
29
|
+
module.onCertificateResponse(integrationId, keySystemId, integrationInstanceId, response, callback)
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
override fun onLicenseRequest(request: Request, callback: LicenseRequestCallback) {
|
|
26
|
-
module.onLicenseRequest(integrationId, keySystemId, request, callback)
|
|
33
|
+
module.onLicenseRequest(integrationId, keySystemId, integrationInstanceId, request, callback)
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
override fun onLicenseResponse(response: Response, callback: LicenseResponseCallback) {
|
|
30
|
-
module.onLicenseResponse(integrationId, keySystemId, response, callback)
|
|
37
|
+
module.onLicenseResponse(integrationId, keySystemId, integrationInstanceId, response, callback)
|
|
31
38
|
}
|
|
32
39
|
}
|
package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegrationFactory.kt
CHANGED
|
@@ -12,6 +12,8 @@ class ProxyContentProtectionIntegrationFactory(
|
|
|
12
12
|
) : ContentProtectionIntegrationFactory {
|
|
13
13
|
|
|
14
14
|
override fun build(config: DRMConfiguration): ContentProtectionIntegration {
|
|
15
|
-
return ProxyContentProtectionIntegration(integrationId, keySystemId, config, module)
|
|
15
|
+
return ProxyContentProtectionIntegration(integrationId, keySystemId, config, module).also {
|
|
16
|
+
module.trackIntegration(it)
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -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),
|
|
@@ -5,14 +5,25 @@ import com.facebook.react.bridge.WritableMap
|
|
|
5
5
|
import com.theoplayer.android.api.theolive.ContentProtectionConfiguration
|
|
6
6
|
import com.theoplayer.android.api.theolive.Endpoint
|
|
7
7
|
import com.theoplayer.android.api.theolive.EndpointMillicastSource
|
|
8
|
+
import com.theoplayer.android.api.theolive.EndpointSource
|
|
8
9
|
import com.theoplayer.android.api.theolive.FairPlayConfiguration
|
|
9
10
|
import com.theoplayer.android.api.theolive.KeySystemConfiguration
|
|
11
|
+
import com.theoplayer.android.api.theolive.PlayoutDelay
|
|
12
|
+
import com.theoplayer.android.api.theolive.WebRTCOptions
|
|
10
13
|
|
|
14
|
+
private const val PROP_SRC = "src"
|
|
15
|
+
private const val PROP_SRC_TYPE = "srcType"
|
|
16
|
+
private const val PROP_PROVIDER = "provider"
|
|
17
|
+
private const val PROP_AD_SYSTEM = "adSystem"
|
|
11
18
|
private const val PROP_MILLICAST_SRC = "millicastSrc"
|
|
12
19
|
private const val PROP_MILLICAST_NAME = "name"
|
|
13
20
|
private const val PROP_MILLICAST_ACCOUNTID = "accountId"
|
|
14
21
|
private const val PROP_MILLICAST_SUBSCRIBER_TOKEN ="subscriberToken"
|
|
15
22
|
private const val PROP_MILLICAST_DIRECTOR_URL = "directorUrl"
|
|
23
|
+
private const val PROP_MILLICAST_WEBRTC = "webrtc"
|
|
24
|
+
private const val PROP_PLAYOUT_DELAY_MS = "playoutDelayMs"
|
|
25
|
+
private const val PROP_PLAYOUT_DELAY_MINIMUM = "minimum"
|
|
26
|
+
private const val PROP_PLAYOUT_DELAY_MAXIMUM = "maximum"
|
|
16
27
|
private const val PROP_HESP_SRC = "hespSrc"
|
|
17
28
|
private const val PROP_HLS_SRC = "hlsSrc"
|
|
18
29
|
private const val PROP_HLS_MPEG_TS_SRC = "hlsMpegTsSrc"
|
|
@@ -32,12 +43,26 @@ private const val PROP_CERTIFICATE_URL = "certificateUrl"
|
|
|
32
43
|
|
|
33
44
|
object EndpointAdapter {
|
|
34
45
|
|
|
46
|
+
private fun fromPlayoutDelay(playoutDelay: PlayoutDelay): WritableMap {
|
|
47
|
+
return Arguments.createMap().apply {
|
|
48
|
+
putInt(PROP_PLAYOUT_DELAY_MINIMUM, playoutDelay.minimum)
|
|
49
|
+
putInt(PROP_PLAYOUT_DELAY_MAXIMUM, playoutDelay.maximum)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private fun fromWebrtcOptions(webrtc: WebRTCOptions): WritableMap {
|
|
54
|
+
return Arguments.createMap().apply {
|
|
55
|
+
webrtc.playoutDelayMs?.let { putMap(PROP_PLAYOUT_DELAY_MS, fromPlayoutDelay(it)) }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
35
59
|
fun fromEndPointMillicastSource(millicastSource: EndpointMillicastSource): WritableMap {
|
|
36
60
|
return Arguments.createMap().apply {
|
|
37
61
|
putString(PROP_MILLICAST_NAME , millicastSource.name)
|
|
38
62
|
putString(PROP_MILLICAST_ACCOUNTID, millicastSource.accountId)
|
|
39
63
|
millicastSource.directorUrl?.let { putString(PROP_MILLICAST_DIRECTOR_URL, it) }
|
|
40
64
|
millicastSource.subscriberToken?.let { putString(PROP_MILLICAST_SUBSCRIBER_TOKEN, it) }
|
|
65
|
+
millicastSource.webrtc?.let { putMap(PROP_MILLICAST_WEBRTC, fromWebrtcOptions(it)) }
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
68
|
|
|
@@ -50,12 +75,20 @@ object EndpointAdapter {
|
|
|
50
75
|
endPoint.adSrc?.let { putString(PROP_AD_SRC, it) }
|
|
51
76
|
endPoint.daiAssetKey?.let { putString(PROP_DAI_ASSET_KEY, it) }
|
|
52
77
|
endPoint.cdn?.let { putString(PROP_CDN, it) }
|
|
78
|
+
endPoint.provider?.let { putString(PROP_PROVIDER, it) }
|
|
79
|
+
endPoint.adSystem?.let { putString(PROP_AD_SYSTEM, it) }
|
|
53
80
|
endPoint.targetLatency?.let { putDouble(PROP_TARGET_LATENCY, it) }
|
|
54
81
|
putInt(PROP_WEIGHT, endPoint.weight)
|
|
55
82
|
putInt(PROP_PRIORITY, endPoint.priority)
|
|
56
83
|
endPoint.contentProtection?.let {
|
|
57
84
|
putMap(PROP_CONTENT_PROTECTION, fromContentProtection(it))
|
|
58
85
|
}
|
|
86
|
+
when (val src = endPoint.src) {
|
|
87
|
+
is EndpointSource.Url -> putString(PROP_SRC, src.value)
|
|
88
|
+
is EndpointSource.Millicast -> putMap(PROP_SRC, fromEndPointMillicastSource(src.source))
|
|
89
|
+
null -> Unit
|
|
90
|
+
}
|
|
91
|
+
endPoint.srcType?.let { putString(PROP_SRC_TYPE, it) }
|
|
59
92
|
}
|
|
60
93
|
}
|
|
61
94
|
|
|
@@ -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
|
-
|
|
29
|
+
null, JSONObject.NULL -> putNull(key)
|
|
30
30
|
is Boolean -> putBoolean(key, value)
|
|
31
31
|
is Int -> putInt(key, value)
|
|
32
|
-
is
|
|
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
|
-
|
|
53
|
+
null, JSONObject.NULL -> pushNull()
|
|
54
54
|
is Boolean -> pushBoolean(value)
|
|
55
55
|
is Int -> pushInt(value)
|
|
56
|
-
is
|
|
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
|