cloudx-react-native 3.2.0 → 3.4.4
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/README.md +40 -652
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/cloudxreactnative/CloudXAdInfo.kt +9 -0
- package/android/src/main/java/com/cloudxreactnative/CloudXModuleImpl.kt +262 -0
- package/android/src/newarch/com/cloudxreactnative/CloudXModule.kt +6 -0
- package/android/src/oldarch/com/cloudxreactnative/CloudXModule.kt +7 -0
- package/cloudx-react-native.podspec +1 -1
- package/ios/CloudX.mm +313 -1
- package/lib/commonjs/CloudX.js +5 -1
- package/lib/commonjs/CloudX.js.map +1 -1
- package/lib/commonjs/CloudXBannerAd.js +4 -0
- package/lib/commonjs/CloudXBannerAd.js.map +1 -1
- package/lib/commonjs/CloudXInterstitialAd.js +4 -0
- package/lib/commonjs/CloudXInterstitialAd.js.map +1 -1
- package/lib/commonjs/CloudXMRECAd.js +4 -0
- package/lib/commonjs/CloudXMRECAd.js.map +1 -1
- package/lib/commonjs/CloudXRewardedAd.js +4 -0
- package/lib/commonjs/CloudXRewardedAd.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeCloudX.js +1 -1
- package/lib/commonjs/specs/NativeCloudX.js.map +1 -1
- package/lib/commonjs/types/Arbiter.js +27 -0
- package/lib/commonjs/types/Arbiter.js.map +1 -0
- package/lib/commonjs/types/ExtraParameters.js +2 -0
- package/lib/commonjs/types/ExtraParameters.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/CloudX.js +5 -1
- package/lib/module/CloudX.js.map +1 -1
- package/lib/module/CloudXBannerAd.js +4 -0
- package/lib/module/CloudXBannerAd.js.map +1 -1
- package/lib/module/CloudXInterstitialAd.js +4 -0
- package/lib/module/CloudXInterstitialAd.js.map +1 -1
- package/lib/module/CloudXMRECAd.js +4 -0
- package/lib/module/CloudXMRECAd.js.map +1 -1
- package/lib/module/CloudXRewardedAd.js +4 -0
- package/lib/module/CloudXRewardedAd.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeCloudX.js +1 -1
- package/lib/module/specs/NativeCloudX.js.map +1 -1
- package/lib/module/types/Arbiter.js +21 -0
- package/lib/module/types/Arbiter.js.map +1 -0
- package/lib/module/types/ExtraParameters.js +2 -0
- package/lib/module/types/ExtraParameters.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/src/CloudX.d.ts.map +1 -1
- package/lib/typescript/src/CloudXBannerAd.d.ts.map +1 -1
- package/lib/typescript/src/CloudXInterstitialAd.d.ts.map +1 -1
- package/lib/typescript/src/CloudXMRECAd.d.ts.map +1 -1
- package/lib/typescript/src/CloudXRewardedAd.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeCloudX.d.ts +7 -1
- package/lib/typescript/src/specs/NativeCloudX.d.ts.map +1 -1
- package/lib/typescript/src/types/AdInfo.d.ts +2 -0
- package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/src/types/Arbiter.d.ts +35 -0
- package/lib/typescript/src/types/Arbiter.d.ts.map +1 -0
- package/lib/typescript/src/types/CloudX.d.ts +3 -0
- package/lib/typescript/src/types/CloudX.d.ts.map +1 -1
- package/lib/typescript/src/types/ExtraParameters.d.ts +7 -0
- package/lib/typescript/src/types/ExtraParameters.d.ts.map +1 -0
- package/lib/typescript/src/types/FullscreenAd.d.ts +3 -0
- package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -1
- package/lib/typescript/src/types/ViewAd.d.ts +2 -0
- package/lib/typescript/src/types/ViewAd.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +2 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +3 -1
- package/src/CloudX.ts +6 -0
- package/src/CloudXBannerAd.ts +6 -0
- package/src/CloudXInterstitialAd.ts +6 -0
- package/src/CloudXMRECAd.ts +6 -0
- package/src/CloudXRewardedAd.ts +6 -0
- package/src/index.ts +9 -0
- package/src/specs/NativeCloudX.ts +12 -1
- package/src/types/AdInfo.ts +3 -0
- package/src/types/Arbiter.ts +62 -0
- package/src/types/CloudX.ts +4 -0
- package/src/types/ExtraParameters.ts +11 -0
- package/src/types/FullscreenAd.ts +4 -0
- package/src/types/ViewAd.ts +2 -0
- package/src/types/index.ts +10 -0
- package/src/version.ts +1 -1
package/android/build.gradle
CHANGED
|
@@ -13,6 +13,15 @@ fun getAdInfo(ad: CloudXAd): WritableMap {
|
|
|
13
13
|
map.putString("networkPlacement", ad.networkPlacement ?: "")
|
|
14
14
|
map.putString("placement", ad.placement ?: "")
|
|
15
15
|
map.putDouble("revenue", ad.revenue)
|
|
16
|
+
map.putMap("adValues", ad.adValues.toWritableMap())
|
|
17
|
+
return map
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fun Map<String, String>.toWritableMap(): WritableMap {
|
|
21
|
+
val map = Arguments.createMap()
|
|
22
|
+
for ((key, value) in this) {
|
|
23
|
+
map.putString(key, value)
|
|
24
|
+
}
|
|
16
25
|
return map
|
|
17
26
|
}
|
|
18
27
|
|
|
@@ -13,6 +13,9 @@ import com.facebook.react.bridge.Arguments
|
|
|
13
13
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
14
14
|
import com.facebook.react.bridge.Promise
|
|
15
15
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
16
|
+
import com.facebook.react.bridge.ReadableArray
|
|
17
|
+
import com.facebook.react.bridge.ReadableMap
|
|
18
|
+
import com.facebook.react.bridge.ReadableType
|
|
16
19
|
import com.facebook.react.bridge.WritableMap
|
|
17
20
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
18
21
|
import io.cloudx.sdk.CloudX
|
|
@@ -21,6 +24,10 @@ import io.cloudx.sdk.CloudXAdFormat
|
|
|
21
24
|
import io.cloudx.sdk.CloudXAdRevenueListener
|
|
22
25
|
import io.cloudx.sdk.CloudXAdView as SdkAdView
|
|
23
26
|
import io.cloudx.sdk.CloudXAdViewListener
|
|
27
|
+
import io.cloudx.sdk.CloudXArbiterBid
|
|
28
|
+
import io.cloudx.sdk.CloudXArbiterConfiguration
|
|
29
|
+
import io.cloudx.sdk.CloudXArbiterListener
|
|
30
|
+
import io.cloudx.sdk.CloudXArbiterResult
|
|
24
31
|
import io.cloudx.sdk.CloudXError
|
|
25
32
|
import io.cloudx.sdk.CloudXInitializationConfiguration
|
|
26
33
|
import io.cloudx.sdk.CloudXInitializationListener
|
|
@@ -31,6 +38,7 @@ import io.cloudx.sdk.CloudXReward
|
|
|
31
38
|
import io.cloudx.sdk.CloudXRewardedAd
|
|
32
39
|
import io.cloudx.sdk.CloudXRewardedListener
|
|
33
40
|
import io.cloudx.sdk.CloudXSdkConfiguration
|
|
41
|
+
import java.util.Locale
|
|
34
42
|
import java.util.concurrent.ConcurrentHashMap
|
|
35
43
|
|
|
36
44
|
class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationContext) : LifecycleEventListener {
|
|
@@ -45,6 +53,7 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
45
53
|
private val adViewAdFormats = ConcurrentHashMap<String, CloudXAdFormat>()
|
|
46
54
|
private val adViewPositions = ConcurrentHashMap<String, String>()
|
|
47
55
|
private val adViewOffsetsDp = ConcurrentHashMap<String, Pair<Float, Float>>()
|
|
56
|
+
private val adViewExtraParameters = ConcurrentHashMap<String, ConcurrentHashMap<String, Any>>()
|
|
48
57
|
private val adUnitIdsToShowAfterCreate = ConcurrentHashMap.newKeySet<String>()
|
|
49
58
|
// Workaround for React Native bug where getCurrentActivity() returns null:
|
|
50
59
|
// https://github.com/facebook/react-native/issues/18345
|
|
@@ -161,6 +170,20 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
161
170
|
CloudX.setDoNotSell(isDoNotSell)
|
|
162
171
|
}
|
|
163
172
|
|
|
173
|
+
// =========================================================================
|
|
174
|
+
// Arbiter
|
|
175
|
+
// =========================================================================
|
|
176
|
+
|
|
177
|
+
fun arbiter(configuration: ReadableMap, promise: Promise) {
|
|
178
|
+
val bids = arbiterBids(configuration)
|
|
179
|
+
val arbiterConfiguration = CloudXArbiterConfiguration.builder(bids).build()
|
|
180
|
+
CloudX.arbiter(arbiterConfiguration, object : CloudXArbiterListener {
|
|
181
|
+
override fun onCompleted(result: CloudXArbiterResult) {
|
|
182
|
+
promise.resolve(result.toWritableMap())
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
164
187
|
// =========================================================================
|
|
165
188
|
// Banner (Programmatic)
|
|
166
189
|
// =========================================================================
|
|
@@ -170,6 +193,7 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
170
193
|
fun setBannerBackgroundColor(adUnitId: String, hexColorString: String) = setAdViewBackgroundColor(adUnitId, CloudXAdFormat.BANNER, hexColorString)
|
|
171
194
|
fun setBannerPlacement(adUnitId: String, placement: String?) = setAdViewPlacement(adUnitId, CloudXAdFormat.BANNER, placement)
|
|
172
195
|
fun setBannerCustomData(adUnitId: String, customData: String?) = setAdViewCustomData(adUnitId, CloudXAdFormat.BANNER, customData)
|
|
196
|
+
fun setBannerExtraParameters(adUnitId: String, extraParameters: ReadableMap) = setAdViewExtraParameters(adUnitId, CloudXAdFormat.BANNER, extraParameters)
|
|
173
197
|
fun updateBannerPosition(adUnitId: String, position: String) = updateAdViewPosition(adUnitId, CloudXAdFormat.BANNER, position, adViewOffsetsDp[adUnitId] ?: DEFAULT_AD_VIEW_OFFSET_DP)
|
|
174
198
|
fun updateBannerOffsets(adUnitId: String, xOffset: Double, yOffset: Double) = updateAdViewPosition(adUnitId, CloudXAdFormat.BANNER, adViewPositions[adUnitId], Pair(xOffset.toFloat(), yOffset.toFloat()))
|
|
175
199
|
fun startBannerAutoRefresh(adUnitId: String) = startAdViewAutoRefresh(adUnitId, CloudXAdFormat.BANNER)
|
|
@@ -187,6 +211,7 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
187
211
|
fun setMRECBackgroundColor(adUnitId: String, hexColorString: String) = setAdViewBackgroundColor(adUnitId, CloudXAdFormat.MREC, hexColorString)
|
|
188
212
|
fun setMRECPlacement(adUnitId: String, placement: String?) = setAdViewPlacement(adUnitId, CloudXAdFormat.MREC, placement)
|
|
189
213
|
fun setMRECCustomData(adUnitId: String, customData: String?) = setAdViewCustomData(adUnitId, CloudXAdFormat.MREC, customData)
|
|
214
|
+
fun setMRECExtraParameters(adUnitId: String, extraParameters: ReadableMap) = setAdViewExtraParameters(adUnitId, CloudXAdFormat.MREC, extraParameters)
|
|
190
215
|
fun updateMRECPosition(adUnitId: String, position: String) = updateAdViewPosition(adUnitId, CloudXAdFormat.MREC, position, adViewOffsetsDp[adUnitId] ?: DEFAULT_AD_VIEW_OFFSET_DP)
|
|
191
216
|
fun updateMRECOffsets(adUnitId: String, xOffset: Double, yOffset: Double) = updateAdViewPosition(adUnitId, CloudXAdFormat.MREC, adViewPositions[adUnitId], Pair(xOffset.toFloat(), yOffset.toFloat()))
|
|
192
217
|
fun startMRECAutoRefresh(adUnitId: String) = startAdViewAutoRefresh(adUnitId, CloudXAdFormat.MREC)
|
|
@@ -203,6 +228,12 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
203
228
|
retrieveInterstitial(adUnitId).load()
|
|
204
229
|
}
|
|
205
230
|
|
|
231
|
+
fun setInterstitialExtraParameters(adUnitId: String, extraParameters: ReadableMap) {
|
|
232
|
+
applyExtraParameters(extraParameters) { key, value ->
|
|
233
|
+
retrieveInterstitial(adUnitId).setExtraParameter(key, value)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
206
237
|
fun isInterstitialReady(adUnitId: String, promise: Promise) {
|
|
207
238
|
promise.resolve(retrieveInterstitial(adUnitId).isAdReady)
|
|
208
239
|
}
|
|
@@ -237,6 +268,12 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
237
268
|
retrieveRewarded(adUnitId).load()
|
|
238
269
|
}
|
|
239
270
|
|
|
271
|
+
fun setRewardedExtraParameters(adUnitId: String, extraParameters: ReadableMap) {
|
|
272
|
+
applyExtraParameters(extraParameters) { key, value ->
|
|
273
|
+
retrieveRewarded(adUnitId).setExtraParameter(key, value)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
240
277
|
fun isRewardedReady(adUnitId: String, promise: Promise) {
|
|
241
278
|
promise.resolve(retrieveRewarded(adUnitId).isAdReady)
|
|
242
279
|
}
|
|
@@ -391,6 +428,7 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
391
428
|
?: return@runOnUiQueueThread
|
|
392
429
|
|
|
393
430
|
adViewAdFormats[adUnitId] = adFormat
|
|
431
|
+
applyPendingExtraParameters(adUnitId, adView)
|
|
394
432
|
|
|
395
433
|
adView.load()
|
|
396
434
|
|
|
@@ -416,6 +454,229 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
416
454
|
}
|
|
417
455
|
}
|
|
418
456
|
|
|
457
|
+
private fun setAdViewExtraParameters(adUnitId: String, adFormat: CloudXAdFormat, extraParameters: ReadableMap) {
|
|
458
|
+
reactApplicationContext.runOnUiQueueThread {
|
|
459
|
+
val adView = retrieveAdView(adUnitId, adFormat)
|
|
460
|
+
if (adView != null) {
|
|
461
|
+
applyExtraParameters(extraParameters) { key, value ->
|
|
462
|
+
adView.setExtraParameter(key, value)
|
|
463
|
+
}
|
|
464
|
+
return@runOnUiQueueThread
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
val pending = adViewExtraParameters.getOrPut(adUnitId) { ConcurrentHashMap() }
|
|
468
|
+
applyExtraParameters(extraParameters) { key, value ->
|
|
469
|
+
if (value == null) {
|
|
470
|
+
pending.remove(key)
|
|
471
|
+
} else {
|
|
472
|
+
pending[key] = value
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
private fun applyPendingExtraParameters(adUnitId: String, adView: SdkAdView) {
|
|
479
|
+
val pending = adViewExtraParameters[adUnitId] ?: return
|
|
480
|
+
for ((key, value) in pending) {
|
|
481
|
+
adView.setExtraParameter(key, value)
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
private fun applyExtraParameters(extraParameters: ReadableMap, apply: (String, Any?) -> Unit) {
|
|
486
|
+
val iterator = extraParameters.keySetIterator()
|
|
487
|
+
while (iterator.hasNextKey()) {
|
|
488
|
+
val key = iterator.nextKey()
|
|
489
|
+
if (key.isBlank()) continue
|
|
490
|
+
apply(key, readableMapValue(extraParameters, key))
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
private fun readableMapValue(map: ReadableMap, key: String): Any? {
|
|
495
|
+
return when (map.getType(key)) {
|
|
496
|
+
ReadableType.Null -> null
|
|
497
|
+
ReadableType.Boolean -> map.getBoolean(key)
|
|
498
|
+
ReadableType.Number -> map.getDouble(key)
|
|
499
|
+
ReadableType.String -> map.getString(key)
|
|
500
|
+
ReadableType.Map -> map.getMap(key)?.let(::readableMapToMap)
|
|
501
|
+
ReadableType.Array -> map.getArray(key)?.let(::readableArrayToList)
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
private fun readableMapToMap(readableMap: ReadableMap): Map<String, Any?> {
|
|
506
|
+
val result = mutableMapOf<String, Any?>()
|
|
507
|
+
val iterator = readableMap.keySetIterator()
|
|
508
|
+
while (iterator.hasNextKey()) {
|
|
509
|
+
val key = iterator.nextKey()
|
|
510
|
+
result[key] = readableMapValue(readableMap, key)
|
|
511
|
+
}
|
|
512
|
+
return result
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
private fun readableArrayToList(readableArray: ReadableArray): List<Any?> {
|
|
516
|
+
val result = mutableListOf<Any?>()
|
|
517
|
+
for (index in 0 until readableArray.size()) {
|
|
518
|
+
result.add(readableArrayValue(readableArray, index))
|
|
519
|
+
}
|
|
520
|
+
return result
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private fun readableArrayValue(array: ReadableArray, index: Int): Any? {
|
|
524
|
+
return when (array.getType(index)) {
|
|
525
|
+
ReadableType.Null -> null
|
|
526
|
+
ReadableType.Boolean -> array.getBoolean(index)
|
|
527
|
+
ReadableType.Number -> array.getDouble(index)
|
|
528
|
+
ReadableType.String -> array.getString(index)
|
|
529
|
+
ReadableType.Map -> array.getMap(index)?.let(::readableMapToMap)
|
|
530
|
+
ReadableType.Array -> array.getArray(index)?.let(::readableArrayToList)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
private fun arbiterBids(configuration: ReadableMap): List<CloudXArbiterBid> {
|
|
535
|
+
if (!configuration.hasKey("bids") || configuration.getType("bids") != ReadableType.Array) {
|
|
536
|
+
return emptyList()
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
val readableBids = configuration.getArray("bids") ?: return emptyList()
|
|
540
|
+
val bids = mutableListOf<CloudXArbiterBid>()
|
|
541
|
+
for (index in 0 until readableBids.size()) {
|
|
542
|
+
if (readableBids.getType(index) != ReadableType.Map) {
|
|
543
|
+
Log.w(TAG, "arbiter: ignoring non-map bid at index=$index")
|
|
544
|
+
continue
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
val bid = readableBids.getMap(index)?.toArbiterBid(index)
|
|
548
|
+
if (bid != null) {
|
|
549
|
+
bids.add(bid)
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return bids
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private fun ReadableMap.toArbiterBid(index: Int): CloudXArbiterBid? {
|
|
556
|
+
val platform = stringValue("platform")?.uppercase(Locale.ROOT)
|
|
557
|
+
return when (platform) {
|
|
558
|
+
"CLOUDX" -> cloudXArbiterBid(index)
|
|
559
|
+
"LEVELPLAY" -> levelPlayArbiterBid(index)
|
|
560
|
+
"PUBMATIC" -> pubMaticArbiterBid(index)
|
|
561
|
+
else -> {
|
|
562
|
+
Log.w(TAG, "arbiter: ignoring bid with unsupported platform=$platform at index=$index")
|
|
563
|
+
null
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
private fun ReadableMap.cloudXArbiterBid(index: Int): CloudXArbiterBid? {
|
|
569
|
+
val ad = if (hasKey("ad") && getType("ad") == ReadableType.Map) getMap("ad") else null
|
|
570
|
+
if (ad == null) {
|
|
571
|
+
Log.w(TAG, "arbiter: ignoring CLOUDX bid with missing ad at index=$index")
|
|
572
|
+
return null
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
val adUnitId = ad.stringValue("adUnitId")
|
|
576
|
+
val adFormat = ad.stringValue("adFormat")?.toCloudXAdFormatOrNull()
|
|
577
|
+
val networkName = ad.stringValue("networkName")
|
|
578
|
+
if (adUnitId.isNullOrBlank() || adFormat == null || networkName.isNullOrBlank()) {
|
|
579
|
+
Log.w(TAG, "arbiter: ignoring CLOUDX bid with missing required ad fields at index=$index")
|
|
580
|
+
return null
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
return CloudXArbiterBid.cloudX(
|
|
584
|
+
ReactNativeCloudXAd(
|
|
585
|
+
adUnitId = adUnitId,
|
|
586
|
+
adFormat = adFormat,
|
|
587
|
+
networkName = networkName,
|
|
588
|
+
networkPlacement = ad.optionalStringValue("networkPlacement"),
|
|
589
|
+
placement = ad.optionalStringValue("placement"),
|
|
590
|
+
revenue = ad.doubleValue("revenue") ?: 0.0,
|
|
591
|
+
adValues = ad.stringMapValue("adValues"),
|
|
592
|
+
)
|
|
593
|
+
)
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
private fun ReadableMap.levelPlayArbiterBid(index: Int): CloudXArbiterBid? {
|
|
597
|
+
val networkName = stringValue("networkName")
|
|
598
|
+
val revenue = doubleValue("revenue")
|
|
599
|
+
val precision = stringValue("precision")
|
|
600
|
+
if (networkName.isNullOrBlank() || revenue == null || precision.isNullOrBlank()) {
|
|
601
|
+
Log.w(TAG, "arbiter: ignoring LEVELPLAY bid with missing required fields at index=$index")
|
|
602
|
+
return null
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
return CloudXArbiterBid.levelPlay(
|
|
606
|
+
networkName = networkName,
|
|
607
|
+
revenue = revenue,
|
|
608
|
+
precision = precision,
|
|
609
|
+
extras = stringMapValue("extras"),
|
|
610
|
+
)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
private fun ReadableMap.pubMaticArbiterBid(index: Int): CloudXArbiterBid? {
|
|
614
|
+
val price = doubleValue("price")
|
|
615
|
+
if (price == null) {
|
|
616
|
+
Log.w(TAG, "arbiter: ignoring PUBMATIC bid with missing price at index=$index")
|
|
617
|
+
return null
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return CloudXArbiterBid.pubmatic(
|
|
621
|
+
price = price,
|
|
622
|
+
partnerName = optionalStringValue("partnerName"),
|
|
623
|
+
extras = stringMapValue("extras"),
|
|
624
|
+
)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
private fun String.toCloudXAdFormatOrNull(): CloudXAdFormat? = when (uppercase(Locale.ROOT)) {
|
|
628
|
+
CloudXAdFormat.BANNER.name -> CloudXAdFormat.BANNER
|
|
629
|
+
CloudXAdFormat.MREC.name -> CloudXAdFormat.MREC
|
|
630
|
+
CloudXAdFormat.INTERSTITIAL.name -> CloudXAdFormat.INTERSTITIAL
|
|
631
|
+
CloudXAdFormat.REWARDED.name -> CloudXAdFormat.REWARDED
|
|
632
|
+
CloudXAdFormat.NATIVE.name -> CloudXAdFormat.NATIVE
|
|
633
|
+
else -> null
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
private fun ReadableMap.stringValue(key: String): String? =
|
|
637
|
+
if (hasKey(key) && getType(key) == ReadableType.String) getString(key) else null
|
|
638
|
+
|
|
639
|
+
private fun ReadableMap.optionalStringValue(key: String): String? =
|
|
640
|
+
stringValue(key)?.takeIf { it.isNotBlank() }
|
|
641
|
+
|
|
642
|
+
private fun ReadableMap.doubleValue(key: String): Double? =
|
|
643
|
+
if (hasKey(key) && getType(key) == ReadableType.Number) getDouble(key) else null
|
|
644
|
+
|
|
645
|
+
private fun ReadableMap.stringMapValue(key: String): Map<String, String> {
|
|
646
|
+
if (!hasKey(key) || getType(key) != ReadableType.Map) return emptyMap()
|
|
647
|
+
val readableMap = getMap(key) ?: return emptyMap()
|
|
648
|
+
val result = mutableMapOf<String, String>()
|
|
649
|
+
val iterator = readableMap.keySetIterator()
|
|
650
|
+
while (iterator.hasNextKey()) {
|
|
651
|
+
val mapKey = iterator.nextKey()
|
|
652
|
+
if (mapKey.isBlank() || readableMap.getType(mapKey) != ReadableType.String) {
|
|
653
|
+
continue
|
|
654
|
+
}
|
|
655
|
+
val value = readableMap.getString(mapKey) ?: continue
|
|
656
|
+
result[mapKey] = value
|
|
657
|
+
}
|
|
658
|
+
return result
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
private fun CloudXArbiterResult.toWritableMap(): WritableMap {
|
|
662
|
+
val map = Arguments.createMap()
|
|
663
|
+
map.putString("id", id)
|
|
664
|
+
map.putString("platform", platform.name)
|
|
665
|
+
map.putString("bidId", bidId)
|
|
666
|
+
map.putMap("extras", extras.toWritableMap())
|
|
667
|
+
return map
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
private data class ReactNativeCloudXAd(
|
|
671
|
+
override val adUnitId: String,
|
|
672
|
+
override val adFormat: CloudXAdFormat,
|
|
673
|
+
override val networkName: String,
|
|
674
|
+
override val networkPlacement: String?,
|
|
675
|
+
override val placement: String?,
|
|
676
|
+
override val revenue: Double,
|
|
677
|
+
override val adValues: Map<String, String>,
|
|
678
|
+
) : CloudXAd
|
|
679
|
+
|
|
419
680
|
private fun updateAdViewPosition(adUnitId: String, adFormat: CloudXAdFormat, position: String?, offsetsDp: Pair<Float, Float>) {
|
|
420
681
|
reactApplicationContext.runOnUiQueueThread {
|
|
421
682
|
val adView = retrieveAdView(adUnitId, adFormat) ?: return@runOnUiQueueThread
|
|
@@ -474,6 +735,7 @@ class CloudXModuleImpl(private val reactApplicationContext: ReactApplicationCont
|
|
|
474
735
|
adViewAdFormats.remove(adUnitId)
|
|
475
736
|
adViewPositions.remove(adUnitId)
|
|
476
737
|
adViewOffsetsDp.remove(adUnitId)
|
|
738
|
+
adViewExtraParameters.remove(adUnitId)
|
|
477
739
|
adUnitIdsToShowAfterCreate.remove(adUnitId)
|
|
478
740
|
}
|
|
479
741
|
}
|
|
@@ -4,6 +4,7 @@ import com.facebook.fbreact.specs.NativeCloudXSpec
|
|
|
4
4
|
import com.facebook.react.bridge.Promise
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
7
8
|
import com.facebook.react.module.annotations.ReactModule
|
|
8
9
|
|
|
9
10
|
@ReactModule(name = CloudXModuleImpl.MODULE_NAME)
|
|
@@ -29,12 +30,14 @@ class CloudXModule(reactContext: ReactApplicationContext) :
|
|
|
29
30
|
|
|
30
31
|
@ReactMethod override fun setHasUserConsent(hasUserConsent: Boolean?) = impl.setHasUserConsent(hasUserConsent)
|
|
31
32
|
@ReactMethod override fun setDoNotSell(isDoNotSell: Boolean?) = impl.setDoNotSell(isDoNotSell)
|
|
33
|
+
@ReactMethod override fun arbiter(configuration: ReadableMap, promise: Promise) = impl.arbiter(configuration, promise)
|
|
32
34
|
|
|
33
35
|
@ReactMethod override fun createBanner(adUnitId: String, position: String) = impl.createBanner(adUnitId, position)
|
|
34
36
|
@ReactMethod override fun createBannerWithOffsets(adUnitId: String, position: String, xOffset: Double, yOffset: Double) = impl.createBannerWithOffsets(adUnitId, position, xOffset, yOffset)
|
|
35
37
|
@ReactMethod override fun setBannerBackgroundColor(adUnitId: String, hexColorString: String) = impl.setBannerBackgroundColor(adUnitId, hexColorString)
|
|
36
38
|
@ReactMethod override fun setBannerPlacement(adUnitId: String, placement: String?) = impl.setBannerPlacement(adUnitId, placement)
|
|
37
39
|
@ReactMethod override fun setBannerCustomData(adUnitId: String, customData: String?) = impl.setBannerCustomData(adUnitId, customData)
|
|
40
|
+
@ReactMethod override fun setBannerExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setBannerExtraParameters(adUnitId, extraParameters)
|
|
38
41
|
@ReactMethod override fun updateBannerPosition(adUnitId: String, position: String) = impl.updateBannerPosition(adUnitId, position)
|
|
39
42
|
@ReactMethod override fun updateBannerOffsets(adUnitId: String, xOffset: Double, yOffset: Double) = impl.updateBannerOffsets(adUnitId, xOffset, yOffset)
|
|
40
43
|
@ReactMethod override fun startBannerAutoRefresh(adUnitId: String) = impl.startBannerAutoRefresh(adUnitId)
|
|
@@ -47,6 +50,7 @@ class CloudXModule(reactContext: ReactApplicationContext) :
|
|
|
47
50
|
@ReactMethod override fun createMRECWithOffsets(adUnitId: String, position: String, xOffset: Double, yOffset: Double) = impl.createMRECWithOffsets(adUnitId, position, xOffset, yOffset)
|
|
48
51
|
@ReactMethod override fun setMRECPlacement(adUnitId: String, placement: String?) = impl.setMRECPlacement(adUnitId, placement)
|
|
49
52
|
@ReactMethod override fun setMRECCustomData(adUnitId: String, customData: String?) = impl.setMRECCustomData(adUnitId, customData)
|
|
53
|
+
@ReactMethod override fun setMRECExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setMRECExtraParameters(adUnitId, extraParameters)
|
|
50
54
|
@ReactMethod override fun updateMRECPosition(adUnitId: String, position: String) = impl.updateMRECPosition(adUnitId, position)
|
|
51
55
|
@ReactMethod override fun updateMRECOffsets(adUnitId: String, xOffset: Double, yOffset: Double) = impl.updateMRECOffsets(adUnitId, xOffset, yOffset)
|
|
52
56
|
@ReactMethod override fun startMRECAutoRefresh(adUnitId: String) = impl.startMRECAutoRefresh(adUnitId)
|
|
@@ -57,11 +61,13 @@ class CloudXModule(reactContext: ReactApplicationContext) :
|
|
|
57
61
|
@ReactMethod override fun setMRECBackgroundColor(adUnitId: String, hexColorString: String) = impl.setMRECBackgroundColor(adUnitId, hexColorString)
|
|
58
62
|
|
|
59
63
|
@ReactMethod override fun loadInterstitial(adUnitId: String) = impl.loadInterstitial(adUnitId)
|
|
64
|
+
@ReactMethod override fun setInterstitialExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setInterstitialExtraParameters(adUnitId, extraParameters)
|
|
60
65
|
@ReactMethod override fun isInterstitialReady(adUnitId: String, promise: Promise) = impl.isInterstitialReady(adUnitId, promise)
|
|
61
66
|
@ReactMethod override fun showInterstitial(adUnitId: String, placement: String?, customData: String?) = impl.showInterstitial(adUnitId, placement, customData)
|
|
62
67
|
@ReactMethod override fun destroyInterstitial(adUnitId: String) = impl.destroyInterstitial(adUnitId)
|
|
63
68
|
|
|
64
69
|
@ReactMethod override fun loadRewarded(adUnitId: String) = impl.loadRewarded(adUnitId)
|
|
70
|
+
@ReactMethod override fun setRewardedExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setRewardedExtraParameters(adUnitId, extraParameters)
|
|
65
71
|
@ReactMethod override fun isRewardedReady(adUnitId: String, promise: Promise) = impl.isRewardedReady(adUnitId, promise)
|
|
66
72
|
@ReactMethod override fun showRewarded(adUnitId: String, placement: String?, customData: String?) = impl.showRewarded(adUnitId, placement, customData)
|
|
67
73
|
@ReactMethod override fun destroyRewarded(adUnitId: String) = impl.destroyRewarded(adUnitId)
|
|
@@ -5,6 +5,7 @@ import com.facebook.react.bridge.Promise
|
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
7
|
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
9
|
|
|
9
10
|
class CloudXModule(reactContext: ReactApplicationContext) :
|
|
10
11
|
ReactContextBaseJavaModule(reactContext) {
|
|
@@ -44,11 +45,14 @@ class CloudXModule(reactContext: ReactApplicationContext) :
|
|
|
44
45
|
impl.setDoNotSell(value)
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
@ReactMethod fun arbiter(configuration: ReadableMap, promise: Promise) = impl.arbiter(configuration, promise)
|
|
49
|
+
|
|
47
50
|
@ReactMethod fun createBanner(adUnitId: String, position: String) = impl.createBanner(adUnitId, position)
|
|
48
51
|
@ReactMethod fun createBannerWithOffsets(adUnitId: String, position: String, xOffset: Double, yOffset: Double) = impl.createBannerWithOffsets(adUnitId, position, xOffset, yOffset)
|
|
49
52
|
@ReactMethod fun setBannerBackgroundColor(adUnitId: String, hexColorString: String) = impl.setBannerBackgroundColor(adUnitId, hexColorString)
|
|
50
53
|
@ReactMethod fun setBannerPlacement(adUnitId: String, placement: String?) = impl.setBannerPlacement(adUnitId, placement)
|
|
51
54
|
@ReactMethod fun setBannerCustomData(adUnitId: String, customData: String?) = impl.setBannerCustomData(adUnitId, customData)
|
|
55
|
+
@ReactMethod fun setBannerExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setBannerExtraParameters(adUnitId, extraParameters)
|
|
52
56
|
@ReactMethod fun updateBannerPosition(adUnitId: String, position: String) = impl.updateBannerPosition(adUnitId, position)
|
|
53
57
|
@ReactMethod fun updateBannerOffsets(adUnitId: String, xOffset: Double, yOffset: Double) = impl.updateBannerOffsets(adUnitId, xOffset, yOffset)
|
|
54
58
|
@ReactMethod fun startBannerAutoRefresh(adUnitId: String) = impl.startBannerAutoRefresh(adUnitId)
|
|
@@ -61,6 +65,7 @@ class CloudXModule(reactContext: ReactApplicationContext) :
|
|
|
61
65
|
@ReactMethod fun createMRECWithOffsets(adUnitId: String, position: String, xOffset: Double, yOffset: Double) = impl.createMRECWithOffsets(adUnitId, position, xOffset, yOffset)
|
|
62
66
|
@ReactMethod fun setMRECPlacement(adUnitId: String, placement: String?) = impl.setMRECPlacement(adUnitId, placement)
|
|
63
67
|
@ReactMethod fun setMRECCustomData(adUnitId: String, customData: String?) = impl.setMRECCustomData(adUnitId, customData)
|
|
68
|
+
@ReactMethod fun setMRECExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setMRECExtraParameters(adUnitId, extraParameters)
|
|
64
69
|
@ReactMethod fun updateMRECPosition(adUnitId: String, position: String) = impl.updateMRECPosition(adUnitId, position)
|
|
65
70
|
@ReactMethod fun updateMRECOffsets(adUnitId: String, xOffset: Double, yOffset: Double) = impl.updateMRECOffsets(adUnitId, xOffset, yOffset)
|
|
66
71
|
@ReactMethod fun startMRECAutoRefresh(adUnitId: String) = impl.startMRECAutoRefresh(adUnitId)
|
|
@@ -71,11 +76,13 @@ class CloudXModule(reactContext: ReactApplicationContext) :
|
|
|
71
76
|
@ReactMethod fun setMRECBackgroundColor(adUnitId: String, hexColorString: String) = impl.setMRECBackgroundColor(adUnitId, hexColorString)
|
|
72
77
|
|
|
73
78
|
@ReactMethod fun loadInterstitial(adUnitId: String) = impl.loadInterstitial(adUnitId)
|
|
79
|
+
@ReactMethod fun setInterstitialExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setInterstitialExtraParameters(adUnitId, extraParameters)
|
|
74
80
|
@ReactMethod fun isInterstitialReady(adUnitId: String, promise: Promise) = impl.isInterstitialReady(adUnitId, promise)
|
|
75
81
|
@ReactMethod fun showInterstitial(adUnitId: String, placement: String?, customData: String?) = impl.showInterstitial(adUnitId, placement, customData)
|
|
76
82
|
@ReactMethod fun destroyInterstitial(adUnitId: String) = impl.destroyInterstitial(adUnitId)
|
|
77
83
|
|
|
78
84
|
@ReactMethod fun loadRewarded(adUnitId: String) = impl.loadRewarded(adUnitId)
|
|
85
|
+
@ReactMethod fun setRewardedExtraParameters(adUnitId: String, extraParameters: ReadableMap) = impl.setRewardedExtraParameters(adUnitId, extraParameters)
|
|
79
86
|
@ReactMethod fun isRewardedReady(adUnitId: String, promise: Promise) = impl.isRewardedReady(adUnitId, promise)
|
|
80
87
|
@ReactMethod fun showRewarded(adUnitId: String, placement: String?, customData: String?) = impl.showRewarded(adUnitId, placement, customData)
|
|
81
88
|
@ReactMethod fun destroyRewarded(adUnitId: String) = impl.destroyRewarded(adUnitId)
|