unified-video-framework
Version:
Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more
66 lines • 2.32 kB
JavaScript
import { DRMErrorCode } from './types/DRMTypes.js';
import { DRMErrorHandler } from './utils/DRMErrorHandler.js';
import { BrowserDetector } from './utils/BrowserDetector.js';
import { WidevineDRM } from './systems/WidevineDRM.js';
import { FairPlayDRM } from './systems/FairPlayDRM.js';
import { PlayReadyDRM } from './systems/PlayReadyDRM.js';
export class DRMManager {
constructor(video, config, debug = false) {
this.activeDRM = null;
this.video = video;
this.config = config;
this.debug = debug;
}
async initialize() {
const type = this.config.type || 'auto';
if (type !== 'auto') {
return this.initSpecific(type);
}
const caps = await BrowserDetector.detectCapabilities();
this.log('DRM capabilities:', caps);
if (BrowserDetector.isSafari() && caps.fairplay && this.config.certificateUrl) {
return this.initSpecific('fairplay');
}
if (caps.widevine) {
return this.initSpecific('widevine');
}
if (caps.playready) {
return this.initSpecific('playready');
}
return {
success: false,
error: DRMErrorHandler.createError(DRMErrorCode.UNSUPPORTED, 'No supported DRM system found in this browser'),
};
}
async initSpecific(type) {
switch (type) {
case 'widevine':
this.activeDRM = new WidevineDRM(this.video, this.config, this.debug);
break;
case 'fairplay':
this.activeDRM = new FairPlayDRM(this.video, this.config, this.debug);
break;
case 'playready':
this.activeDRM = new PlayReadyDRM(this.video, this.config, this.debug);
break;
}
return this.activeDRM.initialize();
}
getHLSConfig() {
return this.activeDRM?.getHLSConfig() || {};
}
getDashProtectionData() {
return this.activeDRM?.getDashProtectionData() || {};
}
async destroy() {
if (this.activeDRM) {
await this.activeDRM.destroy();
this.activeDRM = null;
}
}
log(...args) {
if (this.debug)
console.log('[DRMManager]', ...args);
}
}
//# sourceMappingURL=DRMManager.js.map