drgame-cc 1.0.14 → 1.0.16
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.
- package/README.md +176 -351
- package/build-templates/web-mobile/splash_en - /345/211/257/346/234/254.png +0 -0
- package/{tvui → drres}/config/default.json +30 -11
- package/drscript/BtnExtra.ts +17 -0
- package/drscript/Define.ts +22 -0
- package/drscript/ExitWin.ts +39 -0
- package/drscript/Info.ts +75 -0
- package/drscript/Loader.ts +89 -0
- package/drscript/PlatformAdapter.ts +165 -0
- package/drscript/README - /345/211/257/346/234/254.md" +814 -0
- package/drscript/README.md +814 -0
- package/drscript/ad/AdManager.ts +174 -0
- package/drscript/ad/AdManager.ts.meta +10 -0
- package/drscript/ad/AdSlot.ts +44 -0
- package/drscript/ad/AdSlot.ts.meta +10 -0
- package/drscript/ad/AggregateAdProvider.ts +148 -0
- package/drscript/ad/AggregateAdProvider.ts.meta +10 -0
- package/drscript/ad/IAdProvider.ts +39 -0
- package/drscript/ad/IAdProvider.ts.meta +10 -0
- package/drscript/ad/MockAdProvider.ts +36 -0
- package/drscript/ad/MockAdProvider.ts.meta +10 -0
- package/drscript/ad/SelfAdProvider.ts +41 -0
- package/drscript/ad/SelfAdProvider.ts.meta +10 -0
- package/drscript/ad-sdk/README.md +344 -0
- package/drscript/ad-sdk/README.md.meta +6 -0
- package/drscript/ad-sdk/ad-sdk.d.ts +59 -0
- package/drscript/ad-sdk/ad-sdk.d.ts.meta +6 -0
- package/drscript/ad-sdk/ad-sdk.js +322 -0
- package/drscript/ad-sdk/ad-sdk.js.meta +10 -0
- package/drscript/ad-sdk/adapters/xiaomi-adapter.d.ts +29 -0
- package/drscript/ad-sdk/adapters/xiaomi-adapter.d.ts.meta +6 -0
- package/drscript/ad-sdk/adapters/xiaomi-adapter.js +449 -0
- package/drscript/ad-sdk/adapters/xiaomi-adapter.js.meta +10 -0
- package/drscript/ad-sdk/adapters.meta +13 -0
- package/drscript/ad-sdk/event-emitter.d.ts +12 -0
- package/drscript/ad-sdk/event-emitter.d.ts.meta +6 -0
- package/drscript/ad-sdk/event-emitter.js +65 -0
- package/drscript/ad-sdk/event-emitter.js.meta +10 -0
- package/drscript/ad-sdk/leaderboard/leaderboard.d.ts +23 -0
- package/drscript/ad-sdk/leaderboard/leaderboard.d.ts.meta +6 -0
- package/drscript/ad-sdk/leaderboard/leaderboard.js +193 -0
- package/drscript/ad-sdk/leaderboard/leaderboard.js.meta +10 -0
- package/drscript/ad-sdk/leaderboard.meta +13 -0
- package/drscript/ad-sdk/package.json +46 -0
- package/drscript/ad-sdk/package.json.meta +6 -0
- package/drscript/ad-sdk/reporters/reporter.d.ts +40 -0
- package/drscript/ad-sdk/reporters/reporter.d.ts.meta +6 -0
- package/drscript/ad-sdk/reporters/reporter.js +198 -0
- package/drscript/ad-sdk/reporters/reporter.js.meta +10 -0
- package/drscript/ad-sdk/reporters/superset-lewo.js +413 -0
- package/drscript/ad-sdk/reporters/superset-lewo.js.meta +10 -0
- package/drscript/ad-sdk/reporters.meta +13 -0
- package/drscript/ad-sdk/types/enums.d.ts +64 -0
- package/drscript/ad-sdk/types/enums.d.ts.meta +6 -0
- package/drscript/ad-sdk/types/enums.js +111 -0
- package/drscript/ad-sdk/types/enums.js.meta +10 -0
- package/drscript/ad-sdk/types/index.d.ts +6 -0
- package/drscript/ad-sdk/types/index.d.ts.meta +6 -0
- package/drscript/ad-sdk/types/index.js +15 -0
- package/drscript/ad-sdk/types/index.js.meta +10 -0
- package/drscript/ad-sdk/types/interfaces.d.ts +333 -0
- package/drscript/ad-sdk/types/interfaces.d.ts.meta +6 -0
- package/drscript/ad-sdk/types.meta +13 -0
- package/drscript/config/TvUiConfig.ts +155 -0
- package/drscript/config/TvUiConfig.ts.meta +10 -0
- package/drscript/config/TvUiConfigManager.ts +133 -0
- package/drscript/config/TvUiConfigManager.ts.meta +10 -0
- package/drscript/core/BackManager.ts +40 -0
- package/drscript/core/BackManager.ts.meta +10 -0
- package/drscript/core/NativeBridge.ts +137 -0
- package/drscript/core/NativeBridge.ts.meta +10 -0
- package/drscript/core/TvUi.ts +69 -0
- package/drscript/core/TvUi.ts.meta +10 -0
- package/drscript/core/TvUiRoot.ts +137 -0
- package/drscript/core/TvUiRoot.ts.meta +10 -0
- package/drscript/focus/FocusItem.ts +57 -0
- package/drscript/focus/FocusItem.ts.meta +10 -0
- package/drscript/focus/FocusManager.ts +538 -0
- package/drscript/focus/FocusManager.ts.meta +10 -0
- package/drscript/focus/FocusScope.ts +10 -0
- package/drscript/focus/FocusScope.ts.meta +10 -0
- package/drscript/focus/FocusVisualLayer.ts +238 -0
- package/drscript/focus/FocusVisualLayer.ts.meta +10 -0
- package/drscript/icon/IconConfig.ts +7 -0
- package/drscript/icon/IconConfig.ts.meta +10 -0
- package/drscript/icon/IconManager.ts +97 -0
- package/drscript/icon/IconManager.ts.meta +10 -0
- package/drscript/input/KeyCodeAdapter.ts +23 -0
- package/drscript/input/KeyCodeAdapter.ts.meta +10 -0
- package/drscript/input/RemoteInputManager.ts +105 -0
- package/drscript/input/RemoteInputManager.ts.meta +10 -0
- package/drscript/toast/ToastComponent.ts +35 -0
- package/drscript/toast/ToastComponent.ts.meta +10 -0
- package/drscript/toast/ToastManager.ts +66 -0
- package/drscript/toast/ToastManager.ts.meta +10 -0
- package/drscript/toast/TvExitConfirmDialog.ts +334 -0
- package/drscript/toast/TvExitConfirmDialog.ts.meta +10 -0
- package/drscript/toast/UIFunctions.ts +150 -0
- package/drscript/toast/UIFunctions.ts.meta +10 -0
- package/package.json +3 -2
- package/scripts/postinstall.js +99 -67
- package/bin/drgame.d.ts +0 -632
- package/bin/drgame.js +0 -3010
- /package/{tvui → drres}/config/default.json.meta +0 -0
- /package/{tvui → drres}/config.meta +0 -0
- /package/{tvui → drres}/icons/pointer-blue-60.png +0 -0
- /package/{tvui → drres}/icons/pointer-blue-60.png.meta +0 -0
- /package/{tvui → drres}/icons/pointer-pink-60.png +0 -0
- /package/{tvui → drres}/icons/pointer-pink-60.png.meta +0 -0
- /package/{tvui → drres}/icons/pointer-yellow-60.png +0 -0
- /package/{tvui → drres}/icons/pointer-yellow-60.png.meta +0 -0
- /package/{tvui → drres}/icons.meta +0 -0
- /package/{tvui → drres}/prefab/ExitWin.prefab +0 -0
- /package/{tvui → drres}/prefab/ExitWin.prefab.meta +0 -0
- /package/{tvui → drres}/prefab/Toast.prefab +0 -0
- /package/{tvui → drres}/prefab/Toast.prefab.meta +0 -0
- /package/{tvui → drres}/prefab.meta +0 -0
- /package/{tvui → drres}/tv_exit/Toast.png +0 -0
- /package/{tvui → drres}/tv_exit/Toast.png.meta +0 -0
- /package/{tvui → drres}/tv_exit/close.png +0 -0
- /package/{tvui → drres}/tv_exit/close.png.meta +0 -0
- /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/346/231/256/351/200/232.png" +0 -0
- /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/346/231/256/351/200/232.png.meta" +0 -0
- /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/351/200/211/344/270/255.png" +0 -0
- /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/351/200/211/344/270/255.png.meta" +0 -0
- /package/{tvui → drres}/tv_exit//346/241/206.png" +0 -0
- /package/{tvui → drres}/tv_exit//346/241/206.png.meta" +0 -0
- /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/346/231/256/351/200/232.png" +0 -0
- /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/346/231/256/351/200/232.png.meta" +0 -0
- /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/351/200/211/344/270/255.png" +0 -0
- /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/351/200/211/344/270/255.png.meta" +0 -0
- /package/{tvui → drres}/tv_exit//351/200/200/345/207/272/346/270/270/346/210/217.png" +0 -0
- /package/{tvui → drres}/tv_exit//351/200/200/345/207/272/346/270/270/346/210/217.png.meta" +0 -0
- /package/{tvui → drres}/tv_exit.meta +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import TvUiConfigManager from "../config/TvUiConfigManager";
|
|
2
|
+
import { TvUiAdChannelConfig, TvUiAdSlotConfig } from "../config/TvUiConfig";
|
|
3
|
+
import IAdProvider, { AdRuntimeData, AdShowOptions, AdShowResult } from "./IAdProvider";
|
|
4
|
+
import AggregateAdProvider from "./AggregateAdProvider";
|
|
5
|
+
import SelfAdProvider from "./SelfAdProvider";
|
|
6
|
+
import MockAdProvider from "./MockAdProvider";
|
|
7
|
+
|
|
8
|
+
export default class AdManager {
|
|
9
|
+
private static providers: { [type: string]: IAdProvider } = {};
|
|
10
|
+
|
|
11
|
+
public static init() {
|
|
12
|
+
this.providers = {};
|
|
13
|
+
this.registerProvider(new AggregateAdProvider());
|
|
14
|
+
this.registerProvider(new SelfAdProvider());
|
|
15
|
+
this.registerProvider(new MockAdProvider());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static registerProvider(provider: IAdProvider) {
|
|
19
|
+
if (!provider || !provider.type) return;
|
|
20
|
+
this.providers[provider.type] = provider;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static showSlot(slotId: string, options: AdShowOptions = {}): Promise<boolean> {
|
|
24
|
+
let slotConfig = this.getSlotConfig(slotId);
|
|
25
|
+
if (!slotConfig || slotConfig.enabled === false) {
|
|
26
|
+
if (options.onFail) options.onFail({ message: "ad slot disabled", slotId: slotId });
|
|
27
|
+
return Promise.resolve(false);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let channels = this.getSortedChannels(slotConfig);
|
|
31
|
+
return this.showByChannels(slotId, slotConfig, options, channels, 0, null).then((result: AdShowResult) => {
|
|
32
|
+
if (result && (result.status == "success" || result.status == "loaded")) return true;
|
|
33
|
+
if (result && result.status == "closed") return false;
|
|
34
|
+
if (options.onFail) {
|
|
35
|
+
options.onFail((result && result.error) || { message: "all ad channels failed", slotId: slotId });
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static hideSlot(slotId: string) {
|
|
42
|
+
let slotConfig = this.getSlotConfig(slotId);
|
|
43
|
+
let channels = slotConfig ? this.getSortedChannels(slotConfig) : [];
|
|
44
|
+
if (channels.length > 0) {
|
|
45
|
+
for (let i = 0; i < channels.length; i++) {
|
|
46
|
+
let channel = channels[i];
|
|
47
|
+
let provider = channel && this.providers[channel.type];
|
|
48
|
+
if (provider) provider.hide(slotId, channel);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (let type in this.providers) {
|
|
53
|
+
if (this.providers.hasOwnProperty(type)) this.providers[type].hide(slotId);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static refreshSlot(slotId: string, options: AdShowOptions = {}) {
|
|
58
|
+
this.hideSlot(slotId);
|
|
59
|
+
return this.showSlot(slotId, options);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public static showReward(options: AdShowOptions): Promise<boolean> {
|
|
63
|
+
options = this.mergeOptions(options, { mode: "reward" });
|
|
64
|
+
return this.showSlot((options && options.slotId) || "reward", options);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public static showPopup(options: AdShowOptions): Promise<boolean> {
|
|
68
|
+
options = this.mergeOptions(options, { mode: "popup" });
|
|
69
|
+
return this.showSlot((options && options.slotId) || (options && options.trigger_scene) || "popup", options);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static hidePopup(scene?: string) {
|
|
73
|
+
this.hideSlot(scene || "popup");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private static getSlotConfig(slotId: string): TvUiAdSlotConfig {
|
|
77
|
+
let config = TvUiConfigManager.getConfig();
|
|
78
|
+
let ads = config.ads || {};
|
|
79
|
+
return ads[slotId] || ads["popup"] || null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private static showByChannels(
|
|
83
|
+
slotId: string,
|
|
84
|
+
slotConfig: TvUiAdSlotConfig,
|
|
85
|
+
options: AdShowOptions,
|
|
86
|
+
channels: TvUiAdChannelConfig[],
|
|
87
|
+
index: number,
|
|
88
|
+
lastError: any
|
|
89
|
+
): Promise<AdShowResult> {
|
|
90
|
+
if (index >= channels.length) {
|
|
91
|
+
return Promise.resolve({ status: "failed", error: lastError || { message: "ad channels empty", slotId: slotId } });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let channel = channels[index];
|
|
95
|
+
if (!channel || channel.enabled === false) {
|
|
96
|
+
return this.showByChannels(slotId, slotConfig, options, channels, index + 1, lastError);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let provider = this.providers[channel.type];
|
|
100
|
+
if (!provider) {
|
|
101
|
+
return this.showByChannels(slotId, slotConfig, options, channels, index + 1, { message: "ad provider missing", channel: channel.type });
|
|
102
|
+
}
|
|
103
|
+
if (!provider.isAvailable()) {
|
|
104
|
+
return this.showByChannels(slotId, slotConfig, options, channels, index + 1, { message: "ad provider unavailable", channel: channel.type });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let data: AdRuntimeData = {
|
|
108
|
+
slotId: slotId,
|
|
109
|
+
slotConfig: slotConfig,
|
|
110
|
+
channel: channel,
|
|
111
|
+
options: options
|
|
112
|
+
};
|
|
113
|
+
return provider.load(data).then((runtimeData: AdRuntimeData) => {
|
|
114
|
+
return provider.show(runtimeData);
|
|
115
|
+
}).then((result: AdShowResult) => {
|
|
116
|
+
if (!result || result.status == "failed") {
|
|
117
|
+
if (options && options.mode == "reward") return result || <AdShowResult>{ status: "failed", error: lastError };
|
|
118
|
+
return this.showByChannels(slotId, slotConfig, options, channels, index + 1, result && (result.error || result.data));
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}).catch((error: any) => {
|
|
122
|
+
if (options && options.mode == "reward") return <AdShowResult>{ status: "failed", error: error };
|
|
123
|
+
return this.showByChannels(slotId, slotConfig, options, channels, index + 1, error);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static getSortedChannels(slotConfig: TvUiAdSlotConfig): TvUiAdChannelConfig[] {
|
|
128
|
+
let channels: TvUiAdChannelConfig[] = [];
|
|
129
|
+
let configured = (slotConfig && slotConfig.channels) || [];
|
|
130
|
+
for (let i = 0; i < configured.length; i++) {
|
|
131
|
+
if (configured[i]) channels.push(configured[i]);
|
|
132
|
+
}
|
|
133
|
+
if (slotConfig && slotConfig.fallback) {
|
|
134
|
+
channels.push(this.normalizeFallback(slotConfig.fallback));
|
|
135
|
+
}
|
|
136
|
+
if (!this.hasChannelType(channels, "mock")) {
|
|
137
|
+
channels.push({ type: "mock", priority: 100 });
|
|
138
|
+
}
|
|
139
|
+
channels.sort((a: TvUiAdChannelConfig, b: TvUiAdChannelConfig) => {
|
|
140
|
+
return this.getPriority(a) - this.getPriority(b);
|
|
141
|
+
});
|
|
142
|
+
return channels;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private static normalizeFallback(fallback: TvUiAdChannelConfig): TvUiAdChannelConfig {
|
|
146
|
+
if (fallback.type) return fallback;
|
|
147
|
+
let result: any = this.mergeOptions(<any>fallback, {});
|
|
148
|
+
result.type = (fallback.imagePath || fallback.imageUrl) ? "self" : "mock";
|
|
149
|
+
if (result.priority === undefined) result.priority = 90;
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private static hasChannelType(channels: TvUiAdChannelConfig[], type: string): boolean {
|
|
154
|
+
for (let i = 0; i < channels.length; i++) {
|
|
155
|
+
if (channels[i] && channels[i].type == type) return true;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static getPriority(channel: TvUiAdChannelConfig): number {
|
|
161
|
+
if (!channel || channel.priority === undefined) return 999;
|
|
162
|
+
return channel.priority;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private static mergeOptions(base: AdShowOptions, extra: AdShowOptions): AdShowOptions {
|
|
166
|
+
let result: any = {};
|
|
167
|
+
let key: string;
|
|
168
|
+
base = base || {};
|
|
169
|
+
extra = extra || {};
|
|
170
|
+
for (key in base) result[key] = (<any>base)[key];
|
|
171
|
+
for (key in extra) result[key] = (<any>extra)[key];
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import AdManager from "./AdManager";
|
|
2
|
+
|
|
3
|
+
const { ccclass, property } = cc._decorator;
|
|
4
|
+
|
|
5
|
+
@ccclass
|
|
6
|
+
export default class AdSlot extends cc.Component {
|
|
7
|
+
@property
|
|
8
|
+
slotId: string = "popup";
|
|
9
|
+
|
|
10
|
+
@property
|
|
11
|
+
showOnLoad: boolean = false;
|
|
12
|
+
|
|
13
|
+
onEnable() {
|
|
14
|
+
if (this.showOnLoad) this.show();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
onDisable() {
|
|
18
|
+
this.hide();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public show() {
|
|
22
|
+
AdManager.showSlot(this.slotId, { container: this.node });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public hide() {
|
|
26
|
+
AdManager.hideSlot(this.slotId);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public refresh() {
|
|
30
|
+
AdManager.refreshSlot(this.slotId, { container: this.node });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public static show(slotId: string) {
|
|
34
|
+
return AdManager.showSlot(slotId);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static hide(slotId: string) {
|
|
38
|
+
AdManager.hideSlot(slotId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static refresh(slotId: string) {
|
|
42
|
+
return AdManager.refreshSlot(slotId);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import TvUiConfigManager from "../config/TvUiConfigManager";
|
|
2
|
+
import NativeBridge from "../core/NativeBridge";
|
|
3
|
+
import { TvUiAdChannelConfig } from "../config/TvUiConfig";
|
|
4
|
+
import IAdProvider, { AdRuntimeData, AdShowResult } from "./IAdProvider";
|
|
5
|
+
import { AdSdk, AdPlatform, AdType, AdErrorCode } from "../ad-sdk/ad-sdk";
|
|
6
|
+
|
|
7
|
+
export default class AggregateAdProvider implements IAdProvider {
|
|
8
|
+
public type: string = "aggregate";
|
|
9
|
+
|
|
10
|
+
private static initialized: boolean = false;
|
|
11
|
+
private static initTask: Promise<void> | null = null;
|
|
12
|
+
private static gameReadyNotified: boolean = false;
|
|
13
|
+
private static GAME_VERSION: string = "1.0.0";
|
|
14
|
+
|
|
15
|
+
public isAvailable(): boolean {
|
|
16
|
+
return NativeBridge.hasBridge();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public load(data: AdRuntimeData): Promise<AdRuntimeData> {
|
|
20
|
+
return this.ensureSdk().then(() => data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public show(data: AdRuntimeData): Promise<AdShowResult> {
|
|
24
|
+
return null;
|
|
25
|
+
// let options = data.options || {};
|
|
26
|
+
// let mode = options.mode || data.slotConfig.mode || "popup";
|
|
27
|
+
// if (mode == "reward") {
|
|
28
|
+
// return this.showReward(data);
|
|
29
|
+
// }
|
|
30
|
+
// return this.showPopup(data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public hide(slotId: string, channel?: TvUiAdChannelConfig): void {
|
|
34
|
+
// if (!AggregateAdProvider.initialized || !this.isAvailable()) return;
|
|
35
|
+
// let runtime = TvUiConfigManager.getConfig();
|
|
36
|
+
// try {
|
|
37
|
+
// AdSdk.hidePopupAd({
|
|
38
|
+
// cpId: runtime.cpId || "ppl",
|
|
39
|
+
// trigger_scene: slotId || "",
|
|
40
|
+
// placementId: (channel && channel.placementId) || ""
|
|
41
|
+
// });
|
|
42
|
+
// } catch (error) {
|
|
43
|
+
// console.warn("[AggregateAdProvider] hide popup failed", error);
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private showReward(data: AdRuntimeData): Promise<AdShowResult> {
|
|
48
|
+
let options = data.options || {};
|
|
49
|
+
let channel = data.channel || <any>{};
|
|
50
|
+
let runtime = TvUiConfigManager.getConfig();
|
|
51
|
+
return AdSdk.requestAd({
|
|
52
|
+
adType: AdType.RewardVideo,
|
|
53
|
+
cpId: options.cpId || runtime.cpId || "ppl",
|
|
54
|
+
rewardType: options.reward_type || channel.reward_type || "reward",
|
|
55
|
+
triggerScene: options.trigger_scene || data.slotId,
|
|
56
|
+
extra: options.extra || {}
|
|
57
|
+
}).then((result: any) => {
|
|
58
|
+
if (!result || result.isCompleted !== true) {
|
|
59
|
+
if (options.onClose) options.onClose(result);
|
|
60
|
+
return <AdShowResult>{ status: "closed", data: result };
|
|
61
|
+
}
|
|
62
|
+
if (options.onSuccess) options.onSuccess(result);
|
|
63
|
+
return <AdShowResult>{ status: "success", data: result };
|
|
64
|
+
}).catch((error: any) => {
|
|
65
|
+
if (this.isUserAbandoned(error)) {
|
|
66
|
+
if (options.onClose) options.onClose(error);
|
|
67
|
+
return <AdShowResult>{ status: "closed", data: error };
|
|
68
|
+
}
|
|
69
|
+
return <AdShowResult>{ status: "failed", error: error };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// private showPopup(data: AdRuntimeData): Promise<AdShowResult> {
|
|
74
|
+
// let options = data.options || {};
|
|
75
|
+
// let channel = data.channel || <any>{};
|
|
76
|
+
// let runtime = TvUiConfigManager.getConfig();
|
|
77
|
+
// return AdSdk.requestPopupAd({
|
|
78
|
+
// adType: AdType.Interstitial,
|
|
79
|
+
// cpId: options.cpId || runtime.cpId || "ppl",
|
|
80
|
+
// reward_type: options.reward_type || channel.reward_type || "popup",
|
|
81
|
+
// trigger_scene: options.trigger_scene || data.slotId,
|
|
82
|
+
// placementId: channel.placementId || "",
|
|
83
|
+
// extra: options.extra || {}
|
|
84
|
+
// }).then((result: any) => {
|
|
85
|
+
// if (result && result.isClosed) {
|
|
86
|
+
// if (options.onClose) options.onClose(result);
|
|
87
|
+
// return <AdShowResult>{ status: "closed", data: result };
|
|
88
|
+
// }
|
|
89
|
+
// if (options.onLoad) options.onLoad(result);
|
|
90
|
+
// return <AdShowResult>{ status: "loaded", data: result };
|
|
91
|
+
// }).catch((error: any) => {
|
|
92
|
+
// return <AdShowResult>{ status: "failed", error: error };
|
|
93
|
+
// });
|
|
94
|
+
// }
|
|
95
|
+
|
|
96
|
+
private ensureSdk(): Promise<void> {
|
|
97
|
+
if (AggregateAdProvider.initialized) return Promise.resolve();
|
|
98
|
+
if (AggregateAdProvider.initTask) return AggregateAdProvider.initTask;
|
|
99
|
+
|
|
100
|
+
let runtime = TvUiConfigManager.getConfig();
|
|
101
|
+
let adSdkConfig = runtime.adSdk || {};
|
|
102
|
+
let platform = this.getPlatform(adSdkConfig.platform || "xiaomi");
|
|
103
|
+
let adapterConfig: any = {};
|
|
104
|
+
let customConfig = adSdkConfig.adapterConfig || {};
|
|
105
|
+
let key: string;
|
|
106
|
+
adapterConfig.cpId = runtime.cpId || "ppl";
|
|
107
|
+
for (key in customConfig) adapterConfig[key] = customConfig[key];
|
|
108
|
+
|
|
109
|
+
let adapters: any = {};
|
|
110
|
+
adapters[platform] = adapterConfig;
|
|
111
|
+
|
|
112
|
+
AggregateAdProvider.initTask = AdSdk.init({
|
|
113
|
+
platform: platform,
|
|
114
|
+
adapters: adapters
|
|
115
|
+
}).then(() => {
|
|
116
|
+
AggregateAdProvider.initialized = true;
|
|
117
|
+
this.notifyGameReady(runtime.version || AggregateAdProvider.GAME_VERSION);
|
|
118
|
+
}).catch((error: any) => {
|
|
119
|
+
AggregateAdProvider.initTask = null;
|
|
120
|
+
throw error;
|
|
121
|
+
});
|
|
122
|
+
return AggregateAdProvider.initTask;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private notifyGameReady(version: string) {
|
|
126
|
+
if (AggregateAdProvider.gameReadyNotified) return;
|
|
127
|
+
AggregateAdProvider.gameReadyNotified = true;
|
|
128
|
+
try {
|
|
129
|
+
AdSdk.onGameReady(version || AggregateAdProvider.GAME_VERSION);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.warn("[AggregateAdProvider] onGameReady failed", error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private getPlatform(platform: string): any {
|
|
136
|
+
if (platform == "xiaomi" || !platform) return AdPlatform.Xiaomi;
|
|
137
|
+
return platform;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private isUserAbandoned(error: any): boolean {
|
|
141
|
+
if (!error) return false;
|
|
142
|
+
return error.code == AdErrorCode.UserAbandoned
|
|
143
|
+
|| error.code == 1006
|
|
144
|
+
|| error.isCompleted === false
|
|
145
|
+
|| error.is_completed === false
|
|
146
|
+
|| error.message == "Ad closed by user before completion";
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TvUiAdChannelConfig, TvUiAdSlotConfig } from "../config/TvUiConfig";
|
|
2
|
+
|
|
3
|
+
export interface AdShowOptions {
|
|
4
|
+
slotId?: string;
|
|
5
|
+
mode?: string;
|
|
6
|
+
cpId?: string;
|
|
7
|
+
trigger_scene?: string;
|
|
8
|
+
reward_type?: string;
|
|
9
|
+
extra?: any;
|
|
10
|
+
container?: cc.Node;
|
|
11
|
+
onLoad?: (data?: any) => void;
|
|
12
|
+
onSuccess?: (data?: any) => void;
|
|
13
|
+
onClose?: (data?: any) => void;
|
|
14
|
+
onFail?: (data?: any) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AdRuntimeData {
|
|
18
|
+
slotId: string;
|
|
19
|
+
slotConfig: TvUiAdSlotConfig;
|
|
20
|
+
channel: TvUiAdChannelConfig;
|
|
21
|
+
options: AdShowOptions;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type AdShowResultStatus = "success" | "loaded" | "closed" | "failed";
|
|
25
|
+
|
|
26
|
+
export interface AdShowResult {
|
|
27
|
+
status: AdShowResultStatus;
|
|
28
|
+
data?: any;
|
|
29
|
+
error?: any;
|
|
30
|
+
action?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default interface IAdProvider {
|
|
34
|
+
type: string;
|
|
35
|
+
isAvailable(): boolean;
|
|
36
|
+
load(data: AdRuntimeData): Promise<AdRuntimeData>;
|
|
37
|
+
show(data: AdRuntimeData): Promise<AdShowResult>;
|
|
38
|
+
hide(slotId: string, channel?: TvUiAdChannelConfig): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import IAdProvider, { AdRuntimeData, AdShowResult } from "./IAdProvider";
|
|
2
|
+
|
|
3
|
+
export default class MockAdProvider implements IAdProvider {
|
|
4
|
+
public type: string = "mock";
|
|
5
|
+
|
|
6
|
+
public isAvailable(): boolean {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public load(data: AdRuntimeData): Promise<AdRuntimeData> {
|
|
11
|
+
return Promise.resolve(data);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public show(data: AdRuntimeData): Promise<AdShowResult> {
|
|
15
|
+
let options = data.options || {};
|
|
16
|
+
let mode = options.mode || data.slotConfig.mode || "popup";
|
|
17
|
+
console.log("[MockAdProvider] show", data.slotId, mode);
|
|
18
|
+
return new Promise<AdShowResult>((resolve) => {
|
|
19
|
+
setTimeout(() => {
|
|
20
|
+
let result = { mock: true, slotId: data.slotId };
|
|
21
|
+
if (mode == "reward") {
|
|
22
|
+
let rewardResult = { isCompleted: true, mock: true, slotId: data.slotId };
|
|
23
|
+
if (options.onSuccess) options.onSuccess(rewardResult);
|
|
24
|
+
resolve({ status: "success", data: rewardResult });
|
|
25
|
+
} else {
|
|
26
|
+
if (options.onLoad) options.onLoad(result);
|
|
27
|
+
resolve({ status: "loaded", data: result });
|
|
28
|
+
}
|
|
29
|
+
}, 0);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public hide(slotId: string): void {
|
|
34
|
+
console.log("[MockAdProvider] hide", slotId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import IAdProvider, { AdRuntimeData, AdShowResult } from "./IAdProvider";
|
|
2
|
+
|
|
3
|
+
export default class SelfAdProvider implements IAdProvider {
|
|
4
|
+
public type: string = "self";
|
|
5
|
+
|
|
6
|
+
public isAvailable(): boolean {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public load(data: AdRuntimeData): Promise<AdRuntimeData> {
|
|
11
|
+
return Promise.resolve(data);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public show(data: AdRuntimeData): Promise<AdShowResult> {
|
|
15
|
+
let channel = data.channel || <any>{};
|
|
16
|
+
let options = data.options || {};
|
|
17
|
+
let path = channel.imagePath || (data.slotConfig.fallback && data.slotConfig.fallback.imagePath);
|
|
18
|
+
if (!path || !options.container) {
|
|
19
|
+
if (options.onLoad) options.onLoad({ self: true, slotId: data.slotId });
|
|
20
|
+
return Promise.resolve({ status: "loaded", data: { self: true, slotId: data.slotId } });
|
|
21
|
+
}
|
|
22
|
+
let node = options.container;
|
|
23
|
+
let sprite = node.getComponent(cc.Sprite) || node.addComponent(cc.Sprite);
|
|
24
|
+
sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
|
25
|
+
return new Promise<AdShowResult>((resolve) => {
|
|
26
|
+
cc.loader.loadRes(path, cc.SpriteFrame, (error: Error, frame: cc.SpriteFrame) => {
|
|
27
|
+
if (error || !frame) {
|
|
28
|
+
resolve({ status: "failed", error: error || { message: "self ad frame missing" } });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
sprite.spriteFrame = frame;
|
|
32
|
+
node.active = true;
|
|
33
|
+
if (options.onLoad) options.onLoad({ self: true, slotId: data.slotId });
|
|
34
|
+
resolve({ status: "loaded", data: { self: true, slotId: data.slotId } });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public hide(_slotId: string): void {
|
|
40
|
+
}
|
|
41
|
+
}
|