@chiyou/minigame-framework 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +66 -0
  2. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.d.ts +78 -0
  3. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.js +230 -0
  4. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.d.ts +31 -0
  5. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.js +224 -0
  6. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.d.ts +34 -0
  7. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.js +524 -0
  8. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.d.ts +34 -0
  9. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.js +631 -0
  10. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.d.ts +33 -0
  11. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.js +460 -0
  12. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.d.ts +31 -0
  13. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.js +227 -0
  14. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.d.ts +33 -0
  15. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.js +458 -0
  16. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.d.ts +35 -0
  17. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.js +770 -0
  18. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.d.ts +33 -0
  19. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.js +519 -0
  20. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.d.ts +33 -0
  21. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.js +492 -0
  22. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.d.ts +33 -0
  23. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.js +695 -0
  24. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.d.ts +34 -0
  25. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.js +597 -0
  26. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.d.ts +33 -0
  27. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.js +458 -0
  28. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.d.ts +51 -0
  29. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.js +17 -0
  30. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.d.ts +45 -0
  31. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.js +555 -0
  32. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.d.ts +44 -0
  33. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.js +148 -0
  34. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.d.ts +48 -0
  35. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.js +715 -0
  36. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.d.ts +44 -0
  37. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.js +296 -0
  38. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.d.ts +45 -0
  39. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.js +284 -0
  40. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.d.ts +44 -0
  41. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.js +283 -0
  42. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.d.ts +43 -0
  43. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.js +406 -0
  44. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.d.ts +43 -0
  45. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.js +248 -0
  46. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.d.ts +44 -0
  47. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.js +517 -0
  48. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.d.ts +44 -0
  49. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.js +295 -0
  50. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.d.ts +55 -0
  51. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.js +964 -0
  52. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.d.ts +44 -0
  53. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.js +295 -0
  54. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.d.ts +44 -0
  55. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.js +393 -0
  56. package/dist/Framework/Definition/AdDefinition.d.ts +130 -0
  57. package/dist/Framework/Definition/AdDefinition.js +208 -0
  58. package/dist/Framework/Definition/FrameworkBase.d.ts +13 -0
  59. package/dist/Framework/Definition/FrameworkBase.js +23 -0
  60. package/dist/Framework/Definition/PrivacyDefinition.d.ts +51 -0
  61. package/dist/Framework/Definition/PrivacyDefinition.js +70 -0
  62. package/dist/Framework/Definition/SocialDefinition.d.ts +16 -0
  63. package/dist/Framework/Definition/SocialDefinition.js +2 -0
  64. package/dist/Framework/Definition/SystemDefinition.d.ts +43 -0
  65. package/dist/Framework/Definition/SystemDefinition.js +28 -0
  66. package/dist/Framework/Definition/UIDefinition.d.ts +6 -0
  67. package/dist/Framework/Definition/UIDefinition.js +7 -0
  68. package/dist/Framework/Definition/UserDefinition.d.ts +14 -0
  69. package/dist/Framework/Definition/UserDefinition.js +10 -0
  70. package/dist/Framework/Manager/AdMgr.d.ts +57 -0
  71. package/dist/Framework/Manager/AdMgr.js +684 -0
  72. package/dist/Framework/Manager/AudioMgr.d.ts +28 -0
  73. package/dist/Framework/Manager/AudioMgr.js +265 -0
  74. package/dist/Framework/Manager/BaseMgr.d.ts +18 -0
  75. package/dist/Framework/Manager/BaseMgr.js +114 -0
  76. package/dist/Framework/Manager/EventMgr.d.ts +18 -0
  77. package/dist/Framework/Manager/EventMgr.js +90 -0
  78. package/dist/Framework/Manager/ExcelMgr.d.ts +24 -0
  79. package/dist/Framework/Manager/ExcelMgr.js +156 -0
  80. package/dist/Framework/Manager/LifeCycleMgr.d.ts +20 -0
  81. package/dist/Framework/Manager/LifeCycleMgr.js +110 -0
  82. package/dist/Framework/Manager/NodePoolMgr.d.ts +53 -0
  83. package/dist/Framework/Manager/NodePoolMgr.js +279 -0
  84. package/dist/Framework/Manager/PrivacyMgr.d.ts +15 -0
  85. package/dist/Framework/Manager/PrivacyMgr.js +176 -0
  86. package/dist/Framework/Manager/ResMgr.d.ts +49 -0
  87. package/dist/Framework/Manager/ResMgr.js +337 -0
  88. package/dist/Framework/Manager/SocialMgr.d.ts +23 -0
  89. package/dist/Framework/Manager/SocialMgr.js +220 -0
  90. package/dist/Framework/Manager/SystemMgr.d.ts +24 -0
  91. package/dist/Framework/Manager/SystemMgr.js +222 -0
  92. package/dist/Framework/Manager/TimerMgr.d.ts +11 -0
  93. package/dist/Framework/Manager/TimerMgr.js +63 -0
  94. package/dist/Framework/Manager/UIMgr.d.ts +33 -0
  95. package/dist/Framework/Manager/UIMgr.js +223 -0
  96. package/dist/Framework/Manager/UserMgr.d.ts +15 -0
  97. package/dist/Framework/Manager/UserMgr.js +148 -0
  98. package/dist/Framework/Utils/BezierUtils.d.ts +49 -0
  99. package/dist/Framework/Utils/BezierUtils.js +247 -0
  100. package/dist/Framework/Utils/CSVUtils.d.ts +35 -0
  101. package/dist/Framework/Utils/CSVUtils.js +341 -0
  102. package/dist/Framework/Utils/LogUtils.d.ts +7 -0
  103. package/dist/Framework/Utils/LogUtils.js +32 -0
  104. package/dist/Framework/Utils/NumberUtils.d.ts +16 -0
  105. package/dist/Framework/Utils/NumberUtils.js +44 -0
  106. package/dist/Framework/Utils/TaskUtils.d.ts +10 -0
  107. package/dist/Framework/Utils/TaskUtils.js +24 -0
  108. package/dist/Framework/Utils/TimeUtils.d.ts +19 -0
  109. package/dist/Framework/Utils/TimeUtils.js +33 -0
  110. package/dist/Framework/Utils/WXBizDataCryptUtils.d.ts +12 -0
  111. package/dist/Framework/Utils/WXBizDataCryptUtils.js +37 -0
  112. package/dist/index.d.ts +30 -0
  113. package/dist/index.js +35 -0
  114. package/package.json +40 -0
@@ -0,0 +1,34 @@
1
+ import { AbsAdAdapter } from "./AbsAdAdapter";
2
+ export declare class AdAdapterXiaoMi extends AbsAdAdapter {
3
+ static TAG: string;
4
+ private xmInterstitialAd;
5
+ private xmRewardedVideoAd;
6
+ private xmBannerAds;
7
+ private xmCustomAds;
8
+ init(interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void;
9
+ createBannerAd(adUnitId: string): boolean;
10
+ destroyBannerAd(adUnitId: string): void;
11
+ showBannerAd(adUnitId: string): void;
12
+ hideBannerAd(adUnitId: string): void;
13
+ createInterstitialAd(): void;
14
+ showInterstitialAd(): void;
15
+ destroyInterstitialAd(): void;
16
+ isIntersititialAdShowing(): boolean;
17
+ protected _loadInterstitialAd(isShowImmediately: boolean): void;
18
+ protected _showInterstitialAd(): void;
19
+ createRewardedVideoAd(): void;
20
+ showRewardedVideoAd(): void;
21
+ destroyRewardedVideoAd(): void;
22
+ isRewardedVideoAdLoaded(): boolean;
23
+ isRewardedVideoAdShowing(): boolean;
24
+ protected _loadRewardedVideoAd(isShowImmediately: boolean): void;
25
+ protected _showRewardedVideoAd(): void;
26
+ createCustomAd(adUnitId: string): boolean;
27
+ destroyCustomAd(adUnitId: string): void;
28
+ showCustomAd(adUnitId: string): void;
29
+ hideCustomAd(adUnitId: string): void;
30
+ createPortalAd(adUnitId: string): void;
31
+ destroyPortalAd(adUnitId: string): void;
32
+ showPortalAd(adUnitId: string): void;
33
+ hidePortalAd(adUnitId: string): void;
34
+ }
@@ -0,0 +1,597 @@
1
+ import { InterstitialAd_Callback_Status, RewardedVideoAd_Callback_Status, AdDefinition } from "../../Definition/AdDefinition";
2
+ import { PlatformID } from "../../Definition/SystemDefinition";
3
+ import { LogUtils } from "../../Utils/LogUtils";
4
+ import { AbsAdAdapter, InterstitialAdStatus, RewardedVideoAdStatus } from "./AbsAdAdapter";
5
+ class XMBannerAd {
6
+ constructor(adUnitId, ad, isFirstLoad) {
7
+ this.unitId = adUnitId;
8
+ this.ad = ad;
9
+ this.errorListener = null;
10
+ this.loadListener = null;
11
+ this.resizeListener = null;
12
+ this.isRecreating = false;
13
+ this.isFirstLoad = isFirstLoad;
14
+ }
15
+ destroy() {
16
+ if (this.ad !== null) {
17
+ this.errorListener = null;
18
+ this.loadListener = null;
19
+ if (this.resizeListener !== null) {
20
+ this.ad.offResize(this.resizeListener);
21
+ this.resizeListener = null;
22
+ }
23
+ this.ad.destroy();
24
+ this.ad = null;
25
+ }
26
+ this.isRecreating = false;
27
+ }
28
+ }
29
+ class XMInterstitialAd {
30
+ constructor(adUnitId, callback) {
31
+ this.unitId = adUnitId;
32
+ this.ad = null;
33
+ this.status = InterstitialAdStatus.Status_Init;
34
+ this.callback = callback;
35
+ this.errorListener = null;
36
+ this.loadListener = null;
37
+ this.closeListener = null;
38
+ this.isShowImmediately = false;
39
+ }
40
+ destroy() {
41
+ if (this.ad !== null) {
42
+ if (this.errorListener !== null) {
43
+ this.ad.offError(this.errorListener);
44
+ this.errorListener = null;
45
+ }
46
+ if (this.loadListener !== null) {
47
+ this.ad.offLoad(this.loadListener);
48
+ this.loadListener = null;
49
+ }
50
+ if (this.closeListener !== null) {
51
+ this.ad.offClose(this.closeListener);
52
+ this.closeListener = null;
53
+ }
54
+ this.ad.destroy();
55
+ this.ad = null;
56
+ }
57
+ this.isShowImmediately = false;
58
+ this.status = InterstitialAdStatus.Status_Destroyed;
59
+ }
60
+ }
61
+ class XMRewardedVideoAd {
62
+ constructor(adUnitId, callback) {
63
+ this.unitId = adUnitId;
64
+ this.ad = null;
65
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
66
+ this.callback = callback;
67
+ this.errorListener = null;
68
+ this.loadListener = null;
69
+ this.closeListener = null;
70
+ this.isShowImmediately = false;
71
+ }
72
+ destroy() {
73
+ if (this.ad !== null) {
74
+ if (this.errorListener !== null) {
75
+ this.ad.offError(this.errorListener);
76
+ this.errorListener = null;
77
+ }
78
+ if (this.loadListener !== null) {
79
+ this.ad.offLoad(this.loadListener);
80
+ this.loadListener = null;
81
+ }
82
+ if (this.closeListener !== null) {
83
+ this.ad.offClose(this.closeListener);
84
+ this.closeListener = null;
85
+ }
86
+ this.ad.destroy();
87
+ this.ad = null;
88
+ }
89
+ this.isShowImmediately = false;
90
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
91
+ }
92
+ }
93
+ class XMCustomAd {
94
+ constructor(adUnitId, ad, isFirstLoad) {
95
+ this.unitId = adUnitId;
96
+ this.ad = ad;
97
+ this.errorListener = null;
98
+ this.loadListener = null;
99
+ this.isRecreating = false;
100
+ this.isFirstLoad = isFirstLoad;
101
+ }
102
+ destroy() {
103
+ if (this.ad !== null) {
104
+ this.errorListener = null;
105
+ this.loadListener = null;
106
+ this.ad.destroy();
107
+ this.ad = null;
108
+ }
109
+ this.isRecreating = false;
110
+ }
111
+ }
112
+ export class AdAdapterXiaoMi extends AbsAdAdapter {
113
+ constructor() {
114
+ super(...arguments);
115
+ this.xmInterstitialAd = null;
116
+ this.xmRewardedVideoAd = null;
117
+ this.xmBannerAds = [];
118
+ this.xmCustomAds = [];
119
+ }
120
+ init(interstitialAdUnitId, interstitialAdCallback, rewardedVideoAdUnitId, rewardedVideoAdCallback) {
121
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "init()");
122
+ this.xmInterstitialAd = new XMInterstitialAd(interstitialAdUnitId, interstitialAdCallback);
123
+ this.xmRewardedVideoAd = new XMRewardedVideoAd(rewardedVideoAdUnitId, rewardedVideoAdCallback);
124
+ this.xmBannerAds = [];
125
+ this.xmCustomAds = [];
126
+ }
127
+ createBannerAd(adUnitId) {
128
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createBannerAd()");
129
+ let isFirstLoad = true;
130
+ for (let i = 0; i < this.xmBannerAds.length; i++) {
131
+ if (this.xmBannerAds[i].unitId === adUnitId) {
132
+ isFirstLoad = this.xmBannerAds[i].isFirstLoad;
133
+ break;
134
+ }
135
+ }
136
+ this.destroyBannerAd(adUnitId);
137
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createBannerAd() adUnitId=" + adUnitId);
138
+ let bannerAdInfo = AdDefinition.AdInfoConfig.BannerAd_Info;
139
+ if (bannerAdInfo === null || !bannerAdInfo.shouldShow) {
140
+ return false;
141
+ }
142
+ let bannerAdPlatformInfo = AdDefinition.BannerAdStyleConfig.get(PlatformID.ID_QuickGame_XiaoMi);
143
+ if (bannerAdPlatformInfo === null) {
144
+ return false;
145
+ }
146
+ let bannerAdParam = {
147
+ adUnitId: adUnitId,
148
+ };
149
+ if (bannerAdPlatformInfo.canAutoRefresh) {
150
+ bannerAdParam.adIntervals = bannerAdPlatformInfo.refreshInterval;
151
+ }
152
+ let bannerAd = window["qg"].createBannerAd(bannerAdParam);
153
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createBannerAd() " + (bannerAd !== null ? "success" : "fail"));
154
+ LogUtils.Instance.log("", bannerAd);
155
+ if (!bannerAd) {
156
+ return false;
157
+ }
158
+ let xmBannerAd = new XMBannerAd(adUnitId, bannerAd, isFirstLoad);
159
+ this.xmBannerAds.push(xmBannerAd);
160
+ xmBannerAd.errorListener = (err) => {
161
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.onError()");
162
+ if (err) {
163
+ LogUtils.Instance.log("", err);
164
+ }
165
+ if (!xmBannerAd.isRecreating) {
166
+ xmBannerAd.isRecreating = true;
167
+ this.scheduleOnce(() => {
168
+ xmBannerAd.isRecreating = false;
169
+ this.createBannerAd(adUnitId);
170
+ }, 15);
171
+ }
172
+ };
173
+ xmBannerAd.ad.onError(xmBannerAd.errorListener);
174
+ xmBannerAd.resizeListener = (res) => {
175
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.onResize()");
176
+ if (res) {
177
+ LogUtils.Instance.log("", res);
178
+ }
179
+ };
180
+ xmBannerAd.ad.onResize(xmBannerAd.resizeListener);
181
+ xmBannerAd.loadListener = () => {
182
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.onLoad()");
183
+ if (xmBannerAd.isFirstLoad) {
184
+ xmBannerAd.isFirstLoad = false;
185
+ }
186
+ if (this.adMgr.isPermanentAdShowing()) {
187
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmBannerAd.ad.show()");
188
+ xmBannerAd.ad.show();
189
+ }
190
+ };
191
+ xmBannerAd.ad.onLoad(xmBannerAd.loadListener);
192
+ if (!bannerAdPlatformInfo.canAutoRefresh) {
193
+ if (!xmBannerAd.isRecreating) {
194
+ xmBannerAd.isRecreating = true;
195
+ this.scheduleOnce(() => {
196
+ xmBannerAd.isRecreating = false;
197
+ this.createBannerAd(adUnitId);
198
+ }, bannerAdPlatformInfo.refreshInterval);
199
+ }
200
+ }
201
+ return true;
202
+ }
203
+ destroyBannerAd(adUnitId) {
204
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyBannerAd(): adUnitId=" + adUnitId);
205
+ let index = -1;
206
+ for (let i = 0; i < this.xmBannerAds.length; i++) {
207
+ if (this.xmBannerAds[i].unitId === adUnitId) {
208
+ index = i;
209
+ break;
210
+ }
211
+ }
212
+ if (index >= 0) {
213
+ this.xmBannerAds[index].destroy();
214
+ this.xmBannerAds.splice(index, 1);
215
+ }
216
+ }
217
+ showBannerAd(adUnitId) {
218
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showBannerAd(): adUnitId=" + adUnitId);
219
+ for (let i = 0; i < this.xmBannerAds.length; i++) {
220
+ if (this.xmBannerAds[i].unitId === adUnitId) {
221
+ this.xmBannerAds[i].ad.show();
222
+ break;
223
+ }
224
+ }
225
+ }
226
+ hideBannerAd(adUnitId) {
227
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "hideBannerAd(): adUnitId=" + adUnitId);
228
+ // 小米Banner隐藏后不再展示,故不做操作
229
+ // for (let i = 0; i < this.xmBannerAds.length; i++) {
230
+ // if (this.xmBannerAds[i].unitId === adUnitId) {
231
+ // this.xmBannerAds[i].ad.hide();
232
+ // break;
233
+ // }
234
+ // }
235
+ }
236
+ createInterstitialAd() {
237
+ // 小米插屏广告就是不要destory,直接再次create
238
+ // this.destroyInterstitialAd();
239
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createInterstitialAd() adUnitId=" + this.xmInterstitialAd.unitId);
240
+ let interstitialAd = window["qg"].createInterstitialAd({
241
+ adUnitId: this.xmInterstitialAd.unitId
242
+ });
243
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createInterstitialAd() " + (interstitialAd !== null ? "success" : "fail"));
244
+ LogUtils.Instance.log("", interstitialAd);
245
+ if (!interstitialAd) {
246
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Error;
247
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
248
+ return;
249
+ }
250
+ this.xmInterstitialAd.ad = interstitialAd;
251
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Init;
252
+ this.xmInterstitialAd.errorListener = (err) => {
253
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.onError()");
254
+ if (err) {
255
+ LogUtils.Instance.log("", err);
256
+ }
257
+ if (this.xmInterstitialAd.status !== InterstitialAdStatus.Status_Watching) {
258
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Error;
259
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Error);
260
+ }
261
+ };
262
+ this.xmInterstitialAd.ad.onError(this.xmInterstitialAd.errorListener);
263
+ this.xmInterstitialAd.loadListener = () => {
264
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.onLoad()");
265
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Loaded;
266
+ if (this.xmInterstitialAd.isShowImmediately) {
267
+ this.xmInterstitialAd.isShowImmediately = false;
268
+ this._showInterstitialAd();
269
+ }
270
+ };
271
+ this.xmInterstitialAd.ad.onLoad(this.xmInterstitialAd.loadListener);
272
+ this.xmInterstitialAd.closeListener = () => {
273
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.onClose()");
274
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Watched;
275
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Close);
276
+ this.createInterstitialAd();
277
+ };
278
+ this.xmInterstitialAd.ad.onClose(this.xmInterstitialAd.closeListener);
279
+ }
280
+ showInterstitialAd() {
281
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showInterstitialAd()");
282
+ if (this.xmInterstitialAd.ad === null) {
283
+ return;
284
+ }
285
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.status=" + InterstitialAdStatus[this.xmInterstitialAd.status]);
286
+ switch (this.xmInterstitialAd.status) {
287
+ case InterstitialAdStatus.Status_Destroyed:
288
+ case InterstitialAdStatus.Status_Watching:
289
+ case InterstitialAdStatus.Status_StartToWatch:
290
+ break;
291
+ case InterstitialAdStatus.Status_Loaded:
292
+ this._showInterstitialAd();
293
+ break;
294
+ case InterstitialAdStatus.Status_Watched:
295
+ case InterstitialAdStatus.Status_Init:
296
+ case InterstitialAdStatus.Status_Error:
297
+ this.createInterstitialAd();
298
+ break;
299
+ default:
300
+ break;
301
+ }
302
+ }
303
+ destroyInterstitialAd() {
304
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyInterstitialAd()");
305
+ this.xmInterstitialAd.destroy();
306
+ }
307
+ isIntersititialAdShowing() {
308
+ if (this.xmInterstitialAd.ad === null) {
309
+ return false;
310
+ }
311
+ if (this.xmInterstitialAd.status === InterstitialAdStatus.Status_Watching) {
312
+ return true;
313
+ }
314
+ return false;
315
+ }
316
+ _loadInterstitialAd(isShowImmediately) {
317
+ }
318
+ _showInterstitialAd() {
319
+ if (this.xmInterstitialAd.status !== InterstitialAdStatus.Status_Loaded) {
320
+ return;
321
+ }
322
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_StartToWatch;
323
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.show()");
324
+ this.xmInterstitialAd.ad.show()
325
+ .then(() => {
326
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.show() success");
327
+ if (this.xmInterstitialAd.status === InterstitialAdStatus.Status_StartToWatch) {
328
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Watching;
329
+ this.xmInterstitialAd.callback(InterstitialAd_Callback_Status.Status_Watching);
330
+ }
331
+ }).catch((err) => {
332
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmInterstitialAd.ad.show() error");
333
+ if (err) {
334
+ LogUtils.Instance.log("", err);
335
+ }
336
+ if (this.xmInterstitialAd.status === InterstitialAdStatus.Status_StartToWatch) {
337
+ this.xmInterstitialAd.status = InterstitialAdStatus.Status_Loaded;
338
+ }
339
+ });
340
+ }
341
+ createRewardedVideoAd() {
342
+ this.destroyRewardedVideoAd();
343
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createRewardedVideoAd() adUnitId=" + this.xmRewardedVideoAd.unitId);
344
+ let rewardedVideoAd = window["qg"].createRewardedVideoAd({
345
+ adUnitId: this.xmRewardedVideoAd.unitId
346
+ });
347
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createRewardedVideoAd() " + (rewardedVideoAd !== null ? "success" : "fail"));
348
+ LogUtils.Instance.log("", rewardedVideoAd);
349
+ if (!rewardedVideoAd) {
350
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
351
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
352
+ return;
353
+ }
354
+ this.xmRewardedVideoAd.ad = rewardedVideoAd;
355
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Init;
356
+ this.xmRewardedVideoAd.errorListener = (err) => {
357
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.onError()");
358
+ if (err) {
359
+ LogUtils.Instance.log("", err);
360
+ }
361
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Watching) {
362
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
363
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
364
+ }
365
+ };
366
+ this.xmRewardedVideoAd.ad.onError(this.xmRewardedVideoAd.errorListener);
367
+ this.xmRewardedVideoAd.loadListener = () => {
368
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.onLoad()");
369
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
370
+ if (this.xmRewardedVideoAd.isShowImmediately) {
371
+ this.xmRewardedVideoAd.isShowImmediately = false;
372
+ this._showRewardedVideoAd();
373
+ }
374
+ };
375
+ this.xmRewardedVideoAd.ad.onLoad(this.xmRewardedVideoAd.loadListener);
376
+ this.xmRewardedVideoAd.closeListener = (res) => {
377
+ let isEnded = (res !== null) ? res.isEnded : false;
378
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.onClose()");
379
+ LogUtils.Instance.log("", "isEnded=" + isEnded);
380
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watched;
381
+ if (isEnded) {
382
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Complete);
383
+ }
384
+ else {
385
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Giveup);
386
+ }
387
+ this.scheduleOnce(() => {
388
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
389
+ this._loadRewardedVideoAd(false);
390
+ }
391
+ }, 2);
392
+ };
393
+ this.xmRewardedVideoAd.ad.onClose(this.xmRewardedVideoAd.closeListener);
394
+ this.scheduleOnce(() => {
395
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
396
+ this._loadRewardedVideoAd(false);
397
+ }
398
+ }, 2);
399
+ }
400
+ showRewardedVideoAd() {
401
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showRewardedVideoAd()");
402
+ if (this.xmRewardedVideoAd.ad === null) {
403
+ return;
404
+ }
405
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.status=" + RewardedVideoAdStatus[this.xmRewardedVideoAd.status]);
406
+ switch (this.xmRewardedVideoAd.status) {
407
+ case RewardedVideoAdStatus.Status_Destroyed:
408
+ case RewardedVideoAdStatus.Status_Watching:
409
+ case RewardedVideoAdStatus.Status_StartToWatch:
410
+ break;
411
+ case RewardedVideoAdStatus.Status_Loaded:
412
+ this._showRewardedVideoAd();
413
+ break;
414
+ case RewardedVideoAdStatus.Status_Watched:
415
+ case RewardedVideoAdStatus.Status_Error:
416
+ case RewardedVideoAdStatus.Status_Init:
417
+ this._loadRewardedVideoAd(true);
418
+ break;
419
+ default:
420
+ break;
421
+ }
422
+ }
423
+ destroyRewardedVideoAd() {
424
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyRewardedVideoAd()");
425
+ this.xmRewardedVideoAd.destroy();
426
+ }
427
+ isRewardedVideoAdLoaded() {
428
+ if (this.xmRewardedVideoAd.ad === null) {
429
+ return false;
430
+ }
431
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_Loaded) {
432
+ return true;
433
+ }
434
+ return false;
435
+ }
436
+ isRewardedVideoAdShowing() {
437
+ if (this.xmRewardedVideoAd.ad === null) {
438
+ return false;
439
+ }
440
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_Watching) {
441
+ return true;
442
+ }
443
+ return false;
444
+ }
445
+ _loadRewardedVideoAd(isShowImmediately) {
446
+ this.xmRewardedVideoAd.isShowImmediately = isShowImmediately;
447
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.load()");
448
+ this.xmRewardedVideoAd.ad.load().then(() => {
449
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.load() success");
450
+ }).catch((err) => {
451
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.load() error");
452
+ if (err) {
453
+ LogUtils.Instance.log("", err);
454
+ }
455
+ });
456
+ }
457
+ _showRewardedVideoAd() {
458
+ if (this.xmRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
459
+ return;
460
+ }
461
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_StartToWatch;
462
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.show()");
463
+ this.xmRewardedVideoAd.ad.show()
464
+ .then(() => {
465
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.show() success");
466
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
467
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watching;
468
+ this.xmRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Watching);
469
+ }
470
+ }).catch((err) => {
471
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmRewardedVideoAd.ad.show() error");
472
+ if (err) {
473
+ LogUtils.Instance.log("", err);
474
+ }
475
+ if (this.xmRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
476
+ this.xmRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
477
+ }
478
+ });
479
+ }
480
+ createCustomAd(adUnitId) {
481
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createCustomAd()");
482
+ let isFirstLoad = true;
483
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
484
+ if (this.xmCustomAds[i].unitId === adUnitId) {
485
+ isFirstLoad = this.xmCustomAds[i].isFirstLoad;
486
+ break;
487
+ }
488
+ }
489
+ this.destroyCustomAd(adUnitId);
490
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "createCustomAd() adUnitId=" + adUnitId);
491
+ let customAdInfo = AdDefinition.AdInfoConfig.CustomAd_Info;
492
+ if (customAdInfo === null || !customAdInfo.shouldShow) {
493
+ return;
494
+ }
495
+ let customAdPlatformInfo = AdDefinition.CustomAdStyleConfig.get(PlatformID.ID_QuickGame_XiaoMi);
496
+ if (customAdPlatformInfo === null) {
497
+ return false;
498
+ }
499
+ let customAdPostion = this.calcCustomAdPosition(customAdInfo, customAdPlatformInfo);
500
+ let customAdParam = {
501
+ adUnitId: adUnitId,
502
+ style: {
503
+ left: customAdPostion.left,
504
+ top: customAdPostion.top,
505
+ width: customAdPostion.realWidth,
506
+ height: customAdPostion.realHeight,
507
+ }
508
+ };
509
+ if (customAdPlatformInfo.canAutoRefresh) {
510
+ customAdParam.adIntervals = customAdPlatformInfo.refreshInterval;
511
+ }
512
+ let customAd = window["qg"].createCustomAd(customAdParam);
513
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "qg.createCustomAd() " + (customAd !== null ? "success" : "fail"));
514
+ LogUtils.Instance.log("", customAd);
515
+ if (!customAd) {
516
+ return false;
517
+ }
518
+ let xmCustomAd = new XMCustomAd(adUnitId, customAd, isFirstLoad);
519
+ this.xmCustomAds.push(xmCustomAd);
520
+ xmCustomAd.errorListener = (err) => {
521
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmCustomAd.ad.onError()");
522
+ if (err) {
523
+ LogUtils.Instance.log("", err);
524
+ }
525
+ if (!xmCustomAd.isRecreating) {
526
+ xmCustomAd.isRecreating = true;
527
+ this.scheduleOnce(() => {
528
+ xmCustomAd.isRecreating = false;
529
+ this.createCustomAd(adUnitId);
530
+ }, 15);
531
+ }
532
+ };
533
+ xmCustomAd.ad.onError(xmCustomAd.errorListener);
534
+ xmCustomAd.loadListener = () => {
535
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmCustomAd.ad.onLoad()");
536
+ if (xmCustomAd.isFirstLoad) {
537
+ xmCustomAd.isFirstLoad = false;
538
+ }
539
+ if (this.adMgr.isPermanentAdShowing()) {
540
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "xmCustomAd.ad.show()");
541
+ xmCustomAd.ad.show();
542
+ }
543
+ };
544
+ xmCustomAd.ad.onLoad(xmCustomAd.loadListener);
545
+ if (!customAdPlatformInfo.canAutoRefresh) {
546
+ if (!xmCustomAd.isRecreating) {
547
+ xmCustomAd.isRecreating = true;
548
+ this.scheduleOnce(() => {
549
+ xmCustomAd.isRecreating = false;
550
+ this.createCustomAd(adUnitId);
551
+ }, customAdPlatformInfo.refreshInterval);
552
+ }
553
+ }
554
+ return true;
555
+ }
556
+ destroyCustomAd(adUnitId) {
557
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "destroyCustomAd(): adUnitId=" + adUnitId);
558
+ let index = -1;
559
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
560
+ if (this.xmCustomAds[i].unitId === adUnitId) {
561
+ index = i;
562
+ break;
563
+ }
564
+ }
565
+ if (index >= 0) {
566
+ this.xmCustomAds[index].destroy();
567
+ this.xmCustomAds.splice(index, 1);
568
+ }
569
+ }
570
+ showCustomAd(adUnitId) {
571
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "showCustomAd(): adUnitId=" + adUnitId);
572
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
573
+ if (this.xmCustomAds[i].unitId === adUnitId) {
574
+ this.xmCustomAds[i].ad.show();
575
+ break;
576
+ }
577
+ }
578
+ }
579
+ hideCustomAd(adUnitId) {
580
+ LogUtils.Instance.log(AdAdapterXiaoMi.TAG, "hideCustomAd(): adUnitId=" + adUnitId);
581
+ for (let i = 0; i < this.xmCustomAds.length; i++) {
582
+ if (this.xmCustomAds[i].unitId === adUnitId) {
583
+ this.xmCustomAds[i].ad.hide();
584
+ break;
585
+ }
586
+ }
587
+ }
588
+ createPortalAd(adUnitId) {
589
+ }
590
+ destroyPortalAd(adUnitId) {
591
+ }
592
+ showPortalAd(adUnitId) {
593
+ }
594
+ hidePortalAd(adUnitId) {
595
+ }
596
+ }
597
+ AdAdapterXiaoMi.TAG = "AdAdapterXiaoMi";
@@ -0,0 +1,33 @@
1
+ import { AbsAdAdapter } from './AbsAdAdapter';
2
+ export declare class AdAdapterZhiFuBao extends AbsAdAdapter {
3
+ static TAG: string;
4
+ private zfbInterstitialAd;
5
+ private zfbRewardedVideoAd;
6
+ private zfbBannerAds;
7
+ init(interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void;
8
+ createBannerAd(adUnitId: string): boolean;
9
+ destroyBannerAd(adUnitId: string): void;
10
+ showBannerAd(adUnitId: string): void;
11
+ hideBannerAd(adUnitId: string): void;
12
+ createInterstitialAd(): void;
13
+ showInterstitialAd(): void;
14
+ destroyInterstitialAd(): void;
15
+ isIntersititialAdShowing(): boolean;
16
+ protected _loadInterstitialAd(isShowImmediately: boolean): void;
17
+ protected _showInterstitialAd(): void;
18
+ createRewardedVideoAd(): void;
19
+ showRewardedVideoAd(): void;
20
+ destroyRewardedVideoAd(): void;
21
+ isRewardedVideoAdLoaded(): boolean;
22
+ isRewardedVideoAdShowing(): boolean;
23
+ protected _loadRewardedVideoAd(isShowImmediately: boolean): void;
24
+ protected _showRewardedVideoAd(): void;
25
+ createCustomAd(adUnitId: string): boolean;
26
+ destroyCustomAd(adUnitId: string): void;
27
+ showCustomAd(adUnitId: string): void;
28
+ hideCustomAd(adUnitId: string): void;
29
+ createPortalAd(adUnitId: string): void;
30
+ destroyPortalAd(adUnitId: string): void;
31
+ showPortalAd(adUnitId: string): void;
32
+ hidePortalAd(adUnitId: string): void;
33
+ }