@playcraft/adsdk 1.0.6
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/defines.d.ts +124 -0
- package/dist/esm/index.js +1167 -0
- package/dist/iife/index.js +1163 -0
- package/dist/index.d.mts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +1197 -0
- package/package.json +47 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
type EventName = 'init' | 'boot' | 'ready' | 'start' | 'interaction' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
|
|
2
|
+
|
|
3
|
+
type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Main SDK class providing playable ad functionality and state management.
|
|
6
|
+
* Handles initialization, lifecycle events, and interactions across different ad networks.
|
|
7
|
+
*/
|
|
8
|
+
declare class sdk {
|
|
9
|
+
/** Current version of the SDK */
|
|
10
|
+
static version: string;
|
|
11
|
+
/** Current maximum width of the playable ad container in pixels */
|
|
12
|
+
static maxWidth: number;
|
|
13
|
+
/** Current maximum height of the playable ad container in pixels */
|
|
14
|
+
static maxHeight: number;
|
|
15
|
+
/** Indicates if the current orientation is landscape (width > height) */
|
|
16
|
+
static isLandscape: boolean;
|
|
17
|
+
/** Indicates if the Ad Network is ready and playable ad can be initialized */
|
|
18
|
+
static isReady: boolean;
|
|
19
|
+
/** Indicates if all playable ad resources are loaded and gameplay has started */
|
|
20
|
+
static isStarted: boolean;
|
|
21
|
+
/** Indicates if the playable ad is currently paused */
|
|
22
|
+
static isPaused: boolean;
|
|
23
|
+
/** Indicates if the playable ad has finished */
|
|
24
|
+
static isFinished: boolean;
|
|
25
|
+
/** Current volume level (0-1) */
|
|
26
|
+
static volume: number;
|
|
27
|
+
/** Number of user interactions with the playable ad */
|
|
28
|
+
static interactions: number;
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the SDK and sets up protocol-specific handlers.
|
|
31
|
+
* This must be called as earlier as possible.
|
|
32
|
+
*
|
|
33
|
+
* @param callback Optional function called when ad container is ready
|
|
34
|
+
* @example
|
|
35
|
+
* // Basic initialization
|
|
36
|
+
* sdk.init();
|
|
37
|
+
*
|
|
38
|
+
* // Initialization with callback
|
|
39
|
+
* sdk.init((width, height) => {
|
|
40
|
+
* new App(width, height)
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* @fires init When initialization starts
|
|
44
|
+
* @fires boot When the ad begins booting
|
|
45
|
+
* @fires ready When Ad Network is ready and playable ad can be initialized
|
|
46
|
+
*/
|
|
47
|
+
static init(callback?: InitCallbackType): void;
|
|
48
|
+
/**
|
|
49
|
+
* Starts the playable ad experience.
|
|
50
|
+
* Should be called after all resources are loaded and first frame is rendered.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Call just after all resources are preloaded and first frame is rendered
|
|
54
|
+
* sdk.start();
|
|
55
|
+
*
|
|
56
|
+
* @fires start When the playable ad starts
|
|
57
|
+
* @fires resize When the ad container is initially sized
|
|
58
|
+
*/
|
|
59
|
+
static start(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Marks the playable ad as finished.
|
|
62
|
+
* This triggers network-specific completion handlers.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Call when game/experience is complete
|
|
66
|
+
* sdk.finish();
|
|
67
|
+
*
|
|
68
|
+
* @fires finish When the playable ad is marked as finished
|
|
69
|
+
*/
|
|
70
|
+
static finish(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Triggers a retry/restart of the playable ad.
|
|
73
|
+
* Behavior varies by ad network.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Allow user to try again
|
|
77
|
+
* retryButton.onclick = () => sdk.retry();
|
|
78
|
+
*
|
|
79
|
+
* @fires retry When a retry is triggered
|
|
80
|
+
*/
|
|
81
|
+
static retry(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Triggers the install/download action for the advertised app.
|
|
84
|
+
* Handles different store opening methods across ad networks.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Call when user wants to install
|
|
88
|
+
* installButton.onclick = () => sdk.install();
|
|
89
|
+
*
|
|
90
|
+
* @fires finish If the ad hasn't been marked as finished
|
|
91
|
+
* @fires install When the install action is triggered
|
|
92
|
+
*/
|
|
93
|
+
static install(params?: {
|
|
94
|
+
action_type: 'auto' | 'click';
|
|
95
|
+
timeout: number;
|
|
96
|
+
}): void;
|
|
97
|
+
/**
|
|
98
|
+
* Trigger force resize event
|
|
99
|
+
* Useful when container size changes need to be manually propagated.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* sdk.resize();
|
|
103
|
+
*
|
|
104
|
+
* @fires resize With current maxWidth and maxHeight
|
|
105
|
+
*/
|
|
106
|
+
static resize(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Forces the playable ad into a paused state.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Pause the experience
|
|
112
|
+
* pauseButton.onclick = () => sdk.pause();
|
|
113
|
+
*
|
|
114
|
+
* @fires pause When the ad enters paused state
|
|
115
|
+
*/
|
|
116
|
+
static pause(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Resumes the playable ad from a forced pause state.
|
|
119
|
+
* Only works if the ad was paused via sdk.pause().
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // Resume from pause
|
|
123
|
+
* resumeButton.onclick = () => sdk.resume();
|
|
124
|
+
*
|
|
125
|
+
* @fires resume When the ad resumes from pause
|
|
126
|
+
*/
|
|
127
|
+
static resume(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Registers an event listener.
|
|
130
|
+
*
|
|
131
|
+
* @param event Name of the event to listen for
|
|
132
|
+
* @param fn Callback function to execute when event occurs
|
|
133
|
+
* @param context Optional 'this' context for the callback
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // Listen for user interactions
|
|
137
|
+
* sdk.on('interaction', (count) => {
|
|
138
|
+
* console.log(`User interaction #${count}`);
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* // Listen for resize with context
|
|
142
|
+
* sdk.on('resize', function(width, height) {
|
|
143
|
+
* this.updateLayout(width, height);
|
|
144
|
+
* }, gameInstance);
|
|
145
|
+
*/
|
|
146
|
+
static on(event: EventName, fn: Function, context?: any): void;
|
|
147
|
+
/**
|
|
148
|
+
* Registers a one-time event listener that removes itself after execution.
|
|
149
|
+
*
|
|
150
|
+
* @param event Name of the event to listen for
|
|
151
|
+
* @param fn Callback function to execute when event occurs
|
|
152
|
+
* @param context Optional 'this' context for the callback
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Listen for first interaction only
|
|
156
|
+
* sdk.once('interaction', () => {
|
|
157
|
+
* console.log('First user interaction occurred!');
|
|
158
|
+
* });
|
|
159
|
+
*/
|
|
160
|
+
static once(event: EventName, fn: Function, context?: any): void;
|
|
161
|
+
/**
|
|
162
|
+
* Removes an event listener.
|
|
163
|
+
*
|
|
164
|
+
* @param event Name of the event to stop listening for
|
|
165
|
+
* @param fn Optional callback function to remove (if not provided, removes all listeners for the event)
|
|
166
|
+
* @param context Optional 'this' context to match when removing
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Remove specific listener
|
|
170
|
+
* const handler = () => console.log('Interaction');
|
|
171
|
+
* sdk.off('interaction', handler);
|
|
172
|
+
*
|
|
173
|
+
* // Remove all listeners for an event
|
|
174
|
+
* sdk.off('interaction');
|
|
175
|
+
*/
|
|
176
|
+
static off(event: EventName, fn?: Function, context?: any): void;
|
|
177
|
+
/**
|
|
178
|
+
*
|
|
179
|
+
* @returns 当前渠道
|
|
180
|
+
*/
|
|
181
|
+
static getCurChannel(): "applovin" | "ironsource" | "unity" | "mintegral" | "preview" | "google" | "facebook" | "moloco" | "vungle" | "adcolony" | "tapjoy" | "snapchat" | "tiktok" | "appreciate" | "chartboost" | "pangle" | "mytarget" | "liftoff" | "smadex" | "adikteev" | "bigabid" | "inmobi" | "bigoads";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 微信浏览器引导遮罩层
|
|
186
|
+
* 当用户在微信中点击 Install 按钮时显示,引导用户在浏览器中打开
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* 创建并显示微信浏览器引导遮罩
|
|
190
|
+
*/
|
|
191
|
+
declare function showWechatGuide(): void;
|
|
192
|
+
/**
|
|
193
|
+
* 隐藏微信浏览器引导遮罩
|
|
194
|
+
*/
|
|
195
|
+
declare function hideWechatGuide(): void;
|
|
196
|
+
/**
|
|
197
|
+
* 移除微信浏览器引导遮罩
|
|
198
|
+
*/
|
|
199
|
+
declare function removeWechatGuide(): void;
|
|
200
|
+
|
|
201
|
+
export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
type EventName = 'init' | 'boot' | 'ready' | 'start' | 'interaction' | 'resize' | 'pause' | 'resume' | 'volume' | 'retry' | 'finish' | 'install';
|
|
2
|
+
|
|
3
|
+
type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Main SDK class providing playable ad functionality and state management.
|
|
6
|
+
* Handles initialization, lifecycle events, and interactions across different ad networks.
|
|
7
|
+
*/
|
|
8
|
+
declare class sdk {
|
|
9
|
+
/** Current version of the SDK */
|
|
10
|
+
static version: string;
|
|
11
|
+
/** Current maximum width of the playable ad container in pixels */
|
|
12
|
+
static maxWidth: number;
|
|
13
|
+
/** Current maximum height of the playable ad container in pixels */
|
|
14
|
+
static maxHeight: number;
|
|
15
|
+
/** Indicates if the current orientation is landscape (width > height) */
|
|
16
|
+
static isLandscape: boolean;
|
|
17
|
+
/** Indicates if the Ad Network is ready and playable ad can be initialized */
|
|
18
|
+
static isReady: boolean;
|
|
19
|
+
/** Indicates if all playable ad resources are loaded and gameplay has started */
|
|
20
|
+
static isStarted: boolean;
|
|
21
|
+
/** Indicates if the playable ad is currently paused */
|
|
22
|
+
static isPaused: boolean;
|
|
23
|
+
/** Indicates if the playable ad has finished */
|
|
24
|
+
static isFinished: boolean;
|
|
25
|
+
/** Current volume level (0-1) */
|
|
26
|
+
static volume: number;
|
|
27
|
+
/** Number of user interactions with the playable ad */
|
|
28
|
+
static interactions: number;
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the SDK and sets up protocol-specific handlers.
|
|
31
|
+
* This must be called as earlier as possible.
|
|
32
|
+
*
|
|
33
|
+
* @param callback Optional function called when ad container is ready
|
|
34
|
+
* @example
|
|
35
|
+
* // Basic initialization
|
|
36
|
+
* sdk.init();
|
|
37
|
+
*
|
|
38
|
+
* // Initialization with callback
|
|
39
|
+
* sdk.init((width, height) => {
|
|
40
|
+
* new App(width, height)
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* @fires init When initialization starts
|
|
44
|
+
* @fires boot When the ad begins booting
|
|
45
|
+
* @fires ready When Ad Network is ready and playable ad can be initialized
|
|
46
|
+
*/
|
|
47
|
+
static init(callback?: InitCallbackType): void;
|
|
48
|
+
/**
|
|
49
|
+
* Starts the playable ad experience.
|
|
50
|
+
* Should be called after all resources are loaded and first frame is rendered.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Call just after all resources are preloaded and first frame is rendered
|
|
54
|
+
* sdk.start();
|
|
55
|
+
*
|
|
56
|
+
* @fires start When the playable ad starts
|
|
57
|
+
* @fires resize When the ad container is initially sized
|
|
58
|
+
*/
|
|
59
|
+
static start(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Marks the playable ad as finished.
|
|
62
|
+
* This triggers network-specific completion handlers.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Call when game/experience is complete
|
|
66
|
+
* sdk.finish();
|
|
67
|
+
*
|
|
68
|
+
* @fires finish When the playable ad is marked as finished
|
|
69
|
+
*/
|
|
70
|
+
static finish(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Triggers a retry/restart of the playable ad.
|
|
73
|
+
* Behavior varies by ad network.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Allow user to try again
|
|
77
|
+
* retryButton.onclick = () => sdk.retry();
|
|
78
|
+
*
|
|
79
|
+
* @fires retry When a retry is triggered
|
|
80
|
+
*/
|
|
81
|
+
static retry(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Triggers the install/download action for the advertised app.
|
|
84
|
+
* Handles different store opening methods across ad networks.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Call when user wants to install
|
|
88
|
+
* installButton.onclick = () => sdk.install();
|
|
89
|
+
*
|
|
90
|
+
* @fires finish If the ad hasn't been marked as finished
|
|
91
|
+
* @fires install When the install action is triggered
|
|
92
|
+
*/
|
|
93
|
+
static install(params?: {
|
|
94
|
+
action_type: 'auto' | 'click';
|
|
95
|
+
timeout: number;
|
|
96
|
+
}): void;
|
|
97
|
+
/**
|
|
98
|
+
* Trigger force resize event
|
|
99
|
+
* Useful when container size changes need to be manually propagated.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* sdk.resize();
|
|
103
|
+
*
|
|
104
|
+
* @fires resize With current maxWidth and maxHeight
|
|
105
|
+
*/
|
|
106
|
+
static resize(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Forces the playable ad into a paused state.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Pause the experience
|
|
112
|
+
* pauseButton.onclick = () => sdk.pause();
|
|
113
|
+
*
|
|
114
|
+
* @fires pause When the ad enters paused state
|
|
115
|
+
*/
|
|
116
|
+
static pause(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Resumes the playable ad from a forced pause state.
|
|
119
|
+
* Only works if the ad was paused via sdk.pause().
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // Resume from pause
|
|
123
|
+
* resumeButton.onclick = () => sdk.resume();
|
|
124
|
+
*
|
|
125
|
+
* @fires resume When the ad resumes from pause
|
|
126
|
+
*/
|
|
127
|
+
static resume(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Registers an event listener.
|
|
130
|
+
*
|
|
131
|
+
* @param event Name of the event to listen for
|
|
132
|
+
* @param fn Callback function to execute when event occurs
|
|
133
|
+
* @param context Optional 'this' context for the callback
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // Listen for user interactions
|
|
137
|
+
* sdk.on('interaction', (count) => {
|
|
138
|
+
* console.log(`User interaction #${count}`);
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* // Listen for resize with context
|
|
142
|
+
* sdk.on('resize', function(width, height) {
|
|
143
|
+
* this.updateLayout(width, height);
|
|
144
|
+
* }, gameInstance);
|
|
145
|
+
*/
|
|
146
|
+
static on(event: EventName, fn: Function, context?: any): void;
|
|
147
|
+
/**
|
|
148
|
+
* Registers a one-time event listener that removes itself after execution.
|
|
149
|
+
*
|
|
150
|
+
* @param event Name of the event to listen for
|
|
151
|
+
* @param fn Callback function to execute when event occurs
|
|
152
|
+
* @param context Optional 'this' context for the callback
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* // Listen for first interaction only
|
|
156
|
+
* sdk.once('interaction', () => {
|
|
157
|
+
* console.log('First user interaction occurred!');
|
|
158
|
+
* });
|
|
159
|
+
*/
|
|
160
|
+
static once(event: EventName, fn: Function, context?: any): void;
|
|
161
|
+
/**
|
|
162
|
+
* Removes an event listener.
|
|
163
|
+
*
|
|
164
|
+
* @param event Name of the event to stop listening for
|
|
165
|
+
* @param fn Optional callback function to remove (if not provided, removes all listeners for the event)
|
|
166
|
+
* @param context Optional 'this' context to match when removing
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Remove specific listener
|
|
170
|
+
* const handler = () => console.log('Interaction');
|
|
171
|
+
* sdk.off('interaction', handler);
|
|
172
|
+
*
|
|
173
|
+
* // Remove all listeners for an event
|
|
174
|
+
* sdk.off('interaction');
|
|
175
|
+
*/
|
|
176
|
+
static off(event: EventName, fn?: Function, context?: any): void;
|
|
177
|
+
/**
|
|
178
|
+
*
|
|
179
|
+
* @returns 当前渠道
|
|
180
|
+
*/
|
|
181
|
+
static getCurChannel(): "applovin" | "ironsource" | "unity" | "mintegral" | "preview" | "google" | "facebook" | "moloco" | "vungle" | "adcolony" | "tapjoy" | "snapchat" | "tiktok" | "appreciate" | "chartboost" | "pangle" | "mytarget" | "liftoff" | "smadex" | "adikteev" | "bigabid" | "inmobi" | "bigoads";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 微信浏览器引导遮罩层
|
|
186
|
+
* 当用户在微信中点击 Install 按钮时显示,引导用户在浏览器中打开
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* 创建并显示微信浏览器引导遮罩
|
|
190
|
+
*/
|
|
191
|
+
declare function showWechatGuide(): void;
|
|
192
|
+
/**
|
|
193
|
+
* 隐藏微信浏览器引导遮罩
|
|
194
|
+
*/
|
|
195
|
+
declare function hideWechatGuide(): void;
|
|
196
|
+
/**
|
|
197
|
+
* 移除微信浏览器引导遮罩
|
|
198
|
+
*/
|
|
199
|
+
declare function removeWechatGuide(): void;
|
|
200
|
+
|
|
201
|
+
export { sdk as default, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
|