unified-video-framework 1.4.412 → 1.4.413

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.
Files changed (87) hide show
  1. package/package.json +1 -1
  2. package/packages/core/dist/interfaces/IVideoPlayer.d.ts +0 -22
  3. package/packages/core/dist/interfaces/IVideoPlayer.d.ts.map +1 -1
  4. package/packages/core/src/interfaces/IVideoPlayer.ts +0 -27
  5. package/packages/web/dist/WebPlayer.d.ts +0 -4
  6. package/packages/web/dist/WebPlayer.d.ts.map +1 -1
  7. package/packages/web/dist/WebPlayer.js +62 -73
  8. package/packages/web/dist/WebPlayer.js.map +1 -1
  9. package/packages/web/dist/drm/DRMManager.d.ts +16 -9
  10. package/packages/web/dist/drm/DRMManager.d.ts.map +1 -1
  11. package/packages/web/dist/drm/DRMManager.js +109 -42
  12. package/packages/web/dist/drm/DRMManager.js.map +1 -1
  13. package/packages/web/dist/drm/index.d.ts +15 -0
  14. package/packages/web/dist/drm/index.d.ts.map +1 -0
  15. package/packages/web/dist/drm/index.js +13 -0
  16. package/packages/web/dist/drm/index.js.map +1 -0
  17. package/packages/web/dist/drm/providers/BunnyNetProvider.d.ts +19 -0
  18. package/packages/web/dist/drm/providers/BunnyNetProvider.d.ts.map +1 -0
  19. package/packages/web/dist/drm/providers/BunnyNetProvider.js +112 -0
  20. package/packages/web/dist/drm/providers/BunnyNetProvider.js.map +1 -0
  21. package/packages/web/dist/drm/providers/GenericProvider.d.ts +30 -0
  22. package/packages/web/dist/drm/providers/GenericProvider.d.ts.map +1 -0
  23. package/packages/web/dist/drm/providers/GenericProvider.js +102 -0
  24. package/packages/web/dist/drm/providers/GenericProvider.js.map +1 -0
  25. package/packages/web/dist/drm/systems/BaseDRM.d.ts +18 -0
  26. package/packages/web/dist/drm/systems/BaseDRM.d.ts.map +1 -0
  27. package/packages/web/dist/drm/systems/BaseDRM.js +29 -0
  28. package/packages/web/dist/drm/systems/BaseDRM.js.map +1 -0
  29. package/packages/web/dist/drm/systems/FairPlayDRM.d.ts +32 -0
  30. package/packages/web/dist/drm/systems/FairPlayDRM.d.ts.map +1 -0
  31. package/packages/web/dist/drm/systems/FairPlayDRM.js +198 -0
  32. package/packages/web/dist/drm/systems/FairPlayDRM.js.map +1 -0
  33. package/packages/web/dist/drm/systems/PlayReadyDRM.d.ts +9 -0
  34. package/packages/web/dist/drm/systems/PlayReadyDRM.d.ts.map +1 -0
  35. package/packages/web/dist/drm/systems/PlayReadyDRM.js +92 -0
  36. package/packages/web/dist/drm/systems/PlayReadyDRM.js.map +1 -0
  37. package/packages/web/dist/drm/systems/WidevineDRM.d.ts +9 -0
  38. package/packages/web/dist/drm/systems/WidevineDRM.d.ts.map +1 -0
  39. package/packages/web/dist/drm/systems/WidevineDRM.js +73 -0
  40. package/packages/web/dist/drm/systems/WidevineDRM.js.map +1 -0
  41. package/packages/web/dist/drm/types/BunnyNetTypes.d.ts +20 -0
  42. package/packages/web/dist/drm/types/BunnyNetTypes.d.ts.map +1 -0
  43. package/packages/web/dist/drm/types/BunnyNetTypes.js +8 -0
  44. package/packages/web/dist/drm/types/BunnyNetTypes.js.map +1 -0
  45. package/packages/web/dist/drm/types/DRMTypes.d.ts +56 -49
  46. package/packages/web/dist/drm/types/DRMTypes.d.ts.map +1 -1
  47. package/packages/web/dist/drm/types/DRMTypes.js +19 -13
  48. package/packages/web/dist/drm/types/DRMTypes.js.map +1 -1
  49. package/packages/web/dist/drm/utils/BrowserDetector.d.ts +20 -0
  50. package/packages/web/dist/drm/utils/BrowserDetector.d.ts.map +1 -0
  51. package/packages/web/dist/drm/utils/BrowserDetector.js +168 -0
  52. package/packages/web/dist/drm/utils/BrowserDetector.js.map +1 -0
  53. package/packages/web/dist/drm/utils/CertificateManager.d.ts +15 -0
  54. package/packages/web/dist/drm/utils/CertificateManager.d.ts.map +1 -0
  55. package/packages/web/dist/drm/utils/CertificateManager.js +46 -0
  56. package/packages/web/dist/drm/utils/CertificateManager.js.map +1 -0
  57. package/packages/web/dist/drm/utils/DRMErrorHandler.d.ts +7 -0
  58. package/packages/web/dist/drm/utils/DRMErrorHandler.d.ts.map +1 -0
  59. package/packages/web/dist/drm/utils/DRMErrorHandler.js +49 -0
  60. package/packages/web/dist/drm/utils/DRMErrorHandler.js.map +1 -0
  61. package/packages/web/dist/drm/utils/LicenseRequestHandler.d.ts +15 -0
  62. package/packages/web/dist/drm/utils/LicenseRequestHandler.d.ts.map +1 -0
  63. package/packages/web/dist/drm/utils/LicenseRequestHandler.js +110 -0
  64. package/packages/web/dist/drm/utils/LicenseRequestHandler.js.map +1 -0
  65. package/packages/web/dist/react/WebPlayerView.d.ts +1 -18
  66. package/packages/web/dist/react/WebPlayerView.d.ts.map +1 -1
  67. package/packages/web/dist/react/WebPlayerView.js +0 -5
  68. package/packages/web/dist/react/WebPlayerView.js.map +1 -1
  69. package/packages/web/src/WebPlayer.ts +79 -106
  70. package/packages/web/src/drm/DRMManager.ts +172 -58
  71. package/packages/web/src/drm/index.ts +37 -0
  72. package/packages/web/src/drm/providers/BunnyNetProvider.ts +170 -0
  73. package/packages/web/src/drm/providers/GenericProvider.ts +148 -0
  74. package/packages/web/src/drm/systems/BaseDRM.ts +68 -0
  75. package/packages/web/src/drm/systems/FairPlayDRM.ts +305 -0
  76. package/packages/web/src/drm/systems/PlayReadyDRM.ts +131 -0
  77. package/packages/web/src/drm/systems/WidevineDRM.ts +105 -0
  78. package/packages/web/src/drm/types/BunnyNetTypes.ts +35 -0
  79. package/packages/web/src/drm/types/DRMTypes.ts +70 -76
  80. package/packages/web/src/drm/utils/BrowserDetector.ts +232 -0
  81. package/packages/web/src/drm/utils/CertificateManager.ts +86 -0
  82. package/packages/web/src/drm/utils/DRMErrorHandler.ts +84 -0
  83. package/packages/web/src/drm/utils/LicenseRequestHandler.ts +180 -0
  84. package/packages/web/src/react/WebPlayerView.tsx +1 -28
  85. package/packages/web/src/drm/BunnyCDNDRMProvider.ts +0 -104
  86. package/packages/web/src/drm/FairPlayDRMHandler.ts +0 -322
  87. package/packages/web/src/drm/WidevineDRMHandler.ts +0 -246
@@ -0,0 +1,305 @@
1
+ /**
2
+ * FairPlay DRM Implementation
3
+ * Implements FairPlay DRM for Safari/iOS using WebKit EME APIs
4
+ */
5
+
6
+ import { BaseDRM } from './BaseDRM';
7
+ import { KEY_SYSTEMS, DRMErrorCode } from '../types/DRMTypes';
8
+ import { DRMType } from '@unified-video/core';
9
+ import { CertificateManager } from '../utils/CertificateManager';
10
+ import { DRMErrorHandler } from '../utils/DRMErrorHandler';
11
+
12
+ // WebKit-specific types
13
+ declare global {
14
+ interface HTMLVideoElement {
15
+ webkitSetMediaKeys?: (mediaKeys: any) => void;
16
+ webkitKeys?: any;
17
+ }
18
+
19
+ interface Window {
20
+ WebKitMediaKeys?: any;
21
+ }
22
+ }
23
+
24
+ export class FairPlayDRM extends BaseDRM {
25
+ private certificateManager: CertificateManager;
26
+ private serverCertificate: ArrayBuffer | null = null;
27
+ private encryptedEventHandler: ((event: any) => Promise<void>) | null = null;
28
+ private needKeyEventHandler: ((event: any) => Promise<void>) | null = null;
29
+
30
+ constructor(videoElement: HTMLVideoElement, config: any, debug: boolean = false) {
31
+ super(videoElement, config, debug);
32
+ this.certificateManager = CertificateManager.getInstance();
33
+ }
34
+
35
+ async initialize(): Promise<void> {
36
+ this.log('Initializing FairPlay DRM...');
37
+
38
+ // Load server certificate
39
+ await this.loadCertificate();
40
+
41
+ // Set up encrypted event listeners
42
+ this.setupEncryptedEventListeners();
43
+
44
+ this.log('FairPlay DRM initialized');
45
+ }
46
+
47
+ getKeySystem(): string {
48
+ return KEY_SYSTEMS[DRMType.FAIRPLAY][0];
49
+ }
50
+
51
+ getHLSConfig(): any {
52
+ this.log('Generating HLS.js config for FairPlay');
53
+
54
+ const certificateUrl = this.config.certificateUrl || this.config.fairplayOptions?.certificateUrl;
55
+ const licenseUrl = this.config.licenseUrl || this.config.fairplayOptions?.licenseUrl;
56
+
57
+ return {
58
+ emeEnabled: true,
59
+ drmSystems: {
60
+ [this.getKeySystem()]: {
61
+ licenseUrl: licenseUrl,
62
+ serverCertificateUrl: certificateUrl,
63
+ serverCertificate: this.serverCertificate,
64
+ },
65
+ },
66
+ requestMediaKeySystemAccessFunc: this.createMediaKeySystemAccess.bind(this),
67
+ };
68
+ }
69
+
70
+ getDashProtectionData(): any {
71
+ this.log('Generating dash.js protection data for FairPlay');
72
+
73
+ const licenseUrl = this.config.licenseUrl || this.config.fairplayOptions?.licenseUrl;
74
+
75
+ return {
76
+ [this.getKeySystem()]: {
77
+ serverURL: licenseUrl,
78
+ serverCertificate: this.serverCertificate,
79
+ },
80
+ };
81
+ }
82
+
83
+ async destroy(): Promise<void> {
84
+ // Remove event listeners
85
+ if (this.encryptedEventHandler) {
86
+ this.videoElement.removeEventListener('encrypted', this.encryptedEventHandler as any);
87
+ this.encryptedEventHandler = null;
88
+ }
89
+
90
+ if (this.needKeyEventHandler) {
91
+ this.videoElement.removeEventListener('webkitneedkey', this.needKeyEventHandler as any);
92
+ this.needKeyEventHandler = null;
93
+ }
94
+
95
+ await super.destroy();
96
+ }
97
+
98
+ private async loadCertificate(): Promise<void> {
99
+ const certificateUrl = this.config.certificateUrl || this.config.fairplayOptions?.certificateUrl;
100
+
101
+ if (!certificateUrl) {
102
+ throw DRMErrorHandler.createError(
103
+ DRMErrorCode.CONFIGURATION_ERROR,
104
+ 'FairPlay certificate URL not provided',
105
+ true
106
+ );
107
+ }
108
+
109
+ this.log('Loading FairPlay certificate from:', certificateUrl);
110
+
111
+ // Check cache first
112
+ const cached = this.certificateManager.getCertificate(certificateUrl);
113
+ if (cached) {
114
+ this.log('Using cached certificate');
115
+ this.serverCertificate = cached;
116
+ return;
117
+ }
118
+
119
+ // Fetch certificate
120
+ try {
121
+ const response = await fetch(certificateUrl);
122
+ if (!response.ok) {
123
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
124
+ }
125
+
126
+ this.serverCertificate = await response.arrayBuffer();
127
+
128
+ // Cache for future use
129
+ this.certificateManager.setCertificate(certificateUrl, this.serverCertificate);
130
+
131
+ this.log('FairPlay certificate loaded, size:', this.serverCertificate.byteLength, 'bytes');
132
+ } catch (error: any) {
133
+ throw DRMErrorHandler.createError(
134
+ DRMErrorCode.CERTIFICATE_LOAD_FAILED,
135
+ `Failed to load FairPlay certificate: ${error.message}`,
136
+ true,
137
+ error
138
+ );
139
+ }
140
+ }
141
+
142
+ private setupEncryptedEventListeners(): void {
143
+ // Modern EME encrypted event
144
+ this.encryptedEventHandler = this.onEncrypted.bind(this);
145
+ this.videoElement.addEventListener('encrypted', this.encryptedEventHandler as any);
146
+
147
+ // Legacy WebKit needkey event
148
+ this.needKeyEventHandler = this.onWebKitNeedKey.bind(this);
149
+ this.videoElement.addEventListener('webkitneedkey', this.needKeyEventHandler as any);
150
+
151
+ this.log('FairPlay encrypted event listeners set up');
152
+ }
153
+
154
+ private async onEncrypted(event: any): Promise<void> {
155
+ this.log('Encrypted event received:', event);
156
+
157
+ try {
158
+ const initData = event.initData;
159
+ const initDataType = event.initDataType;
160
+
161
+ await this.createSession(initData, initDataType);
162
+ } catch (error) {
163
+ this.log('Error handling encrypted event:', error);
164
+ throw error;
165
+ }
166
+ }
167
+
168
+ private async onWebKitNeedKey(event: any): Promise<void> {
169
+ this.log('WebKit needkey event received');
170
+
171
+ try {
172
+ const initData = event.initData;
173
+ await this.createSession(initData, 'skd');
174
+ } catch (error) {
175
+ this.log('Error handling webkitneedkey event:', error);
176
+ throw error;
177
+ }
178
+ }
179
+
180
+ private async createSession(initData: ArrayBuffer, initDataType: string): Promise<void> {
181
+ // Create media keys if not already created
182
+ if (!this.mediaKeys) {
183
+ try {
184
+ const keySystemAccess = await navigator.requestMediaKeySystemAccess(
185
+ this.getKeySystem(),
186
+ this.getKeySystemConfiguration()
187
+ );
188
+ this.mediaKeys = await keySystemAccess.createMediaKeys();
189
+ await this.videoElement.setMediaKeys(this.mediaKeys);
190
+
191
+ this.log('FairPlay MediaKeys created and set');
192
+ } catch (error: any) {
193
+ throw DRMErrorHandler.createError(
194
+ DRMErrorCode.MEDIA_KEYS_CREATION_FAILED,
195
+ `Failed to create FairPlay MediaKeys: ${error.message}`,
196
+ true,
197
+ error
198
+ );
199
+ }
200
+ }
201
+
202
+ // Create session
203
+ try {
204
+ this.keySession = this.mediaKeys.createSession();
205
+ this.log('FairPlay session created');
206
+
207
+ // Handle license request
208
+ this.keySession.addEventListener('message', async (event: any) => {
209
+ await this.onMessage(event);
210
+ });
211
+
212
+ // Generate license request
213
+ await this.keySession.generateRequest(initDataType, initData);
214
+ } catch (error: any) {
215
+ throw DRMErrorHandler.createError(
216
+ DRMErrorCode.SESSION_CREATION_FAILED,
217
+ `Failed to create FairPlay session: ${error.message}`,
218
+ true,
219
+ error
220
+ );
221
+ }
222
+ }
223
+
224
+ private async onMessage(event: any): Promise<void> {
225
+ this.log('FairPlay message event:', event.messageType);
226
+
227
+ try {
228
+ const message = event.message;
229
+
230
+ // Convert message to base64 for FairPlay license request
231
+ const messageBase64 = this.arrayBufferToBase64(message);
232
+
233
+ const licenseUrl = this.config.licenseUrl || this.config.fairplayOptions?.licenseUrl;
234
+ if (!licenseUrl) {
235
+ throw DRMErrorHandler.createError(
236
+ DRMErrorCode.CONFIGURATION_ERROR,
237
+ 'FairPlay license URL not provided',
238
+ true
239
+ );
240
+ }
241
+
242
+ // Request license from server
243
+ const license = await this.licenseHandler.requestLicense({
244
+ url: licenseUrl,
245
+ method: 'POST',
246
+ headers: {
247
+ 'Content-Type': 'application/octet-stream',
248
+ ...this.config.headers,
249
+ },
250
+ body: message,
251
+ responseType: 'arraybuffer',
252
+ });
253
+
254
+ // Update session with license (CKC - Content Key Context)
255
+ await this.keySession!.update(license.license);
256
+
257
+ this.log('FairPlay license applied successfully');
258
+ } catch (error: any) {
259
+ throw DRMErrorHandler.createError(
260
+ DRMErrorCode.LICENSE_REQUEST_FAILED,
261
+ `Failed to process FairPlay license: ${error.message}`,
262
+ true,
263
+ error
264
+ );
265
+ }
266
+ }
267
+
268
+ private getKeySystemConfiguration(): MediaKeySystemConfiguration[] {
269
+ return [{
270
+ initDataTypes: ['sinf', 'skd'],
271
+ audioCapabilities: [{
272
+ contentType: 'audio/mp4; codecs="mp4a.40.2"',
273
+ }],
274
+ videoCapabilities: [
275
+ {
276
+ contentType: 'application/vnd.apple.mpegurl',
277
+ robustness: 'SW_SECURE_CRYPTO',
278
+ },
279
+ {
280
+ contentType: 'video/mp4; codecs="avc1.42E01E"',
281
+ robustness: 'SW_SECURE_CRYPTO',
282
+ },
283
+ ],
284
+ distinctiveIdentifier: 'not-allowed',
285
+ persistentState: 'not-allowed',
286
+ sessionTypes: ['temporary'],
287
+ }];
288
+ }
289
+
290
+ private async createMediaKeySystemAccess(): Promise<MediaKeySystemAccess> {
291
+ return navigator.requestMediaKeySystemAccess(
292
+ this.getKeySystem(),
293
+ this.getKeySystemConfiguration()
294
+ );
295
+ }
296
+
297
+ private arrayBufferToBase64(buffer: ArrayBuffer): string {
298
+ const bytes = new Uint8Array(buffer);
299
+ let binary = '';
300
+ for (let i = 0; i < bytes.byteLength; i++) {
301
+ binary += String.fromCharCode(bytes[i]);
302
+ }
303
+ return btoa(binary);
304
+ }
305
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * PlayReady DRM Implementation
3
+ * Implements PlayReady DRM for Edge and IE
4
+ */
5
+
6
+ import { BaseDRM } from './BaseDRM';
7
+ import { KEY_SYSTEMS, DRMErrorCode } from '../types/DRMTypes';
8
+ import { DRMType } from '@unified-video/core';
9
+ import { DRMErrorHandler } from '../utils/DRMErrorHandler';
10
+
11
+ export class PlayReadyDRM extends BaseDRM {
12
+ async initialize(): Promise<void> {
13
+ this.log('Initializing PlayReady DRM...');
14
+
15
+ // PlayReady is primarily configured through HLS.js and dash.js
16
+ // Basic EME setup for validation
17
+ try {
18
+ const keySystemAccess = await navigator.requestMediaKeySystemAccess(
19
+ this.getKeySystem(),
20
+ this.getKeySystemConfiguration()
21
+ );
22
+
23
+ this.log('PlayReady key system access granted');
24
+ this.mediaKeys = await keySystemAccess.createMediaKeys();
25
+
26
+ // For HLS.js and dash.js, they handle the actual EME setup
27
+ // We just validate that the system is available
28
+
29
+ } catch (error: any) {
30
+ // Try fallback key system
31
+ try {
32
+ const fallbackKeySystem = KEY_SYSTEMS[DRMType.PLAYREADY][1];
33
+ const keySystemAccess = await navigator.requestMediaKeySystemAccess(
34
+ fallbackKeySystem,
35
+ this.getKeySystemConfiguration()
36
+ );
37
+
38
+ this.log('PlayReady fallback key system access granted');
39
+ this.mediaKeys = await keySystemAccess.createMediaKeys();
40
+ } catch (fallbackError: any) {
41
+ this.log('PlayReady initialization failed:', fallbackError);
42
+ throw DRMErrorHandler.createError(
43
+ DRMErrorCode.KEY_SYSTEM_ACCESS_DENIED,
44
+ 'Failed to access PlayReady DRM system',
45
+ true,
46
+ fallbackError
47
+ );
48
+ }
49
+ }
50
+
51
+ this.log('PlayReady DRM initialized');
52
+ }
53
+
54
+ getKeySystem(): string {
55
+ return KEY_SYSTEMS[DRMType.PLAYREADY][0];
56
+ }
57
+
58
+ getHLSConfig(): any {
59
+ this.log('Generating HLS.js config for PlayReady');
60
+
61
+ return {
62
+ emeEnabled: true,
63
+ drmSystems: {
64
+ [this.getKeySystem()]: {
65
+ licenseUrl: this.config.licenseUrl || this.config.playreadyOptions?.licenseUrl,
66
+ customData: this.config.customData || this.config.playreadyOptions?.customData,
67
+ },
68
+ // Add fallback key system
69
+ [KEY_SYSTEMS[DRMType.PLAYREADY][1]]: {
70
+ licenseUrl: this.config.licenseUrl || this.config.playreadyOptions?.licenseUrl,
71
+ customData: this.config.customData || this.config.playreadyOptions?.customData,
72
+ },
73
+ },
74
+ requestMediaKeySystemAccessFunc: navigator.requestMediaKeySystemAccess.bind(navigator),
75
+ };
76
+ }
77
+
78
+ getDashProtectionData(): any {
79
+ this.log('Generating dash.js protection data for PlayReady');
80
+
81
+ const licenseUrl = this.config.licenseUrl || this.config.playreadyOptions?.licenseUrl;
82
+
83
+ const protectionData: any = {
84
+ [this.getKeySystem()]: {
85
+ serverURL: licenseUrl,
86
+ },
87
+ // Add fallback key system
88
+ [KEY_SYSTEMS[DRMType.PLAYREADY][1]]: {
89
+ serverURL: licenseUrl,
90
+ },
91
+ };
92
+
93
+ // Add custom headers if provided
94
+ if (this.config.headers && Object.keys(this.config.headers).length > 0) {
95
+ protectionData[this.getKeySystem()].httpRequestHeaders = this.config.headers;
96
+ protectionData[KEY_SYSTEMS[DRMType.PLAYREADY][1]].httpRequestHeaders = this.config.headers;
97
+ }
98
+
99
+ // Add custom data if provided
100
+ const customData = this.config.customData || this.config.playreadyOptions?.customData;
101
+ if (customData) {
102
+ protectionData[this.getKeySystem()].customData = customData;
103
+ protectionData[KEY_SYSTEMS[DRMType.PLAYREADY][1]].customData = customData;
104
+ }
105
+
106
+ return protectionData;
107
+ }
108
+
109
+ private getKeySystemConfiguration(): MediaKeySystemConfiguration[] {
110
+ return [{
111
+ initDataTypes: ['cenc'],
112
+ audioCapabilities: [{
113
+ contentType: 'audio/mp4; codecs="mp4a.40.2"',
114
+ robustness: 'SW_SECURE_CRYPTO',
115
+ }],
116
+ videoCapabilities: [
117
+ {
118
+ contentType: 'video/mp4; codecs="avc1.42E01E"',
119
+ robustness: 'SW_SECURE_CRYPTO',
120
+ },
121
+ {
122
+ contentType: 'video/mp4; codecs="avc1.4d401f"',
123
+ robustness: 'SW_SECURE_CRYPTO',
124
+ },
125
+ ],
126
+ distinctiveIdentifier: 'not-allowed',
127
+ persistentState: 'not-allowed',
128
+ sessionTypes: ['temporary'],
129
+ }];
130
+ }
131
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Widevine DRM Implementation
3
+ * Implements Widevine DRM for Chrome, Firefox, Edge, Android
4
+ */
5
+
6
+ import { BaseDRM } from './BaseDRM';
7
+ import { KEY_SYSTEMS, DRMErrorCode } from '../types/DRMTypes';
8
+ import { DRMType } from '@unified-video/core';
9
+ import { DRMErrorHandler } from '../utils/DRMErrorHandler';
10
+
11
+ export class WidevineDRM extends BaseDRM {
12
+ async initialize(): Promise<void> {
13
+ this.log('Initializing Widevine DRM...');
14
+
15
+ // Widevine is primarily configured through HLS.js and dash.js
16
+ // Basic EME setup for validation
17
+ try {
18
+ const keySystemAccess = await navigator.requestMediaKeySystemAccess(
19
+ this.getKeySystem(),
20
+ this.getKeySystemConfiguration()
21
+ );
22
+
23
+ this.log('Widevine key system access granted');
24
+ this.mediaKeys = await keySystemAccess.createMediaKeys();
25
+
26
+ // For HLS.js and dash.js, they handle the actual EME setup
27
+ // We just validate that the system is available
28
+
29
+ } catch (error: any) {
30
+ this.log('Widevine initialization failed:', error);
31
+ throw DRMErrorHandler.createError(
32
+ DRMErrorCode.KEY_SYSTEM_ACCESS_DENIED,
33
+ 'Failed to access Widevine DRM system',
34
+ true,
35
+ error
36
+ );
37
+ }
38
+
39
+ this.log('Widevine DRM initialized');
40
+ }
41
+
42
+ getKeySystem(): string {
43
+ return KEY_SYSTEMS[DRMType.WIDEVINE][0];
44
+ }
45
+
46
+ getHLSConfig(): any {
47
+ this.log('Generating HLS.js config for Widevine');
48
+
49
+ return {
50
+ emeEnabled: true,
51
+ drmSystems: {
52
+ [this.getKeySystem()]: {
53
+ licenseUrl: this.config.licenseUrl || this.config.widevineOptions?.licenseUrl,
54
+ serverCertificate: this.config.widevineOptions?.serverCertificate,
55
+ },
56
+ },
57
+ requestMediaKeySystemAccessFunc: navigator.requestMediaKeySystemAccess.bind(navigator),
58
+ };
59
+ }
60
+
61
+ getDashProtectionData(): any {
62
+ this.log('Generating dash.js protection data for Widevine');
63
+
64
+ const protectionData: any = {
65
+ [this.getKeySystem()]: {
66
+ serverURL: this.config.licenseUrl || this.config.widevineOptions?.licenseUrl,
67
+ },
68
+ };
69
+
70
+ // Add custom headers if provided
71
+ if (this.config.headers && Object.keys(this.config.headers).length > 0) {
72
+ protectionData[this.getKeySystem()].httpRequestHeaders = this.config.headers;
73
+ }
74
+
75
+ // Add server certificate if provided
76
+ if (this.config.widevineOptions?.serverCertificate) {
77
+ protectionData[this.getKeySystem()].serverCertificate = this.config.widevineOptions.serverCertificate;
78
+ }
79
+
80
+ return protectionData;
81
+ }
82
+
83
+ private getKeySystemConfiguration(): MediaKeySystemConfiguration[] {
84
+ return [{
85
+ initDataTypes: ['cenc'],
86
+ audioCapabilities: [{
87
+ contentType: 'audio/mp4; codecs="mp4a.40.2"',
88
+ robustness: 'SW_SECURE_CRYPTO',
89
+ }],
90
+ videoCapabilities: [
91
+ {
92
+ contentType: 'video/mp4; codecs="avc1.42E01E"',
93
+ robustness: 'SW_SECURE_CRYPTO',
94
+ },
95
+ {
96
+ contentType: 'video/mp4; codecs="avc1.4d401f"',
97
+ robustness: 'SW_SECURE_CRYPTO',
98
+ },
99
+ ],
100
+ distinctiveIdentifier: 'not-allowed',
101
+ persistentState: 'not-allowed',
102
+ sessionTypes: ['temporary'],
103
+ }];
104
+ }
105
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Bunny.net DRM Type Definitions
3
+ * Type definitions specific to Bunny.net MediaCage DRM integration
4
+ */
5
+
6
+ import { DRMType } from '@unified-video/core';
7
+
8
+ export interface BunnyNetConfig {
9
+ libraryId: string;
10
+ videoId: string;
11
+ drmType?: DRMType;
12
+ }
13
+
14
+ export interface BunnyNetEndpoints {
15
+ widevine: string;
16
+ fairplayCert: string;
17
+ fairplayLicense: string;
18
+ playready: string;
19
+ }
20
+
21
+ export const BUNNY_NET_BASE_URL = 'https://video.bunnycdn.com';
22
+
23
+ export const BUNNY_NET_ENDPOINTS = {
24
+ WIDEVINE_LICENSE: (libraryId: string, videoId: string) =>
25
+ `${BUNNY_NET_BASE_URL}/WidevineLicense/${libraryId}/${videoId}`,
26
+
27
+ FAIRPLAY_CERTIFICATE: (libraryId: string) =>
28
+ `${BUNNY_NET_BASE_URL}/FairPlay/${libraryId}/certificate`,
29
+
30
+ FAIRPLAY_LICENSE: (libraryId: string, videoId: string) =>
31
+ `${BUNNY_NET_BASE_URL}/FairPlay/${libraryId}/license/?videoId=${videoId}`,
32
+
33
+ PLAYREADY_LICENSE: (libraryId: string, videoId: string) =>
34
+ `${BUNNY_NET_BASE_URL}/PlayReadyLicense/${libraryId}/${videoId}`,
35
+ };