DRM *** To play DRM-protected content you need additional DRM configuration, which depends on the DRM solution you use. The SDK supports several DRM solutions out of the box through DRM environments. Note: On web, DRM-protected content requires the page to be served over HTTPS. HTTPS isn't required on localhost for testing. DRM with DRMtoday ================= Our player SDK comes with a pre-configured DRMtoday environment out of the box. To use the DRMtoday environment, set the "environment" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#environment) field in the "DrmConfiguration" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/) to DRMtoday and specify additional settings using the "customData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#customdata) object. For example: const playerConfiguration = { autoPlay: true, source: { /* ... */ }, drm: { environment: "DRMtoday", customData: { userId: "YOUR_USER_ID", sessionId: "YOUR_SESSION_ID", merchant: "YOUR_MERCHANT", } as DrmTodayCustomData, }, }; The "customData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#customdata) object must adhere to the "DrmTodayCustomData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmTodayCustomData/) type and is used to configure DRMtoday-specific settings. At a minimum, the "userId", "sessionId", and "merchant" fields should be provided. Note that there are two additional environments available for the DRMtoday platform: "DRMtoday_STAGING" and "DRMtoday_TEST". "DRMtoday_STAGING" points to the staging environment, and "DRMtoday_TEST" points to the test environment. These environments are for testing purposes and should not be used in production. DRM with Verimatrix =================== Our player SDK comes with a pre-configured Verimatrix environment out of the box. To use the Verimatrix environment, set the "environment" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#environment) field in the "DrmConfiguration" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/) to Verimatrix and specify additional settings using the "customData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#customdata) object. For example: const playerConfiguration = { autoPlay: true, source: { /* ... */ }, drm: { environment: "Verimatrix", customData: { deviceId: "YOUR_DEVICE_ID", widevineLicenseUrl: "YOUR_WIDEVINE_LICENSE_URL", playReadyLicenseUrl: "YOUR_PLAYREADY_LICENSE_URL", fairPlayLicenseUrl: "YOUR_FAIRPLAY_LICENSE_URL", fairPlayCertificateUrl: "YOUR_FAIRPLAY_CERTIFICATE_URL", } as VerimatrixCustomData, }, }; The "customData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#customdata) object must adhere to the "VerimatrixCustomData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/VerimatrixCustomData/) type and is used to configure Verimatrix-specific settings. It must include a "deviceId" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/VerimatrixCustomData/#deviceid), which serves as a unique identifier for the device. Additionally, the configuration should specify the license URLs for the targeted DRM systems. DRM with custom DRM environment =============================== Create a custom DRM environment if you need full control over the license acquisition process. To do this, create your own "DrmEnvironment" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmEnvironment/) instance, configure it for the DRM systems you need, and register it globally with "DrmEnvironmentRepository.register" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/classes/DrmEnvironmentRepository/#register). For further explanation of possible DRM system configurations, please refer to: * "WidevineDrmSystem" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/WidevineDrmSystem/) * "FairPlayDrmSystem" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/FairPlayDrmSystem/) * "PlayreadyDrmSystem" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/PlayreadyDrmSystem/) Example setup of a custom DRM environment can look like this: const myDRM: DrmEnvironment = { name: 'myDRM', widevine: { getLicenseUrl: () => 'https://lic.staging.drmtoday.com/license-proxy-widevine/cenc/', getCertificateUrl: () => 'https://lic.staging.drmtoday.com/license-proxy-widevine/cenc/', licenseRequest: widevineLicenseRequestModifier, licenseResponse: widevineLicenseResponseModifier, certificateRequest: widevineLicenseRequestModifier, certificateResponse: widevineLicenseResponseModifier, }, fairplay: { ... }, playready: { ... }, }; DrmEnvironmentRepository.register(myDRM); To use the custom environment, set the "environment" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#environment) field in the "DrmConfiguration" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/) to the custom DRM environment name and specify additional settings using the "customData" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/interfaces/DrmConfiguration/#customdata) object. For example: const playerConfiguration = { autoPlay: true, source: { /* ... */ }, drm: { environment: "myDRM", customData: { // optional data that might be needed by custom DRM environment } }, }; Offline DRM license prefetching =============================== When downloading DRM-protected content for offline playback, the media files are stored on the device but the DRM license must also be acquired and stored separately. Without a stored license the downloaded content cannot be played back without a network connection. The Downloader plugin exposes two methods on "Download" (https://players.castlabs.com/react-native/1.4.2/docs/downloader-plugin-api/interfaces/Download/) to manage offline licenses: * "Download.storeOfflineDrmLicense" (https://players.castlabs.com/react-native/1.4.2/docs/downloader-plugin-api/interfaces/Download/#storeofflinedrmlicense) — acquires a license from the license server and persists it on the device. * "Download.deleteOfflineDrmLicense" (https://players.castlabs.com/react-native/1.4.2/docs/downloader-plugin-api/interfaces/Download/#deleteofflinedrmlicense) — removes the stored license from the device. Both methods require the download to have a DRM configuration (i.e. the content is DRM-protected). They throw a "PrestoPlayError" if the download has no DRM configuration or if license acquisition fails. import { DownloadService } from "@castlabs/react-native-prestoplay-downloader"; const download = await DownloadService.getInstance().getDownload(""); if (download) { // Store an offline license so the content can be played without network await download.storeOfflineDrmLicense(); // Later, remove the stored license (e.g. when the user logs out) await download.deleteOfflineDrmLicense(); } Tracking offline license state ------------------------------ Use "Download.getDrmOfflineState" (https://players.castlabs.com/react-native/1.4.2/docs/downloader-plugin-api/interfaces/Download/#getdrmofflinestate) to read the current license state, or the "useDrmOfflineState" (https://players.castlabs.com/react-native/1.4.2/docs/downloader-plugin-api/functions/useDrmOfflineState/) hook to keep a React component in sync with state changes. import { DrmOfflineState, } from "@castlabs/react-native-prestoplay"; import { useDrmOfflineState, } from "@castlabs/react-native-prestoplay-downloader"; function DownloadItem({ download }) { const drmOfflineState = useDrmOfflineState(download); if (drmOfflineState === DrmOfflineState.NoDrm) { return No DRM, ready for offline playback; } if (drmOfflineState === DrmOfflineState.DrmProtected) { return ( ); } } The "DrmOfflineState" (https://players.castlabs.com/react-native/1.4.2/docs/sdk-api/enumerations/DrmOfflineState/) enum has two values: +----------------------------------------------------+----------------------------------------------------+ | Value | Description | |====================================================|====================================================| | "NoDrm" | Content is not DRM-protected. No license | | | management needed. | +----------------------------------------------------+----------------------------------------------------+ | "DrmProtected" | Content is DRM-protected. Use | | | "storeOfflineDrmLicense" / | | | "deleteOfflineDrmLicense" to manage the offline | | | license. | +----------------------------------------------------+----------------------------------------------------+ Android: "forceSingleDrmSession" -------------------------------- Some Widevine license servers require a single DRM session to be used for both license acquisition and decryption. If offline license prefetching fails on Android, try enabling the "forceSingleDrmSession" flag when initializing the SDK: import { Sdk } from "@castlabs/react-native-prestoplay"; Sdk.initialize({ licenseKey: { /* ... */ }, androidSdkConfiguration: { forceSingleDrmSession: true, }, }); See the Android SDK documentation (https://players.castlabs.com/android/latest/docs/javadoc/player_sdk/com/castlabs/android/PlayerSDK.html#FORCE_SINGLE_DRM_SESSION) for more details on this flag.