@jolibox/implement 1.2.1 → 1.2.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/.rush/temp/package-deps_build.json +4 -4
- package/dist/common/report/task-track/index.d.ts +3 -0
- package/dist/index.js +9 -9
- package/dist/index.native.js +32 -32
- package/dist/native/report/task-tracker.d.ts +2 -3
- package/implement.build.log +2 -2
- package/package.json +5 -5
- package/src/common/report/task-track/index.ts +48 -7
- package/src/h5/api/task.ts +36 -0
- package/src/native/report/task-tracker.ts +19 -2
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 任务上报
|
|
3
|
-
*/
|
|
4
1
|
import { TaskTracker, TaskPoint } from '@/common/report/task-track';
|
|
5
2
|
import { EventEmitter } from '@jolibox/common';
|
|
6
3
|
import type { Track } from '.';
|
|
@@ -21,5 +18,7 @@ export declare class NativeTaskTracker extends TaskTracker {
|
|
|
21
18
|
reporter(point: TaskPoint): Promise<void>;
|
|
22
19
|
reportToNative(point: NativeTaskPoint): Promise<void>;
|
|
23
20
|
tracker(event: TrackEvent, info?: Record<string, unknown> | null): void;
|
|
21
|
+
start(duration?: number): void;
|
|
22
|
+
private tryReportOpenGamePlus;
|
|
24
23
|
}
|
|
25
24
|
export {};
|
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.2.
|
|
3
|
+
> @jolibox/implement@1.2.3 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.2.
|
|
7
|
+
> @jolibox/implement@1.2.3 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,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/implement",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk implement for Native && H5",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.2.
|
|
10
|
-
"@jolibox/types": "1.2.
|
|
11
|
-
"@jolibox/native-bridge": "1.2.
|
|
12
|
-
"@jolibox/ads": "1.2.
|
|
9
|
+
"@jolibox/common": "1.2.3",
|
|
10
|
+
"@jolibox/types": "1.2.3",
|
|
11
|
+
"@jolibox/native-bridge": "1.2.3",
|
|
12
|
+
"@jolibox/ads": "1.2.3",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
14
|
"@jolibox/ui": "1.0.0",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
@@ -17,19 +17,58 @@ export type TaskPoint = {
|
|
|
17
17
|
params?: Record<string, unknown>;
|
|
18
18
|
extraParams?: Record<string, unknown>;
|
|
19
19
|
};
|
|
20
|
+
|
|
21
|
+
enum ECrossFrameEvent {
|
|
22
|
+
JOLIBOX_GAME_OPEN = 'JOLIBOX_GAME_OPEN',
|
|
23
|
+
JOLIBOX_GAME_PLAY = 'JOLIBOX_GAME_PLAY',
|
|
24
|
+
JOLIBOX_GAME_CLOSE = 'JOLIBOX_GAME_CLOSE'
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
export abstract class TaskTracker {
|
|
21
28
|
interval: number;
|
|
22
29
|
lastReportTime = 0;
|
|
23
30
|
visible = true;
|
|
31
|
+
private reportCount = 0; // 添加上报次数计数
|
|
32
|
+
|
|
33
|
+
protected notifyIframeGameEvent = (eventName: string, data: any) => {
|
|
34
|
+
if (window.parent) {
|
|
35
|
+
window.parent.postMessage(
|
|
36
|
+
{
|
|
37
|
+
type: eventName,
|
|
38
|
+
data
|
|
39
|
+
},
|
|
40
|
+
'*'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 上报逻辑:第1次(5s)、第2次(10s)、第3次(15s),然后每3次(15s)上报一次
|
|
46
|
+
// reportCount=1: (5s)
|
|
47
|
+
// reportCount=2: (10s)
|
|
48
|
+
// reportCount=3: (15s)
|
|
49
|
+
// reportCount=4,5: 跳过
|
|
50
|
+
// reportCount=6: (30s)
|
|
51
|
+
// reportCount=7,8: 跳过
|
|
52
|
+
// reportCount=9: (45s)
|
|
53
|
+
private playGame = (duration: number) => {
|
|
54
|
+
this.reportCount++;
|
|
55
|
+
|
|
56
|
+
const shouldReport = this.reportCount <= 3 || (this.reportCount - 3) % 3 === 0;
|
|
57
|
+
|
|
58
|
+
if (shouldReport) {
|
|
59
|
+
this.reporter({
|
|
60
|
+
event: 'PLAY_GAME',
|
|
61
|
+
params: {
|
|
62
|
+
duration
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
this.tracker('PlayGame', { duration });
|
|
66
|
+
this.notifyIframeGameEvent(ECrossFrameEvent.JOLIBOX_GAME_PLAY, { duration });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
24
69
|
|
|
25
70
|
timer = this.createRAFTimer((duration) => {
|
|
26
|
-
this.
|
|
27
|
-
event: 'PLAY_GAME',
|
|
28
|
-
params: {
|
|
29
|
-
duration
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
this.tracker('PlayGame', { duration });
|
|
71
|
+
this.playGame(duration);
|
|
33
72
|
});
|
|
34
73
|
|
|
35
74
|
abstract reporter(point: TaskPoint): void;
|
|
@@ -51,6 +90,7 @@ export abstract class TaskTracker {
|
|
|
51
90
|
}
|
|
52
91
|
});
|
|
53
92
|
this.tracker('OpenGame', { duration: duration ?? 0 });
|
|
93
|
+
this.notifyIframeGameEvent(ECrossFrameEvent.JOLIBOX_GAME_OPEN, { duration: duration ?? 0 });
|
|
54
94
|
this.timer.start();
|
|
55
95
|
}
|
|
56
96
|
|
|
@@ -63,6 +103,7 @@ export abstract class TaskTracker {
|
|
|
63
103
|
}
|
|
64
104
|
});
|
|
65
105
|
this.tracker('CloseGame', { duration });
|
|
106
|
+
this.notifyIframeGameEvent(ECrossFrameEvent.JOLIBOX_GAME_CLOSE, { duration });
|
|
66
107
|
this.timer.stop();
|
|
67
108
|
}
|
|
68
109
|
|
package/src/h5/api/task.ts
CHANGED
|
@@ -2,6 +2,24 @@ import { createCommands, logger } from '@jolibox/common';
|
|
|
2
2
|
import { createAPI, registerCanIUse, t } from './base';
|
|
3
3
|
import { taskTracker } from '../report';
|
|
4
4
|
|
|
5
|
+
enum ECrossFrameEvent {
|
|
6
|
+
JOLIBOX_GAME_TASK_LEVEL_FINISHED = 'JOLIBOX_GAME_TASK_LEVEL_FINISHED',
|
|
7
|
+
JOLIBOX_GAME_TASK_GAME_PLAY_ENDED = 'JOLIBOX_GAME_TASK_GAME_PLAY_ENDED',
|
|
8
|
+
JOLIBOX_GAME_TASK_LEVEL_UPGRADE = 'JOLIBOX_GAME_TASK_LEVEL_UPGRADE'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const notifyIframeGameTaskEvent = (eventName: string, data: any) => {
|
|
12
|
+
if (window.parent) {
|
|
13
|
+
window.parent.postMessage(
|
|
14
|
+
{
|
|
15
|
+
type: eventName,
|
|
16
|
+
data
|
|
17
|
+
},
|
|
18
|
+
'*'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
5
23
|
const commands = createCommands();
|
|
6
24
|
|
|
7
25
|
const onLevelFinished = createAPI('levelFinished', {
|
|
@@ -17,6 +35,13 @@ const onLevelFinished = createAPI('levelFinished', {
|
|
|
17
35
|
implement: async (parmas) => {
|
|
18
36
|
const { levelId, duration, rating, score, variation } = parmas;
|
|
19
37
|
logger.info(`onLevelFinished`, duration, rating, score, variation);
|
|
38
|
+
notifyIframeGameTaskEvent(ECrossFrameEvent.JOLIBOX_GAME_TASK_LEVEL_FINISHED, {
|
|
39
|
+
levelId,
|
|
40
|
+
duration,
|
|
41
|
+
rating,
|
|
42
|
+
score,
|
|
43
|
+
variation
|
|
44
|
+
});
|
|
20
45
|
await Promise.all([
|
|
21
46
|
taskTracker.reporter({
|
|
22
47
|
event: 'COMPLETE_GAME_LEVEL',
|
|
@@ -52,6 +77,12 @@ const onGamePlayEnded = createAPI('gamePlayEnded', {
|
|
|
52
77
|
implement: async (params) => {
|
|
53
78
|
const { duration, rating, score, variation } = params;
|
|
54
79
|
logger.info(`onGamePlayEnded`, duration, rating, score, variation);
|
|
80
|
+
notifyIframeGameTaskEvent(ECrossFrameEvent.JOLIBOX_GAME_TASK_GAME_PLAY_ENDED, {
|
|
81
|
+
duration,
|
|
82
|
+
rating,
|
|
83
|
+
score,
|
|
84
|
+
variation
|
|
85
|
+
});
|
|
55
86
|
await Promise.all([
|
|
56
87
|
taskTracker.tracker('GamePlayEnded', {
|
|
57
88
|
duration,
|
|
@@ -81,6 +112,11 @@ const onLevelUpgrade = createAPI('levelUpgrade', {
|
|
|
81
112
|
})
|
|
82
113
|
),
|
|
83
114
|
implement: async ({ levelId, name }) => {
|
|
115
|
+
logger.info(`onLevelUpgrade`, levelId, name);
|
|
116
|
+
notifyIframeGameTaskEvent(ECrossFrameEvent.JOLIBOX_GAME_TASK_LEVEL_UPGRADE, {
|
|
117
|
+
levelId,
|
|
118
|
+
name
|
|
119
|
+
});
|
|
84
120
|
await Promise.all([
|
|
85
121
|
taskTracker.tracker('LevelUpgrade', {
|
|
86
122
|
name,
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 任务上报
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
import { context } from '@/common/context';
|
|
6
5
|
import { TaskTracker, TaskPoint } from '@/common/report/task-track';
|
|
7
|
-
import { EventEmitter, getApiHost } from '@jolibox/common';
|
|
6
|
+
import { EventEmitter, getApiHost, isBoolean } from '@jolibox/common';
|
|
8
7
|
import { innerFetch as fetch } from '../network';
|
|
9
8
|
import { applyNative } from '@jolibox/native-bridge';
|
|
10
9
|
import type { Track } from '.';
|
|
11
10
|
import type { TrackEvent } from '@jolibox/types';
|
|
11
|
+
import { getGlobalStorage, setGlobalStorage } from '../api/storage';
|
|
12
|
+
|
|
13
|
+
const REPORT_FIRST_OPEN_GAME = 'REPORT_FIRST_OPEN_GAME';
|
|
12
14
|
|
|
13
15
|
type NativeTaskPointEvent =
|
|
14
16
|
| 'OpenGame'
|
|
@@ -52,6 +54,7 @@ export class NativeTaskTracker extends TaskTracker {
|
|
|
52
54
|
if (extraParams) {
|
|
53
55
|
Object.assign(reportBody, extraParams);
|
|
54
56
|
}
|
|
57
|
+
|
|
55
58
|
const reportTask =
|
|
56
59
|
context.platform === 'android'
|
|
57
60
|
? fetch(`/api/base/app-event`, {
|
|
@@ -79,4 +82,18 @@ export class NativeTaskTracker extends TaskTracker {
|
|
|
79
82
|
tracker(event: TrackEvent, info: Record<string, unknown> | null = null) {
|
|
80
83
|
this.track(event, info);
|
|
81
84
|
}
|
|
85
|
+
|
|
86
|
+
start(duration?: number) {
|
|
87
|
+
super.start(duration);
|
|
88
|
+
this.tryReportOpenGamePlus();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private tryReportOpenGamePlus() {
|
|
92
|
+
getGlobalStorage(REPORT_FIRST_OPEN_GAME).then((res) => {
|
|
93
|
+
if (isBoolean(res.data) && res.data) {
|
|
94
|
+
this.tracker('OpenGame_2Plus');
|
|
95
|
+
}
|
|
96
|
+
setGlobalStorage(REPORT_FIRST_OPEN_GAME, true);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
82
99
|
}
|