forked from squaretwo/react-native-iron-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNIronSourceRewardedVideo.js
64 lines (57 loc) · 2.27 KB
/
RNIronSourceRewardedVideo.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
'use strict';
import {
NativeModules,
DeviceEventEmitter,
} from 'react-native';
const RNIronSourceRewardedVideo = NativeModules.RNIronSourceRewardedVideo;
const eventHandlers = {
ironSourceRewardedVideoAvailable: new Map(),
ironSourceRewardedVideoUnavailable: new Map(),
ironSourceRewardedVideoDidStart: new Map(),
ironSourceRewardedVideoClosedByUser: new Map(),
ironSourceRewardedVideoClosedByError: new Map(),
ironSourceRewardedVideoAdStarted: new Map(),
ironSourceRewardedVideoAdEnded: new Map(),
ironSourceRewardedVideoAdRewarded:new Map()
};
const addEventListener = (type, handler) => {
switch (type) {
case 'ironSourceRewardedVideoAvailable':
case 'ironSourceRewardedVideoUnavailable':
case 'ironSourceRewardedVideoDidStart':
case 'ironSourceRewardedVideoClosedByUser':
case 'ironSourceRewardedVideoClosedByError':
case 'ironSourceRewardedVideoAdStarted':
case 'ironSourceRewardedVideoAdEnded':
case 'ironSourceRewardedVideoAdRewarded':
eventHandlers[type].set(handler, DeviceEventEmitter.addListener(type, handler));
break;
default:
console.log(`Event with type ${type} does not exist.`);
}
}
const removeEventListener = (type, handler) => {
if (!eventHandlers[type].has(handler)) {
return;
}
eventHandlers[type].get(handler).remove();
eventHandlers[type].delete(handler);
}
const removeAllListeners = () => {
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoAvailable');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoUnavailable');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoDidStart');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoClosedByUser');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoClosedByError');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoAdStarted');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoAdEnded');
DeviceEventEmitter.removeAllListeners('ironSourceRewardedVideoAdRewarded');
};
module.exports = {
...RNIronSourceRewardedVideo,
initializeRewardedVideo: () => RNIronSourceRewardedVideo.initializeRewardedVideo(),
showRewardedVideo: () => RNIronSourceRewardedVideo.showRewardedVideo(),
addEventListener,
removeEventListener,
removeAllListeners
};