unified-video-framework
Version:
Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more
184 lines • 7.57 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AndroidDRMProtection = void 0;
const react_native_1 = require("react-native");
const core_1 = require("../../core/dist");
const { DRMProtectionModule } = react_native_1.NativeModules;
const drmEventEmitter = new react_native_1.NativeEventEmitter(DRMProtectionModule);
class AndroidDRMProtection {
constructor() {
this.listeners = [];
this.config = { enabled: false };
this.status = {
isProtected: false,
drmSystem: 'none',
isScreenRecordingBlocked: false,
isAudioCaptureBlocked: false,
isScreenshotBlocked: false,
isCasting: false,
screenRecordingDetected: false,
mirroringDetected: false,
};
}
async initialize(config) {
this.config = {
blockScreenRecording: true,
blockAudioCapture: true,
blockScreenshots: true,
allowCasting: true,
blockMirroring: true,
widevineSecurityLevel: 'L1',
...config,
};
if (!this.config.enabled) {
console.log('[DRM-Android] Protection disabled');
return;
}
console.log('[DRM-Android] Initializing...', this.config);
try {
if (this.config.blockScreenshots || this.config.blockScreenRecording) {
await DRMProtectionModule.enableFlagSecure(true);
this.status.isScreenshotBlocked = true;
this.status.isScreenRecordingBlocked = true;
console.log('[DRM-Android] FLAG_SECURE enabled');
}
if (this.config.licenseServerUrl) {
await this.initializeWidevine();
}
if (this.config.blockMirroring) {
await this.startMirroringDetection();
}
if (this.config.allowCasting) {
await this.initializeChromecast();
}
this.setupEventListeners();
this.status.isProtected = true;
console.log('[DRM-Android] Protection initialized');
}
catch (error) {
console.error('[DRM-Android] Initialization failed:', error);
throw error;
}
}
async initializeWidevine() {
console.log('[DRM-Android] Initializing Widevine...');
const widevineConfig = {
licenseServerUrl: this.config.licenseServerUrl,
licenseHeaders: this.config.licenseHeaders,
securityLevel: this.config.widevineSecurityLevel,
};
const result = await DRMProtectionModule.initializeWidevine(widevineConfig);
if (result.success) {
this.status.drmSystem = 'widevine';
this.status.securityLevel = result.securityLevel;
console.log(`[DRM-Android] Widevine initialized with security level: ${result.securityLevel}`);
if (result.securityLevel === 'L3' && this.config.widevineSecurityLevel === 'L1') {
console.warn('[DRM-Android] ⚠️ Requested L1 but got L3 - device may not support hardware DRM');
}
}
else {
throw {
code: core_1.DRMErrorCode.WIDEVINE_NOT_AVAILABLE,
message: 'Widevine initialization failed',
platform: 'android',
recoverable: false,
};
}
}
async startMirroringDetection() {
console.log('[DRM-Android] Starting mirroring detection...');
await DRMProtectionModule.startMirroringDetection();
}
async initializeChromecast() {
console.log('[DRM-Android] Initializing Chromecast...');
await DRMProtectionModule.initializeChromecast({
appId: 'CC1AD845',
});
}
setupEventListeners() {
this.listeners.push(drmEventEmitter.addListener('onScreenRecordingDetected', () => {
console.warn('[DRM-Android] ⚠️ Screen recording detected!');
this.status.screenRecordingDetected = true;
this.config.onScreenRecordingDetected?.();
}));
this.listeners.push(drmEventEmitter.addListener('onMirroringDetected', (event) => {
console.warn('[DRM-Android] ⚠️ Display mirroring detected:', event.displayName);
this.status.mirroringDetected = true;
this.config.onMirroringDetected?.();
}));
this.listeners.push(drmEventEmitter.addListener('onCastingStarted', (event) => {
console.log('[DRM-Android] Casting started:', event.deviceName);
this.status.isCasting = true;
this.status.castDevice = {
name: event.deviceName,
type: 'chromecast',
};
this.config.onCastingStarted?.(event.deviceName, 'chromecast');
}));
this.listeners.push(drmEventEmitter.addListener('onCastingEnded', () => {
console.log('[DRM-Android] Casting ended');
this.status.isCasting = false;
this.status.castDevice = undefined;
this.config.onCastingEnded?.();
}));
this.listeners.push(drmEventEmitter.addListener('onLicenseAcquired', (event) => {
console.log('[DRM-Android] License acquired');
this.status.licenseExpiration = event.expirationTime ? new Date(event.expirationTime) : undefined;
this.config.onLicenseAcquired?.();
}));
this.listeners.push(drmEventEmitter.addListener('onDRMError', (error) => {
console.error('[DRM-Android] DRM Error:', error);
this.config.onDRMError?.(error);
}));
}
getStatus() {
return { ...this.status };
}
setEnabled(enabled) {
this.config.enabled = enabled;
DRMProtectionModule.setEnabled(enabled);
}
setFeature(feature, enabled) {
this.config[feature] = enabled;
switch (feature) {
case 'blockScreenshots':
case 'blockScreenRecording':
DRMProtectionModule.enableFlagSecure(enabled);
this.status.isScreenshotBlocked = enabled;
this.status.isScreenRecordingBlocked = enabled;
break;
}
}
async startCasting(deviceId) {
await DRMProtectionModule.startCasting(deviceId);
}
async stopCasting() {
await DRMProtectionModule.stopCasting();
}
async getAvailableCastDevices() {
const devices = await DRMProtectionModule.getAvailableCastDevices();
return devices.map((device) => ({
id: device.id,
name: device.name,
type: 'chromecast',
isAvailable: device.isAvailable,
capabilities: {
supportsVideo: true,
supportsAudio: true,
supportsDRM: device.supportsDRM,
maxResolution: device.maxResolution,
},
}));
}
async renewLicense() {
await DRMProtectionModule.renewLicense();
}
dispose() {
this.listeners.forEach((listener) => listener.remove());
this.listeners = [];
DRMProtectionModule.dispose();
this.status.isProtected = false;
}
}
exports.AndroidDRMProtection = AndroidDRMProtection;
//# sourceMappingURL=AndroidDRMProtection.js.map