Skip to main content
Skip table of contents

Callback mode

The React Native Player handles license management internally within the code to support multi-DRM through SSP. In certain setups, you might want to manage content licenses through your own mechanisms to generate a licence and share it with the React Native player to play an encrypted content item. You can achieve this by creating your implementation for license fetching in the form of a JS promise and providing it to the CONNECT Player SDK.

Callback mode is currently only available for Web Browsers and browser-based platforms such as Connected TVs.

Example code

The following describes how to prepare your own implementation of a callback promise and provide it to the player. Four examples are provided - one for each DRM system, essentially having the same functionality. Their names are self-explanatory:

  • CallbackModeFairPlay.tsx
  • CallbackModePlayReady.tsx
  • CallbackModeTVKey.tsx
  • CallbackModeWidevine.tsx

These examples provide the typical implementation of callback mode for an SSP licence server.

If you try and run the callback mode examples on an LG TV 2020 (WebOS 5.0) or an older model, playback may not start upon zapping - you may need to first perform a seek to instigate playback.

The React Native player provides a callback property: onLicenseRequest(keySystem:String, source:Object, requestPayload:ArrayBurrer, licenseRequestType:String) . If the application sets this, it will be called whenever the player wants the application to provide any of the following:

  • License data
  • Certificate data
  • Renewed license data

The App should return a promise from this callback. Once the promise is fulfilled, the data provided should be an ArrayBuffer of the reply from the license server.

  • If the promise is rejected, playback will fail and an onError event will be triggered.
  • The player will discard the last promise if a channel/content change is requested before fulfilling or rejecting a promise.

Apps should make sure not to accept/reject promises made for the previous content (if a new request was made).

See the API documentation regarding the parameters passed in the callback.

Using the CallbackModeWidevine example as a reference, define and implement the licence-fetching promise returned by the getWidevineLicense() method of type OnLicenseRequest :

Click here to see the example code.
JS
  const getWidevineLicense: OnLicenseRequest = (keySystem, shakaSource, requestPayload, messageType) => {
    const { licenseURL, token, certificateURL } = content.license;
    let headers = {
      Accept: "application/octet-stream",
      "Content-Type": "application/octet-stream"
    };
    let reqUrl = messageType === 'certificate-request' ? certificateURL : licenseURL;
    return new Promise(function resolver(resolve, reject) {

      let xhr = new XMLHttpRequest();
      xhr.open("POST", reqUrl, true);
      xhr.responseType = "arraybuffer";
      for (let key in headers) {
        if (headers.hasOwnProperty(key)) {
          xhr.setRequestHeader(key, headers[key]);
        }
      }

      xhr.onload = function onload() {
        if (xhr.status === 200) {
          try {
            resolve(new Uint8Array(xhr.response));
          } catch (err) {
            reject("Invalid widevine License:" + err);
          }
        } else {
          reject("Failed to receive license, HTTP status:" + xhr.status);
        }
      };

      xhr.onerror = function onerror(err) {
        reject("Error on license request");
      };
      const tokenKey = "nv-authorizations";
      xhr.setRequestHeader(tokenKey, token);
      xhr.send(requestPayload);
    });
  };

The promise returned by this method will return a byte array (Uint8Array) of the response from the SSP license server if successful ( resolve ), or an error string if the request failed ( reject ). The getWidevineLicense function is then passed as the onLicenseRequest callback property during the OTVPlayer object's construction.

Mixed mode

To change between callback and non-callback mode, the App has to unmount and remount OTVPlayer.

  • If OTVPlayer is mounted with the property onLicenseRequest (callback mode), to ignore the license request, OTVPlayer has to be unmounted and remounted with no onLicenseRequest (non-callback mode).
  • Alternatively, if OTVPlayer is mounted with no onLicenseRequest (non-callback mode), to handle the license request, OTVPlayer has to be unmounted and remounted with onLicenseRequest (callback mode).

If OTVPlayer is not unmounted while changing between callback and non-callback mode, the error 7025 will be thrown indicating mixed mode error.

Click here to see the example code.
JS
  return (
       ...
       <OTVPlayer
        ref={otvplayerInstance}
        source={content.source}
        progressUpdateInterval={1}
        autoplay={true}
        muted={muted}
        volume={volume}
        onLoad={(event: OnLoadParam) => {
          setMessage("onLoad received");
        }}

        ...

        onLicenseRequest={getWidevineLicense}

        ...

       />

      ...
  );
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.