-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
312 lines (288 loc) · 7.92 KB
/
index.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import { NativeEventEmitter, NativeModules } from "react-native";
const { RNPollfish } = NativeModules;
const PollfishEventEmitter = new NativeEventEmitter(RNPollfish);
const PollfishClosedListener = "onPollfishClosed";
const PollfishOpenedListener = "onPollfishOpened";
const PollfishSurveyNotAvailableListener = "onPollfishSurveyNotAvailable";
const PollfishUserRejectedSurveyListener = "onUserRejectedSurvey";
const PollfishSurveyReceivedListener = "onPollfishSurveyReceived";
const PollfishSurveyCompletedListener = "onPollfishSurveyCompleted";
const PollfishUserNotEligibleListener = "onUserNotEligible";
const eventHandlers = {
onPollfishClosed: new Map(),
onPollfishOpened: new Map(),
onPollfishSurveyNotAvailable: new Map(),
onUserRejectedSurvey: new Map(),
onUserNotEligible: new Map(),
onPollfishSurveyReceived: new Map(),
onPollfishSurveyCompleted: new Map(),
};
const removeAllListeners = () => {
PollfishEventEmitter.removeAllListeners(PollfishClosedListener);
PollfishEventEmitter.removeAllListeners(PollfishOpenedListener);
PollfishEventEmitter.removeAllListeners(PollfishSurveyNotAvailableListener);
PollfishEventEmitter.removeAllListeners(PollfishUserRejectedSurveyListener);
PollfishEventEmitter.removeAllListeners(PollfishUserNotEligibleListener);
PollfishEventEmitter.removeAllListeners(PollfishSurveyReceivedListener);
PollfishEventEmitter.removeAllListeners(PollfishSurveyCompletedListener);
};
const addEventListener = (type, handler) => {
switch (type) {
case PollfishClosedListener:
case PollfishOpenedListener:
case PollfishSurveyNotAvailableListener:
case PollfishUserRejectedSurveyListener:
case PollfishUserNotEligibleListener:
case PollfishSurveyReceivedListener:
case PollfishSurveyCompletedListener:
eventHandlers[type].set(
handler,
PollfishEventEmitter.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 Position = {
topLeft: 0,
topRight: 1,
middleLeft: 2,
middleRight: 3,
bottomLeft: 4,
bottomRight: 5,
};
let Params = function (
androidApiKey,
iOSApiKey,
indicatorPosition,
indicatorPadding,
offerwallMode,
releaseMode,
rewardMode,
requestUUID,
userProperties,
clickId,
userId,
rewardInfo,
signature,
placementId
) {
this.androidApiKey = androidApiKey;
this.iOSApiKey = iOSApiKey;
this.indicatorPosition = indicatorPosition;
this.indicatorPadding = indicatorPadding;
this.offerwallMode = offerwallMode;
this.releaseMode = releaseMode;
this.rewardMode = rewardMode;
this.requestUUID = requestUUID;
this.userProperties = userProperties;
this.clickId = clickId;
this.userId = userId;
this.rewardInfo = rewardInfo;
this.signature = signature;
this.placementId = placementId;
};
let Builder = function (androidApiKey, iOSApiKey) {
this._androidApiKey = androidApiKey;
this._iOSApiKey = iOSApiKey;
this._indicatorPosition = Position.topLeft;
this._indicatorPadding = 8;
this._offerwallMode = false;
this._releaseMode = false;
this._rewardMode = false;
this._requestUUID = null;
this._userProperties = {};
this._clickId = null;
this._userId = null;
this._rewardInfo = null;
this._signature = null;
this._placementId = null;
};
/**
* Sets the Position where you wish to place the Pollfish indicator
*
* @param {number} indicatorPosition
* @returns {Builder} itself
*/
Builder.prototype.indicatorPosition = function (indicatorPosition) {
this._indicatorPosition = indicatorPosition;
return this;
};
/**
* Sets the padding from the top or the bottom of the view, according to the Position of Pollfish indicator
*
* @param {number} indicatorPadding
* @returns {Builder} itself
*/
Builder.prototype.indicatorPadding = function (indicatorPadding) {
this._indicatorPadding = indicatorPadding;
return this;
};
/**
* Sets Pollfish to offerwall mode
*
* @param {Boolean} offerwallMode
* @returns {Builder} itself
*/
Builder.prototype.offerwallMode = function (offerwallMode) {
this._offerwallMode = offerwallMode;
return this;
};
/**
* Sets Pollfish SDK to Developer or Release mode
*
* @param {Boolean} releaseMode
* @returns {Builder} itself
*/
Builder.prototype.releaseMode = function (releaseMode) {
this._releaseMode = releaseMode;
return this;
};
/**
* Initializes Pollfish in reward mode
*
* @param {Boolean} rewardMode
* @returns {Builder} itself
*/
Builder.prototype.rewardMode = function (rewardMode) {
this._rewardMode = rewardMode;
return this;
};
/**
* Sets a unique id to identify a user and be passed through server-to-server callbacks
*
* @param {String} requestUUID
* @returns {Builder} itself
*/
Builder.prototype.requestUUID = function (requestUUID) {
this._requestUUID = requestUUID;
return this;
};
/**
* Provides user attributes upfront during initialization
*
* @param {Object} userProperties
* @returns {Builder} itself
*/
Builder.prototype.userProperties = function (userProperties) {
this._userProperties = userProperties;
return this;
};
/**
* A pass throught param that will be passed back through server-to-server callback
*
* @param {String} clickId
* @returns {Builder} itself
*/
Builder.prototype.clickId = function (clickId) {
this._clickId = clickId;
return this;
};
/**
* A unique id to identify a user
*
* @param {String} userId
* @returns
*/
Builder.prototype.userId = function (userId) {
this._userId = userId;
return this;
};
/**
* An optional parameter used to secure the rewardConversion and rewardName parameters passed on RewardInfo object
*
* @param {String} signature
* @returns {Builder} itself
*/
Builder.prototype.signature = function (signature) {
this._signature = signature;
return this;
};
/**
* An object holding information regarding the survey completion reward
*
* @param {Object} rewardInfo
* @returns {Builder} itself
*/
Builder.prototype.rewardInfo = function (rewardInfo) {
this._rewardInfo = rewardInfo;
return this;
};
/**
* The id of the placement to load. If not provided the default placement of the ad unit will be loaded.
*
* @param {String} placementId
* @returns {Builder} itself
*/
Builder.prototype.placementId = function (placementId) {
this._placementId = placementId;
return this;
}
/**
* Creates the initialization params object passed in pollfishpugin.init function
*
* @returns {Params} object which is used to initialize Pollfish
*/
Builder.prototype.build = function () {
return new Params(
this._androidApiKey,
this._iOSApiKey,
this._indicatorPosition,
this._indicatorPadding,
this._offerwallMode,
this._releaseMode,
this._rewardMode,
this._requestUUID,
this._userProperties,
this._clickId,
this._userId,
this._rewardInfo,
this._signature,
this._placementId
);
};
module.exports = {
...RNPollfish,
Position,
Builder,
Params,
PollfishClosedListener,
PollfishOpenedListener,
PollfishSurveyReceivedListener,
PollfishSurveyCompletedListener,
PollfishSurveyNotAvailableListener,
PollfishUserNotEligibleListener,
PollfishUserRejectedSurveyListener,
init: (params) =>
RNPollfish.init(
params.androidApiKey,
params.iOSApiKey,
params.indicatorPosition,
params.indicatorPadding,
params.offerwallMode,
params.releaseMode,
params.rewardMode,
params.requestUUID,
params.userProperties,
params.rewardInfo,
params.clickId,
params.userId,
params.signature,
params.placementId
),
show: () => RNPollfish.show(),
hide: () => RNPollfish.hide(),
isPollfishPanelOpen: (func) => RNPollfish.isPollfishPanelOpen(func),
isPollfishPresent: (func) => RNPollfish.isPollfishPresent(func),
removeAllListeners,
removeEventListener,
addEventListener,
};