TTAdSdk.ts
4.64 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import AppSdk from "./AppSdk";
import TeaSdk, { DotKey } from "./TeaSdk";
import ObjectInstance from "../uitl/ObjectInstance";
export default class TTAdSdk {
/**
*
* @param preload 0 直接加载;1 预加载
*/
async showRewardVideoAd(preload: number = 0, point: string = DotKey.proloading) {
let data = {
type: 1,
preloading: preload,
}
return new Promise((resolve, reject) => {
let isComplete = false;
AppSdk.I.showRewardVideoAd(data, ret => {
console.log("视频回调", JSON.stringify(ret))
let { code, msg } = JSON.parse(ret);
switch (code) {
case -1:
reject('error');
/**'暂无视频广告!每日0点重置'*/;
break;
case 0:
break;
case 100:
break;
case 102:
isComplete = true;
break;
case 101:
console.log("视频点了关闭")
if (isComplete) {
console.log("视频观看完闭并点了关闭")
// TeaSdk.I.dot(DotKey.reward_ad, { from: point });
resolve(1);
} else {
reject('unComplete');
}
break;
default:
reject('加载失败');
// TeaSdk.I.dot(DotKey.reward_ad_fail, { from: point, code: code });
break;
}
})
})
}
async loadFullScreenVideoAd(preload: number = 0) {
let data = {
w: AppSdk.I.width,
h: AppSdk.I.width * 90 / 600,
preloading: preload,
type: 1
}
return new Promise((resolve, reject) => {
AppSdk.I.loadFullScreenVideoAd(JSON.stringify(data), res => {
resolve(res)
})
})
}
async loadNativeExpressAd(x, y, width, height, preload: number = 0) {
let scaleX = AppSdk.I.width / Laya.stage.width;
let scaleY = AppSdk.I.height / Laya.stage.height;
let data = {
type: 1,
preloading: preload,
w: width * scaleX,
h: height * scaleY,
left: x * scaleX,
top: y * scaleY
}
AppSdk.I.loadNativeExpressAd(JSON.stringify(data), res => {
return Promise.resolve(res)
})
}
async loadNativeAdYLH(x, y, width, height, preload: number = 0) {
return new Promise((resolve, reject) => {
let scaleX = AppSdk.I.width / Laya.stage.width;
let scaleY = AppSdk.I.height / Laya.stage.height;
let data = {
type: 1,
preloading: preload,
w: width * scaleX,
h: height * scaleY,
left: x * scaleX,
bottom: AppSdk.I.height - height * scaleY - y * scaleY,
}
// console.log(JSON.stringify(data))
// console.log(AppSdk.I.height, height, y, scaleY)
AppSdk.I.loadNativeAdYLH(JSON.stringify(data), res => {
resolve(JSON.parse(res))
})
})
}
openLoadNativeAdEvent() {
AppSdk.I.openLoadNativeAdEvent()
}
async loadBannerExpressAd(preload: number = 0) {
let data = {
w: AppSdk.I.width,
h: AppSdk.I.width * 90 / 600,
preloading: preload,
type: 1
}
return new Promise((resolve, reject) => {
AppSdk.I.loadBannerExpressAd(JSON.stringify(data), res => {
resolve(res)
})
})
}
closeAdverDialog() {
AppSdk.I.closeAdverDialog();
}
closeAdBanner() {
AppSdk.I.closeAdBanner();
}
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.showInteractionExpressAd(JSON.stringify(data), res => {
resolve(res)
})
})
}
static get I(): TTAdSdk {
return ObjectInstance.get(TTAdSdk) as TTAdSdk;
}
}