unified-video-framework
Version:
Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more
34 lines • 1.21 kB
JavaScript
import { DRMErrorCode } from '../types/DRMTypes.js';
import { DRMErrorHandler } from './DRMErrorHandler.js';
export class CertificateManager {
constructor() {
this.cache = new Map();
}
async fetchCertificate(url, headers) {
const cached = this.cache.get(url);
if (cached)
return cached;
try {
const resp = await fetch(url, {
method: 'GET',
headers: headers || {},
});
if (!resp.ok) {
throw DRMErrorHandler.createError(DRMErrorCode.CERTIFICATE_FETCH_FAILED, `Certificate fetch failed: HTTP ${resp.status}`);
}
const buf = await resp.arrayBuffer();
const cert = new Uint8Array(buf);
this.cache.set(url, cert);
return cert;
}
catch (error) {
if (error.code === DRMErrorCode.CERTIFICATE_FETCH_FAILED)
throw error;
throw DRMErrorHandler.createError(DRMErrorCode.CERTIFICATE_FETCH_FAILED, `Certificate fetch failed: ${error.message}`, error);
}
}
clear() {
this.cache.clear();
}
}
//# sourceMappingURL=CertificateManager.js.map