unified-video-framework 1.4.425 → 1.4.426
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/package.json +1 -1
- package/packages/core/dist/VideoPlayerFactory.d.ts.map +1 -1
- package/packages/core/dist/VideoPlayerFactory.js +7 -0
- package/packages/core/dist/VideoPlayerFactory.js.map +1 -1
- package/packages/core/dist/index.d.ts +2 -0
- package/packages/core/dist/index.d.ts.map +1 -1
- package/packages/core/dist/index.js +1 -0
- package/packages/core/dist/index.js.map +1 -1
- package/packages/core/dist/telemetry/TelemetryManager.d.ts +20 -0
- package/packages/core/dist/telemetry/TelemetryManager.d.ts.map +1 -0
- package/packages/core/dist/telemetry/TelemetryManager.js +49 -0
- package/packages/core/dist/telemetry/TelemetryManager.js.map +1 -0
- package/packages/core/src/VideoPlayerFactory.ts +28 -18
- package/packages/core/src/index.ts +4 -0
- package/packages/core/src/telemetry/TelemetryManager.ts +72 -0
- package/packages/web/dist/WebPlayer.d.ts +0 -2
- package/packages/web/dist/WebPlayer.d.ts.map +1 -1
- package/packages/web/dist/WebPlayer.js +0 -50
- package/packages/web/dist/WebPlayer.js.map +1 -1
- package/packages/web/dist/react/WebPlayerView.d.ts +0 -1
- package/packages/web/dist/react/WebPlayerView.d.ts.map +1 -1
- package/packages/web/dist/react/WebPlayerView.js +0 -5
- package/packages/web/dist/react/WebPlayerView.js.map +1 -1
- package/packages/web/src/WebPlayer.ts +0 -65
- package/packages/web/src/react/WebPlayerView.tsx +0 -6
- package/scripts/fix-imports.js +8 -54
- package/packages/core/src/BasePlayer.d.ts +0 -61
- package/packages/core/src/BasePlayer.d.ts.map +0 -1
- package/packages/core/src/BasePlayer.js +0 -175
- package/packages/core/src/BasePlayer.js.map +0 -1
- package/packages/core/src/VideoPlayerFactory.d.ts +0 -8
- package/packages/core/src/VideoPlayerFactory.d.ts.map +0 -1
- package/packages/core/src/VideoPlayerFactory.js +0 -95
- package/packages/core/src/VideoPlayerFactory.js.map +0 -1
- package/packages/core/src/analytics/adapters/PlayerAnalyticsAdapter.d.ts +0 -18
- package/packages/core/src/analytics/adapters/PlayerAnalyticsAdapter.d.ts.map +0 -1
- package/packages/core/src/analytics/adapters/PlayerAnalyticsAdapter.js +0 -117
- package/packages/core/src/analytics/adapters/PlayerAnalyticsAdapter.js.map +0 -1
- package/packages/core/src/analytics/core/AnalyticsProvider.d.ts +0 -18
- package/packages/core/src/analytics/core/AnalyticsProvider.d.ts.map +0 -1
- package/packages/core/src/analytics/core/AnalyticsProvider.js +0 -99
- package/packages/core/src/analytics/core/AnalyticsProvider.js.map +0 -1
- package/packages/core/src/analytics/core/DynamicAnalyticsManager.d.ts +0 -20
- package/packages/core/src/analytics/core/DynamicAnalyticsManager.d.ts.map +0 -1
- package/packages/core/src/analytics/core/DynamicAnalyticsManager.js +0 -161
- package/packages/core/src/analytics/core/DynamicAnalyticsManager.js.map +0 -1
- package/packages/core/src/analytics/core/EventBatcher.d.ts +0 -32
- package/packages/core/src/analytics/core/EventBatcher.d.ts.map +0 -1
- package/packages/core/src/analytics/core/EventBatcher.js +0 -98
- package/packages/core/src/analytics/core/EventBatcher.js.map +0 -1
- package/packages/core/src/analytics/core/PlayerAnalytics.d.ts +0 -19
- package/packages/core/src/analytics/core/PlayerAnalytics.d.ts.map +0 -1
- package/packages/core/src/analytics/core/PlayerAnalytics.js +0 -80
- package/packages/core/src/analytics/core/PlayerAnalytics.js.map +0 -1
- package/packages/core/src/analytics/index.d.ts +0 -13
- package/packages/core/src/analytics/index.d.ts.map +0 -1
- package/packages/core/src/analytics/index.js +0 -13
- package/packages/core/src/analytics/index.js.map +0 -1
- package/packages/core/src/analytics/types/AnalyticsTypes.d.ts +0 -239
- package/packages/core/src/analytics/types/AnalyticsTypes.d.ts.map +0 -1
- package/packages/core/src/analytics/types/AnalyticsTypes.js +0 -8
- package/packages/core/src/analytics/types/AnalyticsTypes.js.map +0 -1
- package/packages/core/src/analytics/utils/DeviceDetection.d.ts +0 -27
- package/packages/core/src/analytics/utils/DeviceDetection.d.ts.map +0 -1
- package/packages/core/src/analytics/utils/DeviceDetection.js +0 -184
- package/packages/core/src/analytics/utils/DeviceDetection.js.map +0 -1
- package/packages/core/src/chapter-manager.d.ts +0 -39
- package/packages/core/src/chapter-manager.d.ts.map +0 -1
- package/packages/core/src/chapter-manager.js +0 -173
- package/packages/core/src/chapter-manager.js.map +0 -1
- package/packages/core/src/index.d.ts +0 -10
- package/packages/core/src/index.d.ts.map +0 -1
- package/packages/core/src/index.js +0 -8
- package/packages/core/src/index.js.map +0 -1
- package/packages/core/src/interfaces/IVideoPlayer.d.ts +0 -229
- package/packages/core/src/interfaces/IVideoPlayer.d.ts.map +0 -1
- package/packages/core/src/interfaces/IVideoPlayer.js +0 -2
- package/packages/core/src/interfaces/IVideoPlayer.js.map +0 -1
- package/packages/core/src/interfaces.d.ts +0 -455
- package/packages/core/src/interfaces.d.ts.map +0 -1
- package/packages/core/src/interfaces.js +0 -32
- package/packages/core/src/interfaces.js.map +0 -1
- package/packages/core/src/utils/EventEmitter.d.ts +0 -14
- package/packages/core/src/utils/EventEmitter.d.ts.map +0 -1
- package/packages/core/src/utils/EventEmitter.js +0 -55
- package/packages/core/src/utils/EventEmitter.js.map +0 -1
- package/packages/web/src/drm/DRMManager.ts +0 -224
- package/packages/web/src/drm/index.ts +0 -37
- package/packages/web/src/drm/providers/BunnyNetProvider.ts +0 -171
- package/packages/web/src/drm/providers/GenericProvider.ts +0 -151
- package/packages/web/src/drm/systems/BaseDRM.ts +0 -68
- package/packages/web/src/drm/systems/FairPlayDRM.ts +0 -317
- package/packages/web/src/drm/systems/PlayReadyDRM.ts +0 -156
- package/packages/web/src/drm/systems/WidevineDRM.ts +0 -133
- package/packages/web/src/drm/types/BunnyNetTypes.ts +0 -35
- package/packages/web/src/drm/types/DRMTypes.ts +0 -93
- package/packages/web/src/drm/utils/BrowserDetector.ts +0 -281
- package/packages/web/src/drm/utils/CertificateManager.ts +0 -86
- package/packages/web/src/drm/utils/DRMErrorHandler.ts +0 -84
- package/packages/web/src/drm/utils/LicenseRequestHandler.ts +0 -180
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DRM Manager
|
|
3
|
-
* Main orchestrator for all DRM systems
|
|
4
|
-
* Provides a unified interface for HLS.js, dash.js, and native playback
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { DRMType, DRMConfig } from '@unified-video/core';
|
|
8
|
-
import { DRMType as DRMTypeEnum } from '@unified-video/core';
|
|
9
|
-
import { ExtendedDRMConfig, DRMInitResult, DRMError, DRMErrorCode, DRMCapabilities } from './types/DRMTypes';
|
|
10
|
-
import { BrowserDetector } from './utils/BrowserDetector';
|
|
11
|
-
import { BunnyNetProvider } from './providers/BunnyNetProvider';
|
|
12
|
-
import { WidevineDRM } from './systems/WidevineDRM';
|
|
13
|
-
import { FairPlayDRM } from './systems/FairPlayDRM';
|
|
14
|
-
import { PlayReadyDRM } from './systems/PlayReadyDRM';
|
|
15
|
-
import { BaseDRM } from './systems/BaseDRM';
|
|
16
|
-
import { DRMErrorHandler } from './utils/DRMErrorHandler';
|
|
17
|
-
|
|
18
|
-
export class DRMManager {
|
|
19
|
-
private videoElement: HTMLVideoElement;
|
|
20
|
-
private config: ExtendedDRMConfig;
|
|
21
|
-
private drmSystem: BaseDRM | null = null;
|
|
22
|
-
private browserDetector: BrowserDetector;
|
|
23
|
-
private debug: boolean = false;
|
|
24
|
-
|
|
25
|
-
constructor(videoElement: HTMLVideoElement, config: DRMConfig, debug: boolean = false) {
|
|
26
|
-
this.videoElement = videoElement;
|
|
27
|
-
this.config = this.normalizeConfig(config);
|
|
28
|
-
this.debug = debug || this.config.debug || false;
|
|
29
|
-
this.browserDetector = BrowserDetector.getInstance();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Initialize DRM system based on browser capabilities
|
|
34
|
-
*/
|
|
35
|
-
async initialize(): Promise<DRMInitResult> {
|
|
36
|
-
try {
|
|
37
|
-
this.log('Initializing DRM system...');
|
|
38
|
-
|
|
39
|
-
// Check for secure context - EME requires HTTPS or localhost
|
|
40
|
-
if (typeof window !== 'undefined' && !window.isSecureContext) {
|
|
41
|
-
throw DRMErrorHandler.createError(
|
|
42
|
-
DRMErrorCode.SECURE_CONTEXT_REQUIRED,
|
|
43
|
-
'DRM requires a secure context (HTTPS or localhost). Please ensure your site is running over HTTPS.',
|
|
44
|
-
true
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Detect browser capabilities
|
|
49
|
-
const capabilities = await this.browserDetector.detectCapabilities();
|
|
50
|
-
this.log('Browser DRM capabilities:', capabilities);
|
|
51
|
-
|
|
52
|
-
// Determine which DRM system to use
|
|
53
|
-
const drmType = this.selectDRMType(capabilities);
|
|
54
|
-
if (!drmType) {
|
|
55
|
-
const browserName = this.browserDetector.getBrowserName();
|
|
56
|
-
throw DRMErrorHandler.createError(
|
|
57
|
-
DRMErrorCode.UNSUPPORTED_BROWSER,
|
|
58
|
-
`No supported DRM system found in ${browserName}. Please use Chrome, Safari, Firefox, or Edge.`,
|
|
59
|
-
true,
|
|
60
|
-
{ browser: browserName, capabilities }
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.log(`Selected DRM type: ${drmType}`);
|
|
65
|
-
|
|
66
|
-
// Create appropriate DRM system
|
|
67
|
-
this.drmSystem = this.createDRMSystem(drmType);
|
|
68
|
-
|
|
69
|
-
// Initialize the DRM system
|
|
70
|
-
await this.drmSystem.initialize();
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
success: true,
|
|
74
|
-
drmType,
|
|
75
|
-
keySystem: this.drmSystem.getKeySystem(),
|
|
76
|
-
};
|
|
77
|
-
} catch (error: any) {
|
|
78
|
-
this.log('DRM initialization failed:', error);
|
|
79
|
-
|
|
80
|
-
const capabilities = await this.browserDetector.detectCapabilities();
|
|
81
|
-
const drmError = error.code && error.code.startsWith('DRM_')
|
|
82
|
-
? error
|
|
83
|
-
: DRMErrorHandler.createError(
|
|
84
|
-
DRMErrorCode.CONFIGURATION_ERROR,
|
|
85
|
-
error.message || 'DRM initialization failed',
|
|
86
|
-
true,
|
|
87
|
-
{ ...error, capabilities }
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
drmType: this.config.type,
|
|
93
|
-
keySystem: '',
|
|
94
|
-
error: drmError,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get HLS.js configuration for DRM
|
|
101
|
-
*/
|
|
102
|
-
getHLSConfig(): any {
|
|
103
|
-
if (!this.drmSystem) {
|
|
104
|
-
throw new Error('DRM system not initialized. Call initialize() first.');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return this.drmSystem.getHLSConfig();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get dash.js protection data for DRM
|
|
112
|
-
*/
|
|
113
|
-
getDashProtectionData(): any {
|
|
114
|
-
if (!this.drmSystem) {
|
|
115
|
-
throw new Error('DRM system not initialized. Call initialize() first.');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return this.drmSystem.getDashProtectionData();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Cleanup DRM resources
|
|
123
|
-
*/
|
|
124
|
-
async destroy(): Promise<void> {
|
|
125
|
-
if (this.drmSystem) {
|
|
126
|
-
this.log('Destroying DRM system');
|
|
127
|
-
await this.drmSystem.destroy();
|
|
128
|
-
this.drmSystem = null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Select appropriate DRM type based on config and capabilities
|
|
134
|
-
*/
|
|
135
|
-
private selectDRMType(capabilities: DRMCapabilities): DRMType | null {
|
|
136
|
-
// If config specifies a type and it's supported, use it
|
|
137
|
-
if (this.config.type) {
|
|
138
|
-
const typeSupported = this.isDRMTypeSupported(this.config.type, capabilities);
|
|
139
|
-
if (typeSupported) {
|
|
140
|
-
return this.config.type;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
this.log(`Requested DRM type ${this.config.type} not supported, falling back to browser default`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Otherwise, use browser's preferred DRM system
|
|
147
|
-
return capabilities.supportedType;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Check if specific DRM type is supported
|
|
152
|
-
*/
|
|
153
|
-
private isDRMTypeSupported(drmType: DRMType, capabilities: DRMCapabilities): boolean {
|
|
154
|
-
switch (drmType) {
|
|
155
|
-
case DRMTypeEnum.WIDEVINE:
|
|
156
|
-
return capabilities.widevine;
|
|
157
|
-
case DRMTypeEnum.FAIRPLAY:
|
|
158
|
-
return capabilities.fairplay;
|
|
159
|
-
case DRMTypeEnum.PLAYREADY:
|
|
160
|
-
return capabilities.playready;
|
|
161
|
-
default:
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Create DRM system instance
|
|
168
|
-
*/
|
|
169
|
-
private createDRMSystem(drmType: DRMType): BaseDRM {
|
|
170
|
-
switch (drmType) {
|
|
171
|
-
case DRMTypeEnum.FAIRPLAY:
|
|
172
|
-
return new FairPlayDRM(this.videoElement, this.config, this.debug);
|
|
173
|
-
|
|
174
|
-
case DRMTypeEnum.WIDEVINE:
|
|
175
|
-
return new WidevineDRM(this.videoElement, this.config, this.debug);
|
|
176
|
-
|
|
177
|
-
case DRMTypeEnum.PLAYREADY:
|
|
178
|
-
return new PlayReadyDRM(this.videoElement, this.config, this.debug);
|
|
179
|
-
|
|
180
|
-
default:
|
|
181
|
-
throw DRMErrorHandler.createError(
|
|
182
|
-
DRMErrorCode.CONFIGURATION_ERROR,
|
|
183
|
-
`Unsupported DRM type: ${drmType}`,
|
|
184
|
-
true
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Normalize and enrich DRM config
|
|
191
|
-
*/
|
|
192
|
-
private normalizeConfig(config: DRMConfig): ExtendedDRMConfig {
|
|
193
|
-
const extended = { ...config } as ExtendedDRMConfig;
|
|
194
|
-
|
|
195
|
-
// Auto-detect Bunny.net and enhance config
|
|
196
|
-
if (BunnyNetProvider.isBunnyNetConfig(config)) {
|
|
197
|
-
extended.provider = 'bunny';
|
|
198
|
-
|
|
199
|
-
// Extract IDs if available
|
|
200
|
-
const ids = BunnyNetProvider.extractIdsFromUrl(config.licenseUrl);
|
|
201
|
-
if (ids.libraryId) extended.libraryId = ids.libraryId;
|
|
202
|
-
if (ids.videoId) extended.videoId = ids.videoId;
|
|
203
|
-
|
|
204
|
-
this.log('Detected Bunny.net DRM configuration');
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Set defaults
|
|
208
|
-
extended.retryConfig = extended.retryConfig || {
|
|
209
|
-
maxRetries: 3,
|
|
210
|
-
retryDelay: 1000,
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
return extended;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Debug logging
|
|
218
|
-
*/
|
|
219
|
-
private log(...args: any[]): void {
|
|
220
|
-
if (this.debug) {
|
|
221
|
-
console.log('[DRMManager]', ...args);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DRM System - Public API
|
|
3
|
-
* Exports for the DRM system
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Main DRM Manager
|
|
7
|
-
export { DRMManager } from './DRMManager';
|
|
8
|
-
|
|
9
|
-
// Providers
|
|
10
|
-
export { BunnyNetProvider } from './providers/BunnyNetProvider';
|
|
11
|
-
export { GenericProvider } from './providers/GenericProvider';
|
|
12
|
-
|
|
13
|
-
// Types
|
|
14
|
-
export type {
|
|
15
|
-
ExtendedDRMConfig,
|
|
16
|
-
DRMCapabilities,
|
|
17
|
-
LicenseRequest,
|
|
18
|
-
LicenseResponse,
|
|
19
|
-
DRMInitResult,
|
|
20
|
-
DRMError,
|
|
21
|
-
} from './types/DRMTypes';
|
|
22
|
-
|
|
23
|
-
export { DRMErrorCode, KEY_SYSTEMS } from './types/DRMTypes';
|
|
24
|
-
|
|
25
|
-
export type { BunnyNetConfig, BunnyNetEndpoints } from './types/BunnyNetTypes';
|
|
26
|
-
export { BUNNY_NET_BASE_URL, BUNNY_NET_ENDPOINTS } from './types/BunnyNetTypes';
|
|
27
|
-
|
|
28
|
-
// Utilities
|
|
29
|
-
export { BrowserDetector } from './utils/BrowserDetector';
|
|
30
|
-
export { DRMErrorHandler } from './utils/DRMErrorHandler';
|
|
31
|
-
export { CertificateManager } from './utils/CertificateManager';
|
|
32
|
-
|
|
33
|
-
// DRM Systems (for advanced usage)
|
|
34
|
-
export { BaseDRM } from './systems/BaseDRM';
|
|
35
|
-
export { WidevineDRM } from './systems/WidevineDRM';
|
|
36
|
-
export { FairPlayDRM } from './systems/FairPlayDRM';
|
|
37
|
-
export { PlayReadyDRM } from './systems/PlayReadyDRM';
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunny.net DRM Provider
|
|
3
|
-
* Helper utilities for Bunny.net MediaCage DRM integration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { DRMType, DRMConfig } from '@unified-video/core';
|
|
7
|
-
import { DRMType as DRMTypeEnum } from '@unified-video/core';
|
|
8
|
-
import { ExtendedDRMConfig } from '../types/DRMTypes';
|
|
9
|
-
import { BunnyNetConfig, BUNNY_NET_ENDPOINTS } from '../types/BunnyNetTypes';
|
|
10
|
-
|
|
11
|
-
export class BunnyNetProvider {
|
|
12
|
-
/**
|
|
13
|
-
* Generate complete DRM config from Bunny.net credentials
|
|
14
|
-
*/
|
|
15
|
-
static createDRMConfig(config: BunnyNetConfig): ExtendedDRMConfig {
|
|
16
|
-
const { libraryId, videoId, drmType = DRMTypeEnum.WIDEVINE } = config;
|
|
17
|
-
|
|
18
|
-
const drmConfig: ExtendedDRMConfig = {
|
|
19
|
-
type: drmType,
|
|
20
|
-
licenseUrl: this.getLicenseUrl(drmType, libraryId, videoId),
|
|
21
|
-
provider: 'bunny',
|
|
22
|
-
libraryId,
|
|
23
|
-
videoId,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Add FairPlay-specific settings
|
|
27
|
-
if (drmType === DRMTypeEnum.FAIRPLAY) {
|
|
28
|
-
drmConfig.certificateUrl = this.getCertificateUrl(libraryId);
|
|
29
|
-
drmConfig.fairplayOptions = {
|
|
30
|
-
certificateUrl: this.getCertificateUrl(libraryId),
|
|
31
|
-
licenseUrl: this.getLicenseUrl(drmType, libraryId, videoId),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Add Widevine-specific settings
|
|
36
|
-
if (drmType === DRMTypeEnum.WIDEVINE) {
|
|
37
|
-
drmConfig.widevineOptions = {
|
|
38
|
-
licenseUrl: this.getLicenseUrl(drmType, libraryId, videoId),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Add PlayReady-specific settings
|
|
43
|
-
if (drmType === DRMTypeEnum.PLAYREADY) {
|
|
44
|
-
drmConfig.playreadyOptions = {
|
|
45
|
-
licenseUrl: this.getLicenseUrl(drmType, libraryId, videoId),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return drmConfig;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Get license URL for specific DRM type
|
|
54
|
-
*/
|
|
55
|
-
static getLicenseUrl(drmType: DRMType, libraryId: string, videoId: string): string {
|
|
56
|
-
switch (drmType) {
|
|
57
|
-
case DRMTypeEnum.WIDEVINE:
|
|
58
|
-
return BUNNY_NET_ENDPOINTS.WIDEVINE_LICENSE(libraryId, videoId);
|
|
59
|
-
|
|
60
|
-
case DRMTypeEnum.FAIRPLAY:
|
|
61
|
-
return BUNNY_NET_ENDPOINTS.FAIRPLAY_LICENSE(libraryId, videoId);
|
|
62
|
-
|
|
63
|
-
case DRMTypeEnum.PLAYREADY:
|
|
64
|
-
return BUNNY_NET_ENDPOINTS.PLAYREADY_LICENSE(libraryId, videoId);
|
|
65
|
-
|
|
66
|
-
default:
|
|
67
|
-
throw new Error(`Unsupported DRM type for Bunny.net: ${drmType}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get certificate URL (FairPlay only)
|
|
73
|
-
*/
|
|
74
|
-
static getCertificateUrl(libraryId: string): string {
|
|
75
|
-
return BUNNY_NET_ENDPOINTS.FAIRPLAY_CERTIFICATE(libraryId);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Validate Bunny.net DRM configuration
|
|
80
|
-
*/
|
|
81
|
-
static validateConfig(config: BunnyNetConfig): { valid: boolean; error?: string } {
|
|
82
|
-
if (!config.libraryId || !config.videoId) {
|
|
83
|
-
return {
|
|
84
|
-
valid: false,
|
|
85
|
-
error: 'Bunny.net DRM requires libraryId and videoId',
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!/^\d+$/.test(config.libraryId)) {
|
|
90
|
-
return {
|
|
91
|
-
valid: false,
|
|
92
|
-
error: 'libraryId must be a numeric string',
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return { valid: true };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Auto-detect if a DRM config is for Bunny.net
|
|
101
|
-
*/
|
|
102
|
-
static isBunnyNetConfig(config: DRMConfig): boolean {
|
|
103
|
-
return !!(
|
|
104
|
-
config.licenseUrl?.includes('bunnycdn.com') ||
|
|
105
|
-
config.certificateUrl?.includes('bunnycdn.com') ||
|
|
106
|
-
config.fairplayOptions?.licenseUrl?.includes('bunnycdn.com') ||
|
|
107
|
-
config.fairplayOptions?.certificateUrl?.includes('bunnycdn.com') ||
|
|
108
|
-
config.widevineOptions?.licenseUrl?.includes('bunnycdn.com') ||
|
|
109
|
-
config.playreadyOptions?.licenseUrl?.includes('bunnycdn.com')
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Extract library and video IDs from Bunny.net URLs
|
|
115
|
-
*/
|
|
116
|
-
static extractIdsFromUrl(url: string): { libraryId?: string; videoId?: string } {
|
|
117
|
-
if (!url) return {};
|
|
118
|
-
|
|
119
|
-
const widevineMatch = url.match(/WidevineLicense\/([^/]+)\/([^/?]+)/);
|
|
120
|
-
const fairplayLicenseMatch = url.match(/FairPlay\/([^/]+)\/license.*videoId=([^&]+)/);
|
|
121
|
-
const fairplayCertMatch = url.match(/FairPlay\/([^/]+)\/certificate/);
|
|
122
|
-
const playreadyMatch = url.match(/PlayReadyLicense\/([^/]+)\/([^/?]+)/);
|
|
123
|
-
|
|
124
|
-
if (widevineMatch) {
|
|
125
|
-
return { libraryId: widevineMatch[1], videoId: widevineMatch[2] };
|
|
126
|
-
}
|
|
127
|
-
if (fairplayLicenseMatch) {
|
|
128
|
-
return { libraryId: fairplayLicenseMatch[1], videoId: fairplayLicenseMatch[2] };
|
|
129
|
-
}
|
|
130
|
-
if (fairplayCertMatch) {
|
|
131
|
-
return { libraryId: fairplayCertMatch[1] };
|
|
132
|
-
}
|
|
133
|
-
if (playreadyMatch) {
|
|
134
|
-
return { libraryId: playreadyMatch[1], videoId: playreadyMatch[2] };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Create multi-DRM config for Bunny.net (auto-detects browser)
|
|
142
|
-
*/
|
|
143
|
-
static createMultiDRMConfig(libraryId: string, videoId: string): ExtendedDRMConfig {
|
|
144
|
-
// Primary Widevine config with FairPlay fallback
|
|
145
|
-
const config: ExtendedDRMConfig = {
|
|
146
|
-
type: DRMTypeEnum.WIDEVINE,
|
|
147
|
-
licenseUrl: this.getLicenseUrl(DRMTypeEnum.WIDEVINE, libraryId, videoId),
|
|
148
|
-
provider: 'bunny',
|
|
149
|
-
libraryId,
|
|
150
|
-
videoId,
|
|
151
|
-
|
|
152
|
-
// Widevine options
|
|
153
|
-
widevineOptions: {
|
|
154
|
-
licenseUrl: this.getLicenseUrl(DRMTypeEnum.WIDEVINE, libraryId, videoId),
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
// FairPlay options (for Safari fallback)
|
|
158
|
-
fairplayOptions: {
|
|
159
|
-
certificateUrl: this.getCertificateUrl(libraryId),
|
|
160
|
-
licenseUrl: this.getLicenseUrl(DRMTypeEnum.FAIRPLAY, libraryId, videoId),
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
// PlayReady options (for Edge fallback)
|
|
164
|
-
playreadyOptions: {
|
|
165
|
-
licenseUrl: this.getLicenseUrl(DRMTypeEnum.PLAYREADY, libraryId, videoId),
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
return config;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic DRM Provider
|
|
3
|
-
* Helper utilities for generic DRM configurations
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { DRMType, DRMConfig } from '@unified-video/core';
|
|
7
|
-
import { ExtendedDRMConfig } from '../types/DRMTypes';
|
|
8
|
-
|
|
9
|
-
export class GenericProvider {
|
|
10
|
-
/**
|
|
11
|
-
* Create generic DRM config with sensible defaults
|
|
12
|
-
*/
|
|
13
|
-
static createDRMConfig(config: {
|
|
14
|
-
drmType: DRMType;
|
|
15
|
-
licenseUrl: string;
|
|
16
|
-
certificateUrl?: string;
|
|
17
|
-
headers?: Record<string, string>;
|
|
18
|
-
customData?: string;
|
|
19
|
-
}): ExtendedDRMConfig {
|
|
20
|
-
const drmConfig: ExtendedDRMConfig = {
|
|
21
|
-
type: config.drmType,
|
|
22
|
-
licenseUrl: config.licenseUrl,
|
|
23
|
-
certificateUrl: config.certificateUrl,
|
|
24
|
-
headers: config.headers,
|
|
25
|
-
customData: config.customData,
|
|
26
|
-
provider: 'generic',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Add type-specific options
|
|
30
|
-
const DRMTypeEnum = require('../../../core/src/interfaces').DRMType;
|
|
31
|
-
switch (config.drmType) {
|
|
32
|
-
case DRMTypeEnum.FAIRPLAY:
|
|
33
|
-
if (config.certificateUrl) {
|
|
34
|
-
drmConfig.fairplayOptions = {
|
|
35
|
-
certificateUrl: config.certificateUrl,
|
|
36
|
-
licenseUrl: config.licenseUrl,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
|
|
41
|
-
case DRMTypeEnum.WIDEVINE:
|
|
42
|
-
drmConfig.widevineOptions = {
|
|
43
|
-
licenseUrl: config.licenseUrl,
|
|
44
|
-
};
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case DRMTypeEnum.PLAYREADY:
|
|
48
|
-
drmConfig.playreadyOptions = {
|
|
49
|
-
licenseUrl: config.licenseUrl,
|
|
50
|
-
customData: config.customData,
|
|
51
|
-
};
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return drmConfig;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Validate generic DRM configuration
|
|
60
|
-
*/
|
|
61
|
-
static validateConfig(config: DRMConfig): { valid: boolean; error?: string } {
|
|
62
|
-
if (!config.type) {
|
|
63
|
-
return {
|
|
64
|
-
valid: false,
|
|
65
|
-
error: 'DRM type is required',
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!config.licenseUrl) {
|
|
70
|
-
return {
|
|
71
|
-
valid: false,
|
|
72
|
-
error: 'License URL is required',
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// FairPlay requires certificate URL
|
|
77
|
-
const DRMTypeEnum = require('../../../core/src/interfaces').DRMType;
|
|
78
|
-
if (config.type === DRMTypeEnum.FAIRPLAY) {
|
|
79
|
-
const certificateUrl = config.certificateUrl || config.fairplayOptions?.certificateUrl;
|
|
80
|
-
if (!certificateUrl) {
|
|
81
|
-
return {
|
|
82
|
-
valid: false,
|
|
83
|
-
error: 'FairPlay requires certificateUrl',
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Validate URL format
|
|
89
|
-
try {
|
|
90
|
-
new URL(config.licenseUrl);
|
|
91
|
-
} catch (e) {
|
|
92
|
-
return {
|
|
93
|
-
valid: false,
|
|
94
|
-
error: 'Invalid license URL format',
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (config.certificateUrl) {
|
|
99
|
-
try {
|
|
100
|
-
new URL(config.certificateUrl);
|
|
101
|
-
} catch (e) {
|
|
102
|
-
return {
|
|
103
|
-
valid: false,
|
|
104
|
-
error: 'Invalid certificate URL format',
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return { valid: true };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Create multi-DRM config for generic provider
|
|
114
|
-
*/
|
|
115
|
-
static createMultiDRMConfig(config: {
|
|
116
|
-
widevine: { licenseUrl: string };
|
|
117
|
-
fairplay: { licenseUrl: string; certificateUrl: string };
|
|
118
|
-
playready?: { licenseUrl: string; customData?: string };
|
|
119
|
-
headers?: Record<string, string>;
|
|
120
|
-
}): ExtendedDRMConfig {
|
|
121
|
-
// Primary Widevine config with FairPlay and PlayReady fallbacks
|
|
122
|
-
const DRMTypeEnum = require('../../../core/src/interfaces').DRMType;
|
|
123
|
-
const drmConfig: ExtendedDRMConfig = {
|
|
124
|
-
type: DRMTypeEnum.WIDEVINE,
|
|
125
|
-
licenseUrl: config.widevine.licenseUrl,
|
|
126
|
-
provider: 'generic',
|
|
127
|
-
headers: config.headers,
|
|
128
|
-
|
|
129
|
-
// Widevine options
|
|
130
|
-
widevineOptions: {
|
|
131
|
-
licenseUrl: config.widevine.licenseUrl,
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
// FairPlay options
|
|
135
|
-
fairplayOptions: {
|
|
136
|
-
certificateUrl: config.fairplay.certificateUrl,
|
|
137
|
-
licenseUrl: config.fairplay.licenseUrl,
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
// PlayReady options (optional)
|
|
141
|
-
playreadyOptions: config.playready
|
|
142
|
-
? {
|
|
143
|
-
licenseUrl: config.playready.licenseUrl,
|
|
144
|
-
customData: config.playready.customData,
|
|
145
|
-
}
|
|
146
|
-
: undefined,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
return drmConfig;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base DRM System
|
|
3
|
-
* Abstract base class for all DRM system implementations
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ExtendedDRMConfig, LicenseRequest, LicenseResponse } from '../types/DRMTypes';
|
|
7
|
-
import { LicenseRequestHandler } from '../utils/LicenseRequestHandler';
|
|
8
|
-
|
|
9
|
-
export abstract class BaseDRM {
|
|
10
|
-
protected videoElement: HTMLVideoElement;
|
|
11
|
-
protected config: ExtendedDRMConfig;
|
|
12
|
-
protected debug: boolean;
|
|
13
|
-
protected licenseHandler: LicenseRequestHandler;
|
|
14
|
-
protected mediaKeys: MediaKeys | null = null;
|
|
15
|
-
protected keySession: MediaKeySession | null = null;
|
|
16
|
-
|
|
17
|
-
constructor(videoElement: HTMLVideoElement, config: ExtendedDRMConfig, debug: boolean = false) {
|
|
18
|
-
this.videoElement = videoElement;
|
|
19
|
-
this.config = config;
|
|
20
|
-
this.debug = debug;
|
|
21
|
-
this.licenseHandler = new LicenseRequestHandler(config, debug);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Initialize DRM system
|
|
26
|
-
*/
|
|
27
|
-
abstract initialize(): Promise<void>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Get key system identifier
|
|
31
|
-
*/
|
|
32
|
-
abstract getKeySystem(): string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get HLS.js configuration
|
|
36
|
-
*/
|
|
37
|
-
abstract getHLSConfig(): any;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get dash.js protection data
|
|
41
|
-
*/
|
|
42
|
-
abstract getDashProtectionData(): any;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Cleanup resources
|
|
46
|
-
*/
|
|
47
|
-
async destroy(): Promise<void> {
|
|
48
|
-
if (this.keySession) {
|
|
49
|
-
try {
|
|
50
|
-
await this.keySession.close();
|
|
51
|
-
} catch (error) {
|
|
52
|
-
this.log('Error closing key session:', error);
|
|
53
|
-
}
|
|
54
|
-
this.keySession = null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
this.mediaKeys = null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Debug logging
|
|
62
|
-
*/
|
|
63
|
-
protected log(...args: any[]): void {
|
|
64
|
-
if (this.debug) {
|
|
65
|
-
console.log(`[${this.constructor.name}]`, ...args);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|