@adjoe/react-native-adjoe-sdk 0.0.0-stage → 5.1.3
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 +33 -2
- package/android/build.gradle +93 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/BasicUtil.kt +361 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/ErrorsUtil.kt +113 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/PlaytimeProtectionImpl.kt +150 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/PlaytimeStudioImpl.kt +313 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkImpl.kt +173 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkPackage.kt +55 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/StudioUtil.kt +421 -0
- package/android/src/main/java/io/adjoe/sdk/reactnative/Util.kt +40 -0
- package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeProtection.kt +25 -0
- package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkModule.kt +57 -0
- package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeStudio.kt +66 -0
- package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeProtection.kt +29 -0
- package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkModule.kt +68 -0
- package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeStudio.kt +83 -0
- package/ios/AdjoeSdk.xcodeproj/project.pbxproj +281 -0
- package/ios/AdjoeSdk.xcodeproj/xcuserdata/hamid.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/AdjoeSdk.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/ErrorsUtil.swift +180 -0
- package/ios/PlaytimeProtectionImpl.swift +20 -0
- package/ios/PlaytimeSdkImpl.swift +173 -0
- package/ios/PlaytimeStudioImpl.swift +272 -0
- package/ios/RNPlaytimeBasic.mm +187 -0
- package/ios/RNPlaytimeHelpers.h +21 -0
- package/ios/RNPlaytimeHelpers.m +94 -0
- package/ios/RNPlaytimeProtection.mm +77 -0
- package/ios/RNPlaytimeStudio.mm +265 -0
- package/package.json +35 -4
- package/react-native-adjoe-sdk.podspec +30 -0
- package/src/Playtime.js +158 -0
- package/src/PlaytimeException.js +140 -0
- package/src/PlaytimeProtection.js +40 -0
- package/src/PlaytimeStudio.js +110 -0
- package/src/index.js +8 -0
- package/src/specs/NativePlaytimeProtection.ts +9 -0
- package/src/specs/NativePlaytimeStudio.ts +23 -0
- package/src/specs/NativeRNPlaytimeSdk.ts +17 -0
- package/src-ts/Playtime.d.ts +407 -0
- package/src-ts/PlaytimeException.d.ts +87 -0
- package/src-ts/PlaytimeProtection.d.ts +106 -0
- package/src-ts/PlaytimeStudio.d.ts +818 -0
- package/src-ts/index.d.ts +8 -0
- package/tsconfig.json +114 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
package io.adjoe.sdk.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
|
|
6
|
+
import io.adjoe.sdk.protection.PlaytimeProtection
|
|
7
|
+
|
|
8
|
+
import java.util.concurrent.atomic.AtomicBoolean
|
|
9
|
+
|
|
10
|
+
class PlaytimeProtectionImpl(
|
|
11
|
+
private val reactContext: ReactApplicationContext
|
|
12
|
+
) {
|
|
13
|
+
|
|
14
|
+
@Suppress("DEPRECATION")
|
|
15
|
+
fun faceVerification(promise: Promise) {
|
|
16
|
+
try {
|
|
17
|
+
val activity = reactContext.getCurrentActivity()
|
|
18
|
+
if (activity == null) {
|
|
19
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The SDK does not guarantee that exactly one callback method is
|
|
24
|
+
// invoked, so the promise is settled at most once.
|
|
25
|
+
val settled = AtomicBoolean(false)
|
|
26
|
+
val resolveOnce = { result: String ->
|
|
27
|
+
if (settled.compareAndSet(false, true)) {
|
|
28
|
+
promise.resolve(result)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
PlaytimeProtection.faceVerification(
|
|
33
|
+
activity,
|
|
34
|
+
object : PlaytimeProtection.FaceVerificationCallback {
|
|
35
|
+
override fun onSuccess() {
|
|
36
|
+
resolveOnce(FaceVerificationResult.SUCCESS)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun onAlreadyVerified() {
|
|
40
|
+
resolveOnce(FaceVerificationResult.ALREADY_VERIFIED)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override fun onCancel() {
|
|
44
|
+
resolveOnce(FaceVerificationResult.CANCELLED)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override fun onNotInitialized() {
|
|
48
|
+
resolveOnce(FaceVerificationResult.NOT_INITIALIZED)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun onTosIsNotAccepted() {
|
|
52
|
+
resolveOnce(FaceVerificationResult.TOS_NOT_ACCEPTED)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun onLivenessCheckFailed() {
|
|
56
|
+
resolveOnce(FaceVerificationResult.LIVENESS_CHECK_FAILED)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun onPendingReview() {
|
|
60
|
+
resolveOnce(FaceVerificationResult.PENDING_REVIEW)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun onMaxAttemptsReached() {
|
|
64
|
+
resolveOnce(FaceVerificationResult.MAX_ATTEMPTS_REACHED)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override fun onError(exception: Exception?) {
|
|
68
|
+
if (settled.compareAndSet(false, true)) {
|
|
69
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(exception))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
} catch (t: Throwable) {
|
|
75
|
+
ErrorsUtil.reject(promise, t)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Suppress("DEPRECATION")
|
|
80
|
+
fun faceVerificationStatus(promise: Promise) {
|
|
81
|
+
try {
|
|
82
|
+
val settled = AtomicBoolean(false)
|
|
83
|
+
val resolveOnce = { status: String ->
|
|
84
|
+
if (settled.compareAndSet(false, true)) {
|
|
85
|
+
promise.resolve(status)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
PlaytimeProtection.faceVerificationStatus(
|
|
90
|
+
object : PlaytimeProtection.FaceVerificationStatusCallback {
|
|
91
|
+
override fun onVerified() {
|
|
92
|
+
resolveOnce(FaceVerificationStatus.VERIFIED)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override fun onNotVerified() {
|
|
96
|
+
resolveOnce(FaceVerificationStatus.NOT_VERIFIED)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override fun onNotInitialized() {
|
|
100
|
+
resolveOnce(FaceVerificationStatus.NOT_INITIALIZED)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
override fun onTosIsNotAccepted() {
|
|
104
|
+
resolveOnce(FaceVerificationStatus.TOS_NOT_ACCEPTED)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
override fun onPendingReview() {
|
|
108
|
+
resolveOnce(FaceVerificationStatus.PENDING_REVIEW)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
override fun onMaxAttemptsReached() {
|
|
112
|
+
resolveOnce(FaceVerificationStatus.MAX_ATTEMPTS_REACHED)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override fun onError(exception: Exception?) {
|
|
116
|
+
if (settled.compareAndSet(false, true)) {
|
|
117
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(exception))
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
} catch (t: Throwable) {
|
|
123
|
+
ErrorsUtil.reject(promise, t)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private object FaceVerificationResult {
|
|
128
|
+
const val SUCCESS = "SUCCESS"
|
|
129
|
+
const val ALREADY_VERIFIED = "ALREADY_VERIFIED"
|
|
130
|
+
const val CANCELLED = "CANCELLED"
|
|
131
|
+
const val NOT_INITIALIZED = "NOT_INITIALIZED"
|
|
132
|
+
const val TOS_NOT_ACCEPTED = "TOS_NOT_ACCEPTED"
|
|
133
|
+
const val LIVENESS_CHECK_FAILED = "LIVENESS_CHECK_FAILED"
|
|
134
|
+
const val PENDING_REVIEW = "PENDING_REVIEW"
|
|
135
|
+
const val MAX_ATTEMPTS_REACHED = "MAX_ATTEMPTS_REACHED"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private object FaceVerificationStatus {
|
|
139
|
+
const val VERIFIED = "VERIFIED"
|
|
140
|
+
const val NOT_VERIFIED = "NOT_VERIFIED"
|
|
141
|
+
const val NOT_INITIALIZED = "NOT_INITIALIZED"
|
|
142
|
+
const val TOS_NOT_ACCEPTED = "TOS_NOT_ACCEPTED"
|
|
143
|
+
const val PENDING_REVIEW = "PENDING_REVIEW"
|
|
144
|
+
const val MAX_ATTEMPTS_REACHED = "MAX_ATTEMPTS_REACHED"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
companion object {
|
|
148
|
+
const val NAME = "PlaytimeProtection"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
package io.adjoe.sdk.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReadableArray
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
|
|
9
|
+
import io.adjoe.sdk.studio.PlaytimeCampaign
|
|
10
|
+
import io.adjoe.sdk.studio.PlaytimeCampaignsListener
|
|
11
|
+
import io.adjoe.sdk.studio.PlaytimeDeeplinkListener
|
|
12
|
+
import io.adjoe.sdk.studio.PlaytimeCampaignsResponse
|
|
13
|
+
import io.adjoe.sdk.studio.PlaytimeOpenInstalledCampaignListener
|
|
14
|
+
import io.adjoe.sdk.studio.PlaytimeOpenStoreListener
|
|
15
|
+
import io.adjoe.sdk.studio.PlaytimeImpressionType
|
|
16
|
+
import io.adjoe.sdk.studio.PlaytimeExecuteImpressionListener
|
|
17
|
+
import io.adjoe.sdk.studio.PlaytimePermissionsListener
|
|
18
|
+
import io.adjoe.sdk.studio.PlaytimeTosListener
|
|
19
|
+
import io.adjoe.sdk.studio.TosConsentAction
|
|
20
|
+
import io.adjoe.sdk.connect.RewardsConnectRegistrationListener
|
|
21
|
+
import io.adjoe.sdk.connect.RewardsConnectResetListener
|
|
22
|
+
import io.adjoe.sdk.PlaytimeException
|
|
23
|
+
import io.adjoe.sdk.studio.PlaytimeStudio
|
|
24
|
+
|
|
25
|
+
import io.adjoe.sdk.reactnative.StudioUtil.constructCampaignOptionsFrom
|
|
26
|
+
import io.adjoe.sdk.reactnative.StudioUtil.constructInstalledCampaignOptionsFrom
|
|
27
|
+
|
|
28
|
+
class PlaytimeStudioImpl(
|
|
29
|
+
private val reactContext: ReactApplicationContext
|
|
30
|
+
) {
|
|
31
|
+
|
|
32
|
+
private val cache: MutableMap<String?, PlaytimeCampaign> = HashMap()
|
|
33
|
+
|
|
34
|
+
private fun cacheKeyOf(campaign: PlaytimeCampaign): String? =
|
|
35
|
+
if (campaign.token.isNullOrEmpty()) campaign.campaignUUID else campaign.token
|
|
36
|
+
|
|
37
|
+
private fun cacheKeyOf(campaignMap: ReadableMap?): String? {
|
|
38
|
+
val token = campaignMap?.getString(StudioUtil.JsonKey.TOKEN)
|
|
39
|
+
return if (token.isNullOrEmpty()) {
|
|
40
|
+
campaignMap?.getString(StudioUtil.JsonKey.CAMPAIGN_UUID)
|
|
41
|
+
} else {
|
|
42
|
+
token
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun updateTosConsent(action: Double, promise: Promise) {
|
|
47
|
+
val consentAction =
|
|
48
|
+
if (action.toInt() == 1) TosConsentAction.WITHDRAW else TosConsentAction.ACCEPT
|
|
49
|
+
PlaytimeStudio.updateTosConsent(consentAction, object : PlaytimeTosListener {
|
|
50
|
+
override fun onUpdated() {
|
|
51
|
+
promise.resolve(null)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
override fun onError(error: PlaytimeException) {
|
|
55
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fun getCampaigns(campaignOptionsMap: ReadableMap?, promise: Promise) {
|
|
61
|
+
val options = constructCampaignOptionsFrom(campaignOptionsMap)
|
|
62
|
+
PlaytimeStudio.getCampaigns(options, createCampaignsListener(promise))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fun getOfferDetails(tokens: ReadableArray?, campaignOptionsMap: ReadableMap?, promise: Promise) {
|
|
66
|
+
val options = constructCampaignOptionsFrom(campaignOptionsMap)
|
|
67
|
+
val tokenList = ArrayList<String>()
|
|
68
|
+
if (tokens != null) {
|
|
69
|
+
for (i in 0 until tokens.size()) {
|
|
70
|
+
tokens.getString(i)?.let { tokenList.add(it) }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
PlaytimeStudio.getOfferDetails(tokenList, options, createCampaignsListener(promise))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fun getInstalledCampaigns(optionsMap: ReadableMap?, promise: Promise) {
|
|
77
|
+
val options = constructInstalledCampaignOptionsFrom(optionsMap)
|
|
78
|
+
PlaytimeStudio.getInstalledCampaigns(options, createCampaignsListener(promise))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fun openInStore(campaignMap: ReadableMap?, useInlineInstall: Boolean, promise: Promise) {
|
|
82
|
+
val cacheKey = cacheKeyOf(campaignMap)
|
|
83
|
+
val campaign = cacheKey?.let { cache[it] }
|
|
84
|
+
|
|
85
|
+
if (cacheKey == null || campaign == null) {
|
|
86
|
+
ErrorsUtil.reject(promise, ErrorsUtil.campaignIsNullError())
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
PlaytimeStudio.openInStore(campaign, useInlineInstall, object : PlaytimeOpenStoreListener {
|
|
91
|
+
override fun onFinished() {
|
|
92
|
+
promise.resolve(null)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override fun onError(error: PlaytimeException) {
|
|
96
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override fun onAlreadyClicking() {
|
|
100
|
+
ErrorsUtil.reject(
|
|
101
|
+
promise,
|
|
102
|
+
ErrorsUtil.getFunctionError("openInStore", "Request is already in progress")
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fun openInstalledCampaign(campaignMap: ReadableMap?, promise: Promise) {
|
|
109
|
+
val cacheKey = cacheKeyOf(campaignMap)
|
|
110
|
+
val campaign = cacheKey?.let { cache[it] }
|
|
111
|
+
|
|
112
|
+
if (campaign == null) {
|
|
113
|
+
ErrorsUtil.reject(promise, ErrorsUtil.campaignIsNullError())
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
PlaytimeStudio.openInstalledCampaign(campaign, object : PlaytimeOpenInstalledCampaignListener {
|
|
118
|
+
override fun onOpened() {
|
|
119
|
+
promise.resolve(null)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
override fun onError(error: PlaytimeException) {
|
|
123
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fun openChatbot(campaignMap: ReadableMap?, promise: Promise) {
|
|
129
|
+
try {
|
|
130
|
+
val cacheKey = cacheKeyOf(campaignMap)
|
|
131
|
+
val campaign = cacheKey?.let { cache[it] }
|
|
132
|
+
|
|
133
|
+
val activity = reactContext.getCurrentActivity()
|
|
134
|
+
if (activity != null) {
|
|
135
|
+
PlaytimeStudio.openChatbot(activity, campaign, createDeeplinkListener(promise))
|
|
136
|
+
} else {
|
|
137
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
138
|
+
}
|
|
139
|
+
} catch (e: Exception) {
|
|
140
|
+
ErrorsUtil.reject(promise, e)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fun resetRewardsConnect(promise: Promise) {
|
|
145
|
+
PlaytimeStudio.resetRewardsConnect(object : RewardsConnectResetListener {
|
|
146
|
+
override fun onSuccess() {
|
|
147
|
+
promise.resolve(null)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
override fun onFailure(registrationError: PlaytimeException) {
|
|
151
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(registrationError))
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
fun executeCampaignImpression(campaignMap: ReadableMap?, impressionType: Double, promise: Promise) {
|
|
157
|
+
val cacheKey = cacheKeyOf(campaignMap)
|
|
158
|
+
val campaign = cacheKey?.let { cache[it] }
|
|
159
|
+
|
|
160
|
+
val playtimeImpressionType =
|
|
161
|
+
if (impressionType.toInt() == 1) PlaytimeImpressionType.ENGAGED else PlaytimeImpressionType.DEFAULT
|
|
162
|
+
|
|
163
|
+
if (cacheKey == null || campaign == null) {
|
|
164
|
+
ErrorsUtil.reject(promise, ErrorsUtil.campaignIsNullError())
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
PlaytimeStudio.executeCampaignImpression(campaign, playtimeImpressionType,
|
|
169
|
+
object : PlaytimeExecuteImpressionListener {
|
|
170
|
+
override fun onFinished() {
|
|
171
|
+
promise.resolve(null)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override fun onError(error: PlaytimeException) {
|
|
175
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
override fun onAlreadyEngaging() {
|
|
179
|
+
ErrorsUtil.reject(
|
|
180
|
+
promise,
|
|
181
|
+
ErrorsUtil.getFunctionError("executeCampaignImpression", "Request is already in progress")
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fun executeOfferImpression(token: String, appID: String, promise: Promise) {
|
|
188
|
+
PlaytimeStudio.executeOfferImpression(token, appID, object : PlaytimeExecuteImpressionListener {
|
|
189
|
+
override fun onFinished() {
|
|
190
|
+
promise.resolve(null)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
override fun onError(error: PlaytimeException) {
|
|
194
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
override fun onAlreadyEngaging() {
|
|
198
|
+
ErrorsUtil.reject(
|
|
199
|
+
promise,
|
|
200
|
+
ErrorsUtil.getFunctionError("executeOfferImpression", "Request is already in progress")
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fun registerRewardsConnect(promise: Promise) {
|
|
207
|
+
val activity = reactContext.getCurrentActivity()
|
|
208
|
+
if (activity != null) {
|
|
209
|
+
PlaytimeStudio.registerRewardsConnect(activity, object : RewardsConnectRegistrationListener {
|
|
210
|
+
override fun onSuccess() {
|
|
211
|
+
promise.resolve(null)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
override fun onFailure(registrationError: PlaytimeException) {
|
|
215
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(registrationError))
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
} else {
|
|
219
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
fun showCampaignDetails(campaignMap: ReadableMap?, promise: Promise) {
|
|
224
|
+
val cacheKey = cacheKeyOf(campaignMap)
|
|
225
|
+
val campaign = cacheKey?.let { cache[it] }
|
|
226
|
+
|
|
227
|
+
if (campaign == null) {
|
|
228
|
+
ErrorsUtil.reject(promise, ErrorsUtil.campaignIsNullError())
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
val activity = reactContext.getCurrentActivity()
|
|
233
|
+
if (activity != null) {
|
|
234
|
+
PlaytimeStudio.showCampaignDetails(activity, campaign, createDeeplinkListener(promise))
|
|
235
|
+
} else {
|
|
236
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
fun showOfferDetails(token: String, appID: String, promise: Promise) {
|
|
241
|
+
val activity = reactContext.getCurrentActivity()
|
|
242
|
+
if (activity != null) {
|
|
243
|
+
PlaytimeStudio.showOfferDetails(activity, token, appID, createDeeplinkListener(promise))
|
|
244
|
+
} else {
|
|
245
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
fun showInstalledCampaigns(promise: Promise) {
|
|
250
|
+
val activity = reactContext.getCurrentActivity()
|
|
251
|
+
if (activity != null) {
|
|
252
|
+
PlaytimeStudio.showInstalledCampaigns(activity, createDeeplinkListener(promise))
|
|
253
|
+
} else {
|
|
254
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fun showPermissionsPrompt(promise: Promise) {
|
|
259
|
+
try {
|
|
260
|
+
val activity = reactContext.getCurrentActivity()
|
|
261
|
+
if (activity != null) {
|
|
262
|
+
PlaytimeStudio.showPermissionsPrompt(activity, object : PlaytimePermissionsListener {
|
|
263
|
+
override fun onReceived() {
|
|
264
|
+
promise.resolve(null)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
override fun onError(error: PlaytimeException) {
|
|
268
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
} else {
|
|
272
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
273
|
+
}
|
|
274
|
+
} catch (e: Exception) {
|
|
275
|
+
ErrorsUtil.reject(promise, e)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private fun createCampaignsListener(promise: Promise): PlaytimeCampaignsListener {
|
|
280
|
+
return object : PlaytimeCampaignsListener {
|
|
281
|
+
override fun onReceived(response: PlaytimeCampaignsResponse) {
|
|
282
|
+
val campaigns = Arguments.createArray()
|
|
283
|
+
for (campaign in response.campaigns) {
|
|
284
|
+
cache[cacheKeyOf(campaign)] = campaign
|
|
285
|
+
campaigns.pushMap(StudioUtil.campaignToReadableMap(campaign))
|
|
286
|
+
}
|
|
287
|
+
val result = Arguments.createMap()
|
|
288
|
+
result.putArray(StudioUtil.JsonKey.CAMPAIGNS, campaigns)
|
|
289
|
+
promise.resolve(result)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
override fun onError(error: PlaytimeException) {
|
|
293
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private fun createDeeplinkListener(promise: Promise): PlaytimeDeeplinkListener {
|
|
299
|
+
return object : PlaytimeDeeplinkListener {
|
|
300
|
+
override fun onOpened() {
|
|
301
|
+
promise.resolve(null)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
override fun onError(error: PlaytimeException) {
|
|
305
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
companion object {
|
|
311
|
+
const val NAME = "PlaytimeStudio"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
package io.adjoe.sdk.reactnative
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
9
|
+
|
|
10
|
+
import io.adjoe.sdk.Playtime
|
|
11
|
+
import io.adjoe.sdk.PlaytimeEvent
|
|
12
|
+
import io.adjoe.sdk.PlaytimeEventListener
|
|
13
|
+
import io.adjoe.sdk.PlaytimeException
|
|
14
|
+
import io.adjoe.sdk.PlaytimeInitListener
|
|
15
|
+
import io.adjoe.sdk.PlaytimeCatalogLaunchListener
|
|
16
|
+
import io.adjoe.sdk.PlaytimeImpressionEventListener
|
|
17
|
+
import io.adjoe.sdk.PlaytimeTeardownListener
|
|
18
|
+
|
|
19
|
+
class RNPlaytimeSdkImpl(
|
|
20
|
+
private val reactContext: ReactApplicationContext
|
|
21
|
+
) {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The listener currently registered with the SDK. It is retained so that it stays
|
|
25
|
+
* registered and can be released when the publisher removes it again.
|
|
26
|
+
*/
|
|
27
|
+
private var eventListener: PlaytimeEventListener? = null
|
|
28
|
+
|
|
29
|
+
fun initPlaytime(options: ReadableMap?, promise: Promise) {
|
|
30
|
+
try {
|
|
31
|
+
val initOptions = BasicUtil.constructInitOptionsFrom(options)
|
|
32
|
+
Playtime.initPlaytime(initOptions, object : PlaytimeInitListener {
|
|
33
|
+
override fun onSuccess() {
|
|
34
|
+
promise.resolve(null)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun onError(error: PlaytimeException) {
|
|
38
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
} catch (e: Exception) {
|
|
42
|
+
ErrorsUtil.reject(promise, e)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun showCatalog(catalogOptions: ReadableMap?, promise: Promise) {
|
|
47
|
+
try {
|
|
48
|
+
val options = BasicUtil.constructCatalogOptionsFrom(catalogOptions)
|
|
49
|
+
val localActivity: Activity? = reactContext.getCurrentActivity()
|
|
50
|
+
if (localActivity == null) {
|
|
51
|
+
ErrorsUtil.reject(promise, ErrorsUtil.getActivityIsNullError())
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
Playtime.showCatalog(localActivity, options, object : PlaytimeCatalogLaunchListener {
|
|
55
|
+
override fun onCatalogLaunched() {
|
|
56
|
+
promise.resolve(null)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun onError(error: PlaytimeException) {
|
|
60
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
} catch (e: Exception) {
|
|
64
|
+
ErrorsUtil.reject(promise, e)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fun getStatus(promise: Promise) {
|
|
69
|
+
try {
|
|
70
|
+
val status = Playtime.getStatus()
|
|
71
|
+
promise.resolve(BasicUtil.statusToReadableMap(status))
|
|
72
|
+
} catch (e: Exception) {
|
|
73
|
+
ErrorsUtil.reject(promise, e)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fun teardown(promise: Promise) {
|
|
78
|
+
try {
|
|
79
|
+
Playtime.teardown(object : PlaytimeTeardownListener {
|
|
80
|
+
override fun onSuccess() {
|
|
81
|
+
eventListener = null
|
|
82
|
+
promise.resolve(null)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun onError(error: PlaytimeException) {
|
|
86
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
} catch (e: Exception) {
|
|
90
|
+
ErrorsUtil.reject(promise, e)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Registers a listener which forwards every Playtime SDK event to JavaScript as a
|
|
96
|
+
* device event, since a publisher's JS listener object cannot cross the TurboModule
|
|
97
|
+
* bridge. The JS side bridges the device event back to the listener's `didReceive`
|
|
98
|
+
* callback via a NativeEventEmitter.
|
|
99
|
+
*/
|
|
100
|
+
fun addEventListener(promise: Promise) {
|
|
101
|
+
try {
|
|
102
|
+
val listener = object : PlaytimeEventListener {
|
|
103
|
+
override fun didReceive(event: PlaytimeEvent) {
|
|
104
|
+
emitPlaytimeEvent(event)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
Playtime.addEventListener(listener)
|
|
108
|
+
this.eventListener = listener
|
|
109
|
+
promise.resolve(null)
|
|
110
|
+
} catch (e: Exception) {
|
|
111
|
+
ErrorsUtil.reject(promise, e)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun removeEventListener(promise: Promise) {
|
|
116
|
+
try {
|
|
117
|
+
Playtime.removeEventListener()
|
|
118
|
+
eventListener = null
|
|
119
|
+
promise.resolve(null)
|
|
120
|
+
} catch (e: Exception) {
|
|
121
|
+
ErrorsUtil.reject(promise, e)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fun executeImpressionEvent(catalogPlacement: ReadableMap?, promise: Promise) {
|
|
126
|
+
try {
|
|
127
|
+
val placement = BasicUtil.constructCatalogPlacementFrom(catalogPlacement)
|
|
128
|
+
if (placement == null) {
|
|
129
|
+
ErrorsUtil.reject(
|
|
130
|
+
promise,
|
|
131
|
+
ErrorsUtil.getFunctionError(
|
|
132
|
+
"executeImpressionEvent",
|
|
133
|
+
"The catalog placement is missing or invalid."
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
Playtime.executeImpressionEvent(placement, object : PlaytimeImpressionEventListener {
|
|
139
|
+
override fun onSuccess() {
|
|
140
|
+
promise.resolve(null)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
override fun onError(error: PlaytimeException) {
|
|
144
|
+
ErrorsUtil.reject(promise, ErrorsUtil.toPlaytimeException(error))
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
} catch (e: Exception) {
|
|
148
|
+
ErrorsUtil.reject(promise, e)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Forwards a Playtime SDK event to JavaScript as a device event under
|
|
154
|
+
* [EVENT_PLAYTIME_EVENT]. The JS NativeEventEmitter subscription relays it to the
|
|
155
|
+
* publisher's registered listener.
|
|
156
|
+
*/
|
|
157
|
+
private fun emitPlaytimeEvent(event: PlaytimeEvent) {
|
|
158
|
+
try {
|
|
159
|
+
reactContext
|
|
160
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
161
|
+
.emit(EVENT_PLAYTIME_EVENT, BasicUtil.playtimeEventToReadableMap(event))
|
|
162
|
+
} catch (e: Exception) {
|
|
163
|
+
// The JS context may already be gone; dropping the event is the only option here.
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
companion object {
|
|
168
|
+
const val NAME = "RNPlaytimeSdk"
|
|
169
|
+
|
|
170
|
+
/** The device event name under which SDK events are delivered to JavaScript. */
|
|
171
|
+
const val EVENT_PLAYTIME_EVENT = "onPlaytimeEvent"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package io.adjoe.sdk.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* TurboModule-aware package. Extends [BaseReactPackage] and reports all
|
|
11
|
+
* modules as TurboModules through [getReactModuleInfoProvider].
|
|
12
|
+
*/
|
|
13
|
+
class RNPlaytimeSdkPackage : BaseReactPackage() {
|
|
14
|
+
|
|
15
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
16
|
+
return when (name) {
|
|
17
|
+
RNPlaytimeSdkModule.NAME -> RNPlaytimeSdkModule(reactContext)
|
|
18
|
+
RNPlaytimeStudio.NAME -> RNPlaytimeStudio(reactContext)
|
|
19
|
+
RNPlaytimeProtection.NAME -> RNPlaytimeProtection(reactContext)
|
|
20
|
+
else -> null
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
25
|
+
return ReactModuleInfoProvider {
|
|
26
|
+
val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
27
|
+
mapOf(
|
|
28
|
+
RNPlaytimeSdkModule.NAME to ReactModuleInfo(
|
|
29
|
+
RNPlaytimeSdkModule.NAME,
|
|
30
|
+
RNPlaytimeSdkModule.NAME,
|
|
31
|
+
false, // canOverrideExistingModule
|
|
32
|
+
false, // needsEagerInit
|
|
33
|
+
false, // isCxxModule
|
|
34
|
+
isTurboModule
|
|
35
|
+
),
|
|
36
|
+
RNPlaytimeStudio.NAME to ReactModuleInfo(
|
|
37
|
+
RNPlaytimeStudio.NAME,
|
|
38
|
+
RNPlaytimeStudio.NAME,
|
|
39
|
+
false,
|
|
40
|
+
false,
|
|
41
|
+
false,
|
|
42
|
+
isTurboModule
|
|
43
|
+
),
|
|
44
|
+
RNPlaytimeProtection.NAME to ReactModuleInfo(
|
|
45
|
+
RNPlaytimeProtection.NAME,
|
|
46
|
+
RNPlaytimeProtection.NAME,
|
|
47
|
+
false,
|
|
48
|
+
false,
|
|
49
|
+
false,
|
|
50
|
+
isTurboModule
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|