drgame-cc 1.0.55 → 1.0.56

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.
@@ -20,6 +20,7 @@ export class PlatformAdapter {
20
20
  private static isVIP: boolean = false;
21
21
 
22
22
  private static contentId: string = "";
23
+ private static cpId: string = "";
23
24
 
24
25
  // ========================================================================
25
26
  // 初始化
@@ -34,6 +35,7 @@ export class PlatformAdapter {
34
35
  // ── 初始化渠道类型 ──
35
36
  this.appItem = PlatformUtil.getUrlParam('appItem') as EAppItem || EAppItem.LeWo;
36
37
  this.isVIP = PlatformUtil.getUrlParam('isVIP') === '1';
38
+ this.cpId = 'cp_001';
37
39
 
38
40
  // ── UI 初始化 ──
39
41
  this.focus.setFocusStyle(focusIcon);
@@ -43,9 +45,18 @@ export class PlatformAdapter {
43
45
  this.contentId = minigameID.toString();
44
46
 
45
47
  // ── 初始化广告 SDK ──
48
+ await this.initAdSdk(cnName);
49
+ }
50
+
51
+ // ========================================================================
52
+ // 广告 SDK 初始化
53
+ // ========================================================================
54
+
55
+ /** 初始化广告 SDK(含事件注册) */
56
+ private static async initAdSdk(cnName: string) {
46
57
  await AdSdk.init({
47
58
  platform: AdPlatform.Xiaomi,
48
- adapters: { [AdPlatform.Xiaomi]: { cpId: this.contentId } },
59
+ cpId: this.cpId,
49
60
  reporter: {
50
61
  app_item: this.appItem,
51
62
  content_type: this.appItem === EAppItem.LeWo ? "乐窝" : "游戏",
@@ -126,7 +137,7 @@ export class PlatformAdapter {
126
137
  try {
127
138
  const result = await AdSdk.requestAd({
128
139
  adType: AdType.RewardVideo,
129
- cpId: this.contentId,
140
+ cpId: this.cpId,
130
141
  rewardType: rewardType || "reward",
131
142
  triggerScene: scene || "reward",
132
143
  extra: {}
@@ -5,7 +5,7 @@
5
5
  import { AdPlatform, AdEvent } from './types/enums';
6
6
  import {
7
7
  IAdSdk,
8
- IAdSdkConfig,
8
+ IAdSdkInitConfig,
9
9
  IAdRequest,
10
10
  IAdRewardResult,
11
11
  IDeviceInfo,
@@ -23,7 +23,7 @@ export { AdPlatform, AdType, AdEvent, AdErrorCode, DevicePlatform, KeyCode, KeyA
23
23
  // 接口(type-only)
24
24
  export type {
25
25
  IAdSdk,
26
- IAdSdkConfig,
26
+ IAdSdkInitConfig,
27
27
  IAdAdapter,
28
28
  IAdapterConfig,
29
29
  IAdRequest,
@@ -56,4 +56,4 @@ export type {
56
56
  IAddPointParams,
57
57
  IRankItem,
58
58
  IRankResult,
59
- } from './types/interfaces';
59
+ } from './types/interfaces';
@@ -48,7 +48,7 @@ class AdSdkImpl {
48
48
 
49
49
  /**
50
50
  * 初始化 SDK
51
- * @param {import('./types/interfaces').IAdSdkConfig} config
51
+ * @param {import('./types/interfaces').IAdSdkInitConfig} config
52
52
  */
53
53
  async init(config) {
54
54
  if (this._initialized) {
@@ -59,7 +59,7 @@ class AdSdkImpl {
59
59
  this._currentPlatform = config.platform;
60
60
  this._globalEventHandler = config.onEvent || null;
61
61
 
62
- // 注册自定义适配器
62
+ // 注册自定义适配器(如提供了 customAdapters 兼容旧用法)
63
63
  if (config.customAdapters) {
64
64
  for (const adapter of config.customAdapters) {
65
65
  this._adapters.set(adapter.platform, adapter);
@@ -80,9 +80,9 @@ class AdSdkImpl {
80
80
  this._adapters.set(config.platform, instance);
81
81
  }
82
82
 
83
- // 初始化当前平台的适配器
83
+ // 初始化当前平台的适配器(从 config.cpId 构建适配器配置)
84
84
  const adapter = this._adapters.get(config.platform);
85
- const adapterConfig = (config.adapters && config.adapters[config.platform]) || {};
85
+ const adapterConfig = { cpId: config.cpId };
86
86
  await adapter.init(adapterConfig);
87
87
 
88
88
  // 桥接适配器事件到全局
@@ -312,16 +312,12 @@ export interface IAdAdapter {
312
312
  // SDK 配置 & 主接口
313
313
  // ────────────────────────────────────────
314
314
 
315
- /** SDK 初始化配置 */
316
- export interface IAdSdkConfig {
317
- /** 默认广告平台 */
315
+ /** SDK 初始化配置(简化版,直接传入 cpId 即可) */
316
+ export interface IAdSdkInitConfig {
317
+ /** 广告平台 */
318
318
  platform: AdPlatform;
319
- /** 各平台适配器配置 */
320
- adapters?: Partial<Record<AdPlatform, IAdapterConfig>>;
321
- /** 自定义适配器实例(优先级高于内置适配器) */
322
- customAdapters?: IAdAdapter[];
323
- /** 全局事件监听 */
324
- onEvent?: (event: AdEvent, data: IAdEventData) => void;
319
+ /** CP 标识 */
320
+ cpId: string;
325
321
  /** 数据上报配置(不传则不上报) */
326
322
  reporter?: IReporterConfig;
327
323
  }
@@ -332,7 +328,7 @@ export interface IAdSdk {
332
328
  readonly currentPlatform: AdPlatform;
333
329
 
334
330
  /** 初始化 SDK */
335
- init(config: IAdSdkConfig): Promise<void>;
331
+ init(config: IAdSdkInitConfig): Promise<void>;
336
332
 
337
333
  /** 获取设备信息 */
338
334
  getDeviceInfo(): Promise<IDeviceInfo>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drgame-cc",
3
- "version": "1.0.55",
3
+ "version": "1.0.56",
4
4
  "description": "道然游戏适配包",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",