UNPKG

unified-video-framework

Version:

Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more

63 lines 2.52 kB
import { BaseDRM } from './BaseDRM.js'; import { KEY_SYSTEMS, DRMErrorCode } from '../types/DRMTypes.js'; import { DRMErrorHandler } from '../utils/DRMErrorHandler.js'; export class WidevineDRM extends BaseDRM { getKeySystem() { return KEY_SYSTEMS.WIDEVINE; } async initialize() { try { const config = [{ initDataTypes: ['cenc'], videoCapabilities: [{ contentType: 'video/mp4; codecs="avc1.42E01E"', robustness: this.config.videoRobustness || 'SW_SECURE_CRYPTO', }], audioCapabilities: [{ contentType: 'audio/mp4; codecs="mp4a.40.2"', robustness: this.config.audioRobustness || 'SW_SECURE_CRYPTO', }], persistentState: this.config.persistentState || 'optional', distinctiveIdentifier: this.config.distinctiveIdentifier || 'optional', }]; await navigator.requestMediaKeySystemAccess(KEY_SYSTEMS.WIDEVINE, config); this.log('Widevine access granted'); return { success: true, drmType: 'widevine', keySystem: KEY_SYSTEMS.WIDEVINE }; } catch (error) { return { success: false, error: DRMErrorHandler.createError(DRMErrorCode.INITIALIZATION_FAILED, `Widevine init failed: ${error.message}`, error), }; } } getHLSConfig() { return { emeEnabled: true, widevineLicenseUrl: this.config.licenseUrl, drmSystems: { 'com.widevine.alpha': { licenseUrl: this.config.licenseUrl, }, }, licenseXhrSetup: this.config.headers ? (xhr) => { for (const [k, v] of Object.entries(this.config.headers)) { xhr.setRequestHeader(k, v); } } : undefined, }; } getDashProtectionData() { return { [KEY_SYSTEMS.WIDEVINE]: { serverURL: this.config.licenseUrl, httpRequestHeaders: this.config.headers || {}, withCredentials: this.config.withCredentials || false, }, }; } async destroy() { this.log('Widevine DRM destroyed'); } } //# sourceMappingURL=WidevineDRM.js.map