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

DRM protected content only plays when in remote debugjs mode #1921

Closed
sanjeevghimire opened this issue Feb 20, 2020 · 7 comments
Closed

DRM protected content only plays when in remote debugjs mode #1921

sanjeevghimire opened this issue Feb 20, 2020 · 7 comments
Labels
stale Closed due to inactivity or lack or resources

Comments

@sanjeevghimire
Copy link

sanjeevghimire commented Feb 20, 2020

I have a video streaming app and plays DRM protected content. The video only plays when i debug mode only. If I turn off the debug mode the video doesn't play and displays, video not available.

Which player are you experiencing the problem on:

  • iOS
@EyMaddis
Copy link

EyMaddis commented Feb 20, 2020

If you override the getLicense() method, the spc variable is not available outside of debugging mode (because of a bug).
Use the third parameter for a base64 representation.

@sanjeevghimire
Copy link
Author

@EyMaddis I tried adding the third parameter also and its not playing. Is there a sample I can look into?

@EyMaddis
Copy link

EyMaddis commented Feb 21, 2020

Unfortunately not, I also do not use this right now. I was just trying to implement my DRM service (Axinom) and was hacking around with manually decoding the base64 (third parameter). However, for me the fix was to avoid getLicense and only set the header 'Content-Type': 'application/octet-stream'.

Maybe you can post your getLicense and I can take a look.

Edit: Check if your getLicense code is used at all. See here: https://github.com/react-native-community/react-native-video/pull/1445/files#diff-2a97390647ad4fd466bccc2c92e7864eR236

Related Issue: #1445

Another edit:
I found my next-level hackery license code that is unnecessary since the header solved all of this.
Maybe this can help you, however I patched react-native video on the line I linked above:

getLicense: async (
          spc: string,
          contentId: string,
          spcBase64: string
        ) => {
          try {
            console.warn('sending license request!', spcBase64)
            const blob = Buffer.from(spcBase64, 'base64')
            // const blob = Buffer.from(spcString, 'ascii')
            console.warn('sending license request!', blob)
            const license = await fetch(fairplay.licenseUrl, {
              method: 'POST',
              headers: {
                'Content-Type': 'application/octet-stream',
              },
              body: blob,
            })
              .then(response => {
                console.warn('got license as blob!')
                return response.blob()
              })
              .then(response => {
                // React Native does not properly handle
                console.warn('blob2base64')
                return new Promise((resolve, reject) => {
                  const reader = new FileReader()
                  reader.onload = () => {
                    const dataURL = reader.result
                    console.warn('Got DATA URL!')
                    resolve(
                      // @ts-ignore
                      dataURL.replace(
                        'data:application/octet-stream;base64,',
                        ''
                      )
                    )
                  }
                  reader.onerror = err => {
                    reject(new Error('could not turn '))
                  }
                  reader.readAsDataURL(response)
                })
              })
              .catch(error => {
                console.error('Fairplay error', error)
              })
            return license
          } catch (e) {
            console.error('could not get license', e)
          }
        },```

@sanjeevghimire
Copy link
Author

@EyMaddis

This is based on the approved PR: feature/ios-drm-support

getLicense: ({ spc, contentId, spcBase64 }, props) => {
              console.log("spc", spc);
              console.log("spcBase64", spcBase64);
              return fetch("https://fp-keyos.licensekeyserver.com/getkey/", {
                method: "POST",
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded",
                  customdata: xml
                },
                body: `spc=${spcBase64}&assetId=${contentId}`
              }).then(r => r.text());
            }

@EyMaddis
Copy link

Then go into your node_modules folder, and find this line:
https://github.com/react-native-community/react-native-video/pull/1445/files#diff-2a97390647ad4fd466bccc2c92e7864eR236

Then change it to if (data), restart the bundler and try again. Xcode should now log something for spcBase64 in the xcode console.

@sanjeevghimire
Copy link
Author

yep that fixed it. thanks @EyMaddis

@EyMaddis
Copy link

Please close this ticket and maybe offer your support on the other PR, if possible :)

@hueniverse hueniverse added the stale Closed due to inactivity or lack or resources label Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Closed due to inactivity or lack or resources
Projects
None yet
Development

No branches or pull requests

3 participants