@jolibox/implement 1.1.13-beta.2 → 1.1.13-beta.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/.rush/temp/package-deps_build.json +6 -6
- package/dist/common/ads/anti-cheating.d.ts +5 -0
- package/dist/index.js +3 -3
- package/dist/index.native.js +5 -5
- package/implement.build.log +2 -2
- package/package.json +4 -4
- package/src/common/ads/anti-cheating.test.ts +4 -2
- package/src/common/ads/anti-cheating.ts +10 -4
- package/src/common/ads/index.ts +51 -33
- package/src/h5/http/utils/__tests__/xua.test.ts +1 -1
- package/src/native/api/ads.ts +1 -1
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.1.13-beta.
|
|
3
|
+
> @jolibox/implement@1.1.13-beta.4 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.1.13-beta.
|
|
7
|
+
> @jolibox/implement@1.1.13-beta.4 build:esm
|
|
8
8
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/implement",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk implement for Native && H5",
|
|
4
|
-
"version": "1.1.13-beta.
|
|
4
|
+
"version": "1.1.13-beta.4",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.1.13-beta.
|
|
10
|
-
"@jolibox/types": "1.1.13-beta.
|
|
11
|
-
"@jolibox/native-bridge": "1.
|
|
9
|
+
"@jolibox/common": "1.1.13-beta.4",
|
|
10
|
+
"@jolibox/types": "1.1.13-beta.4",
|
|
11
|
+
"@jolibox/native-bridge": "1.1.13-beta.4",
|
|
12
12
|
"localforage": "1.10.0",
|
|
13
13
|
"@jolibox/ui": "1.0.0",
|
|
14
14
|
"web-vitals": "4.2.4"
|
|
@@ -20,7 +20,9 @@ describe('createLeadingNotifiableDebounce', () => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
it('should ban initial call', async () => {
|
|
23
|
-
|
|
23
|
+
(window as any).__joliboxLocalStorage__ = window.localStorage;
|
|
24
|
+
|
|
25
|
+
(window as any).__joliboxLocalStorage__.clear();
|
|
24
26
|
|
|
25
27
|
const adsAntiCheating = new AdsAntiCheating(track, http, () => true, config);
|
|
26
28
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
@@ -32,7 +34,7 @@ describe('createLeadingNotifiableDebounce', () => {
|
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
it('should ban continous calling', async () => {
|
|
35
|
-
|
|
37
|
+
(window as any).__joliboxLocalStorage__.clear();
|
|
36
38
|
|
|
37
39
|
const adsAntiCheating = new AdsAntiCheating(track, http, () => true, config);
|
|
38
40
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -24,6 +24,12 @@ export interface IAdsAntiCheatingConfig {
|
|
|
24
24
|
highFreqThreshold?: number; // default 2000 (2s)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
declare global {
|
|
28
|
+
interface Window {
|
|
29
|
+
__joliboxLocalStorage__: Storage;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
export class AdsAntiCheating {
|
|
28
34
|
private checkShouldBanInitial: ReturnType<typeof createInitialStrategy>;
|
|
29
35
|
private checkShouldBanHighFreq: ReturnType<typeof createHighFreqStrategy>;
|
|
@@ -177,7 +183,7 @@ const createBanForTimeStrategy = (
|
|
|
177
183
|
_records: [] as CallAdsHistory[],
|
|
178
184
|
init() {
|
|
179
185
|
try {
|
|
180
|
-
const fromStorage = JSON.parse(window.
|
|
186
|
+
const fromStorage = JSON.parse(window.__joliboxLocalStorage__.getItem(TIMESTAMP_STORAGE_KEY) ?? '[]');
|
|
181
187
|
if (Array.isArray(fromStorage)) {
|
|
182
188
|
this._records = fromStorage;
|
|
183
189
|
} else {
|
|
@@ -192,7 +198,7 @@ const createBanForTimeStrategy = (
|
|
|
192
198
|
},
|
|
193
199
|
set values(value: CallAdsHistory[]) {
|
|
194
200
|
try {
|
|
195
|
-
window.
|
|
201
|
+
window.__joliboxLocalStorage__.setItem(TIMESTAMP_STORAGE_KEY, JSON.stringify(value));
|
|
196
202
|
} catch {
|
|
197
203
|
// console.error('Failed to save timestamps');
|
|
198
204
|
// do nothing
|
|
@@ -205,7 +211,7 @@ const createBanForTimeStrategy = (
|
|
|
205
211
|
_record: false,
|
|
206
212
|
init() {
|
|
207
213
|
try {
|
|
208
|
-
const fromStorage = JSON.parse(window.
|
|
214
|
+
const fromStorage = JSON.parse(window.__joliboxLocalStorage__.getItem(BAN_FOR_TIME_KEY) ?? 'false');
|
|
209
215
|
if (typeof fromStorage === 'boolean') {
|
|
210
216
|
this._record = fromStorage;
|
|
211
217
|
}
|
|
@@ -228,7 +234,7 @@ const createBanForTimeStrategy = (
|
|
|
228
234
|
},
|
|
229
235
|
set value(value: boolean) {
|
|
230
236
|
try {
|
|
231
|
-
window.
|
|
237
|
+
window.__joliboxLocalStorage__.setItem(BAN_FOR_TIME_KEY, JSON.stringify(value));
|
|
232
238
|
} catch {
|
|
233
239
|
// do nothing
|
|
234
240
|
}
|
package/src/common/ads/index.ts
CHANGED
|
@@ -377,6 +377,55 @@ export class JoliboxAdsImpl {
|
|
|
377
377
|
* @returns IAdBreakParams
|
|
378
378
|
*/
|
|
379
379
|
private wrapAdBreakParams = (params: IAdBreakParams): IAdBreakParams => {
|
|
380
|
+
let googleHasResponse = false;
|
|
381
|
+
|
|
382
|
+
/* hook adBreakDone to track adBreakDone event -- start */
|
|
383
|
+
const originAdBreakDone = params.adBreakDone;
|
|
384
|
+
const adBreakDone = (placementInfo: IPlacementInfo) => {
|
|
385
|
+
googleHasResponse = true;
|
|
386
|
+
this.adsActionDetection.adBreakIsShowing = false;
|
|
387
|
+
this.track('CallAdBreakDone', {
|
|
388
|
+
breakType: placementInfo.breakType,
|
|
389
|
+
breakName: placementInfo.breakName ?? '',
|
|
390
|
+
breakFormat: placementInfo.breakFormat,
|
|
391
|
+
breakStatus: placementInfo.breakStatus
|
|
392
|
+
});
|
|
393
|
+
if (originAdBreakDone) {
|
|
394
|
+
originAdBreakDone(placementInfo);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
params.adBreakDone = adBreakDone;
|
|
398
|
+
/* hook adBreakDone to track adBreakDone event -- end */
|
|
399
|
+
|
|
400
|
+
/* hook for reward -- start */
|
|
401
|
+
if (params.type === 'reward') {
|
|
402
|
+
const originBeforeReward = params.beforeReward;
|
|
403
|
+
const wrapShowAdFn = (originShowAdFn: () => void) => () => {
|
|
404
|
+
this.track('CallShowAdFn', null);
|
|
405
|
+
originShowAdFn();
|
|
406
|
+
};
|
|
407
|
+
const beforeReward = (originShowAdFn: () => void) => {
|
|
408
|
+
googleHasResponse = true;
|
|
409
|
+
if (originBeforeReward) {
|
|
410
|
+
originBeforeReward(wrapShowAdFn(originShowAdFn));
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
params.beforeReward = beforeReward;
|
|
414
|
+
|
|
415
|
+
window.setTimeout(() => {
|
|
416
|
+
if (!googleHasResponse) {
|
|
417
|
+
this.track('CallAdBreakTimeout', { type: params.type });
|
|
418
|
+
params.adBreakDone?.({
|
|
419
|
+
breakType: params.type,
|
|
420
|
+
breakName: params.name ?? '',
|
|
421
|
+
breakFormat: 'reward',
|
|
422
|
+
breakStatus: 'timeout'
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}, 10000); // Timeout duration in milliseconds, 10 seconds
|
|
426
|
+
}
|
|
427
|
+
/* hook for reward -- end */
|
|
428
|
+
|
|
380
429
|
const isPreroll = (params: IAdBreakParams): params is IPrerollParams => {
|
|
381
430
|
return params.type === 'preroll';
|
|
382
431
|
};
|
|
@@ -396,6 +445,7 @@ export class JoliboxAdsImpl {
|
|
|
396
445
|
const originAfterAd = params.afterAd;
|
|
397
446
|
|
|
398
447
|
const beforeAd = () => {
|
|
448
|
+
googleHasResponse = true;
|
|
399
449
|
adEventEmitter.emit('isAdShowing', true);
|
|
400
450
|
this.track('CallBeforeAd', {
|
|
401
451
|
type: params.type,
|
|
@@ -407,6 +457,7 @@ export class JoliboxAdsImpl {
|
|
|
407
457
|
};
|
|
408
458
|
|
|
409
459
|
const afterAd = () => {
|
|
460
|
+
googleHasResponse = true;
|
|
410
461
|
adEventEmitter.emit('isAdShowing', false);
|
|
411
462
|
this.track('CallAfterAd', {
|
|
412
463
|
type: params.type,
|
|
@@ -529,39 +580,6 @@ export class JoliboxAdsImpl {
|
|
|
529
580
|
|
|
530
581
|
const type = params.type;
|
|
531
582
|
|
|
532
|
-
/* hook adBreakDone to track adBreakDone event -- start */
|
|
533
|
-
const originAdBreakDone = params.adBreakDone;
|
|
534
|
-
const adBreakDone = (placementInfo: IPlacementInfo) => {
|
|
535
|
-
this.adsActionDetection.adBreakIsShowing = false;
|
|
536
|
-
this.track('CallAdBreakDone', {
|
|
537
|
-
breakType: placementInfo.breakType,
|
|
538
|
-
breakName: placementInfo.breakName ?? '',
|
|
539
|
-
breakFormat: placementInfo.breakFormat,
|
|
540
|
-
breakStatus: placementInfo.breakStatus
|
|
541
|
-
});
|
|
542
|
-
if (originAdBreakDone) {
|
|
543
|
-
originAdBreakDone(placementInfo);
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
params.adBreakDone = adBreakDone;
|
|
547
|
-
/* hook adBreakDone to track adBreakDone event -- end */
|
|
548
|
-
|
|
549
|
-
/* hook beforeAd to track beforeAd event -- start */
|
|
550
|
-
if (params.type === 'reward') {
|
|
551
|
-
const originBeforeReward = params.beforeReward;
|
|
552
|
-
const wrapShowAdFn = (originShowAdFn: () => void) => () => {
|
|
553
|
-
this.track('CallShowAdFn', null);
|
|
554
|
-
originShowAdFn();
|
|
555
|
-
};
|
|
556
|
-
const beforeReward = (originShowAdFn: () => void) => {
|
|
557
|
-
if (originBeforeReward) {
|
|
558
|
-
originBeforeReward(wrapShowAdFn(originShowAdFn));
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
params.beforeReward = beforeReward;
|
|
562
|
-
}
|
|
563
|
-
/* hook beforeAd to track beforeAd event -- end */
|
|
564
|
-
|
|
565
583
|
let paramsToTrack;
|
|
566
584
|
switch (type) {
|
|
567
585
|
case 'preroll':
|
|
@@ -4,7 +4,7 @@ import { isValidUUIDV4 } from '@jolibox/common';
|
|
|
4
4
|
|
|
5
5
|
describe('xua', () => {
|
|
6
6
|
it('test xua', () => {
|
|
7
|
-
|
|
7
|
+
(window as any).__joliboxLocalStorage__ = window.localStorage;
|
|
8
8
|
const xua = xUserAgent();
|
|
9
9
|
const deviceInfoRegex = /.* (\(.*\) ).*/;
|
|
10
10
|
const deviceInfoMatch = xua.match(deviceInfoRegex);
|
package/src/native/api/ads.ts
CHANGED