TTAdSdk.ts
3.1 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
94
95
96
97
98
99
100
101
102
103
104
105
106
import ObjectInstance from "../uitl/ObjectInstance";
import PcSdk from "./PcSdk";
export default class TTAdSdk {
/**
*
* @param preload 0 直接加载;1 预加载
*/
async showRewardVideoAd(preload: number = 0) {
let data = {
type: 1,
preloading: preload,
}
return new Promise((resolve, reject) => {
let isComplete = false;
PcSdk.I.showRewardVideoAd(data, ret => {
let { code, message } = JSON.parse(ret);
switch (code) {
case -1:
reject('error');
/**'暂无视频广告!每日0点重置'*/;
break;
case 102:
isComplete = true;
break;
case 101:
if (isComplete) {
resolve();
} else {
reject('unComplete');
}
break;
}
})
})
}
async loadFullScreenVideoAd(preload: number = 0) {
let data = {
w: PcSdk.I.width,
h: PcSdk.I.width * 90 / 600,
preloading: preload,
type: 1
}
return new Promise((resolve, reject) => {
PcSdk.I.loadFullScreenVideoAd(JSON.stringify(data),res=>{
resolve(res)
})
})
}
async loadNativeExpressAd(x, y, width, height, type = 1, preload: number = 0) {
let scaleX = PcSdk.I.width / Laya.stage.width;
let scaleY = PcSdk.I.height / Laya.stage.height;
let data = {
type: type,
preloading: preload,
w: width * scaleX,
h: height * scaleY,
left: x * scaleX,
top: y * scaleY
}
PcSdk.I.loadNativeExpressAd(JSON.stringify(data),res=>{
return Promise.resolve(res)
})
}
async loadBannerExpressAd(preload: number = 0) {
let data = {
w: PcSdk.I.width,
h: PcSdk.I.width * 90 / 600,
preloading: preload,
type: 1
}
return new Promise((resolve, reject) => {
PcSdk.I.loadBannerExpressAd(JSON.stringify(data),res=>{
resolve(res)
})
})
}
closeAdverDialog() {
PcSdk.I.closeAdverDialog();
}
closeAdBanner() {
PcSdk.I.closeAdBanner();
}
async showInteractionExpressAd(preload: number = 0) {
let data = {
w: PcSdk.I.width * 0.8,
h: PcSdk.I.height,
preloading: preload,
}
return new Promise((resolve, reject) => {
let isComplete = false;
PcSdk.I.showInteractionExpressAd(JSON.stringify(data),res=>{
resolve(res)
})
})
}
static get I(): TTAdSdk {
return ObjectInstance.get(TTAdSdk) as TTAdSdk;
}
}