AppSdk.ts
8.61 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import ObjectInstance from "../uitl/ObjectInstance";
import AdManager from "./AdManager";
import RedpacketModel from "./model/RedpacketModel";
import LuckDrawModel from "./LuckDrawModel";
import { AppSdkData } from "./sdkData/AppSdkData";
import { LuckDrawData } from "./sdkData/LuckDrawData";
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;
public uid: number
public isMyBridge: boolean
public isHide: boolean
static async init() {
AppSdk.I.getSystemInfo()
AppSdk.I.initGameConfig();
AdManager.I.init();//预加载广告
await ObjectInstance.get(RedpacketModel).init();
LuckDrawModel.I.init();
}
initSdk() {
return new Promise(async (resolve, reject) => {
await this.getUserInfo();
resolve(1)
})
}
private get myBridge() {
if (typeof MyBridge !== 'undefined') {
return MyBridge;
} else {
console.error(' no register myBridge!!!')
}
}
/**获取基本版本信息以及手机的配置 */
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];
}
private getUserInfo() {
return new Promise(async (resolve, reject) => {
console.log("-------------getUserInfo回调 前---------------")
this.myBridge.getGameUserInfo((ret) => {
console.log("-------------getUserInfo回调---------------", ret)
let res = JSON.parse(ret);
AppSdkData.I.initData(res);
resolve(1)
});
})
}
initGameConfig() {
this._gameConfig = this.getGameConfig();
}
/**
* 震动
* @param key 0 短震动 1 长震动
*/
vibrate(key: number = 0) {
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);
}
/**
* 获取游戏配置
*/
public getGameConfig() {
let result = this.myBridge.getGameConfig();
console.log("获取游戏配置",JSON.stringify(result))
LuckDrawData.I.initData(JSON.parse(result)['draw']);//转盘数据配置
return JSON.parse(result);
}
/**
* 要求发放金币
* @param key 1红包
*/
async addGold(key = 1) {
return new Promise<any>(async (resolve, reject) => {
await this.myBridge.addGold(key, res => {
console.log("要求发放金币",JSON.stringify(res))
res = JSON.parse(res)
const { code, data, msg } = res;
if ('0' === code || !code) {
resolve(data)
} else {
reject(msg);
}
});
})
}
/**
* 要求发放金币 可翻倍类型
*/
async rewardInfo() {
return new Promise<any>(async (resolve, reject) => {
this.myBridge.rewardInfo(res => {
res = JSON.parse(res)
const { code, data, msg } = res;
if ('0' === code || !code) {
resolve(data.coin);
} else {
reject(msg);
}
});
})
}
/**
* 获取双倍金币
* @param type 1原金币 2双倍金币
*/
async twofoldReward(type: number = 1) {
return new Promise<any>(async (resolve, reject) => {
this.myBridge.twofoldReward(type, res => {
res = JSON.parse(res)
const { code, data, msg } = res;
if ('0' === code || !code) {
resolve(data.coin);
} 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.loadFullScreenVideoAd(data, JBCallback)
}
/**信息流广告 */
loadNativeExpressAd(data: any, JBCallback: Function) {
this.myBridge.loadNativeExpressAd(data, JBCallback)
}
/**信息流广告- 优量汇 */
loadNativeAdYLH(data: any, JBCallback: Function) {
this.myBridge.loadNativeAd(data, JBCallback)
}
// 打开信息流-优量汇
openLoadNativeAdEvent(){
this.myBridge.openLoadNativeAdEvent()
}
/**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 = () => {
AppSdk.I.isMyBridge = true;
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,
}