UNPKG

unified-video-framework

Version:

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

35 lines (28 loc) 1.15 kB
import { ExtendedDRMConfig, DRMInitResult } from '../types/DRMTypes'; export abstract class BaseDRM { protected video: HTMLVideoElement; protected config: ExtendedDRMConfig; protected debug: boolean; constructor(video: HTMLVideoElement, config: ExtendedDRMConfig, debug: boolean = false) { this.video = video; this.config = config; this.debug = debug; } abstract initialize(): Promise<DRMInitResult>; abstract destroy(): Promise<void>; abstract getKeySystem(): string; getHLSConfig(): Record<string, any> { return {}; } getDashProtectionData(): Record<string, any> { return {}; } protected log(...args: any[]): void { if (this.debug) console.log('[DRM]', ...args); } protected async requestLicense(url: string, body: ArrayBuffer, headers?: Record<string, string>): Promise<ArrayBuffer> { const resp = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/octet-stream', ...(headers || {}) }, body, }); if (!resp.ok) throw new Error(`License request failed: HTTP ${resp.status}`); return resp.arrayBuffer(); } }