Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iOS): rewrite DRM Module #4136

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

KrzysztofMoch
Copy link
Collaborator

@KrzysztofMoch KrzysztofMoch commented Sep 2, 2024

Summary

I have re-implemented DRM module for Apple devices. New Implementation use AVContentKeySession instead of resource loader.

fixes #4177 #3675 #3467

Motivation

Motivation is to fix issue with DRM Airplay and add visionOS support (in old implementation it was not possible)

Test plan

  • I have test app with Fairplay stream (which unfortunately I cannot share)
  • Also to play DRM content you need to have real device, simulator will not work

Tested on

  • iOS is tested by me
  • tvOS is not tested and I don't have real device to do it
  • visionOS is not tested and I don't have real device to do it

@KrzysztofMoch KrzysztofMoch changed the title [WIP] feat(iOS): rewrite DRM Module feat(iOS): rewrite DRM Module Sep 4, 2024
@KrzysztofMoch KrzysztofMoch marked this pull request as ready for review September 4, 2024 15:58
@KrzysztofMoch
Copy link
Collaborator Author

@freeboub should I add someone else to reviewers ?

@freeboub
Copy link
Collaborator

freeboub commented Sep 4, 2024

Maybe @paul-rinaldi or @paulrinaldi would like to test this version ? I can review but not test on my side ...

@freeboub
Copy link
Collaborator

freeboub commented Sep 4, 2024

I added some small comments, but it looks like good job 👍
If you are looking for other testers, you can try to ping last issue openers which are linked to DRM on ios. they may have a look to the PR or test it !

@paul-rinaldi
Copy link
Contributor

I added some small comments, but it looks like good job 👍
If you are looking for other testers, you can try to ping last issue openers which are linked to DRM on ios. they may have a look to the PR or test it !

I don't have a tv with iOS on it or vision OS. I have physical iPhones and physical iPads I could test with if you would like me to but it sounds like the PR creator already did that.

Sorry I could not be more helpful.

@freeboub
Copy link
Collaborator

freeboub commented Sep 4, 2024

I added some small comments, but it looks like good job 👍
If you are looking for other testers, you can try to ping last issue openers which are linked to DRM on ios. they may have a look to the PR or test it !

I don't have a tv with iOS on it or vision OS. I have physical iPhones and physical iPads I could test with if you would like me to but it sounds like the PR creator already did that.

Sorry I could not be more helpful.

My proposal was linked to your message on discord in fact !

@rohankm
Copy link

rohankm commented Sep 6, 2024

I added some small comments, but it looks like good job 👍
If you are looking for other testers, you can try to ping last issue openers which are linked to DRM on ios. they may have a look to the PR or test it !

I have tested it and it works fine also it solved buffering issues in drm videos.

src/Video.tsx Show resolved Hide resolved
@freeboub
Copy link
Collaborator

freeboub commented Sep 6, 2024

Looks good to me. Please build a release after merging this PR :)

@KrzysztofMoch
Copy link
Collaborator Author

Sure I will give this PR to tests for our client and after it will do it! Thanks!

@rohankm
Copy link

rohankm commented Sep 18, 2024

Waiting for the merge

ios/Video/RCTVideo.swift Outdated Show resolved Hide resolved
@freeboub freeboub self-requested a review September 18, 2024 14:35
Comment on lines 461 to 460
if source.drm != nil || _localSourceEncryptionKeyScheme != nil {
_resouceLoaderDelegate = RCTResourceLoaderDelegate(
if source.drm?.type != nil {
Copy link
Collaborator Author

@KrzysztofMoch KrzysztofMoch Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freeboub source.drm is never nil is structure with nils even if we don't pass anything are you okay with checking drm.type ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand, you want to change
let drm: DRMParams?
by
let drm: DRMParams

And check only type ?
if that's the case, I agree !

Something like this patch:

diff --git a/ios/Video/DataStructures/VideoSource.swift b/ios/Video/DataStructures/VideoSource.swift
index e672929f..45e5b2d3 100644
--- a/ios/Video/DataStructures/VideoSource.swift
+++ b/ios/Video/DataStructures/VideoSource.swift
@@ -10,7 +10,7 @@ struct VideoSource {
     let cropEnd: Int64?
     let customMetadata: CustomMetadata?
     /* DRM */
-    let drm: DRMParams?
+    let drm: DRMParams
     var textTracks: [TextTrack] = []
 
     let json: NSDictionary?
@@ -28,7 +28,7 @@ struct VideoSource {
             self.cropStart = nil
             self.cropEnd = nil
             self.customMetadata = nil
-            self.drm = nil
+            self.drm = DRMParams(nil)
             return
         }
         self.json = json
diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift
index 908e3eb8..64130675 100644
--- a/ios/Video/RCTVideo.swift
+++ b/ios/Video/RCTVideo.swift
@@ -421,7 +421,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
                 "type": _source?.type ?? NSNull(),
                 "isNetwork": NSNumber(value: _source?.isNetwork ?? false),
             ],
-            "drm": source.drm?.json ?? NSNull(),
+            "drm": source.drm.json ?? NSNull(),
             "target": reactTag as Any,
         ])

Copy link
Collaborator Author

@KrzysztofMoch KrzysztofMoch Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant:
in current impl source.drm is never null it will be always struct with some values (if drm is not setted but user all values will be just null). But now as I think I can aloso check if source.drm.json != nil bcs if json is null it means that users notting passed to it

case .unsupportedDRMType:
return NSLocalizedString("Verifiy that you are using fairplay (on Apple devices)", comment: "")
case .simulatorDRMNotSuported:
return NSLocalizedString("You need to test DRM conent on real device", comment: "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofMoch there is a typo in "content"

@maksymhcode-care
Copy link

Is this ready to be merged?

@@ -1329,11 +1326,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

func setLicenseResult(_ license: String!, _ licenseUrl: String!) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofMoch I am reviewing use of String! and it is a bad practice and can lead to some issues, see: #4181

It is just hide the warning, so no need to test the value ...
I think it would be better to change like I propose (not sure of the consequences inside _drmManager)

Suggested change
func setLicenseResult(_ license: String!, _ licenseUrl: String!) {
func setLicenseResult(_ license: String?, _ licenseUrl: String?) {

@@ -1329,11 +1326,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

func setLicenseResult(_ license: String!, _ licenseUrl: String!) {
_resouceLoaderDelegate?.setLicenseResult(license, licenseUrl)
_drmManager?.setJSLicenseResult(license: license, licenseUrl: licenseUrl)
}

func setLicenseResultError(_ error: String!, _ licenseUrl: String!) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

Suggested change
func setLicenseResultError(_ error: String!, _ licenseUrl: String!) {
func setLicenseResultError(_ error: String?, _ licenseUrl: String?) {

case .offlineDRMNotSuported:
return NSLocalizedString("You tried to use Offline DRM but it is not supported yet", comment: "")
case .unsupportedDRMType:
return NSLocalizedString("You tried to use unsupporeted DRM type", comment: "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KrzysztofMoch there is a typo in "unsupported"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: IOS DRM Custom License Request Not Working
6 participants