AppSdk.ts
6.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import { EventEnum } from "../event/EventEnum";
import { EventCenter } from "../event/EventCenter";
import ObjectInstance from "../uitl/ObjectInstance";
export default class AppSdk {
private _width: number;
private _height: number;
private _channel: string;
private _version: string;
private _level: number;
private _gameConfig: number;
public pangolinId: string;
public adnetId: string;
init() {
this.getSystemInfo();
}
private get myBridge() {
if (MyBridge) {
return MyBridge;
}
}
/**获取基本版本信息以及手机的配置 */
private getSystemInfo(key: number = 0) {
let ret = this.myBridge.getSystemInfo(key);
let { w, h, versionName, channel, pangolin, adnet, level } = JSON.parse(ret);
[this._width, this._height, this._version,
this._channel, this.pangolinId,
this.adnetId, this._level] = [w, h, versionName, channel, pangolin, adnet, level];
}
initGameConfig() {
this._gameConfig = this.getGameConfig();
}
/**
* 震动
* @param key 0 短震动 1 长震动
*/
vibrate(key: number = 1) {
this.myBridge.openSystemFun(key);
}
/**隐藏启动屏 */
hideSplash() {
this.myBridge.hideSplash();
}
/**弹出提现 */
withDrawal() {
this.myBridge.withDrawal();
}
/**意见反馈 */
feedback() {
this.myBridge.feedback();
}
/**
* key 默认0 ,签到 1
*/
personal() {
this.myBridge.personal();
}
/**邀请好友*/
invitation() {
this.myBridge.invitation();
}
/**邀请好友*/
openReward() {
this.myBridge.openReward();
}
/**签到*/
openSignin() {
this.myBridge.openSingin();
}
putData(key: String, value: String) {
this.myBridge.putData(key, value);
}
/**
* @param key 存数据的时候的唯一key
* @return 存储的数据
* */
getData(key: String) {
let ret = this.myBridge.getData(key);
return JSON.parse(ret);
}
/**
* 获取金币配表
* @param key 1红包 2 摇一摇红包
*/
getGameConfig() {
let result = this.myBridge.getGameConfig();
return JSON.parse(result);
}
/**
* 要求发放金币
* @param key 1红包
*/
async addGold(key=1) {
return new Promise<any>(async (resolve, reject) => {
await this.myBridge.addGold(key, res => {
res = JSON.parse(res)
const { code, data, msg } = res;
if ('0' === code || !code) {
resolve(data)
} else {
reject(msg);
}
});
})
}
/**获取总金币 */
async myCoin() {
return new Promise<any>(async (resolve, reject) => {
await this.myBridge.myCoin(res => {
res = JSON.parse(res)
const { code, data, msg } = res;
if ('0' === code || !code) {
resolve(data['coin'])
} else {
reject(msg);
}
});
})
}
/**获取当前提现的档位 */
async minWithDrawal() {
return new Promise<any>(async (resolve, reject) => {
await this.myBridge.minWithDrawal(res => {
res = JSON.parse(res)
const { code, data, msg } = res;
if ('0' === code || !code) {
resolve(data['money'])
} else {
reject(msg);
}
});
})
}
/**上报埋点 */
appDotLog(key: string, value?) {
this.myBridge.appDotLog(key, value);
}
/**热云打点 */
appDotTracKing(key: string) {
this.myBridge.appDotTracKing(key);
}
setCallback(funName: string, pramas?: any) {
console.log('---------------setCallback---- this.myBridge---' + JSON.stringify(this.myBridge))
return new Promise((resolve, reject) => {
this.myBridge[funName](pramas, res => {
let { code, data } = JSON.parse(res);
if ('0' === code) {
resolve(data);
} else {
reject(0);
}
})
})
}
closeAdverDialog() {
this.myBridge.closeAdverDialog();
}
closeAdBanner() {
this.myBridge.closeAdBanner();
}
/**激励视频 */
showRewardVideoAd(value: IVideo, JBCallback: Function) {
this.myBridge.showRewardVideoAd(value, JBCallback)
}
/** 全屏广告*/
loadFullScreenVideoAd(data: any, JBCallback: Function) {
this.myBridge.showRewardVideoAd(data, JBCallback)
}
/**信息流广告 */
loadNativeExpressAd(data: any, JBCallback: Function) {
this.myBridge.loadNativeExpressAd(data, JBCallback)
}
/**banner */
loadBannerExpressAd(data: any, JBCallback: Function) {
this.myBridge.loadBannerExpressAd(data, JBCallback)
}
/**插屏广告 */
showInteractionExpressAd(data: any, JBCallback: Function) {
this.myBridge.showInteractionExpressAd(data, JBCallback)
}
get level() {
return this._level;
}
get width() {
return this._width;
}
get height() {
return this._height;
}
get version() {
return this._version;
}
get channel() {
return this._channel;
}
protected get bridge() {
return null;
}
get gameConfig() {
return this._gameConfig;
}
static get I(): AppSdk {
return ObjectInstance.get(AppSdk);
}
}
// //这里是浏览器环境下, 接收web传过来的消息
window.onMyBridgeReady = () => {
console.log("onMyBridgeReady load finish, cost:" + (new Date().getTime()) + "ms");
MyBridge.App.onResume = (...ret) => {
console.log(' laya onResume', ret)
}
MyBridge.App.onPause = (...ret) => {
console.log(' laya onPause', ret)
}
}
interface IVideo {
preloading: number,
type: number,
}