DRMAgent Class

DRMAgent is a class provided for the webOSDev API.

Methods

TypeNameDescription
ConstructorDRMAgentCreates a DRM agent.
MethodgetClientIdReturns a client ID of DRM.
getDrmTypeReturns a DRM type to be set.
getErrorCodeReturns an error code from the DRM service.
getErrorTextReturns a text represented by an error from the DRM service.
getRightsErrorReturns error information when an error of the DRM license occurs during content playback.
loadCreates a client instance for a given type of DRM.
isLoadedChecks whether a DRM client that corresponds to given application ID exists.
sendDrmMessageSends a DRM message to a DRM service.
unloadRemoves a DRM client instance and deallocates relevant resources.

DRMAgent

Description

Create a DRM agent.

Properties

NameTypeDescription
typeStringThe type of DRM.
  • PLAYREADY: PlayReady

getClientId

Description

Returns a client ID of DRM.

Parameters

None​

Example

function loadPlayer() {
  var player = document.querySelector('video');
  var options = {
    mediaTransportType: 'PLAYREADY',
    option: {
      drm: {
        type: drmAgent.getDrmType(),
        clientId: drmAgent.getClientId(),
      },
    },
  };
  var mediaOption = encodeURI(JSON.stringify(options));
  var source = document.createElement('source');
  source.setAttribute('src', CONTENT_URL);
  source.setAttribute('type', 'video/mp4;mediaOption=' + mediaOption);
  player.appendChild(source);
  player.load();
}

See also

  • None

getDrmType

Description

Returns a DRM type to be set.

Parameters

None

Call returns

NameTypeDescription
typeStringThe DRM type.
  • PLAYREADY: PlayReady

Example

function loadPlayer() {
  var player = document.querySelector('video');
  var options = {
    mediaTransportType: 'PLAYREADY',
    option: {
      drm: {
        type: drmAgent.getDrmType(),
        clientId: drmAgent.getClientId(),
      },
    },
  };
  var mediaOption = encodeURI(JSON.stringify(options));
  var source = document.createElement('source');
  source.setAttribute('src', CONTENT_URL);
  source.setAttribute('type', 'video/mp4;mediaOption=' + mediaOption);
  player.appendChild(source);
  player.load();
}

See also

  • None

getErrorCode

Description

Returns an error code from the DRM service.

Parameters

None

Call returns

Returns the error code.

Example

drmAgent.load({
  onSuccess: function (res) {
    sendDrmMessage();
  },
  onFailure: function (res) {
    // API calling error
    console.log('error -', res.errorCode, '/', res.errorText);
    // or but it does not guarantee sync
    console.log(
      'error -',
      drmAgent.getErrorCode(),
      '/',
      drmAgent.getErrorText()
    );
  },
});

See also

getErrorText

Description

Returns a text represented by an error from the DRM service.

Parameters

None

Call returns

Returns the error text from the DRM service.

Example

drmAgent.load({
  onSuccess: function (res) {
    sendDrmMessage();
  },
  onFailure: function (res) {
    // API calling error
    console.log('error -', res.errorCode, '/', res.errorText);
    // or but it does not guarantee sync
    console.log(
      'error -',
      drmAgent.getErrorCode(),
      '/',
      drmAgent.getErrorText()
    );
  },
});

See also

getRightsError

Description

Returns error information when an error of the DRM license occurs during content playback.
This method is supported in the following DRM type only:

  • PlayReady

Parameters

NameTypeDescriptionRequired
paramsObjectThe JSON object containing handlers

Properties

NameTypeDescriptionRequired
onSuccessFunctionThe callback function called when the method succeeds.Yes
onFailureFunctionThe callback function called when the method fails.Yes
Yes

Success Callback Returns

NameTypeDescriptionRequired
returnValueBooleanFlag that indicates success/failure of the request.
  • true: Success
  • false: Failure
Yes
subscribedBooleanFlag that indicates whether the subscription is enabled or not.
  • true: Enabled
  • false: Not enabled
Yes
errorCodeNumbererrorCode contains the error code if the method fails. The method will return errorCode only if it fails.
See the Error Codes Reference of this method for more details.
No
errorTextStringerrorText contains the error text if the method fails. The method will return errorText only if it fails.
See the Error Codes Reference of this method for more details.
No

Failure Callback Returns

NameTypeDescription
errorObjectThe JSON Object containing DRM service's error details.
Properties
NameTypeDescription
errorCodeNumberThe error code returned when the method fails.
errorTextStringThe error text returned when the method fails.

Call returns

Returns undefined.

Example

function getRightsError() {
  drmAgent.getRightsError({
    onSuccess: function (res) {
      // playready only
      // handle error
    },
    onFailure: function (res) {
      // API calling error
    },
  });
}

See also

  • None

isLoaded

Description

Checks whether a DRM client that corresponds to given application ID exists.

Parameters

NameTypeDescriptionRequired
paramsObjectJSON object containing handlers.
Properties
NameTypeDescription
onSuccessFunctionThe callback function called when the method succeeds.
onFailureFunctionThe callback function called when the method fails.
Yes

Success Callback Returns

NameTypeDescription
responseObjectJSON Object containing DRM service's error details.
Properties
NameTypeDescription
loadStatusBooleanIndicates the DRM client is loaded.
  • true: the DRM client is loaded.
  • false: the DRM client is not loaded.
clientIdStringReturns the loaded client ID when the DRM client is loaded successfully.
drmTypeStringReturns the client type of DRM when the DRM client is loaded successfully.

Failure Callback Returns

NameTypeDescription
errorObjectJSON Object containing DRM service's error details.
Properties
NameTypeDescription
errorCodeNumberThe error code returned when the method fails.
errorTextStringThe error text returned when the method fails.

Example

function isDrmLoaded() {
  drmAgent.isLoaded({
    onSuccess: function (res) {
      if (res.loadStatus === true) {
        loadDrm();
      } else {
        sendDrmMessage();
      }
    },
    onFailure: function (res) {
      // API calling error
    },
  });
}

See also

load

Description

Creates a client instance for a certain type of DRM.
The DRM type is specified when a DRM agent is created.

Parameters

NameTypeDescriptionRequired
paramsObjectThe JSON object containing handlers.
Properties
NameTypeDescription
onSuccessFunctionThe callback function called when the method succeeds.
onFailureFunctionThe callback function called when the method fails.
Yes

Success Callback Returns (loadCallback)

NameTypeDescription
responseObjectThe JSON object of return value.
Properties
NameTypeDescription
clientIdStringIf the DRM agent loaded the DRM client successfully, return its client ID.

Failure Callback Returns (failureCallback)

NameTypeDescription
errorObjectJSON Object containing DRM service's error details.
Properties
NameTypeDescription
errorCodeNumberThe error code returned when the method fails.
errorTextStringThe error text returned when the method fails.

Call returns

Returns undefined.

Example

function loadDrm() {
  drmAgent.load({
    onSuccess: function (res) {
      sendDrmMessage();
    },
    onFailure: function (res) {
      // API calling error
    },
  });
}

See also

sendDrmMessage

Description

Sends a DRM message to a DRM service.
After receiving the message, the DRM service starts to parse the message and perform the DRM operation.

Parameters

NameTypeDescriptionRequired
paramsObjectJSON object containing handlers.
Properties
NameTypeDescription
msgStringThe message to be provided to the underlying DRM server, which is formatted according to the DRM type.
onSuccessFunctionThe callback function called when the method succeeds.
onFailureFunctionThe callback function called when the method fails.
No

Success Callback Returns (sendDrmMessageCallback)

NameTypeDescription
responseObjectThe JSON Object of result after sending messages.
Properties
NameTypeAttributesDescription
msgIdString<optional>The unique ID of message which has led to this resulting message.
resultCodeNumber<optional>The result code only for PlayReady.
resultMsgString<optional>The DRM system specific result message only for PlayReady.

Failure Callback Returns (failureCallback)

NameTypeDescription
errorObjectThe JSON Object containing DRM service's error details.
Properties
NameTypeDescription
errorCodeNumberThe error code returned when the method fails.
errorTextStringThe error text returned when the method fails.

Example

function sendDrmMessage() {
  drmAgent.sendDrmMessage({
    msg: 'some messages',
    onSuccess: function (res) {
      loadPlayer();
    },
    onFailure: function (res) {
      // API calling error
    },
  });
}

See also

  • None

unload

Description

Removes a DRM client instance and deallocates relevant resources.

Parameters

NameTypeDescriptionRequired
paramsObjectThe JSON object containing handlers.
Properties
NameTypeDescription
onSuccessFunctionThe callback function called when the method succeeds.
onFailureFunctionThe callback function called when the method fails.
Yes

Success Callback Returns (unloadCallback)

NameTypeDescription
responseObjectEmpty JSON Object

Failure Callback Returns (failureCallback)

NameTypeDescription
errorObjectThe JSON Object containing DRM service's error details.
Properties
NameTypeDescription
errorCodeNumberThe error code returned when the method fails.
errorTextStringThe error text returned when the method fails.

Call returns

Returns undefined.

Example

function unloadDrm() {
  drmAgent.unload({
    onSuccess: function (res) {
      // do something
    },
    onFailure: function (res) {
      // API calling error
    },
  });
}

See also

Error code reference

NameTypeDescription
NOT_ERRORNumberNo error.
CLIENT_NOT_LOADEDNumberThe DRM client is not loaded.
VENDOR_ERRORNumberThe vendor managed error.
API_NOT_SUPPORTEDNumberThis API is not supported in the activated DRM.
WRONG_CLIENT_IDNumberThere is no process matching to the client ID.
KEY_NOT_FOUNDNumberIt cannot find a key file in DRM store.
INVALID_PARAMSNumberA part of parameters is not valid data or format.
UNSUPPORTED_DRM_TYPENumberIt's not a supported DRM type.
INVALID_KEY_FORMATNumberThe key file is not a valid format.
INVALID_TIME_INFONumberIt cannot get the valid time information.
DRM_TYPE_UNMATCHEDNumberThe DRM type of the currently loaded client is not matched with the DRM type that was set when the DRM agent is created.
UNKNOWN_ERRORNumberIt's an unknown error.
No Headings