unified-video-framework
Version:
Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more
172 lines • 6.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.iOSDRMProtection = 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 iOSDRMProtection {
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,
...config,
};
if (!this.config.enabled) {
console.log('[DRM-iOS] Protection disabled');
return;
}
console.log('[DRM-iOS] Initializing...', this.config);
try {
if (this.config.licenseServerUrl && this.config.certificateUrl) {
await this.initializeFairPlay();
}
if (this.config.blockScreenRecording) {
await this.startScreenCaptureDetection();
}
if (this.config.allowCasting) {
await this.initializeAirPlay();
}
this.setupEventListeners();
this.status.isProtected = true;
console.log('[DRM-iOS] Protection initialized');
}
catch (error) {
console.error('[DRM-iOS] Initialization failed:', error);
throw error;
}
}
async initializeFairPlay() {
console.log('[DRM-iOS] Initializing FairPlay...');
const fairPlayConfig = {
licenseServerUrl: this.config.licenseServerUrl,
certificateUrl: this.config.certificateUrl,
licenseHeaders: this.config.licenseHeaders,
};
const result = await DRMProtectionModule.initializeFairPlay(fairPlayConfig);
if (result.success) {
this.status.drmSystem = 'fairplay';
console.log('[DRM-iOS] FairPlay initialized successfully');
}
else {
throw {
code: core_1.DRMErrorCode.FAIRPLAY_NOT_AVAILABLE,
message: 'FairPlay initialization failed',
platform: 'ios',
recoverable: false,
};
}
}
async startScreenCaptureDetection() {
console.log('[DRM-iOS] Starting screen capture detection...');
await DRMProtectionModule.startScreenCaptureDetection();
this.status.isScreenRecordingBlocked = true;
}
async initializeAirPlay() {
console.log('[DRM-iOS] Initializing AirPlay...');
await DRMProtectionModule.initializeAirPlay({
allowMirroring: false,
});
}
setupEventListeners() {
this.listeners.push(drmEventEmitter.addListener('onScreenCaptureDetected', () => {
console.warn('[DRM-iOS] ⚠️ Screen capture detected!');
this.status.screenRecordingDetected = true;
this.config.onScreenRecordingDetected?.();
}));
this.listeners.push(drmEventEmitter.addListener('onExternalDisplayDetected', (event) => {
console.warn('[DRM-iOS] ⚠️ External display detected:', event);
this.status.mirroringDetected = true;
this.config.onMirroringDetected?.();
}));
this.listeners.push(drmEventEmitter.addListener('onAirPlayStarted', (event) => {
console.log('[DRM-iOS] AirPlay started:', event.deviceName);
this.status.isCasting = true;
this.status.castDevice = {
name: event.deviceName,
type: 'airplay',
};
this.config.onCastingStarted?.(event.deviceName, 'airplay');
}));
this.listeners.push(drmEventEmitter.addListener('onAirPlayEnded', () => {
console.log('[DRM-iOS] AirPlay ended');
this.status.isCasting = false;
this.status.castDevice = undefined;
this.config.onCastingEnded?.();
}));
this.listeners.push(drmEventEmitter.addListener('onLicenseAcquired', () => {
console.log('[DRM-iOS] FairPlay license acquired');
this.config.onLicenseAcquired?.();
}));
this.listeners.push(drmEventEmitter.addListener('onDRMError', (error) => {
console.error('[DRM-iOS] 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 'blockScreenRecording':
if (enabled) {
this.startScreenCaptureDetection();
}
break;
}
}
async startCasting(deviceId) {
await DRMProtectionModule.startAirPlay(deviceId);
}
async stopCasting() {
await DRMProtectionModule.stopAirPlay();
}
async getAvailableCastDevices() {
const devices = await DRMProtectionModule.getAvailableAirPlayDevices();
return devices.map((device) => ({
id: device.id,
name: device.name,
type: 'airplay',
isAvailable: device.isAvailable,
capabilities: {
supportsVideo: true,
supportsAudio: true,
supportsDRM: device.supportsFairPlay,
maxResolution: device.maxResolution,
},
}));
}
async renewLicense() {
await DRMProtectionModule.renewFairPlayLicense();
}
dispose() {
this.listeners.forEach((listener) => listener.remove());
this.listeners = [];
DRMProtectionModule.dispose();
this.status.isProtected = false;
}
}
exports.iOSDRMProtection = iOSDRMProtection;
//# sourceMappingURL=iOSDRMProtection.js.map