@jolibox/implement 1.1.34 → 1.1.36-beta.1
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 +9 -6
- package/dist/common/context/index.d.ts +2 -1
- package/dist/h5/api/index.d.ts +1 -0
- package/dist/h5/api/platformAdsHandle/GamedistributionAdsHandler.d.ts +25 -0
- package/dist/h5/api/runtime.d.ts +1 -0
- package/dist/index.js +9 -9
- package/dist/index.native.js +29 -29
- package/dist/native/api/index.d.ts +1 -0
- package/dist/native/api/runtime.d.ts +1 -0
- package/implement.build.log +2 -2
- package/package.json +5 -5
- package/src/common/context/index.ts +8 -7
- package/src/h5/api/ads.ts +5 -0
- package/src/h5/api/index.ts +1 -0
- package/src/h5/api/platformAdsHandle/GamedistributionAdsHandler.ts +123 -0
- package/src/h5/api/runtime.ts +11 -0
- package/src/h5/bootstrap/index.ts +6 -5
- package/src/native/api/index.ts +1 -0
- package/src/native/api/runtime.ts +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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.1.
|
|
3
|
+
> @jolibox/implement@1.1.36-beta.1 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.1.
|
|
7
|
+
> @jolibox/implement@1.1.36-beta.1 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.1.
|
|
4
|
+
"version": "1.1.36-beta.1",
|
|
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.
|
|
10
|
-
"@jolibox/types": "1.1.
|
|
11
|
-
"@jolibox/native-bridge": "1.1.
|
|
12
|
-
"@jolibox/ads": "1.1.
|
|
9
|
+
"@jolibox/common": "1.1.36-beta.1",
|
|
10
|
+
"@jolibox/types": "1.1.36-beta.1",
|
|
11
|
+
"@jolibox/native-bridge": "1.1.36-beta.1",
|
|
12
|
+
"@jolibox/ads": "1.1.36-beta.1",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
14
|
"@jolibox/ui": "1.0.0",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
@@ -40,7 +40,8 @@ export enum SDKEnvironment {
|
|
|
40
40
|
jolibox = 'jolibox', // 默认
|
|
41
41
|
dlightek = 'dlightek', // 传音
|
|
42
42
|
funmax = 'funmax', // 小米
|
|
43
|
-
huaweiQuick = 'huaweiQuick' // 华为快应用
|
|
43
|
+
huaweiQuick = 'huaweiQuick', // 华为快应用
|
|
44
|
+
gamedistribution = 'gamedistribution'
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
type Viewport = {
|
|
@@ -49,8 +50,7 @@ type Viewport = {
|
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
function hasMetaTag(name: string, content: string): boolean {
|
|
52
|
-
|
|
53
|
-
return metaTag !== null;
|
|
53
|
+
return document?.head.querySelector(`meta[name="${name}"][content="${content}"]`) !== null;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const wrapContext = () => {
|
|
@@ -136,14 +136,15 @@ const wrapContext = () => {
|
|
|
136
136
|
return env.deviceInfo.lang;
|
|
137
137
|
},
|
|
138
138
|
get sdkEnvironment(): SDKEnvironment {
|
|
139
|
-
|
|
140
|
-
if (hasDlightekMeta) {
|
|
139
|
+
if (hasMetaTag('dlightek', 'jolibox')) {
|
|
141
140
|
return SDKEnvironment.dlightek;
|
|
142
141
|
}
|
|
143
|
-
|
|
144
|
-
if (huaweiQuick) {
|
|
142
|
+
if (urlParams.get('huaweiQuick') === 'true') {
|
|
145
143
|
return SDKEnvironment.huaweiQuick;
|
|
146
144
|
}
|
|
145
|
+
if (hasMetaTag('gamedistribution', 'jolibox')) {
|
|
146
|
+
return SDKEnvironment.gamedistribution;
|
|
147
|
+
}
|
|
147
148
|
return SDKEnvironment.jolibox;
|
|
148
149
|
},
|
|
149
150
|
get viewport(): Viewport {
|
package/src/h5/api/ads.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { context, SDKEnvironment } from '@/common/context';
|
|
|
20
20
|
import '../rewards';
|
|
21
21
|
import DlightekAdsHandler from './platformAdsHandle/DlightekAdsHandler';
|
|
22
22
|
import HuaweiQuickAdsHandler from './platformAdsHandle/HuaweiQuickAdsHandler';
|
|
23
|
+
import GamedistributionAdsHandler from './platformAdsHandle/GamedistributionAdsHandler';
|
|
23
24
|
|
|
24
25
|
declare global {
|
|
25
26
|
interface Window {
|
|
@@ -98,6 +99,10 @@ class H5AdsManager {
|
|
|
98
99
|
this.cacheHandler = HuaweiQuickAdsHandler.getInstance();
|
|
99
100
|
break;
|
|
100
101
|
}
|
|
102
|
+
case SDKEnvironment.gamedistribution: {
|
|
103
|
+
this.cacheHandler = GamedistributionAdsHandler.getInstance();
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
101
106
|
default: {
|
|
102
107
|
const joliboxAds = new JoliboxAdsForGame(this.context);
|
|
103
108
|
this.cacheHandler = new JoliboxAdsHandler(joliboxAds);
|
package/src/h5/api/index.ts
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAdsInitParams,
|
|
3
|
+
IAdConfigParams,
|
|
4
|
+
IAdBreakParams,
|
|
5
|
+
IAdUnitParams,
|
|
6
|
+
JoliboxAdsForGame
|
|
7
|
+
} from '@jolibox/ads';
|
|
8
|
+
import { IAdsHandler } from '../ads';
|
|
9
|
+
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
// gamedistribution
|
|
13
|
+
gdsdk: {
|
|
14
|
+
preloadAd: (type: string) => Promise<void>;
|
|
15
|
+
showAd: (type: string) => Promise<{ adType: string; args: { success: boolean } }>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default class GamedistributionAdsHandler implements IAdsHandler {
|
|
21
|
+
private static instance: GamedistributionAdsHandler;
|
|
22
|
+
|
|
23
|
+
private constructor() {
|
|
24
|
+
// 不需要初始化
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static getInstance(): GamedistributionAdsHandler {
|
|
28
|
+
if (!GamedistributionAdsHandler.instance) {
|
|
29
|
+
GamedistributionAdsHandler.instance = new GamedistributionAdsHandler();
|
|
30
|
+
}
|
|
31
|
+
return GamedistributionAdsHandler.instance;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getAdsInstance(): JoliboxAdsForGame {
|
|
35
|
+
return GamedistributionAdsHandler.getInstance() as unknown as JoliboxAdsForGame;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
init(): void {
|
|
39
|
+
// 不需要初始化
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
adConfig(params: IAdConfigParams): void {
|
|
43
|
+
if (params.onReady) params.onReady();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
adBreak(params: IAdBreakParams): Promise<void> | void {
|
|
47
|
+
try {
|
|
48
|
+
if (params.type === 'reward') {
|
|
49
|
+
window.gdsdk
|
|
50
|
+
.preloadAd('rewarded')
|
|
51
|
+
.then(() => {
|
|
52
|
+
params.beforeReward?.(() => {
|
|
53
|
+
if (params.beforeAd) params.beforeAd();
|
|
54
|
+
|
|
55
|
+
window.gdsdk
|
|
56
|
+
.showAd('rewarded')
|
|
57
|
+
.then((response) => {
|
|
58
|
+
if (response?.args?.success) {
|
|
59
|
+
params.adViewed?.();
|
|
60
|
+
} else {
|
|
61
|
+
params.adDismissed?.();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (params.afterAd) params.afterAd();
|
|
65
|
+
|
|
66
|
+
params.adBreakDone?.({
|
|
67
|
+
breakType: params.type,
|
|
68
|
+
breakName: params.name,
|
|
69
|
+
breakFormat: 'reward',
|
|
70
|
+
breakStatus: response?.args?.success ? 'viewed' : 'dismissed'
|
|
71
|
+
});
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
console.log('showReward error => ', error);
|
|
75
|
+
|
|
76
|
+
params.adBreakDone?.({
|
|
77
|
+
breakType: params.type,
|
|
78
|
+
breakName: params.name,
|
|
79
|
+
breakFormat: 'reward',
|
|
80
|
+
breakStatus: 'noAdPreloaded'
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
})
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
console.log('preloadAd error => ', error);
|
|
87
|
+
|
|
88
|
+
params.adBreakDone?.({
|
|
89
|
+
breakType: params.type,
|
|
90
|
+
breakName: params.name,
|
|
91
|
+
breakFormat: 'reward',
|
|
92
|
+
breakStatus: 'noAdPreloaded'
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
if (params.type !== 'preroll' && params.beforeAd) params.beforeAd();
|
|
97
|
+
window.gdsdk.showAd('interstitial').then(() => {
|
|
98
|
+
if (params.type !== 'preroll' && params.afterAd) params.afterAd();
|
|
99
|
+
|
|
100
|
+
params.adBreakDone?.({
|
|
101
|
+
breakType: params.type,
|
|
102
|
+
breakName: params.type === 'preroll' ? undefined : params.name,
|
|
103
|
+
breakFormat: 'interstitial',
|
|
104
|
+
breakStatus: 'viewed'
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.log('adBreak error => ', e);
|
|
110
|
+
|
|
111
|
+
params.adBreakDone?.({
|
|
112
|
+
breakType: params.type,
|
|
113
|
+
breakName: params.type === 'preroll' ? undefined : params.name,
|
|
114
|
+
breakFormat: params.type === 'reward' ? 'reward' : 'interstitial',
|
|
115
|
+
breakStatus: 'error'
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
adUnit(): void {
|
|
121
|
+
// 不需要初始化
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createCommands } from '@jolibox/common';
|
|
2
|
+
|
|
3
|
+
const commands = createCommands();
|
|
4
|
+
|
|
5
|
+
commands.registerCommand('RuntimeSDK.loadFinishedEvent', () => {
|
|
6
|
+
console.log('RuntimeSDK.loadFinishedEvent');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
commands.registerCommand('RuntimeSDK.loadProgressEvent', (progress) => {
|
|
10
|
+
console.log('RuntimeSDK.loadProgressEvent', progress);
|
|
11
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { hostEmitter } from '@jolibox/common';
|
|
1
|
+
import { hostEmitter, InternalGlobalJSError, UserCustomError } from '@jolibox/common';
|
|
2
2
|
import { taskTracker, track } from '../report';
|
|
3
3
|
import { onFCP, onLCP, onTTFB } from 'web-vitals';
|
|
4
4
|
import { context } from '@/common/context';
|
|
5
|
+
import { httpClientManager } from '../http';
|
|
6
|
+
import { IResponse } from '@jolibox/ads';
|
|
7
|
+
import { reportError } from '@/common/report/errors/report';
|
|
5
8
|
|
|
6
9
|
function trackPerformance() {
|
|
7
10
|
onFCP((metric) => {
|
|
@@ -30,10 +33,8 @@ function trackPerformance() {
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
function addDomContentLoaded() {
|
|
33
|
-
hostEmitter.on('onDocumentReady', (startTime: number) => {
|
|
34
|
-
hostEmitter.emit('LifecycleEvent.onReady', {
|
|
35
|
-
isLogin: false
|
|
36
|
-
});
|
|
36
|
+
hostEmitter.on('onDocumentReady', async (startTime: number) => {
|
|
37
|
+
hostEmitter.emit('LifecycleEvent.onReady', { isLogin: false });
|
|
37
38
|
|
|
38
39
|
if (context.mpType === 'game') {
|
|
39
40
|
taskTracker.start(Date.now() - startTime);
|
package/src/native/api/index.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createCommands } from '@jolibox/common';
|
|
2
|
+
import { t, createSyncAPI } from './base';
|
|
3
|
+
import { emitNative } from '@jolibox/native-bridge';
|
|
4
|
+
import { context } from '@/common/context';
|
|
5
|
+
|
|
6
|
+
const commands = createCommands();
|
|
7
|
+
|
|
8
|
+
const onLoadFinished = createSyncAPI('onLoadFinished', {
|
|
9
|
+
implement: () => {
|
|
10
|
+
emitNative('cpLoadFinishEvent', {}, context.webviewId, true);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
let lastProgress: number | null = null;
|
|
15
|
+
let scheduled = false;
|
|
16
|
+
let lastEmitTime = 0;
|
|
17
|
+
const THROTTLE_INTERVAL = 200;
|
|
18
|
+
|
|
19
|
+
function notifyProgress(progress: number) {
|
|
20
|
+
emitNative('cpLoadProgressEvent', { progress }, context.webviewId, true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const onLoadProgress = createSyncAPI('onLoadProgress', {
|
|
24
|
+
paramsSchema: t.tuple(t.number()),
|
|
25
|
+
implement: (progress) => {
|
|
26
|
+
lastProgress = progress;
|
|
27
|
+
if (!scheduled) {
|
|
28
|
+
scheduled = true;
|
|
29
|
+
requestAnimationFrame(function frame() {
|
|
30
|
+
const now = Date.now();
|
|
31
|
+
if (now - lastEmitTime >= THROTTLE_INTERVAL) {
|
|
32
|
+
if (lastProgress !== null) {
|
|
33
|
+
notifyProgress(lastProgress);
|
|
34
|
+
lastEmitTime = now;
|
|
35
|
+
lastProgress = null;
|
|
36
|
+
}
|
|
37
|
+
scheduled = false;
|
|
38
|
+
} else {
|
|
39
|
+
requestAnimationFrame(frame);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
commands.registerCommand('RuntimeSDK.loadFinishedEvent', onLoadFinished);
|
|
47
|
+
|
|
48
|
+
commands.registerCommand('RuntimeSDK.loadProgressEvent', onLoadProgress);
|