@react-native-video/drm 7.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +95 -0
  3. package/ReactNativeVideoDrm.podspec +31 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +135 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/twg/videodrm/DRMManager/DRMManager.kt +107 -0
  10. package/android/src/main/java/com/twg/videodrm/DRMPlugin.kt +12 -0
  11. package/android/src/main/java/com/twg/videodrm/PluginManager.kt +53 -0
  12. package/android/src/main/java/com/twg/videodrm/VideoDrmPackage.kt +22 -0
  13. package/ios/DRMManager/DRMManager+AVContentKeySessionDelegate.swift +63 -0
  14. package/ios/DRMManager/DRMManager.swift +229 -0
  15. package/ios/DRMPlugin.swift +21 -0
  16. package/ios/PluginManager.swift +72 -0
  17. package/lib/module/PluginManager.nitro.js +4 -0
  18. package/lib/module/PluginManager.nitro.js.map +1 -0
  19. package/lib/module/index.js +12 -0
  20. package/lib/module/index.js.map +1 -0
  21. package/lib/module/package.json +1 -0
  22. package/lib/typescript/package.json +1 -0
  23. package/lib/typescript/src/PluginManager.nitro.d.ts +10 -0
  24. package/lib/typescript/src/PluginManager.nitro.d.ts.map +1 -0
  25. package/lib/typescript/src/index.d.ts +4 -0
  26. package/lib/typescript/src/index.d.ts.map +1 -0
  27. package/nitro.json +17 -0
  28. package/nitrogen/generated/android/ReactNativeVideoDrm+autolinking.cmake +81 -0
  29. package/nitrogen/generated/android/ReactNativeVideoDrm+autolinking.gradle +27 -0
  30. package/nitrogen/generated/android/ReactNativeVideoDrmOnLoad.cpp +44 -0
  31. package/nitrogen/generated/android/ReactNativeVideoDrmOnLoad.hpp +25 -0
  32. package/nitrogen/generated/android/c++/JHybridPluginManagerSpec.cpp +53 -0
  33. package/nitrogen/generated/android/c++/JHybridPluginManagerSpec.hpp +65 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/videodrm/HybridPluginManagerSpec.kt +58 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/videodrm/ReactNativeVideoDrmOnLoad.kt +35 -0
  36. package/nitrogen/generated/ios/ReactNativeVideoDrm+autolinking.rb +60 -0
  37. package/nitrogen/generated/ios/ReactNativeVideoDrm-Swift-Cxx-Bridge.cpp +32 -0
  38. package/nitrogen/generated/ios/ReactNativeVideoDrm-Swift-Cxx-Bridge.hpp +51 -0
  39. package/nitrogen/generated/ios/ReactNativeVideoDrm-Swift-Cxx-Umbrella.hpp +43 -0
  40. package/nitrogen/generated/ios/ReactNativeVideoDrmAutolinking.mm +33 -0
  41. package/nitrogen/generated/ios/ReactNativeVideoDrmAutolinking.swift +25 -0
  42. package/nitrogen/generated/ios/c++/HybridPluginManagerSpecSwift.cpp +11 -0
  43. package/nitrogen/generated/ios/c++/HybridPluginManagerSpecSwift.hpp +79 -0
  44. package/nitrogen/generated/ios/swift/HybridPluginManagerSpec.swift +50 -0
  45. package/nitrogen/generated/ios/swift/HybridPluginManagerSpec_cxx.swift +138 -0
  46. package/nitrogen/generated/shared/c++/HybridPluginManagerSpec.cpp +23 -0
  47. package/nitrogen/generated/shared/c++/HybridPluginManagerSpec.hpp +63 -0
  48. package/package.json +135 -0
  49. package/src/PluginManager.nitro.ts +8 -0
  50. package/src/index.tsx +15 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 TheWidlarzGroup
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @react-native-video/drm
2
+
3
+ DRM plugin for react-native-video. It adds Widevine (Android) and FairPlay (iOS, visionOS) playback support via the react-native-video plugin system.
4
+
5
+ ## Requirements
6
+
7
+ - react-native-video >= 7.0.0-alpha.3
8
+ - react-native-nitro-modules >= 0.27.2
9
+
10
+ ## Installation
11
+
12
+ ```sh
13
+ npm install @react-native-video/drm react-native-video react-native-nitro-modules
14
+ # then for iOS
15
+ npx pod-install
16
+ ```
17
+
18
+ Notes
19
+ - This library uses Nitro Modules; autolinking is supported. No manual native changes are needed besides running CocoaPods on iOS.
20
+ - On Expo, use a prebuild workflow (npx expo prebuild) — pure managed apps aren’t supported.
21
+
22
+ ## Quick start
23
+
24
+ Enable the plugin once at app start, then pass DRM params on your video source.
25
+
26
+ ```tsx
27
+ import React from 'react';
28
+ import { Platform } from 'react-native';
29
+ import { VideoView, useVideoPlayer } from 'react-native-video';
30
+ import { enable, isEnabled } from '@react-native-video/drm';
31
+
32
+ // Enable at startup (required on Android; safe on iOS)
33
+ enable();
34
+
35
+ export default function Player() {
36
+ const player = useVideoPlayer({
37
+ uri: 'https://example.com/stream.m3u8',
38
+ // Request headers used by the media request and (on iOS default flow) the license request
39
+ headers: { Authorization: 'Bearer <token>' },
40
+ drm: {
41
+ // Optional: defaults to platform (fairplay on Apple, widevine on Android)
42
+ type: Platform.select({ ios: 'fairplay', default: 'widevine' }),
43
+
44
+ // Android (Widevine)
45
+ licenseUrl: 'https://license.example.com/widevine',
46
+ licenseHeaders: { 'x-custom': 'value' },
47
+ multiSession: true,
48
+
49
+ // iOS (FairPlay)
50
+ // For FairPlay provide certificateUrl and (optionally) contentId.
51
+ // When contentId is not provided, the plugin tries to infer it from the skd:// key URL.
52
+ certificateUrl: Platform.OS === 'ios' ? 'https://license.example.com/fps.cer' : undefined,
53
+ },
54
+ });
55
+
56
+ return <VideoView player={player} style={{ flex: 1 }} />;
57
+ }
58
+ ```
59
+
60
+ ## API
61
+
62
+ From `@react-native-video/drm`:
63
+
64
+ - `enable(): void` — registers the plugin. Call once during app startup (Android requires it; iOS tries to auto-enable, but calling is safe).
65
+ - `disable(): void` — unregisters the plugin.
66
+ - `isEnabled: boolean` — plugin registration status.
67
+
68
+ DRM params (provided via `useVideoPlayer({ drm: ... })` or equivalent config in react-native-video):
69
+
70
+ - `type?: 'widevine' | 'fairplay' | string` — DRM system. Defaults: Android → widevine, Apple → fairplay.
71
+ - `licenseUrl?: string` — license server URL. Required for both Widevine and FairPlay default flows.
72
+ - `licenseHeaders?: Record<string, string>` — headers for license requests (Android only).
73
+ - `multiSession?: boolean` — allow multiple sessions (Android only).
74
+ - `certificateUrl?: string` — FairPlay application certificate URL (iOS/visionOS).
75
+ - `contentId?: string` — FairPlay content ID (iOS/visionOS). If omitted, inferred from `skd://` key URL when possible.
76
+ - `getLicense?: (payload) => Promise<string>` — iOS custom license fetch. Receives `{ contentId, licenseUrl, keyUrl, spc }` and must resolve to a base64-encoded CKC.
77
+
78
+ ## Platform notes
79
+
80
+ - iOS/visionOS
81
+ - FairPlay is not supported on the simulator — test on a real device.
82
+ - Default license flow posts SPC bytes to `licenseUrl` and uses `source.headers` (not `licenseHeaders`). Use `getLicense` for full control.
83
+ - Provide `certificateUrl`; set `contentId` if your server needs it.
84
+ - Android
85
+ - Widevine is handled via ExoPlayer (Media3). Use `licenseHeaders` for request headers and `multiSession` if needed.
86
+
87
+ ## Troubleshooting
88
+
89
+ - “Failed to fetch certificate/license” — verify URLs are reachable and correct, and that headers/tokens are included. On iOS default flow, set headers in `source.headers`.
90
+ - “Unsupported DRM type” — set `drm.type` appropriately or omit it to use platform defaults.
91
+ - “DRM not working on simulator” — FairPlay does not work on the iOS simulator.
92
+
93
+ ## License
94
+
95
+ MIT
@@ -0,0 +1,31 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "ReactNativeVideoDrm"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/TheWidlarzGroup/react-native-video-drm.git", :tag => "#{s.version}" }
15
+
16
+
17
+ s.source_files = [
18
+ "ios/**/*.{swift}",
19
+ "ios/**/*.{m,mm}",
20
+ "cpp/**/*.{hpp,cpp}",
21
+ ]
22
+
23
+ s.dependency 'React-jsi'
24
+ s.dependency 'React-callinvoker'
25
+ s.dependency 'ReactNativeVideo'
26
+
27
+ load 'nitrogen/generated/ios/ReactNativeVideoDrm+autolinking.rb'
28
+ add_nitrogen_files(s)
29
+
30
+ install_modules_dependencies(s)
31
+ end
@@ -0,0 +1,24 @@
1
+ project(ReactNativeVideoDrm)
2
+ cmake_minimum_required(VERSION 3.9.0)
3
+
4
+ set(PACKAGE_NAME ReactNativeVideoDrm)
5
+ set(CMAKE_VERBOSE_MAKEFILE ON)
6
+ set(CMAKE_CXX_STANDARD 20)
7
+
8
+ # Define C++ library and add all sources
9
+ add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
10
+
11
+ # Add Nitrogen specs :)
12
+ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/ReactNativeVideoDrm+autolinking.cmake)
13
+
14
+ # Set up local includes
15
+ include_directories("src/main/cpp" "../cpp")
16
+
17
+ find_library(LOG_LIB log)
18
+
19
+ # Link all libraries together
20
+ target_link_libraries(
21
+ ${PACKAGE_NAME}
22
+ ${LOG_LIB}
23
+ android # <-- Android core
24
+ )
@@ -0,0 +1,135 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['VideoDrm_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+ def reactNativeArchitectures() {
19
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
20
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
21
+ }
22
+
23
+ apply plugin: "com.android.library"
24
+ apply plugin: "kotlin-android"
25
+ apply from: '../nitrogen/generated/android/ReactNativeVideoDrm+autolinking.gradle'
26
+
27
+ apply plugin: "com.facebook.react"
28
+
29
+ def getExtOrIntegerDefault(name) {
30
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["VideoDrm_" + name]).toInteger()
31
+ }
32
+
33
+ android {
34
+ namespace "com.twg.videodrm"
35
+
36
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
37
+
38
+ defaultConfig {
39
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
40
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
41
+
42
+ externalNativeBuild {
43
+ cmake {
44
+ cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
45
+ arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
46
+ abiFilters (*reactNativeArchitectures())
47
+
48
+ buildTypes {
49
+ debug {
50
+ cppFlags "-O1 -g"
51
+ }
52
+ release {
53
+ cppFlags "-O2"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ externalNativeBuild {
61
+ cmake {
62
+ path "CMakeLists.txt"
63
+ }
64
+ }
65
+
66
+ packagingOptions {
67
+ excludes = [
68
+ "META-INF",
69
+ "META-INF/**",
70
+ "**/libc++_shared.so",
71
+ "**/libfbjni.so",
72
+ "**/libjsi.so",
73
+ "**/libfolly_json.so",
74
+ "**/libfolly_runtime.so",
75
+ "**/libglog.so",
76
+ "**/libhermes.so",
77
+ "**/libhermes-executor-debug.so",
78
+ "**/libhermes_executor.so",
79
+ "**/libreactnative.so",
80
+ "**/libreactnativejni.so",
81
+ "**/libturbomodulejsijni.so",
82
+ "**/libreact_nativemodule_core.so",
83
+ "**/libjscexecutor.so"
84
+ ]
85
+ }
86
+
87
+ buildFeatures {
88
+ buildConfig true
89
+ prefab true
90
+ }
91
+
92
+ buildTypes {
93
+ release {
94
+ minifyEnabled false
95
+ }
96
+ }
97
+
98
+ lintOptions {
99
+ disable "GradleCompatible"
100
+ }
101
+
102
+ compileOptions {
103
+ sourceCompatibility JavaVersion.VERSION_1_8
104
+ targetCompatibility JavaVersion.VERSION_1_8
105
+ }
106
+
107
+ sourceSets {
108
+ main {
109
+ java.srcDirs += [
110
+ "generated/java",
111
+ "generated/jni"
112
+ ]
113
+ }
114
+ }
115
+ }
116
+
117
+ repositories {
118
+ mavenCentral()
119
+ google()
120
+ }
121
+
122
+ def kotlin_version = getExtOrDefault("kotlinVersion")
123
+
124
+ dependencies {
125
+ implementation "com.facebook.react:react-android"
126
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
127
+
128
+ implementation "androidx.media3:media3-common:1.4.1"
129
+ implementation "androidx.media3:media3-exoplayer:1.4.1"
130
+ implementation "androidx.media3:media3-datasource-okhttp:1.4.1"
131
+
132
+ implementation project(":react-native-nitro-modules")
133
+ implementation project(":react-native-video")
134
+ }
135
+
@@ -0,0 +1,5 @@
1
+ VideoDrm_kotlinVersion=2.0.21
2
+ VideoDrm_minSdkVersion=24
3
+ VideoDrm_targetSdkVersion=34
4
+ VideoDrm_compileSdkVersion=35
5
+ VideoDrm_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,6 @@
1
+ #include <jni.h>
2
+ #include "ReactNativeVideoDrmOnLoad.hpp"
3
+
4
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
5
+ return margelo::nitro::videodrm::initialize(vm);
6
+ }
@@ -0,0 +1,107 @@
1
+ package com.twg.videodrm.DRMManager
2
+
3
+ import android.content.Context
4
+ import androidx.annotation.OptIn
5
+ import androidx.media3.common.MediaItem.DrmConfiguration
6
+ import androidx.media3.common.util.UnstableApi
7
+ import androidx.media3.common.util.Util
8
+ import androidx.media3.datasource.okhttp.OkHttpDataSource
9
+ import androidx.media3.exoplayer.drm.DefaultDrmSessionManager
10
+ import androidx.media3.exoplayer.drm.DrmSessionManager
11
+ import androidx.media3.exoplayer.drm.FrameworkMediaDrm
12
+ import androidx.media3.exoplayer.drm.HttpMediaDrmCallback
13
+ import androidx.media3.exoplayer.drm.MediaDrmCallback
14
+ import com.twg.video.core.player.DRMManagerSpec
15
+ import com.margelo.nitro.NitroModules
16
+ import com.margelo.nitro.video.NativeDrmParams
17
+ import com.twg.video.core.player.buildHttpDataSourceFactory
18
+ import com.twg.video.core.plugins.NativeVideoPlayerSource
19
+ import java.util.UUID
20
+
21
+ class DRMManager(val source: NativeVideoPlayerSource) : DRMManagerSpec {
22
+ private var hasDrmFailed = false
23
+ private val context: Context
24
+ get() {
25
+ return NitroModules.applicationContext ?: throw Error("Context is not found")
26
+ }
27
+
28
+ private var headersHash = -1
29
+ private var httpDataSourceFactory: OkHttpDataSource.Factory? = null
30
+
31
+ private fun shouldRebuildHttpDataSource(): Boolean {
32
+ val header = source.config.headers
33
+ if (header == null) {
34
+ return false
35
+ }
36
+
37
+ val hash = header.hashCode()
38
+ if (hash == headersHash) {
39
+ return false
40
+ }
41
+
42
+ headersHash = hash
43
+ return true
44
+ }
45
+
46
+ private fun getHttpDataSourceFactory(): OkHttpDataSource.Factory {
47
+ if (shouldRebuildHttpDataSource() || httpDataSourceFactory == null) {
48
+ httpDataSourceFactory = buildHttpDataSourceFactory(context, source)
49
+ }
50
+
51
+ return httpDataSourceFactory ?: throw Error("Couldn't build HttpDataSourceFactory")
52
+ }
53
+
54
+ @OptIn(UnstableApi::class)
55
+ override fun buildDrmSessionManager(
56
+ drmParams: NativeDrmParams,
57
+ drmUuid: UUID?,
58
+ retryCount: Int
59
+ ): DrmSessionManager {
60
+ try {
61
+ val uuid = drmUuid ?: throw Error("DRM UUID is not set")
62
+ val mediaDrm = FrameworkMediaDrm.newInstance(uuid)
63
+ val mediaDrmCallback = HttpMediaDrmCallback(
64
+ drmParams.licenseUrl,
65
+ getHttpDataSourceFactory(),
66
+ )
67
+
68
+ if (drmParams.licenseHeaders != null) {
69
+ for ((key, value) in drmParams.licenseHeaders) {
70
+ mediaDrmCallback.setKeyRequestProperty(key, value)
71
+ }
72
+ }
73
+
74
+ if (hasDrmFailed) {
75
+ mediaDrm.setPropertyString("securityLevel", "L3")
76
+ }
77
+
78
+ return DefaultDrmSessionManager.Builder()
79
+ .setUuidAndExoMediaDrmProvider(uuid) { mediaDrm }
80
+ .setKeyRequestParameters(null)
81
+ .setMultiSession(drmParams.multiSession == true)
82
+ .build(mediaDrmCallback)
83
+ } catch (err: Exception) {
84
+ if (retryCount < 3) {
85
+ hasDrmFailed = true
86
+ return buildDrmSessionManager(drmParams, drmUuid, retryCount + 1)
87
+ }
88
+
89
+ throw err
90
+ }
91
+ }
92
+
93
+ @OptIn(UnstableApi::class)
94
+ override fun getDRMConfiguration(drmParams: NativeDrmParams): DrmConfiguration {
95
+ val uuid = Util.getDrmUuid(drmParams.type ?: "widevine") ?: throw Error("DRM UUID is not set")
96
+
97
+ val configurationBuilder = DrmConfiguration.Builder(uuid)
98
+ .setMultiSession(drmParams.multiSession == true)
99
+ .setLicenseUri(drmParams.licenseUrl)
100
+
101
+ drmParams.licenseHeaders?.let {
102
+ configurationBuilder.setLicenseRequestHeaders(it)
103
+ }
104
+
105
+ return configurationBuilder.build()
106
+ }
107
+ }
@@ -0,0 +1,12 @@
1
+ package com.twg.videodrm
2
+
3
+ import com.twg.videodrm.DRMManager.DRMManager
4
+ import com.twg.video.core.player.DRMManagerSpec
5
+ import com.twg.video.core.plugins.NativeVideoPlayerSource
6
+ import com.twg.video.core.plugins.ReactNativeVideoPlugin
7
+
8
+ class DRMPlugin(name: String) : ReactNativeVideoPlugin(name) {
9
+ override fun getDRMManager(source: NativeVideoPlayerSource): DRMManagerSpec? {
10
+ return DRMManager(source)
11
+ }
12
+ }
@@ -0,0 +1,53 @@
1
+ package com.margelo.nitro.videodrm
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip
4
+ import com.twg.videodrm.DRMPlugin
5
+ import com.twg.video.core.plugins.PluginsRegistry
6
+
7
+ @DoNotStrip
8
+ class PluginManager : HybridPluginManagerSpec() {
9
+ private var plugin: DRMPlugin? = null
10
+
11
+ override val isEnabled: Boolean
12
+ get() = plugin != null
13
+
14
+ override fun enable() {
15
+ if (isEnabled) {
16
+ return
17
+ }
18
+
19
+ initializePlugin()
20
+ }
21
+
22
+ override fun disable() {
23
+ if (!isEnabled) {
24
+ return
25
+ }
26
+
27
+ destroyPlugin()
28
+ }
29
+
30
+ private fun initializePlugin() {
31
+ plugin = DRMPlugin("ReactNativeVideoDRM")
32
+
33
+ plugin?.let {
34
+ PluginsRegistry.shared.register(it)
35
+ } ?: throw Error("Failed to initialize DRM plugin.")
36
+ }
37
+
38
+ private fun destroyPlugin() {
39
+ plugin?.let {
40
+ PluginsRegistry.shared.unregister(it)
41
+ } ?: throw Error("Plugin is not initialized!")
42
+
43
+ plugin = null
44
+ }
45
+
46
+ override fun dispose() {
47
+ if (isEnabled) {
48
+ try {
49
+ destroyPlugin()
50
+ } catch (_: Exception) { }
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,22 @@
1
+ package com.twg.videodrm
2
+
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+
8
+ class VideoDrmPackage : TurboReactPackage() {
9
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
10
+ return null
11
+ }
12
+
13
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
14
+ return ReactModuleInfoProvider { HashMap() }
15
+ }
16
+
17
+ companion object {
18
+ init {
19
+ System.loadLibrary("ReactNativeVideoDrm")
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,63 @@
1
+ //
2
+ // DRMManager+AVContentKeySessionDelegate.swift
3
+ // ReactNativeVideoDrm
4
+ //
5
+ // Created by Krzysztof Moch on 07/08/2025.
6
+ //
7
+
8
+ import AVFoundation
9
+ import Foundation
10
+ import NitroModules
11
+
12
+ extension DRMManager: AVContentKeySessionDelegate {
13
+ func contentKeySession(
14
+ _: AVContentKeySession,
15
+ didProvide keyRequest: AVContentKeyRequest
16
+ ) {
17
+ handleContentKeyRequest(keyRequest: keyRequest)
18
+ }
19
+
20
+ func contentKeySession(
21
+ _: AVContentKeySession,
22
+ didProvideRenewingContentKeyRequest keyRequest: AVContentKeyRequest
23
+ ) {
24
+ handleContentKeyRequest(keyRequest: keyRequest)
25
+ }
26
+
27
+ func contentKeySession(
28
+ _: AVContentKeySession,
29
+ shouldRetry _: AVContentKeyRequest,
30
+ reason retryReason: AVContentKeyRequest.RetryReason
31
+ ) -> Bool {
32
+ let retryReasons: [AVContentKeyRequest.RetryReason] = [
33
+ .timedOut,
34
+ .receivedResponseWithExpiredLease,
35
+ .receivedObsoleteContentKey,
36
+ ]
37
+ return retryReasons.contains(retryReason)
38
+ }
39
+
40
+ func contentKeySession(
41
+ _: AVContentKeySession,
42
+ didProvide keyRequest: AVPersistableContentKeyRequest
43
+ ) {
44
+ handleError(
45
+ error: RuntimeError.error(
46
+ withMessage:
47
+ "Persistable content key requests are not supported in This Plugin. Please see Offline Video SDK if you need this functionality."
48
+ ),
49
+ for: keyRequest
50
+ )
51
+ }
52
+
53
+ func contentKeySession(
54
+ _: AVContentKeySession,
55
+ contentKeyRequest _: AVContentKeyRequest,
56
+ didFailWithError error: Error
57
+ ) {
58
+ // TODO: Handle error appropriately
59
+ print(
60
+ "[ReactNativeVideo] DRMManager: Content key request failed with error: \(error.localizedDescription)"
61
+ )
62
+ }
63
+ }