@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.
- package/LICENSE +20 -0
- package/README.md +95 -0
- package/ReactNativeVideoDrm.podspec +31 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +135 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/twg/videodrm/DRMManager/DRMManager.kt +107 -0
- package/android/src/main/java/com/twg/videodrm/DRMPlugin.kt +12 -0
- package/android/src/main/java/com/twg/videodrm/PluginManager.kt +53 -0
- package/android/src/main/java/com/twg/videodrm/VideoDrmPackage.kt +22 -0
- package/ios/DRMManager/DRMManager+AVContentKeySessionDelegate.swift +63 -0
- package/ios/DRMManager/DRMManager.swift +229 -0
- package/ios/DRMPlugin.swift +21 -0
- package/ios/PluginManager.swift +72 -0
- package/lib/module/PluginManager.nitro.js +4 -0
- package/lib/module/PluginManager.nitro.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/PluginManager.nitro.d.ts +10 -0
- package/lib/typescript/src/PluginManager.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/ReactNativeVideoDrm+autolinking.cmake +81 -0
- package/nitrogen/generated/android/ReactNativeVideoDrm+autolinking.gradle +27 -0
- package/nitrogen/generated/android/ReactNativeVideoDrmOnLoad.cpp +44 -0
- package/nitrogen/generated/android/ReactNativeVideoDrmOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JHybridPluginManagerSpec.cpp +53 -0
- package/nitrogen/generated/android/c++/JHybridPluginManagerSpec.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/videodrm/HybridPluginManagerSpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/videodrm/ReactNativeVideoDrmOnLoad.kt +35 -0
- package/nitrogen/generated/ios/ReactNativeVideoDrm+autolinking.rb +60 -0
- package/nitrogen/generated/ios/ReactNativeVideoDrm-Swift-Cxx-Bridge.cpp +32 -0
- package/nitrogen/generated/ios/ReactNativeVideoDrm-Swift-Cxx-Bridge.hpp +51 -0
- package/nitrogen/generated/ios/ReactNativeVideoDrm-Swift-Cxx-Umbrella.hpp +43 -0
- package/nitrogen/generated/ios/ReactNativeVideoDrmAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeVideoDrmAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridPluginManagerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridPluginManagerSpecSwift.hpp +79 -0
- package/nitrogen/generated/ios/swift/HybridPluginManagerSpec.swift +50 -0
- package/nitrogen/generated/ios/swift/HybridPluginManagerSpec_cxx.swift +138 -0
- package/nitrogen/generated/shared/c++/HybridPluginManagerSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridPluginManagerSpec.hpp +63 -0
- package/package.json +135 -0
- package/src/PluginManager.nitro.ts +8 -0
- package/src/index.tsx +15 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//
|
|
2
|
+
// DRMManager.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
|
+
import ReactNativeVideo
|
|
12
|
+
|
|
13
|
+
class DRMManager: NSObject, DRMManagerSpec {
|
|
14
|
+
static let queue = DispatchQueue(
|
|
15
|
+
label: "ReactNativeVideoDrmContentKeyDelegateQueue"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
let contentKeySession: AVContentKeySession
|
|
19
|
+
weak var source: NativeVideoPlayerSource?
|
|
20
|
+
|
|
21
|
+
var drmParams: NativeDrmParams? {
|
|
22
|
+
return source?.config.drm
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
init(source: NativeVideoPlayerSource) {
|
|
26
|
+
contentKeySession = AVContentKeySession(keySystem: .fairPlayStreaming)
|
|
27
|
+
self.source = source
|
|
28
|
+
|
|
29
|
+
super.init()
|
|
30
|
+
contentKeySession.setDelegate(self, queue: DRMManager.queue)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func createContentKeyRequest(
|
|
34
|
+
for asset: AVURLAsset,
|
|
35
|
+
drmParams: NativeDrmParams
|
|
36
|
+
) throws {
|
|
37
|
+
if drmParams.type != "fairplay" {
|
|
38
|
+
throw RuntimeError.error(
|
|
39
|
+
withMessage:
|
|
40
|
+
"Unsupported DRM type: \(String(describing: drmParams.type))"
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
contentKeySession.addContentKeyRecipient(asset)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// MARK: - Internal Methods
|
|
48
|
+
internal func handleError(error: Error, for keyRequest: AVContentKeyRequest) {
|
|
49
|
+
print(
|
|
50
|
+
"[ReactNativeVideo] DRM Error: \(error.localizedDescription) for source \(source?.uri ?? "unknown source")"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
keyRequest.processContentKeyResponseError(error)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
internal func handleContentKeyRequest(keyRequest: AVContentKeyRequest) {
|
|
57
|
+
Task {
|
|
58
|
+
do {
|
|
59
|
+
try await processContentKeyRequest(keyRequest: keyRequest)
|
|
60
|
+
} catch {
|
|
61
|
+
handleError(error: error, for: keyRequest)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
internal func finishProcessingContentKeyRequest(
|
|
67
|
+
keyRequest: AVContentKeyRequest,
|
|
68
|
+
license: Data
|
|
69
|
+
) throws {
|
|
70
|
+
let keyResponse = AVContentKeyResponse(
|
|
71
|
+
fairPlayStreamingKeyResponseData: license
|
|
72
|
+
)
|
|
73
|
+
keyRequest.processContentKeyResponse(keyResponse)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// MARK: - Private Methods
|
|
77
|
+
|
|
78
|
+
private func processContentKeyRequest(keyRequest: AVContentKeyRequest)
|
|
79
|
+
async throws
|
|
80
|
+
{
|
|
81
|
+
guard let assetId = getAssetId(keyRequest: keyRequest),
|
|
82
|
+
let assetIdData = assetId.data(using: .utf8)
|
|
83
|
+
else {
|
|
84
|
+
throw RuntimeError.error(
|
|
85
|
+
withMessage:
|
|
86
|
+
"No asset ID found for content key request (For \(source?.uri ?? "unknown source"))"
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let appCertificate = try await requestApplicationCertificate()
|
|
91
|
+
let spcData = try await keyRequest.makeStreamingContentKeyRequestData(
|
|
92
|
+
forApp: appCertificate,
|
|
93
|
+
contentIdentifier: assetIdData
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if let getLicense = drmParams?.getLicense {
|
|
97
|
+
|
|
98
|
+
guard let licenseUrl = drmParams?.licenseUrl,
|
|
99
|
+
let keyUrl = keyRequest.identifier as? String
|
|
100
|
+
else {
|
|
101
|
+
throw RuntimeError.error(
|
|
102
|
+
withMessage:
|
|
103
|
+
"Missing required parameters for getLicense (For \(source?.uri ?? "unknown source"))"
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let payload = OnGetLicensePayload(
|
|
108
|
+
contentId: assetId,
|
|
109
|
+
licenseUrl: licenseUrl,
|
|
110
|
+
keyUrl: keyUrl,
|
|
111
|
+
spc: spcData.base64EncodedString()
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
// Get Promise from JavaScript
|
|
115
|
+
let getLicenseJS = try await getLicense(payload).await()
|
|
116
|
+
|
|
117
|
+
// Resolve Promise from JavaScript
|
|
118
|
+
let license = try await getLicenseJS.await()
|
|
119
|
+
|
|
120
|
+
guard let licenseData = Data(base64Encoded: license) else {
|
|
121
|
+
throw RuntimeError.error(
|
|
122
|
+
withMessage:
|
|
123
|
+
"Invalid license data received from getLicense (For \(source?.uri ?? "unknown source"))"
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try finishProcessingContentKeyRequest(
|
|
128
|
+
keyRequest: keyRequest,
|
|
129
|
+
license: licenseData
|
|
130
|
+
)
|
|
131
|
+
} else {
|
|
132
|
+
|
|
133
|
+
// Try "Default" License Request
|
|
134
|
+
let license = try await requestLicense(spcData: spcData)
|
|
135
|
+
try finishProcessingContentKeyRequest(
|
|
136
|
+
keyRequest: keyRequest,
|
|
137
|
+
license: license
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private func requestApplicationCertificate() async throws -> Data {
|
|
143
|
+
guard let urlString = drmParams?.certificateUrl,
|
|
144
|
+
let url = URL(string: urlString)
|
|
145
|
+
else {
|
|
146
|
+
throw RuntimeError.error(
|
|
147
|
+
withMessage:
|
|
148
|
+
"No certificate URL provided (For \(source?.uri ?? "unknown source"))"
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let (data, response) = try await URLSession.shared.data(from: url)
|
|
153
|
+
|
|
154
|
+
guard let httpResponse = response as? HTTPURLResponse,
|
|
155
|
+
httpResponse.statusCode == 200
|
|
156
|
+
else {
|
|
157
|
+
throw RuntimeError.error(
|
|
158
|
+
withMessage: "Failed to fetch certificate from \(urlString)"
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if let base64EncodedData = String(data: data, encoding: .utf8),
|
|
163
|
+
let certData = Data(base64Encoded: base64EncodedData)
|
|
164
|
+
{
|
|
165
|
+
return certData
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return data
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private func requestLicense(spcData: Data) async throws -> Data {
|
|
172
|
+
guard let licenseServerUrlString = drmParams?.licenseUrl,
|
|
173
|
+
let licenseServerUrl = URL(string: licenseServerUrlString)
|
|
174
|
+
else {
|
|
175
|
+
throw RuntimeError.error(
|
|
176
|
+
withMessage:
|
|
177
|
+
"No license URL provided (For \(source?.uri ?? "unknown source"))"
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var request = URLRequest(url: licenseServerUrl)
|
|
182
|
+
request.httpMethod = "POST"
|
|
183
|
+
request.httpBody = spcData
|
|
184
|
+
|
|
185
|
+
// Use source headers for now, there was some issues with headers in the DRM params
|
|
186
|
+
if let headers = source?.config.headers {
|
|
187
|
+
for (key, value) in headers {
|
|
188
|
+
request.setValue(value, forHTTPHeaderField: key)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let (data, response) = try await URLSession.shared.data(for: request)
|
|
193
|
+
|
|
194
|
+
guard let httpResponse = response as? HTTPURLResponse else {
|
|
195
|
+
throw RuntimeError.error(
|
|
196
|
+
withMessage:
|
|
197
|
+
"Invalid response from license server (For \(source?.uri ?? "unknown source")) - \(String(describing: response))"
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
guard httpResponse.statusCode == 200 else {
|
|
202
|
+
throw RuntimeError.error(
|
|
203
|
+
withMessage:
|
|
204
|
+
"License request failed with status code \(httpResponse.statusCode) (For \(source?.uri ?? "unknown source"))"
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
guard !data.isEmpty else {
|
|
209
|
+
throw RuntimeError.error(
|
|
210
|
+
withMessage:
|
|
211
|
+
"License response is empty (For \(source?.uri ?? "unknown source"))"
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return data
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private func getAssetId(keyRequest: AVContentKeyRequest) -> String? {
|
|
219
|
+
if let assetId = drmParams?.contentId {
|
|
220
|
+
return assetId
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if let url = keyRequest.identifier as? String {
|
|
224
|
+
return url.replacingOccurrences(of: "skd://", with: "")
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return nil
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// DRMPlugin.swift
|
|
3
|
+
// ReactNativeVideoDrm
|
|
4
|
+
//
|
|
5
|
+
// Created by Krzysztof Moch on 07/08/2025.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import ReactNativeVideo
|
|
10
|
+
|
|
11
|
+
class DRMPlugin: ReactNativeVideoPlugin {
|
|
12
|
+
override func getDRMManager(source: any NativeVideoPlayerSource) -> (any DRMManagerSpec)? {
|
|
13
|
+
#if targetEnvironment(simulator)
|
|
14
|
+
// DRM is not supported on the simulator.
|
|
15
|
+
print("[ReactNativeVideoDRM] DRM is not supported on the simulator. Returning nil.")
|
|
16
|
+
return nil
|
|
17
|
+
#else
|
|
18
|
+
return DRMManager(source: source)
|
|
19
|
+
#endif
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PluginManager.swift
|
|
3
|
+
// ReactNativeVideoDrm
|
|
4
|
+
//
|
|
5
|
+
// Created by Krzysztof Moch on 07/08/2025.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
import ReactNativeVideo
|
|
10
|
+
|
|
11
|
+
class PluginManager: HybridPluginManagerSpec {
|
|
12
|
+
var plugin: DRMPlugin? = nil
|
|
13
|
+
|
|
14
|
+
override init() {
|
|
15
|
+
super.init()
|
|
16
|
+
do {
|
|
17
|
+
try enable()
|
|
18
|
+
} catch {
|
|
19
|
+
// Handle error if needed, for example log it
|
|
20
|
+
print("Failed to enable DRM plugin: \(error)")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var isEnabled: Bool {
|
|
25
|
+
return plugin != nil
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func enable() throws {
|
|
29
|
+
if isEnabled {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try initializePlugin()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func disable() throws {
|
|
37
|
+
if !isEnabled {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try destroyPlugin()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private func initializePlugin() throws {
|
|
45
|
+
plugin = DRMPlugin(name: "ReactNativeVideoDRM")
|
|
46
|
+
|
|
47
|
+
guard let plugin else {
|
|
48
|
+
throw RuntimeError.error(withMessage: "Failed to initialize DRM plugin.")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
PluginsRegistry.shared.register(plugin: plugin)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private func destroyPlugin() throws {
|
|
55
|
+
guard let plugin else {
|
|
56
|
+
throw RuntimeError.error(withMessage: "Plugin is not initialized.")
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
PluginsRegistry.shared.unregister(plugin: plugin)
|
|
60
|
+
self.plugin = nil
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func dispose() {
|
|
64
|
+
if isEnabled {
|
|
65
|
+
do {
|
|
66
|
+
try destroyPlugin()
|
|
67
|
+
} catch {
|
|
68
|
+
// ignore errors during disposal
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["PluginManager.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
const PluginManager = NitroModules.createHybridObject('PluginManager');
|
|
5
|
+
export function enable() {
|
|
6
|
+
return PluginManager.enable();
|
|
7
|
+
}
|
|
8
|
+
export function disable() {
|
|
9
|
+
return PluginManager.disable();
|
|
10
|
+
}
|
|
11
|
+
export const isEnabled = PluginManager.isEnabled;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","PluginManager","createHybridObject","enable","disable","isEnabled"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,MAAMC,aAAa,GACjBD,YAAY,CAACE,kBAAkB,CAAoB,eAAe,CAAC;AAErE,OAAO,SAASC,MAAMA,CAAA,EAAG;EACvB,OAAOF,aAAa,CAACE,MAAM,CAAC,CAAC;AAC/B;AAEA,OAAO,SAASC,OAAOA,CAAA,EAAG;EACxB,OAAOH,aAAa,CAACG,OAAO,CAAC,CAAC;AAChC;AAEA,OAAO,MAAMC,SAAkB,GAAGJ,aAAa,CAACI,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface PluginManager extends HybridObject<{
|
|
3
|
+
ios: 'swift';
|
|
4
|
+
android: 'kotlin';
|
|
5
|
+
}> {
|
|
6
|
+
enable(): void;
|
|
7
|
+
disable(): void;
|
|
8
|
+
readonly isEnabled: boolean;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=PluginManager.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginManager.nitro.d.ts","sourceRoot":"","sources":["../../../src/PluginManager.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,aACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,MAAM,IAAI,IAAI,CAAC;IACf,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAMA,wBAAgB,MAAM,SAErB;AAED,wBAAgB,OAAO,SAEtB;AAED,eAAO,MAAM,SAAS,EAAE,OAAiC,CAAC"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["videodrm"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "ReactNativeVideoDrm"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["videodrm"],
|
|
8
|
+
"androidCxxLibName": "ReactNativeVideoDrm"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"PluginManager": {
|
|
12
|
+
"swift": "PluginManager",
|
|
13
|
+
"kotlin": "PluginManager"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"ignorePaths": ["node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#
|
|
2
|
+
# ReactNativeVideoDrm+autolinking.cmake
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/ReactNativeVideoDrm+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_REACTNATIVEVIDEODRM_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
ReactNativeVideoDrm PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/ReactNativeVideoDrmOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridPluginManagerSpec.cpp
|
|
37
|
+
# Android-specific Nitrogen C++ sources
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridPluginManagerSpec.cpp
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
42
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
43
|
+
target_compile_definitions(
|
|
44
|
+
ReactNativeVideoDrm PRIVATE
|
|
45
|
+
-DFOLLY_NO_CONFIG=1
|
|
46
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
47
|
+
-DFOLLY_USE_LIBCPP=1
|
|
48
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
49
|
+
-DFOLLY_MOBILE=1
|
|
50
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
51
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
52
|
+
# Once we target android-23 above, we can comment
|
|
53
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
54
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Add all libraries required by the generated specs
|
|
58
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
59
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
60
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
61
|
+
|
|
62
|
+
# Link all libraries together
|
|
63
|
+
target_link_libraries(
|
|
64
|
+
ReactNativeVideoDrm
|
|
65
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
66
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
67
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
71
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
72
|
+
target_link_libraries(
|
|
73
|
+
ReactNativeVideoDrm
|
|
74
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
75
|
+
)
|
|
76
|
+
else()
|
|
77
|
+
target_link_libraries(
|
|
78
|
+
ReactNativeVideoDrm
|
|
79
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
80
|
+
)
|
|
81
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ReactNativeVideoDrm+autolinking.gradle
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/ReactNativeVideoDrm+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 ReactNativeVideoDrm is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ReactNativeVideoDrmOnLoad.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#ifndef BUILDING_REACTNATIVEVIDEODRM_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error ReactNativeVideoDrmOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "ReactNativeVideoDrmOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridPluginManagerSpec.hpp"
|
|
19
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::videodrm {
|
|
22
|
+
|
|
23
|
+
int initialize(JavaVM* vm) {
|
|
24
|
+
using namespace margelo::nitro;
|
|
25
|
+
using namespace margelo::nitro::videodrm;
|
|
26
|
+
using namespace facebook;
|
|
27
|
+
|
|
28
|
+
return facebook::jni::initialize(vm, [] {
|
|
29
|
+
// Register native JNI methods
|
|
30
|
+
margelo::nitro::videodrm::JHybridPluginManagerSpec::registerNatives();
|
|
31
|
+
|
|
32
|
+
// Register Nitro Hybrid Objects
|
|
33
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
34
|
+
"PluginManager",
|
|
35
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
36
|
+
static DefaultConstructableObject<JHybridPluginManagerSpec::javaobject> object("com/margelo/nitro/videodrm/PluginManager");
|
|
37
|
+
auto instance = object.create();
|
|
38
|
+
return instance->cthis()->shared();
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
} // namespace margelo::nitro::videodrm
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ReactNativeVideoDrmOnLoad.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include <jni.h>
|
|
9
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
10
|
+
|
|
11
|
+
namespace margelo::nitro::videodrm {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the native (C++) part of ReactNativeVideoDrm, and autolinks all Hybrid Objects.
|
|
15
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
|
|
16
|
+
* Example:
|
|
17
|
+
* ```cpp (cpp-adapter.cpp)
|
|
18
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
+
* return margelo::nitro::videodrm::initialize(vm);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
int initialize(JavaVM* vm);
|
|
24
|
+
|
|
25
|
+
} // namespace margelo::nitro::videodrm
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridPluginManagerSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "JHybridPluginManagerSpec.hpp"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro::videodrm {
|
|
15
|
+
|
|
16
|
+
jni::local_ref<JHybridPluginManagerSpec::jhybriddata> JHybridPluginManagerSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
17
|
+
return makeCxxInstance(jThis);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void JHybridPluginManagerSpec::registerNatives() {
|
|
21
|
+
registerHybrid({
|
|
22
|
+
makeNativeMethod("initHybrid", JHybridPluginManagerSpec::initHybrid),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
size_t JHybridPluginManagerSpec::getExternalMemorySize() noexcept {
|
|
27
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
28
|
+
return method(_javaPart);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void JHybridPluginManagerSpec::dispose() noexcept {
|
|
32
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
33
|
+
method(_javaPart);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Properties
|
|
37
|
+
bool JHybridPluginManagerSpec::getIsEnabled() {
|
|
38
|
+
static const auto method = javaClassStatic()->getMethod<jboolean()>("isEnabled");
|
|
39
|
+
auto __result = method(_javaPart);
|
|
40
|
+
return static_cast<bool>(__result);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Methods
|
|
44
|
+
void JHybridPluginManagerSpec::enable() {
|
|
45
|
+
static const auto method = javaClassStatic()->getMethod<void()>("enable");
|
|
46
|
+
method(_javaPart);
|
|
47
|
+
}
|
|
48
|
+
void JHybridPluginManagerSpec::disable() {
|
|
49
|
+
static const auto method = javaClassStatic()->getMethod<void()>("disable");
|
|
50
|
+
method(_javaPart);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
} // namespace margelo::nitro::videodrm
|