adgent-sdk 0.1.1

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 ADDED
@@ -0,0 +1,461 @@
1
+ # Adgent SDK
2
+
3
+ <div align="center">
4
+
5
+ [![License](https://img.shields.io/badge/License-Proprietary-red.svg)](#license)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
7
+ [![VAST 4.x](https://img.shields.io/badge/VAST-4.x-green.svg)](https://www.iab.com/guidelines/vast/)
8
+ [![Size](https://img.shields.io/badge/Size-<20KB-blueviolet.svg)](#performance)
9
+
10
+ </div>
11
+
12
+ Lightweight, framework-agnostic VAST Player SDK for Smart TV platforms.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Overview](#overview)
17
+ - [Features](#features)
18
+ - [Quick Start](#quick-start)
19
+ - [Installation](#installation)
20
+ - [Configuration](#configuration)
21
+ - [Usage](#usage)
22
+ - [Basic Setup](#basic-setup)
23
+ - [Event Handling](#event-handling)
24
+ - [Platform Detection](#platform-detection)
25
+ - [API Reference](#api-reference)
26
+ - [AdgentSDK Class](#adgetsdk-class)
27
+ - [Configuration Options](#configuration-options)
28
+ - [Events](#events)
29
+ - [Platform Support](#platform-support)
30
+ - [Performance](#performance)
31
+ - [Development](#development)
32
+ - [License](#license)
33
+
34
+ ---
35
+
36
+ ## Overview
37
+
38
+ Adgent SDK is a high-performance, lightweight VAST (Video Ad Serving Template) player SDK designed specifically for Smart TV platforms. It provides a robust foundation for displaying video advertisements with full VAST 4.x compliance while maintaining minimal footprint.
39
+
40
+ ### Why Adgent SDK?
41
+
42
+ - **Zero Framework Dependencies**: Works with any JavaScript/TypeScript project
43
+ - **Smart TV Optimized**: Purpose-built for WebOS, Tizen, Vidaa, and WhaleOS
44
+ - **Production Ready**: Battle-tested error handling and recovery mechanisms
45
+ - **Type-Safe**: Full TypeScript support with typed APIs
46
+
47
+ ---
48
+
49
+ ## Features
50
+
51
+ | Feature | Description |
52
+ |---------|-------------|
53
+ | **VAST 4.x Compliance** | Full wrapper resolution, tracking events, and smart media file selection |
54
+ | **Multi-Platform** | Native adapters for WebOS, Tizen, Vidaa, WhaleOS, and generic web environments |
55
+ | **Minimal Footprint** | Target size under 20KB gzipped, single dependency (`fast-xml-parser`) |
56
+ | **Fault Tolerant** | Nuclear Mute autoplay strategy with soft-fail recovery mechanisms |
57
+ | **Remote Control Ready** | Built-in focus management and key code normalization |
58
+ | **Event Driven** | Comprehensive event system for granular ad playback control |
59
+
60
+ ---
61
+
62
+ ## Quick Start
63
+
64
+ Get up and running in 3 simple steps:
65
+
66
+ ```bash
67
+ # 1. Install the SDK
68
+ npm install adgent-sdk
69
+
70
+ # 2. Import and initialize
71
+ import { AdgentSDK } from 'adgent-sdk';
72
+
73
+ const sdk = new AdgentSDK({
74
+ container: document.getElementById('ad-container'),
75
+ vastUrl: 'https://example.com/vast.xml',
76
+ });
77
+
78
+ await sdk.init();
79
+
80
+ # 3. Start ad playback
81
+ await sdk.play();
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Installation
87
+
88
+ ### NPM
89
+
90
+ ```bash
91
+ npm install adgent-sdk
92
+ ```
93
+
94
+ ### Yarn
95
+
96
+ ```bash
97
+ yarn add adgent-sdk
98
+ ```
99
+
100
+ ### CDN
101
+
102
+ ```html
103
+ <script src="https://cdn.example.com/adgent-sdk.min.js"></script>
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Configuration
109
+
110
+ ### Configuration Options
111
+
112
+ | Parameter | Type | Required | Default | Description |
113
+ |-----------|------|----------|---------|-------------|
114
+ | `container` | `HTMLElement` | Yes | - | Container element for the ad player |
115
+ | `vastUrl` | `string` | Yes | - | VAST tag URL to fetch ad data |
116
+ | `targetBitrate` | `number` | No | `2500` | Preferred bitrate in kbps (2500 ≈ 1080p) |
117
+ | `maxWrapperDepth` | `number` | No | `5` | Maximum VAST wrapper chain depth |
118
+ | `timeout` | `number` | No | `10000` | Request timeout in milliseconds |
119
+ | `debug` | `boolean` | No | `false` | Enable debug logging for development |
120
+ | `skipOffset` | `number` | No | - | Override skip offset in seconds |
121
+ | `skipButtonText` | `string` | No | `'Skip Ad'` | Custom skip button text |
122
+ | `mutedAutoplay` | `boolean` | No | `true` | Enable muted autoplay for compliance |
123
+
124
+ ### Callback Events
125
+
126
+ | Callback | Type | Description |
127
+ |----------|------|-------------|
128
+ | `onStart` | `() => void` | Triggered when ad starts playing |
129
+ | `onProgress` | `(progress: AdProgress) => void` | Periodic progress updates |
130
+ | `onComplete` | `() => void` | Triggered when ad finishes normally |
131
+ | `onSkip` | `() => void` | Triggered when user skips the ad |
132
+ | `onError` | `(error: AdError) => void` | Triggered on any ad-related error |
133
+ | `onPause` | `() => void` | Triggered when ad is paused |
134
+ | `onResume` | `() => void` | Triggered when ad resumes from pause |
135
+ | `onClick` | `(url: string) => void` | Triggered when user clicks the ad |
136
+
137
+ ---
138
+
139
+ ## Usage
140
+
141
+ ### Basic Setup
142
+
143
+ ```typescript
144
+ import { AdgentSDK } from 'adgent-sdk';
145
+
146
+ // Initialize the SDK
147
+ const sdk = new AdgentSDK({
148
+ container: document.getElementById('ad-container')!,
149
+ vastUrl: 'https://example.com/vast.xml',
150
+ targetBitrate: 2500,
151
+ mutedAutoplay: true,
152
+ skipButtonText: 'Skip in 5s',
153
+ onStart: () => {
154
+ console.log('Ad playback started');
155
+ },
156
+ onComplete: () => {
157
+ console.log('Ad completed successfully');
158
+ // Resume main content playback
159
+ },
160
+ onError: (err) => {
161
+ console.error('Ad error:', err);
162
+ // Graceful fallback - resume main content
163
+ },
164
+ onSkip: () => {
165
+ console.log('User skipped the ad');
166
+ }
167
+ });
168
+
169
+ // Initialize and prepare
170
+ await sdk.init();
171
+
172
+ // Play the ad
173
+ await sdk.play();
174
+ ```
175
+
176
+ ### Event Handling
177
+
178
+ #### Using Callbacks
179
+
180
+ ```typescript
181
+ const sdk = new AdgentSDK({
182
+ container: document.getElementById('ad-container')!,
183
+ vastUrl: 'https://example.com/vast.xml',
184
+ onStart: () => console.log('Ad started'),
185
+ onProgress: (progress) => {
186
+ console.log(`Progress: ${progress.percent}%`);
187
+ console.log(`Current time: ${progress.currentTime}s`);
188
+ console.log(`Duration: ${progress.duration}s`);
189
+ },
190
+ onComplete: () => console.log('Ad completed'),
191
+ onSkip: () => console.log('Ad skipped'),
192
+ onPause: () => console.log('Ad paused'),
193
+ onResume: () => console.log('Ad resumed'),
194
+ onClick: (url) => {
195
+ console.log(`Clicked: ${url}`);
196
+ window.open(url, '_blank');
197
+ },
198
+ onError: (error) => {
199
+ console.error('Error code:', error.code);
200
+ console.error('Error message:', error.message);
201
+ }
202
+ });
203
+ ```
204
+
205
+ #### Using Event Listener API
206
+
207
+ ```typescript
208
+ // Subscribe to events
209
+ const unsubscribe = sdk.on((event) => {
210
+ switch (event.type) {
211
+ case 'start':
212
+ console.log('Ad playback started');
213
+ break;
214
+ case 'quartile':
215
+ console.log(`Quartile reached: ${event.data.quartile}`);
216
+ console.log(`Progress: ${event.data.percent}%`);
217
+ break;
218
+ case 'complete':
219
+ console.log('Ad completed successfully');
220
+ break;
221
+ case 'skip':
222
+ console.log('User skipped the ad');
223
+ break;
224
+ case 'error':
225
+ console.error('Ad error:', event.data);
226
+ break;
227
+ case 'click':
228
+ console.log('Ad clicked, URL:', event.data.url);
229
+ break;
230
+ }
231
+ });
232
+
233
+ // Unsubscribe when done
234
+ unsubscribe();
235
+ ```
236
+
237
+ #### Event Types
238
+
239
+ | Event Type | Data | Description |
240
+ |------------|------|-------------|
241
+ | `start` | `{ timestamp: number }` | Ad started playing |
242
+ | `quartile` | `{ quartile: number, percent: number }` | Quartile milestone reached (25, 50, 75, 100) |
243
+ | `complete` | `{ timestamp: number }` | Ad finished successfully |
244
+ | `skip` | `{ timestamp: number }` | User skipped the ad |
245
+ | `error` | `{ code: number, message: string }` | An error occurred |
246
+ | `click` | `{ url: string }` | User clicked the ad |
247
+ | `pause` | `{ timestamp: number }` | Ad was paused |
248
+ | `resume` | `{ timestamp: number }` | Ad resumed from pause |
249
+
250
+ ### Platform Detection
251
+
252
+ ```typescript
253
+ import { getPlatformAdapter, Platform } from 'adgent-sdk';
254
+
255
+ // Get platform-specific adapter
256
+ const adapter = getPlatformAdapter();
257
+
258
+ console.log('Platform:', adapter.platform);
259
+ // Output: 'tizen' | 'webos' | 'vidaa' | 'whaleos' | 'generic'
260
+
261
+ // Check platform capabilities
262
+ if (adapter.capabilities.sendBeacon) {
263
+ console.log('Beacon API available for tracking');
264
+ }
265
+
266
+ if (adapter.capabilities.hdr) {
267
+ console.log('HDR playback supported');
268
+ }
269
+
270
+ // Access platform-specific utilities
271
+ adapter.utils.normalizeKeyCode('ArrowRight'); // Returns platform-specific key code
272
+ adapter.utils.focusElement(element);
273
+ ```
274
+
275
+ ---
276
+
277
+ ## API Reference
278
+
279
+ ### AdgentSDK Class
280
+
281
+ #### Constructor
282
+
283
+ ```typescript
284
+ new AdgentSDK(config: AdgentConfig): AdgentSDK
285
+ ```
286
+
287
+ Creates a new AdgentSDK instance with the specified configuration.
288
+
289
+ #### Methods
290
+
291
+ | Method | Returns | Description |
292
+ |--------|---------|-------------|
293
+ | `init()` | `Promise<void>` | Initializes SDK, fetches VAST, prepares player |
294
+ | `play()` | `Promise<void>` | Starts ad playback |
295
+ | `pause()` | `Promise<void>` | Pauses ad playback |
296
+ | `resume()` | `Promise<void>` | Resumes ad playback |
297
+ | `stop()` | `Promise<void>` | Stops ad playback |
298
+ | `skip()` | `Promise<void>` | Skips the current ad |
299
+ | `destroy()` | `Promise<void>` | Cleans up resources, removes event listeners |
300
+ | `on(callback)` | `UnsubscribeFn` | Subscribe to ad events |
301
+ | `getState()` | `AdState` | Get current ad playback state |
302
+
303
+ #### Usage Example
304
+
305
+ ```typescript
306
+ const sdk = new AdgentSDK({
307
+ container: document.getElementById('ad-container')!,
308
+ vastUrl: 'https://example.com/vast.xml',
309
+ });
310
+
311
+ // Initialize
312
+ await sdk.init();
313
+
314
+ // Play
315
+ await sdk.play();
316
+
317
+ // Pause after 5 seconds
318
+ setTimeout(() => {
319
+ await sdk.pause();
320
+
321
+ // Resume after 2 seconds
322
+ setTimeout(() => {
323
+ sdk.resume();
324
+ }, 2000);
325
+ }, 5000);
326
+
327
+ // Cleanup when done
328
+ sdk.destroy();
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Platform Support
334
+
335
+ ### Supported Platforms
336
+
337
+ | Platform | Version | Status |
338
+ |----------|---------|--------|
339
+ | **WebOS** | 3.0+ | ✅ Fully Supported |
340
+ | **Tizen** | 4.0+ | ✅ Fully Supported |
341
+ | **Vidaa** | 2.0+ | ✅ Fully Supported |
342
+ | **WhaleOS** | 1.0+ | ✅ Fully Supported |
343
+ | **Generic Web** | Modern browsers | ✅ Fully Supported |
344
+
345
+ ### Platform-Specific Features
346
+
347
+ #### WebOS
348
+ - Native video player integration
349
+ - LG remote control support
350
+ - WebOS specific tracking endpoints
351
+
352
+ #### Tizen
353
+ - Tizen TV Player API
354
+ - Samsung remote control mapping
355
+ - Tizen analytics integration
356
+
357
+ #### Vidaa
358
+ - HisenseVidaa OS support
359
+ - Vidaa remote control codes
360
+ - Lightweight implementation
361
+
362
+ #### WhaleOS
363
+ - Naver Whale browser support
364
+ - Whale-specific optimizations
365
+
366
+ ---
367
+
368
+ ## Performance
369
+
370
+ ### Size Comparison
371
+
372
+ | Metric | Value |
373
+ |--------|-------|
374
+ | Gzipped Size | < 20 KB |
375
+ | Minified Size | ~50 KB |
376
+ | Dependencies | 1 (`fast-xml-parser`) |
377
+
378
+ ### Optimization Tips
379
+
380
+ 1. **Enable Tree Shaking**: Use ES modules for optimal bundle size
381
+ 2. **Lazy Load**: Only load SDK when ad playback is needed
382
+ 3. **VAST Caching**: Cache VAST responses to reduce network requests
383
+ 4. **Bitrate Selection**: Set appropriate `targetBitrate` for your platform
384
+
385
+ ```typescript
386
+ // Example: Optimized configuration
387
+ const sdk = new AdgentSDK({
388
+ container: document.getElementById('ad-container')!,
389
+ vastUrl: cachedVastUrl, // Use cached VAST when available
390
+ targetBitrate: 1500, // Appropriate for most Smart TVs
391
+ timeout: 5000, // Faster timeout for better UX
392
+ });
393
+ ```
394
+
395
+ ---
396
+
397
+ ## Development
398
+
399
+ ### Setup
400
+
401
+ ```bash
402
+ # Clone the repository
403
+ git clone https://github.com/your-org/adgent-sdk.git
404
+
405
+ # Navigate to project directory
406
+ cd adgent-sdk
407
+
408
+ # Install dependencies
409
+ npm install
410
+
411
+ # Install dev dependencies
412
+ npm run install:dev
413
+ ```
414
+
415
+ ### Available Scripts
416
+
417
+ | Command | Description |
418
+ |---------|-------------|
419
+ | `npm run build` | Build the library for production |
420
+ | `npm run build:watch` | Build in watch mode for development |
421
+ | `npm run typecheck` | Run TypeScript type checking |
422
+ | `npm run lint` | Lint the codebase |
423
+ | `npm run test` | Run unit tests |
424
+ | `npm run test:watch` | Run tests in watch mode |
425
+ | `npm run dev` | Start development server |
426
+ | `npm run docs` | Generate documentation |
427
+
428
+ ### Project Structure
429
+
430
+ ```
431
+ adgent-sdk/
432
+ ├── src/
433
+ │ ├── core/ # Core SDK functionality
434
+ │ ├── adapters/ # Platform-specific adapters
435
+ │ ├── utils/ # Utility functions
436
+ │ ├── types/ # TypeScript type definitions
437
+ │ └── index.ts # Main entry point
438
+ ├── test/ # Test files
439
+ ├── dist/ # Built output
440
+ ├── docs/ # Documentation
441
+ └── package.json
442
+ ```
443
+
444
+ ### Contributing
445
+
446
+ 1. Fork the repository
447
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
448
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
449
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
450
+ 5. Open a Pull Request
451
+
452
+ ---
453
+
454
+ ## License
455
+
456
+ Proprietary - All rights reserved.
457
+
458
+ This software and its source code are the exclusive property of the copyright holder. No part of this software may be reproduced, distributed, or transmitted in any form or by any means, including photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the copyright holder, except in the case of brief quotations embodied in critical reviews and certain other non-commercial uses permitted by copyright law.
459
+
460
+ For licensing inquiries, please contact: license@example.com
461
+ # adgent-sdk