Skip to content

Commit

Permalink
move localSourceEncryptionKeyScheme into drm params
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMoch committed Sep 6, 2024
1 parent eb8be58 commit 51ff367
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ios/Video/DataStructures/DRMParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct DRMParams {
let contentId: String?
let certificateUrl: String?
let base64Certificate: Bool?
let localSourceEncryptionKeyScheme: String?

let json: NSDictionary?

Expand All @@ -17,6 +18,7 @@ struct DRMParams {
self.certificateUrl = nil
self.base64Certificate = nil
self.headers = nil
self.localSourceEncryptionKeyScheme = nil
return
}
self.json = json
Expand All @@ -36,5 +38,6 @@ struct DRMParams {
} else {
self.headers = nil
}
localSourceEncryptionKeyScheme = json["localSourceEncryptionKeyScheme"] as? String
}
}
2 changes: 1 addition & 1 deletion ios/Video/Features/DRMManager+Persitable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AVFoundation

extension DRMManager {
func handlePersistableKeyRequest(keyRequest: AVPersistableContentKeyRequest) async throws {
if let localSourceEncryptionKeyScheme {
if let localSourceEncryptionKeyScheme = drmParams?.localSourceEncryptionKeyScheme {
try handleEmbeddedKey(keyRequest: keyRequest, scheme: localSourceEncryptionKeyScheme)
} else {
// Offline DRM is not supported yet - if you need it please check out the following issue:
Expand Down
3 changes: 1 addition & 2 deletions ios/Video/Features/DRMManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DRMManager: NSObject {
let contentKeySession: AVContentKeySession

var drmParams: DRMParams?
var localSourceEncryptionKeyScheme: String?
var reactTag: NSNumber?
var onVideoError: RCTDirectEventBlock?
var onGetLicense: RCTDirectEventBlock?
Expand Down Expand Up @@ -47,7 +46,7 @@ class DRMManager: NSObject {
func handleContentKeyRequest(keyRequest: AVContentKeyRequest) {
Task {
do {
if localSourceEncryptionKeyScheme != nil {
if drmParams?.localSourceEncryptionKeyScheme != nil {
#if os(iOS)
try keyRequest.respondByRequestingPersistableContentKeyRequestAndReturnError()
return
Expand Down
8 changes: 1 addition & 7 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

private var _playerViewController: RCTVideoPlayerViewController?
private var _videoURL: NSURL?
private var _localSourceEncryptionKeyScheme: String?

/* Required to publish events */
private var _eventDispatcher: RCTEventDispatcher?
Expand Down Expand Up @@ -447,7 +446,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}
#endif

if source.drm != nil || _localSourceEncryptionKeyScheme != nil {
if source.drm != nil {
if _drmManager == nil {
_drmManager = DRMManager()
}
Expand Down Expand Up @@ -575,11 +574,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
DispatchQueue.global(qos: .default).async(execute: initializeSource)
}

@objc
func setLocalSourceEncryptionKeyScheme(_ keyScheme: String) {
_localSourceEncryptionKeyScheme = keyScheme
}

func playerItemPrepareText(asset: AVAsset!, assetOptions: NSDictionary?, uri: String) async -> AVPlayerItem {
if (self._textTracks == nil) || self._textTracks?.isEmpty == true || (uri.hasSuffix(".m3u8")) {
return await self.playerItemPropegateMetadata(AVPlayerItem(asset: asset))
Expand Down
7 changes: 6 additions & 1 deletion src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onTextTrackDataChanged,
onVideoTracks,
onAspectRatio,
localSourceEncryptionKeyScheme,
...rest
},
ref,
Expand Down Expand Up @@ -163,6 +164,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
);

const selectedDrm = source.drm || drm;

const _drm = !selectedDrm
? undefined
: {
Expand All @@ -174,6 +176,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
base64Certificate: selectedDrm.base64Certificate,
useExternalGetLicense: !!selectedDrm.getLicense,
multiDrm: selectedDrm.multiDrm,
localSourceEncryptionKeyScheme:
selectedDrm.localSourceEncryptionKeyScheme ||
localSourceEncryptionKeyScheme,
};

return {
Expand All @@ -193,7 +198,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
textTracksAllowChunklessPreparation:
resolvedSource.textTracksAllowChunklessPreparation,
};
}, [drm, source]);
}, [drm, localSourceEncryptionKeyScheme, source]);

const _selectedTextTrack = useMemo(() => {
if (!selectedTextTrack) {
Expand Down
2 changes: 1 addition & 1 deletion src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Drm = Readonly<{
base64Certificate?: boolean; // ios default: false
useExternalGetLicense?: boolean; // ios
multiDrm?: WithDefault<boolean, false>; // android
localSourceEncryptionKeyScheme?: string; // ios
}>;

type TextTracks = ReadonlyArray<
Expand Down Expand Up @@ -325,7 +326,6 @@ export interface VideoNativeProps extends ViewProps {
fullscreenOrientation?: WithDefault<string, 'all'>;
progressUpdateInterval?: Float;
restoreUserInterfaceForPIPStopCompletionHandler?: boolean;
localSourceEncryptionKeyScheme?: string;
debug?: DebugConfig;
showNotificationControls?: WithDefault<boolean, false>; // Android, iOS
bufferConfig?: BufferConfig; // Android
Expand Down
2 changes: 2 additions & 0 deletions src/types/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type Drm = Readonly<{
certificateUrl?: string; // ios
base64Certificate?: boolean; // ios default: false
multiDrm?: boolean; // android
localSourceEncryptionKeyScheme?: string; // ios
/* eslint-disable @typescript-eslint/no-unused-vars */
getLicense?: (
spcBase64: string,
Expand Down Expand Up @@ -283,6 +284,7 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
/** @deprecated */
useSecureView?: boolean; // Android
volume?: number;
/** @deprecated use **localSourceEncryptionKeyScheme** key in **drm** props instead */
localSourceEncryptionKeyScheme?: string;
debug?: DebugConfig;
allowsExternalPlayback?: boolean; // iOS
Expand Down

0 comments on commit 51ff367

Please sign in to comment.