UNPKG

react-native-theoplayer

Version:

A THEOplayer video component for react-native.

178 lines (176 loc) 8.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NativeContentProtectionRegistry = exports.ContentProtectionRegistry = void 0; var _reactNative = require("react-native"); var _NativeLicenseRequest = require("./NativeLicenseRequest"); var _NativeLicenseResponse = require("./NativeLicenseResponse"); var _NativeCertificateRequest = require("./NativeCertificateRequest"); var _NativeCertificateResponse = require("./NativeCertificateResponse"); var _TypeUtils = require("../utils/TypeUtils"); const NativeContentProtectionModule = _reactNative.NativeModules.THEORCTContentProtectionModule; class NativeContentProtectionRegistry { registeredFactories = []; currentIntegration = undefined; constructor() { this.emitter = new _reactNative.NativeEventEmitter(NativeContentProtectionModule); this.emitter.addListener('onBuildIntegration', this.onBuildIntegrationRequest); this.emitter.addListener('onCertificateRequest', this.onCertificateRequest); this.emitter.addListener('onCertificateResponse', this.onCertificateResponse); this.emitter.addListener('onLicenseRequest', this.onLicenseRequest); this.emitter.addListener('onLicenseResponse', this.onLicenseResponse); this.emitter.addListener('onExtractFairplayContentId', this.onExtractFairplayContentId); } registerContentProtectionIntegration(integrationId, keySystemId, integrationFactory) { this.registeredFactories.push({ integrationId, keySystemId, integrationFactory }); NativeContentProtectionModule.registerContentProtectionIntegration(integrationId, keySystemId); } getFactory(integrationId, keySystemId) { return this.registeredFactories.find(init => init.integrationId === integrationId && init.keySystemId === keySystemId)?.integrationFactory; } getIntegration(integrationId, keySystemId) { return this.currentIntegration?.integrationId === integrationId && this.currentIntegration?.keySystemId === keySystemId ? this.currentIntegration?.integration : undefined; } onBuildIntegrationRequest = event => { const { requestId, integrationId, keySystemId, drmConfig } = event; console.log('NativeContentProtectionModule', `onBuildIntegrationRequest ${integrationId} ${keySystemId}`); const factory = this.getFactory(integrationId, keySystemId); if (factory) { this.currentIntegration = { integrationId, keySystemId, integration: factory.build(drmConfig) }; NativeContentProtectionModule.onBuildProcessed({ requestId, resultString: 'success' }); } else { NativeContentProtectionModule.onBuildProcessed({ requestId, resultString: 'failed' }); } }; onCertificateRequest = async request => { const { requestId, integrationId, keySystemId } = request; console.log('NativeContentProtectionModule', `onCertificateRequest ${integrationId} ${keySystemId}`); const integration = this.getIntegration(integrationId, keySystemId); if (integration?.onCertificateRequest) { const result = await integration.onCertificateRequest((0, _NativeCertificateRequest.fromNativeCertificateRequest)(request)); // TODO: we also want to support ArrayBufferView results if ((0, _TypeUtils.isBufferSource)(result)) { const nativeResponse = (0, _NativeCertificateResponse.toNativeCertificateResponseResult)(requestId, integrationId, keySystemId, result); NativeContentProtectionModule.onCertificateRequestProcessedAsCertificate(nativeResponse); } else if (result) { const modifiedNativeRequest = (0, _NativeCertificateRequest.toNativeCertificateRequest)(requestId, integrationId, keySystemId, result); NativeContentProtectionModule.onCertificateRequestProcessedAsRequest(modifiedNativeRequest); } } else { NativeContentProtectionModule.onCertificateRequestProcessedAsRequest(request); } }; onCertificateResponse = async response => { const { requestId, integrationId, keySystemId } = response; console.log('NativeContentProtectionModule', `onCertificateResponse ${integrationId} ${keySystemId}`); const integration = this.getIntegration(integrationId, keySystemId); if (integration?.onCertificateResponse) { const responseResult = await integration.onCertificateResponse((0, _NativeCertificateResponse.fromNativeCertificateResponse)(response)); // TODO: we also want to support ArrayBufferView results const modifiedNativeResponse = (0, _NativeCertificateResponse.toNativeCertificateResponseResult)(requestId, integrationId, keySystemId, responseResult); NativeContentProtectionModule.onCertificateResponseProcessed(modifiedNativeResponse); } else { NativeContentProtectionModule.onCertificateResponseProcessed(response); } }; onLicenseRequest = async request => { const { requestId, integrationId, keySystemId } = request; console.log('NativeContentProtectionModule', `onLicenseRequest ${integrationId} ${keySystemId}`); const integration = this.getIntegration(integrationId, keySystemId); // Optionally let the custom integration modify the request. if (integration?.onLicenseRequest) { const result = await integration.onLicenseRequest((0, _NativeLicenseRequest.fromNativeLicenseRequest)(request)); // TODO: we also want to support ArrayBufferView results if ((0, _TypeUtils.isBufferSource)(result)) { const nativeResponse = (0, _NativeLicenseResponse.toNativeLicenseResponseResult)(requestId, integrationId, keySystemId, result); NativeContentProtectionModule.onLicenseRequestProcessedAsLicense(nativeResponse); } else if (result) { const modifiedNativeRequest = (0, _NativeLicenseRequest.toNativeLicenseRequest)(requestId, integrationId, keySystemId, result); NativeContentProtectionModule.onLicenseRequestProcessedAsRequest(modifiedNativeRequest); } } else { NativeContentProtectionModule.onLicenseRequestProcessedAsRequest(request); } }; onLicenseResponse = async response => { const { requestId, integrationId, keySystemId } = response; console.log('NativeContentProtectionModule', `onLicenseResponse ${integrationId} ${keySystemId}`); const integration = this.getIntegration(integrationId, keySystemId); if (integration?.onLicenseResponse) { const responseResult = await integration.onLicenseResponse((0, _NativeLicenseResponse.fromNativeLicenseResponse)(response)); // TODO: we also want to support ArrayBufferView results const modifiedNativeResponse = (0, _NativeLicenseResponse.toNativeLicenseResponseResult)(requestId, integrationId, keySystemId, responseResult); NativeContentProtectionModule.onLicenseResponseProcessed(modifiedNativeResponse); } else { NativeContentProtectionModule.onLicenseResponseProcessed(response); } }; onExtractFairplayContentId = async event => { const { integrationId, keySystemId, fairplaySkdUrl, requestId } = event; console.log('NativeContentProtectionModule', `onExtractFairplayContentId ${integrationId} ${keySystemId}`); const integration = this.getIntegration(integrationId, keySystemId); if (integration?.extractFairplayContentId) { const contentId = await integration.extractFairplayContentId(fairplaySkdUrl); NativeContentProtectionModule.onExtractFairplayContentIdProcessed({ requestId, contentId }); } else { const contentId = fairplaySkdUrl; NativeContentProtectionModule.onExtractFairplayContentIdProcessed({ requestId, contentId }); } }; } /** * The registry for adding custom content protection (DRM) integrations. * * @category Content Protection * @public */ exports.NativeContentProtectionRegistry = NativeContentProtectionRegistry; const ContentProtectionRegistry = exports.ContentProtectionRegistry = new NativeContentProtectionRegistry(); //# sourceMappingURL=ContentProtectionRegistry.js.map