forked from finalem/react-native-appodeal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappodeal.js
144 lines (128 loc) · 5.05 KB
/
appodeal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
import {
NativeModules,
NativeEventEmitter,
Platform,
} from 'react-native';
const RNAppodeal = NativeModules.RNAppodeal;
const NONE = 0;
const INTERSTITIAL = 3;
const BANNER = 4;
const BANNER_BOTTOM = 8;
const BANNER_TOP = 16;
const REWARDED_VIDEO = 128;
const NON_SKIPPABLE_VIDEO = 256;
const eventEmitter = new NativeEventEmitter(RNAppodeal);
const eventHandlers = {
onInterstitialLoaded: 'onInterstitialLoaded',
onInterstitialClicked: 'onInterstitialClicked',
onInterstitialClosed: 'onInterstitialClosed',
onInterstitialFailedToLoad: 'onInterstitialFailedToLoad',
onInterstitialShown: 'onInterstitialShown',
onBannerClicked: 'onBannerClicked',
onBannerFailedToLoad: 'onBannerFailedToLoad',
onBannerLoaded: 'onBannerLoaded',
onBannerShown: 'onBannerShown',
onRewardedVideoClosed: 'onRewardedVideoClosed',
onRewardedVideoFailedToLoad: 'onRewardedVideoFailedToLoad',
onRewardedVideoFinished: 'onRewardedVideoFinished',
onRewardedVideoLoaded: 'onRewardedVideoLoaded',
onRewardedVideoShown: 'onRewardedVideoShown',
onNonSkippableVideoClosed: 'onNonSkippableVideoClosed',
onNonSkippableVideoFailedToLoad: 'onNonSkippableVideoFailedToLoad',
onNonSkippableVideoFinished: 'onNonSkippableVideoFinished',
onNonSkippableVideoLoaded: 'onNonSkippableVideoLoaded',
onNonSkippableVideoShown: 'onNonSkippableVideoShown',
};
const LogLevel = {
none: 'none',
debug: 'debug',
verbose: 'verbose'
}
const Gender = {
male: 'male',
female: 'female',
other: 'other'
}
const _subscriptions = new Map();
const addEventListener = (event, handler) => {
const mappedEvent = eventHandlers[event];
if (mappedEvent) {
let listener;
listener = eventEmitter.addListener(mappedEvent, handler);
_subscriptions.set(handler, listener);
return {
remove: () => removeEventListener(event, handler)
};
} else {
console.warn(`Trying to subscribe to unknown event: "${event}"`);
return {
remove: () => {},
};
}
};
const removeEventListener = (type, handler) => {
const listener = _subscriptions.get(handler);
if (!listener) {
return;
}
listener.remove();
_subscriptions.delete(handler);
};
const removeAllListeners = () => {
_subscriptions.forEach((listener, key, map) => {
listener.remove();
map.delete(key);
});
};
const canShow = Platform.select({
ios: (adTypes, placement, cb = () => {}) => RNAppodeal.canShow(adTypes, placement, cb),
android: (adType, placement, cb = () => {}) => RNAppodeal.canShow({adType , placement}, cb),
});
module.exports = {
...RNAppodeal,
INTERSTITIAL,
BANNER,
BANNER_TOP,
BANNER_BOTTOM,
REWARDED_VIDEO,
NON_SKIPPABLE_VIDEO,
LogLevel,
Gender,
addEventListener,
removeEventListener,
removeAllListeners,
showToast: (message) => RNAppodeal.showToast(message),
initialize: (appKey, adTypes) => RNAppodeal.initialize(appKey, adTypes),
show: (adTypes, placement, cb = () => {}) => RNAppodeal.show(adTypes, placement, cb),
isLoaded: (adTypes, cb = () => {}) => RNAppodeal.isLoaded(adTypes, cb),
cache: (adTypes) => RNAppodeal.cache(adTypes),
hide: (adTypes) => RNAppodeal.hide(adTypes),
setAutoCache: (adTypes, value) => RNAppodeal.setAutoCache(adTypes, value),
isPrecache: (adTypes, cb = () => {}) => RNAppodeal.isPrecache(adTypes, cb),
setTabletBanners: (value) => RNAppodeal.setTabletBanners(value),
setSmartBanners: (value) => RNAppodeal.setSmartBanners(value),
setBannerAnimation: (value) => RNAppodeal.setBannerAnimation(value),
setBannerBackground: (value) => RNAppodeal.setBannerBackground(value),
setTesting: (value) => RNAppodeal.setTesting(value),
setLogLevel: (value) => RNAppodeal.setLogLevel(value),
setChildDirectedTreatment: (value) => RNAppodeal.setChildDirectedTreatment(value),
setOnLoadedTriggerBoth: (adTypes, value) => RNAppodeal.setOnLoadedTriggerBoth(adTypes, value),
disableNetwork: (network, adTypes) => RNAppodeal.disableNetwork(network, adTypes),
disableLocationPermissionCheck: () => RNAppodeal.disableLocationPermissionCheck(),
disableWriteExternalStoragePermissionCheck: () => RNAppodeal.disableWriteExternalStoragePermissionCheck(),
requestAndroidMPermissions: (cb = () => {}) => RNAppodeal.requestAndroidMPermissions(cb),
muteVideosIfCallsMuted: (value) => RNAppodeal.muteVideosIfCallsMuted(appKey, adTypes),
showTestScreen: () => RNAppodeal.showTestScreen(),
getVersion: (cb = () => {}) => RNAppodeal.getVersion(cb),
canShow,
setCustomStringRule: (name, value) => RNAppodeal.setCustomStringRule(name, value),
setCustomBooleanRule: (name, value) => RNAppodeal.setCustomBooleanRule(name, value),
setCustomIntegerRule: (name, value) => RNAppodeal.setCustomIntegerRule(name, value),
setCustomDoubleRule: (name, value) => RNAppodeal.setCustomDoubleRule(name, value),
trackInAppPurchase: (amount, currency) => RNAppodeal.trackInAppPurchase(amount, currency),
getRewardParameters: (placement, cb = () => {}) => RNAppodeal.getRewardParameters(placement, cb),
setAge: (age) => RNAppodeal.setAge(age),
setGender: (gender) => RNAppodeal.setGender(gender),
setUserId: (id) => RNAppodeal.setUserId(id),
};