TTAdSdk.ts
2.81 KB
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
import { AppSdk } from "./AppSdk";
import ObjectInstance from "../uitl/ObjectInstance";
export default class TTAdSdk {
async showRewardVideoAd( preload: number = 0) {
let data = {
w: AppSdk.I.width,
h: AppSdk.I.height,
preloading: preload,
}
return new Promise((resolve, reject) => {
let isComplete = false;
AppSdk.I.callAppWithBack(ret => {
let { code, message } = JSON.parse(ret);
switch (code) {
case -1:
reject('error');
/**'暂无视频广告!每日0点重置'*/;
break;
case 200:
isComplete = true;
break;
case 100:
break;
case 0:
if (isComplete) {
resolve();
} else {
reject('unComplete');
}
break;
}
}, 'showRewardVideoAd', 1, JSON.stringify(data))
})
}
async loadFullScreenVideoAd( preload: number = 0) {
let data = {
preloading: preload,
}
return new Promise((resolve, reject) => {
let isComplete = false;
AppSdk.I.callAppWithBack(ret => {
}, 'loadFullScreenVideoAd', 1, JSON.stringify(data))
})
}
async loadNativeExpressAd( x, y, width, height) {
let scaleX = AppSdk.I.width / Laya.stage.width;
let scaleY = AppSdk.I.height / Laya.stage.height;
let data = {
w: width * scaleX,
h: height * scaleY,
left: x * scaleX,
top: y * scaleY
}
AppSdk.I.callAppWithBack(ret => {
}, 'loadNativeExpressAd', JSON.stringify(data))
}
async loadBannerExpressAd() {
let data = {
w: AppSdk.I.width,
h: AppSdk.I.width * 90 / 600,
}
AppSdk.I.callAppWithBack(ret => {
}, 'loadBannerExpressAd', 2, JSON.stringify(data))
}
hideAd() {
AppSdk.I.callApp('close_adver_dialog');
}
async showInteractionExpressAd( preload: number = 0) {
let data = {
w: AppSdk.I.width * 0.8,
h: AppSdk.I.height,
preloading: preload,
}
return new Promise((resolve, reject) => {
let isComplete = false;
AppSdk.I.callAppWithBack(ret => {
}, 'showInteractionExpressAd', JSON.stringify(data))
})
}
static get I(): TTAdSdk {
return ObjectInstance.get(TTAdSdk) as TTAdSdk;
}
}