@ad-execute-manager/core 2.0.0-alpha.1 → 2.0.0-alpha.3
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/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/{core/AdExecuteManager.d.ts → AdExecuteManager.d.ts} +114 -8
- package/dist/_util.d.ts +18 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -15
- package/dist/index.js +1 -1
- package/package.json +56 -11
- package/dist/ad/InterstitialAdFather.d.ts +0 -131
- package/dist/ad/InterstitialAdNovel.d.ts +0 -457
- package/dist/ad/RewardAdFather.d.ts +0 -131
- package/dist/ad/RewardAdNovel.d.ts +0 -464
- package/dist/ad/index.d.ts +0 -4
- package/dist/const/const.d.ts +0 -20
- package/dist/core/index.d.ts +0 -2
- package/dist/helper/AdAnalyticsJS.d.ts +0 -132
- package/dist/helper/CountRecorder.d.ts +0 -59
- package/dist/helper/EventEmitter.d.ts +0 -15
- package/dist/helper/Logger.d.ts +0 -35
- package/dist/helper/LovelUnlockManager.d.ts +0 -233
- package/dist/helper/PubSub.d.ts +0 -9
- package/dist/helper/RewardAdGlobalRecorder.d.ts +0 -109
- package/dist/helper/RewardAdSceneTriggerManager.d.ts +0 -71
- package/dist/helper/SerializableError.d.ts +0 -9
- package/dist/helper/Storage.d.ts +0 -124
- package/dist/helper/index.d.ts +0 -10
- package/dist/typings/ad.d.ts +0 -188
- package/dist/typings/common.d.ts +0 -14
- package/dist/typings/tracker.d.ts +0 -1
- package/dist/utils/functional.d.ts +0 -13
- /package/dist/{core/compose.d.ts → compose.d.ts} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 singcl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @singcl/core
|
|
2
|
+
|
|
3
|
+
Core functionality for ad execution management including AdExecuteManager, utility functions, and middleware composition.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @singcl/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **AdExecuteManager**: A powerful ad execution management class for handling reward-based ads, interstitial ads, and other advertising formats
|
|
14
|
+
- **compose**: A middleware composition utility inspired by Koa
|
|
15
|
+
- **needRetryAdError**: A utility function for determining if an ad error should be retried
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### AdExecuteManager
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { AdExecuteManager } from '@singcl/core';
|
|
23
|
+
|
|
24
|
+
const adManager = new AdExecuteManager({
|
|
25
|
+
// Configuration options
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Initialize ad
|
|
29
|
+
const result = await adManager.init();
|
|
30
|
+
|
|
31
|
+
// Show ad
|
|
32
|
+
const showResult = await adManager.show();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Middleware Composition
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
import { compose } from '@singcl/core';
|
|
39
|
+
|
|
40
|
+
const middlewares = [
|
|
41
|
+
async (ctx, next) => {
|
|
42
|
+
console.log('Middleware 1 start');
|
|
43
|
+
await next();
|
|
44
|
+
console.log('Middleware 1 end');
|
|
45
|
+
},
|
|
46
|
+
async (ctx, next) => {
|
|
47
|
+
console.log('Middleware 2 start');
|
|
48
|
+
await next();
|
|
49
|
+
console.log('Middleware 2 end');
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const composedMiddleware = compose(middlewares);
|
|
54
|
+
await composedMiddleware({});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Error Retry Utility
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import { needRetryAdError } from '@singcl/core';
|
|
61
|
+
|
|
62
|
+
const apiError = {
|
|
63
|
+
errMsg: 'ad_show_timeout: normal',
|
|
64
|
+
timeout: 5000
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const shouldRetry = needRetryAdError({
|
|
68
|
+
apiError,
|
|
69
|
+
configuredAdTimeout: 5000,
|
|
70
|
+
errorRetryStrategy: {
|
|
71
|
+
timeout: true,
|
|
72
|
+
background: true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log('Should retry:', shouldRetry);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API
|
|
80
|
+
|
|
81
|
+
### AdExecuteManager
|
|
82
|
+
|
|
83
|
+
The main class for managing ad execution with support for initialization, showing, and error handling.
|
|
84
|
+
|
|
85
|
+
### compose
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
function compose(middlewares: Array<(ctx: any, next: () => Promise<void>) => Promise<void>>): (ctx: any) => Promise<void>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### needRetryAdError
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
function needRetryAdError({
|
|
95
|
+
apiError,
|
|
96
|
+
configuredAdTimeout,
|
|
97
|
+
errorRetryStrategy
|
|
98
|
+
}: {
|
|
99
|
+
apiError: { errMsg?: string; timeout?: number };
|
|
100
|
+
configuredAdTimeout: number;
|
|
101
|
+
errorRetryStrategy?: {
|
|
102
|
+
timeout?: boolean;
|
|
103
|
+
background?: boolean;
|
|
104
|
+
};
|
|
105
|
+
}): boolean
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
@@ -3,15 +3,15 @@ export type AdTask = {
|
|
|
3
3
|
/**
|
|
4
4
|
* RewardAdFather的子类实例
|
|
5
5
|
*/
|
|
6
|
-
adInstance:
|
|
6
|
+
adInstance: any;
|
|
7
7
|
/**
|
|
8
8
|
* 广告执行选项
|
|
9
9
|
*/
|
|
10
|
-
options:
|
|
10
|
+
options: any;
|
|
11
11
|
/**
|
|
12
12
|
* 回调集合
|
|
13
13
|
*/
|
|
14
|
-
callbackCollection:
|
|
14
|
+
callbackCollection: any;
|
|
15
15
|
/**
|
|
16
16
|
* 广告执行成功的回调函数
|
|
17
17
|
*/
|
|
@@ -32,6 +32,24 @@ export type AdTask = {
|
|
|
32
32
|
* 广告任务是否已被拒绝
|
|
33
33
|
*/
|
|
34
34
|
_isRejected: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* 广告任务后台恢复前台时预估重试次数
|
|
37
|
+
*/
|
|
38
|
+
_retryCount: number;
|
|
39
|
+
/**
|
|
40
|
+
* 广告任务后台恢复前台时预估重试次数的原因
|
|
41
|
+
*/
|
|
42
|
+
_retryMsg: string;
|
|
43
|
+
};
|
|
44
|
+
export type ErrorRetryStrategy = {
|
|
45
|
+
/**
|
|
46
|
+
* 是否重试超时错误
|
|
47
|
+
*/
|
|
48
|
+
timeout?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 是否重试后台错误
|
|
51
|
+
*/
|
|
52
|
+
background?: boolean;
|
|
35
53
|
};
|
|
36
54
|
export type IConstructArgs = {
|
|
37
55
|
/**
|
|
@@ -42,6 +60,18 @@ export type IConstructArgs = {
|
|
|
42
60
|
* 是否打印日志
|
|
43
61
|
*/
|
|
44
62
|
log?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* 是否启用前后台监听, 进入后台时候未执行的任务放入任务栈,等待进入前台恢复执行
|
|
65
|
+
*/
|
|
66
|
+
enableVisibilityListener?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 最大重试次数, 默认为1 0表示不重试
|
|
69
|
+
*/
|
|
70
|
+
maxRetryCount?: number;
|
|
71
|
+
/**
|
|
72
|
+
* 进入后台时广告展示错误时重试策略
|
|
73
|
+
*/
|
|
74
|
+
errorRetryStrategy?: ErrorRetryStrategy;
|
|
45
75
|
};
|
|
46
76
|
declare class AdExecuteManager {
|
|
47
77
|
/**
|
|
@@ -55,6 +85,18 @@ declare class AdExecuteManager {
|
|
|
55
85
|
* @returns {AdExecuteManager}
|
|
56
86
|
*/
|
|
57
87
|
static getInstance(args?: IConstructArgs): AdExecuteManager;
|
|
88
|
+
/**
|
|
89
|
+
* 获取单例实例
|
|
90
|
+
* @param {IConstructArgs} [args]
|
|
91
|
+
* @returns {AdExecuteManager}
|
|
92
|
+
*/
|
|
93
|
+
static build(args?: IConstructArgs): AdExecuteManager;
|
|
94
|
+
/**
|
|
95
|
+
* 获取单例实例
|
|
96
|
+
* @param {IConstructArgs} [args]
|
|
97
|
+
* @returns {AdExecuteManager}
|
|
98
|
+
*/
|
|
99
|
+
static "new"(args?: IConstructArgs): AdExecuteManager;
|
|
58
100
|
/**
|
|
59
101
|
* 获取单例实例
|
|
60
102
|
* @returns {AdExecuteManager}
|
|
@@ -82,7 +124,71 @@ declare class AdExecuteManager {
|
|
|
82
124
|
* @type {AdTask|null}
|
|
83
125
|
*/
|
|
84
126
|
_currentTask: AdTask | null;
|
|
127
|
+
/**
|
|
128
|
+
* @type {boolean}
|
|
129
|
+
*/
|
|
130
|
+
_isForeground: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* @type {Function|null}
|
|
133
|
+
*/
|
|
134
|
+
_appShowListener: Function | null;
|
|
135
|
+
/**
|
|
136
|
+
* @type {Function|null}
|
|
137
|
+
*/
|
|
138
|
+
_appHideListener: Function | null;
|
|
139
|
+
/**
|
|
140
|
+
* @type {boolean}
|
|
141
|
+
*/
|
|
142
|
+
_enableVisibilityListener: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* @type {number}
|
|
145
|
+
*/
|
|
146
|
+
_maxRetryCount: number;
|
|
147
|
+
/**
|
|
148
|
+
* @type {Array.<AdTask>}
|
|
149
|
+
*/
|
|
150
|
+
_retryQueue: Array<AdTask>;
|
|
151
|
+
/**
|
|
152
|
+
* 进入后台时广告展示错误时重试策略
|
|
153
|
+
*/
|
|
154
|
+
_errorRetryStrategy: {
|
|
155
|
+
timeout: boolean;
|
|
156
|
+
background: boolean;
|
|
157
|
+
};
|
|
85
158
|
logger: Logger;
|
|
159
|
+
initialize(_args: any): this;
|
|
160
|
+
/**
|
|
161
|
+
* 初始化前后台监听器
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
private _initVisibilityListener;
|
|
165
|
+
/**
|
|
166
|
+
* 处理应用进入后台
|
|
167
|
+
* @private
|
|
168
|
+
*/
|
|
169
|
+
private _handleAppHide;
|
|
170
|
+
/**
|
|
171
|
+
* 处理应用进入前台
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
private _handleAppShow;
|
|
175
|
+
/**
|
|
176
|
+
* 销毁前后台监听器
|
|
177
|
+
*/
|
|
178
|
+
destroyVisibilityListener(): void;
|
|
179
|
+
/**
|
|
180
|
+
* 启用前后台监听
|
|
181
|
+
*/
|
|
182
|
+
enableVisibilityListener(): void;
|
|
183
|
+
/**
|
|
184
|
+
* 禁用前后台监听
|
|
185
|
+
*/
|
|
186
|
+
disableVisibilityListener(): void;
|
|
187
|
+
/**
|
|
188
|
+
* 获取前后台监听器状态
|
|
189
|
+
* @returns {boolean} 是否启用
|
|
190
|
+
*/
|
|
191
|
+
isVisibilityListenerEnabled(): boolean;
|
|
86
192
|
/**
|
|
87
193
|
* 添加广告任务
|
|
88
194
|
* @param {import('../ad/RewardAdFather.js').default} adInstance RewardAdFather的子类实例
|
|
@@ -91,9 +197,9 @@ declare class AdExecuteManager {
|
|
|
91
197
|
* @param {import('../typings/ad.js').CallbackCollection} ctx.collection 回调集合
|
|
92
198
|
* @returns {Promise} 广告执行结果的Promise
|
|
93
199
|
*/
|
|
94
|
-
addTask(adInstance:
|
|
95
|
-
options:
|
|
96
|
-
collection:
|
|
200
|
+
addTask(adInstance: any, ctx: {
|
|
201
|
+
options: any;
|
|
202
|
+
collection: any;
|
|
97
203
|
}): Promise<any>;
|
|
98
204
|
/**
|
|
99
205
|
* 组合所有任务
|
|
@@ -106,7 +212,7 @@ declare class AdExecuteManager {
|
|
|
106
212
|
clearTasks(): void;
|
|
107
213
|
/**
|
|
108
214
|
* 获取当前未完成的任务总数
|
|
109
|
-
*
|
|
215
|
+
* 包括任务栈中待执行的任务、中间件链中未完成的任务和重试队列中的任务
|
|
110
216
|
* @returns {number} 未完成的任务数量
|
|
111
217
|
*/
|
|
112
218
|
getTaskCount(): number;
|
|
@@ -126,4 +232,4 @@ declare class AdExecuteManager {
|
|
|
126
232
|
*/
|
|
127
233
|
whenAllTasksComplete(): Promise<void>;
|
|
128
234
|
}
|
|
129
|
-
import { Logger } from '
|
|
235
|
+
import { Logger } from '@ad-execute-manager/helper';
|
package/dist/_util.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否需要重试
|
|
3
|
+
* @param {object} param
|
|
4
|
+
* @param {object} param.apiError 广告错误信息
|
|
5
|
+
* @param {number} param.configuredAdTimeout 配置的广告超时时间
|
|
6
|
+
* @param {object} [param.errorRetryStrategy] 错误重试策略
|
|
7
|
+
* @param {boolean} [param.errorRetryStrategy.timeout] 是否需要重试超时错误
|
|
8
|
+
* @param {boolean} [param.errorRetryStrategy.background] 是否需要重试后台错误
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function needRetryAdError({ apiError, configuredAdTimeout, errorRetryStrategy }: {
|
|
12
|
+
apiError: object;
|
|
13
|
+
configuredAdTimeout: number;
|
|
14
|
+
errorRetryStrategy?: {
|
|
15
|
+
timeout?: boolean;
|
|
16
|
+
background?: boolean;
|
|
17
|
+
};
|
|
18
|
+
}): boolean;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{AdExecuteManager:()=>src_AdExecuteManager});const helper_namespaceObject=require("@ad-execute-manager/helper");function isTimeoutError(e,t){return(null==e?void 0:e.errMsg)&&"string"==typeof e.errMsg&&e.errMsg.startsWith("ad_show_timeout: normal")&&(null==e?void 0:e.timeout)==t}function isBackgroundError(e){return(null==e?void 0:e.errMsg)&&"string"==typeof e.errMsg&&(e.errMsg.startsWith("app in background is not support show ad")||e.errMsg.startsWith("other controller is presented"))}function needRetryAdError({apiError:e,configuredAdTimeout:t,errorRetryStrategy:r}){return!!((null==r?void 0:r.timeout)&&isTimeoutError(e,t)||(null==r?void 0:r.background)&&isBackgroundError(e))}const compose=e=>e.map(e=>(t,r)=>async i=>await e(Object.assign({},t,i),r)).reduce((e,t)=>(r,i)=>e(r,t(r,i))),src_compose=compose;class AdExecuteManager{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;_isForeground=!0;_appShowListener=null;_appHideListener=null;_enableVisibilityListener=!1;_maxRetryCount=1;_retryQueue=[];_errorRetryStrategy={timeout:!0,background:!0};constructor(e){this.logger=new helper_namespaceObject.Logger({prefix:"AdExecuteManager",enabled:!!(null==e?void 0:e.log)}),(null==e?void 0:e.errorRetryStrategy)&&(this._errorRetryStrategy=Object.assign({},this._errorRetryStrategy,null==e?void 0:e.errorRetryStrategy)),this._enableVisibilityListener=null==e?void 0:e.enableVisibilityListener,this._maxRetryCount=(null==e?void 0:e.maxRetryCount)??1,this._enableVisibilityListener&&this._initVisibilityListener()}initialize(e){return this}static getInstance(e){return AdExecuteManager._instance||(AdExecuteManager._instance=new AdExecuteManager(e)),AdExecuteManager._instance}static build(e){return AdExecuteManager._instance||(AdExecuteManager._instance=new AdExecuteManager(e)),AdExecuteManager._instance}static new(e){return new AdExecuteManager(e)}static getSafeInstance(){return AdExecuteManager._instance?AdExecuteManager._instance:(this.logger.error("AdExecuteManager实例不存在"),null)}_initVisibilityListener(){!("u"<typeof tt)&&tt.onAppShow&&tt.onAppHide?(this._appShowListener=()=>{this._isForeground=!0,this._handleAppShow()},this._appHideListener=()=>{this._isForeground=!1,this._handleAppHide()},tt.onAppShow(this._appShowListener),tt.onAppHide(this._appHideListener),this.logger.info("前后台监听器已初始化")):this.logger.warn("tt API不可用,无法监听前后台状态")}_handleAppHide(){if(this._isRunning&&this._currentBatchTasks.length>0){let e=this._currentBatchTasks.filter(e=>{var t;return e.id!==(null==(t=this._currentTask)?void 0:t.id)&&!e._isResolved&&!e._isRejected});e.length>0&&(this.logger.info(`将 ${e.length} 个未执行的任务放回任务栈,任务ID: ${e.map(e=>e.id).join(",")}`),this._taskStack=[...e,...this._taskStack],this._currentBatchTasks=this._currentBatchTasks.filter(t=>!e.some(e=>e.id===t.id)))}}_handleAppShow(){this._retryQueue.length>0&&(this.logger.info(`应用进入前台:优先执行重试队列,任务数: ${this._retryQueue.length}, 任务ID: ${this._retryQueue.map(e=>e.id).join(",")}`),this._taskStack=[...this._retryQueue,...this._taskStack],this._retryQueue=[]),this._taskStack.length>0&&!this._isRunning&&(this.logger.info(`应用进入前台:恢复待执行任务数: ${this._taskStack.length}, 任务ID: ${this._taskStack.map(e=>e.id).join(",")}`),this._compose())}destroyVisibilityListener(){this._appShowListener&&"u">typeof tt&&tt.offAppShow&&(tt.offAppShow(this._appShowListener),this._appShowListener=null),this._appHideListener&&"u">typeof tt&&tt.offAppHide&&(tt.offAppHide(this._appHideListener),this._appHideListener=null),this.logger.info("前后台监听器已销毁")}enableVisibilityListener(){this._enableVisibilityListener||(this._enableVisibilityListener=!0,this._initVisibilityListener()),this.logger.info("前后台监听器已启用")}disableVisibilityListener(){this._enableVisibilityListener&&(this._enableVisibilityListener=!1,this.destroyVisibilityListener()),this.logger.info("前后台监听器已禁用")}isVisibilityListenerEnabled(){return this._enableVisibilityListener}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((r,i)=>{let s={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:r,reject:i,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1,_retryCount:0,_retryMsg:"ok"};this._taskStack.push(s),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}if(!this._isForeground){this.logger.info(`应用处于后台,暂停任务执行,任务ID: ${this._taskStack.map(e=>e.id).join(",")}`),this._isRunning=!1;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,r)=>{let{adInstance:i,options:s,callbackCollection:n,resolve:a,id:o,_retryCount:c,_retryMsg:l}=e,_={count:c,retry:c>0,message:l};if(e._isResolved||e._isRejected)return void await r(t);this._currentTask=e;try{let c=async e=>{await r(Object.assign({},t,e))},l=await i.initialize(s).ad({options:s,collection:n,recovered:_},c),h=Object.assign({id:o,recovered:_},l);if(this.logger.info(`任务执行成功,成功信息:${JSON.stringify(h)}`),needRetryAdError({apiError:null==h?void 0:h.apiError,configuredAdTimeout:i._adTimeoutTime,errorRetryStrategy:this._errorRetryStrategy})&&!this._isForeground&&e._retryCount<this._maxRetryCount){var u;e._retryCount++,e._retryMsg=(null==h||null==(u=h.apiError)?void 0:u.errMsg)||"unknown";let t=`任务 ${o} 在后台失败,加入重试队列 (即将第 ${e._retryCount} 次重试, 最大重试次数 ${this._maxRetryCount}, 重试原因: ${e._retryMsg})`;this.logger.warn(t),h.recovered.retry=!0,h.recovered.count=e._retryCount,h.recovered.message=e._retryMsg,e._isResolved=!1,e._isRejected=!1,this._retryQueue.push(e)}else e._isResolved=!0;a(h),null==i||i.record(h)}catch(n){let s=Object.assign({id:o,apiError:n,recovered:_});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(s)}`),e._isRejected=!0;try{null==i||i.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}a(s),null==i||i.record(s),await r(t)}}),r={roundTasks:t.length};compose(t)(r,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._retryQueue.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear retry task error: ",e)}}),this._taskStack=[],this._retryQueue=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)+this._retryQueue.filter(e=>!e._isResolved&&!e._isRejected).length}isRunning(){return this._isRunning}getCurrentTaskId(){var e;return(null==(e=this._currentTask)?void 0:e.id)||null}whenAllTasksComplete(){return new Promise(e=>{let t=null,r=()=>{let i=0===this._taskStack.length,s=!this._isRunning,n=null===this._currentTask,a=0===this._currentBatchTasks.length||this._currentBatchTasks.every(e=>e._isResolved||e._isRejected),o=0===this._retryQueue.length;i&&s&&n&&a&&o?(t&&clearTimeout(t),e()):t=setTimeout(r,500)};r()})}}const src_AdExecuteManager=AdExecuteManager;for(var __rspack_i in exports.AdExecuteManager=__webpack_exports__.AdExecuteManager,__webpack_exports__)-1===["AdExecuteManager"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export default AdExecuteManager;
|
|
2
|
-
import AdExecuteManager from './core/AdExecuteManager';
|
|
3
|
-
import RewardAdFather from './ad/RewardAdFather';
|
|
4
|
-
import { SerializableError } from './helper/SerializableError';
|
|
5
|
-
import { Logger } from './helper/Logger';
|
|
6
|
-
import Storage from './helper/Storage';
|
|
7
|
-
import { CountRecorder } from './helper/CountRecorder';
|
|
8
|
-
import RewardAdGlobalRecorder from './helper/RewardAdGlobalRecorder';
|
|
9
|
-
import RewardAdSceneTriggerManager from './helper/RewardAdSceneTriggerManager';
|
|
10
|
-
import AdAnalyticsJS from './helper/AdAnalyticsJS';
|
|
11
|
-
import RewardAdNovel from './ad/RewardAdNovel';
|
|
12
|
-
import InterstitialAdFather from './ad/InterstitialAdFather';
|
|
13
|
-
import InterstitialAdNovel from './ad/InterstitialAdNovel';
|
|
14
|
-
import PubSub from './helper/PubSub';
|
|
15
|
-
export { AdExecuteManager, RewardAdFather, SerializableError, Logger, Storage, CountRecorder, RewardAdGlobalRecorder, RewardAdSceneTriggerManager, AdAnalyticsJS, RewardAdNovel, InterstitialAdFather, InterstitialAdNovel, PubSub };
|
|
1
|
+
export { default as AdExecuteManager } from "./AdExecuteManager.js";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{Logger as e}from"@ad-execute-manager/helper";class t{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;_isForeground=!0;_appShowListener=null;_appHideListener=null;_enableVisibilityListener=!1;_maxRetryCount=1;_retryQueue=[];_errorRetryStrategy={timeout:!0,background:!0};constructor(t){this.logger=new e({prefix:"AdExecuteManager",enabled:!!(null==t?void 0:t.log)}),(null==t?void 0:t.errorRetryStrategy)&&(this._errorRetryStrategy=Object.assign({},this._errorRetryStrategy,null==t?void 0:t.errorRetryStrategy)),this._enableVisibilityListener=null==t?void 0:t.enableVisibilityListener,this._maxRetryCount=(null==t?void 0:t.maxRetryCount)??1,this._enableVisibilityListener&&this._initVisibilityListener()}initialize(e){return this}static getInstance(e){return t._instance||(t._instance=new t(e)),t._instance}static build(e){return t._instance||(t._instance=new t(e)),t._instance}static new(e){return new t(e)}static getSafeInstance(){return t._instance?t._instance:(this.logger.error("AdExecuteManager实例不存在"),null)}_initVisibilityListener(){!("u"<typeof tt)&&tt.onAppShow&&tt.onAppHide?(this._appShowListener=()=>{this._isForeground=!0,this._handleAppShow()},this._appHideListener=()=>{this._isForeground=!1,this._handleAppHide()},tt.onAppShow(this._appShowListener),tt.onAppHide(this._appHideListener),this.logger.info("前后台监听器已初始化")):this.logger.warn("tt API不可用,无法监听前后台状态")}_handleAppHide(){if(this._isRunning&&this._currentBatchTasks.length>0){let e=this._currentBatchTasks.filter(e=>{var t;return e.id!==(null==(t=this._currentTask)?void 0:t.id)&&!e._isResolved&&!e._isRejected});e.length>0&&(this.logger.info(`将 ${e.length} 个未执行的任务放回任务栈,任务ID: ${e.map(e=>e.id).join(",")}`),this._taskStack=[...e,...this._taskStack],this._currentBatchTasks=this._currentBatchTasks.filter(t=>!e.some(e=>e.id===t.id)))}}_handleAppShow(){this._retryQueue.length>0&&(this.logger.info(`应用进入前台:优先执行重试队列,任务数: ${this._retryQueue.length}, 任务ID: ${this._retryQueue.map(e=>e.id).join(",")}`),this._taskStack=[...this._retryQueue,...this._taskStack],this._retryQueue=[]),this._taskStack.length>0&&!this._isRunning&&(this.logger.info(`应用进入前台:恢复待执行任务数: ${this._taskStack.length}, 任务ID: ${this._taskStack.map(e=>e.id).join(",")}`),this._compose())}destroyVisibilityListener(){this._appShowListener&&"u">typeof tt&&tt.offAppShow&&(tt.offAppShow(this._appShowListener),this._appShowListener=null),this._appHideListener&&"u">typeof tt&&tt.offAppHide&&(tt.offAppHide(this._appHideListener),this._appHideListener=null),this.logger.info("前后台监听器已销毁")}enableVisibilityListener(){this._enableVisibilityListener||(this._enableVisibilityListener=!0,this._initVisibilityListener()),this.logger.info("前后台监听器已启用")}disableVisibilityListener(){this._enableVisibilityListener&&(this._enableVisibilityListener=!1,this.destroyVisibilityListener()),this.logger.info("前后台监听器已禁用")}isVisibilityListenerEnabled(){return this._enableVisibilityListener}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((i,r)=>{let s={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:i,reject:r,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1,_retryCount:0,_retryMsg:"ok"};this._taskStack.push(s),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}if(!this._isForeground){this.logger.info(`应用处于后台,暂停任务执行,任务ID: ${this._taskStack.map(e=>e.id).join(",")}`),this._isRunning=!1;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,i)=>{let{adInstance:r,options:s,callbackCollection:n,resolve:a,id:l,_retryCount:o,_retryMsg:c}=e,h={count:o,retry:o>0,message:c};if(e._isResolved||e._isRejected)return void await i(t);this._currentTask=e;try{let o=async e=>{await i(Object.assign({},t,e))},c=await r.initialize(s).ad({options:s,collection:n,recovered:h},o),u=Object.assign({id:l,recovered:h},c);if(this.logger.info(`任务执行成功,成功信息:${JSON.stringify(u)}`),function({apiError:e,configuredAdTimeout:t,errorRetryStrategy:i}){var r;return!!((null==i?void 0:i.timeout)&&(null==e?void 0:e.errMsg)&&"string"==typeof e.errMsg&&e.errMsg.startsWith("ad_show_timeout: normal")&&(null==e?void 0:e.timeout)==t)||!!((null==i?void 0:i.background)&&(null==(r=e)?void 0:r.errMsg)&&"string"==typeof r.errMsg&&(r.errMsg.startsWith("app in background is not support show ad")||r.errMsg.startsWith("other controller is presented")))}({apiError:null==u?void 0:u.apiError,configuredAdTimeout:r._adTimeoutTime,errorRetryStrategy:this._errorRetryStrategy})&&!this._isForeground&&e._retryCount<this._maxRetryCount){var _;e._retryCount++,e._retryMsg=(null==u||null==(_=u.apiError)?void 0:_.errMsg)||"unknown";let t=`任务 ${l} 在后台失败,加入重试队列 (即将第 ${e._retryCount} 次重试, 最大重试次数 ${this._maxRetryCount}, 重试原因: ${e._retryMsg})`;this.logger.warn(t),u.recovered.retry=!0,u.recovered.count=e._retryCount,u.recovered.message=e._retryMsg,e._isResolved=!1,e._isRejected=!1,this._retryQueue.push(e)}else e._isResolved=!0;a(u),null==r||r.record(u)}catch(n){let s=Object.assign({id:l,apiError:n,recovered:h});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(s)}`),e._isRejected=!0;try{null==r||r.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:l,apiError:e})))}a(s),null==r||r.record(s),await i(t)}}),i={roundTasks:t.length};t.map(e=>(t,i)=>async r=>await e(Object.assign({},t,r),i)).reduce((e,t)=>(i,r)=>e(i,t(i,r)))(i,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._retryQueue.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear retry task error: ",e)}}),this._taskStack=[],this._retryQueue=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)+this._retryQueue.filter(e=>!e._isResolved&&!e._isRejected).length}isRunning(){return this._isRunning}getCurrentTaskId(){var e;return(null==(e=this._currentTask)?void 0:e.id)||null}whenAllTasksComplete(){return new Promise(e=>{let t=null,i=()=>{let r=0===this._taskStack.length,s=!this._isRunning,n=null===this._currentTask,a=0===this._currentBatchTasks.length||this._currentBatchTasks.every(e=>e._isResolved||e._isRejected),l=0===this._retryQueue.length;r&&s&&n&&a&&l?(t&&clearTimeout(t),e()):t=setTimeout(i,500)};i()})}}let i=t;export{i as AdExecuteManager};
|
package/package.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ad-execute-manager/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
|
+
"description": "Core functionality for ad execution management including AdExecuteManager, utility functions, and middleware composition.",
|
|
4
5
|
"type": "module",
|
|
5
|
-
"main": "./dist/index.cjs",
|
|
6
|
-
"module": "./dist/index.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
6
|
"exports": {
|
|
12
7
|
".": {
|
|
13
8
|
"import": "./dist/index.js",
|
|
@@ -15,10 +10,60 @@
|
|
|
15
10
|
"types": "./dist/index.d.ts"
|
|
16
11
|
}
|
|
17
12
|
},
|
|
18
|
-
"
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "singcl",
|
|
20
|
+
"email": "iambabyer@gmail.com",
|
|
21
|
+
"url": "https://github.com/singcl"
|
|
22
|
+
},
|
|
19
23
|
"license": "MIT",
|
|
20
|
-
"homepage": "https://npmjs.com/package/@
|
|
21
|
-
"
|
|
22
|
-
"
|
|
24
|
+
"homepage": "https://npmjs.com/package/@singcl/core",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/singcl/ad-execute-manager.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/singcl/ad-execute-manager/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=14.0.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"core",
|
|
37
|
+
"ad-manager",
|
|
38
|
+
"ad-execution",
|
|
39
|
+
"middleware",
|
|
40
|
+
"compose",
|
|
41
|
+
"utilities",
|
|
42
|
+
"javascript",
|
|
43
|
+
"nodejs"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rslib build && tsc",
|
|
47
|
+
"dev": "rslib build --watch",
|
|
48
|
+
"format": "prettier --write .",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"test": "rstest",
|
|
51
|
+
"prepublishOnly": "npm run build"
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@ad-execute-manager/helper": "^2.0.0-alpha.2"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@babel/eslint-parser": "^7.28.5",
|
|
59
|
+
"@babel/preset-env": "^7.28.5",
|
|
60
|
+
"@eslint/js": "^9.39.1",
|
|
61
|
+
"@rslib/core": "^0.18.5",
|
|
62
|
+
"@rstest/core": "^0.7.2",
|
|
63
|
+
"eslint": "^9.39.2",
|
|
64
|
+
"eslint-plugin-import": "^2.32.0",
|
|
65
|
+
"globals": "^16.5.0",
|
|
66
|
+
"prettier": "^3.7.3",
|
|
67
|
+
"typescript": "^5.9.3"
|
|
23
68
|
}
|
|
24
69
|
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
export default InterstitialAdFather;
|
|
2
|
-
export type IRewordAdConfig = import("../typings/ad.js").IRewordAdConfig;
|
|
3
|
-
export type CallbackCollection = import("../typings/ad.js").CallbackCollection;
|
|
4
|
-
export type IConstructArgs = import("../typings/ad.js").IConstructArgs;
|
|
5
|
-
export type IRewardedVideoAd = {
|
|
6
|
-
/**
|
|
7
|
-
* 显示激励视频广告
|
|
8
|
-
*/
|
|
9
|
-
show: () => Promise<void>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* @typedef IRewardedVideoAd
|
|
13
|
-
* @property {() => Promise.<void>} show 显示激励视频广告
|
|
14
|
-
*/
|
|
15
|
-
declare class InterstitialAdFather {
|
|
16
|
-
/** @type {IRewordAdConfig | null} */
|
|
17
|
-
static args: IRewordAdConfig | null;
|
|
18
|
-
/**
|
|
19
|
-
* @param {IRewordAdConfig} args
|
|
20
|
-
*/
|
|
21
|
-
static buildArgs(args: IRewordAdConfig): void;
|
|
22
|
-
/**
|
|
23
|
-
* 使用管理器执行广告
|
|
24
|
-
* @param {Object} adInstance 广告实例
|
|
25
|
-
* @param {Object} ctx 上下文对象,用于传递数据和状态
|
|
26
|
-
* @param {Object} ctx.options 广告执行选项
|
|
27
|
-
* @param {Object} ctx.options.log 是否打印日志
|
|
28
|
-
* @param {Object} ctx.collection 回调集合
|
|
29
|
-
* @returns {Promise} 广告执行结果的Promise
|
|
30
|
-
*/
|
|
31
|
-
static executeWithManager(adInstance: any, ctx: {
|
|
32
|
-
options: {
|
|
33
|
-
log: any;
|
|
34
|
-
};
|
|
35
|
-
collection: any;
|
|
36
|
-
}): Promise<any>;
|
|
37
|
-
/**
|
|
38
|
-
* @param {IConstructArgs} args
|
|
39
|
-
*/
|
|
40
|
-
constructor(args: IConstructArgs);
|
|
41
|
-
_initSign: string;
|
|
42
|
-
_preserveOnEnd: boolean;
|
|
43
|
-
_interstitialAd: any;
|
|
44
|
-
_ttErrorMsgs: string[];
|
|
45
|
-
_ttErrorCodes: number[];
|
|
46
|
-
_adConfig: {};
|
|
47
|
-
/**
|
|
48
|
-
* 初始化
|
|
49
|
-
* 子类可以选择覆盖此方法,或使用默认实现
|
|
50
|
-
* @param {IRewordAdConfig} params
|
|
51
|
-
* @param {(v: IRewardedVideoAd) => void} [callback] 初始化成功回调
|
|
52
|
-
* @returns {this} 当前实例
|
|
53
|
-
*/
|
|
54
|
-
initialize(params: IRewordAdConfig, callback?: (v: IRewardedVideoAd) => void): this;
|
|
55
|
-
initialized(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* 执行广告展示
|
|
58
|
-
* @abstract
|
|
59
|
-
* @param {Object} [ctx] 上下文对象,用于传递数据和状态
|
|
60
|
-
* @param {IRewordAdConfig} [ctx.options] 广告执行选项
|
|
61
|
-
* @param {CallbackCollection} [ctx.collection] 回调集合
|
|
62
|
-
* @param {Function} next 执行下一个任务的回调函数,在洋葱模型中手动调用以继续执行流程
|
|
63
|
-
* @returns {Promise<unknown>} 广告执行结果的Promise
|
|
64
|
-
* @throws {Error} 子类必须实现此方法
|
|
65
|
-
*/
|
|
66
|
-
ad(ctx?: {
|
|
67
|
-
options?: IRewordAdConfig;
|
|
68
|
-
collection?: CallbackCollection;
|
|
69
|
-
}, next?: Function): Promise<unknown>;
|
|
70
|
-
/**
|
|
71
|
-
* 确保广告按顺序执行
|
|
72
|
-
* @param {Object} [ctx] 上下文对象,用于传递数据和状态
|
|
73
|
-
* @param {IRewordAdConfig} [ctx.options] 广告执行选项
|
|
74
|
-
* @param {CallbackCollection} [ctx.collection] 回调集合
|
|
75
|
-
* @returns {Promise.<unknown>} 广告执行结果的Promise
|
|
76
|
-
*/
|
|
77
|
-
addExecuteManager(ctx?: {
|
|
78
|
-
options?: IRewordAdConfig;
|
|
79
|
-
collection?: CallbackCollection;
|
|
80
|
-
}): Promise<unknown>;
|
|
81
|
-
destroy(): void;
|
|
82
|
-
/**
|
|
83
|
-
* 清理广告实例
|
|
84
|
-
* @abstract 清理广告实例,子类必须实现此方法
|
|
85
|
-
*/
|
|
86
|
-
clear(): void;
|
|
87
|
-
/**
|
|
88
|
-
* 任务执行完成后始终执行的一个方法
|
|
89
|
-
* @abstract 任务执行完成后始终执行的一个方法,子类需要用到时实现此方法
|
|
90
|
-
* @param {object} [_args] 执行结果信息
|
|
91
|
-
*/
|
|
92
|
-
record(_args?: object): this;
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @param {({isEnded: boolean, count: number}) => void} callback
|
|
96
|
-
*/
|
|
97
|
-
onClose(callback: ({ isEnded: boolean, count: number }: any) => void): void;
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
* @param {({isEnded: boolean, count: number}) => void} callback
|
|
101
|
-
*/
|
|
102
|
-
offClose(callback: ({ isEnded: boolean, count: number }: any) => void): void;
|
|
103
|
-
/**
|
|
104
|
-
* show
|
|
105
|
-
* @returns { Promise.<void>}
|
|
106
|
-
* @params {{errMsg: string; errCode: number}} err
|
|
107
|
-
*/
|
|
108
|
-
show(): Promise<void>;
|
|
109
|
-
/**
|
|
110
|
-
* load
|
|
111
|
-
* @returns { Promise.<void>}
|
|
112
|
-
*/
|
|
113
|
-
load(): Promise<void>;
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* @param {({errMsg: string; errCode: number}) => void} callback
|
|
117
|
-
*/
|
|
118
|
-
onError(callback: any): void;
|
|
119
|
-
/**
|
|
120
|
-
*
|
|
121
|
-
* @param {({errMsg: string; errCode: number}) => void} callback
|
|
122
|
-
*/
|
|
123
|
-
offError(callback: any): void;
|
|
124
|
-
onLoad(callback: any): void;
|
|
125
|
-
offLoad(callback: any): void;
|
|
126
|
-
/**
|
|
127
|
-
* 站位方法,没有任何左右
|
|
128
|
-
* @returns
|
|
129
|
-
*/
|
|
130
|
-
placeholder(): any;
|
|
131
|
-
}
|