DRMAgent Class

DRMAgent is a class provided for the webOSDev API.

Methods

TypeNameDescription
Constructor
Creates a DRM agent.
Method
Returns the client ID.
Returns the DRM type that is set.
Returns the error code from the DRM service.
Returns the error text from the DRM service.
Returns error information when a DRM licensing error occurs during content playback.
Creates a client instance for a given type of DRM.
Checks whether a DRM client that corresponds to the given application ID exists.
Sends a DRM message to the DRM service.
Removes a DRM client instance and deallocates relevant resources.

DRMAgent

Description

Creates a DRM agent.

Properties

NameTypeDescription
type
String
The type of DRM.
  • PLAYREADY: PlayReady

getClientId

Description

Returns the 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 the DRM type to be set.

Parameters

None

Call returns

NameTypeDescription
type
String
The 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);
    // but it does not guarantee synchronization.
    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);
    // but it does not guarantee synchronization.
    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
params
Object
The JSON object containing handlers
Properties
NameTypeDescriptionRequired
onSuccess
Function
The callback function called when the method succeeds.
Yes
onFailure
Function
The callback function called when the method fails.
Yes
Yes

Success callback returns

NameTypeDescriptionRequired
returnValue
Boolean
Flag that indicates success/failure of the request.
  • true: Success
  • false: Failure
Yes
subscribed
Boolean
Flag that indicates whether the subscription is enabled or not.
  • true: Enabled
  • false: Not enabled
Yes
errorCode
Number
`errorCode` contains the error code if the method fails. The method returns `errorCode` only if it fails.
See the
Error code reference of this method for more details.
No
errorText
String
`errorText` contains the error text if the method fails. The method returns `errorText` only if it fails.
See the
Error code reference of this method for more details.
No

Failure callback returns

NameTypeDescription
error
Object
The JSON object containing DRM client status.
Properties
NameTypeDescription
errorCode
Number
The error code returned when the method fails.
errorText
String
The 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 the given application ID exists.

Parameters

NameTypeDescriptionRequired
params
Object
The JSON object containing handlers.
Properties
NameTypeDescription
onSuccess
Function
The callback function called when the method succeeds.
onFailure
Function
The callback function called when the method fails.
Yes

Success callback returns

NameTypeDescription
response
Object
The JSON object containing DRM client status.
Properties
NameTypeDescription
loadStatus
Boolean
Indicates whether the DRM client is loaded.
  • true: The DRM client is loaded.
  • false: The DRM client is not loaded.
clientId
String
Returns the loaded client ID when the DRM client is loaded successfully.
drmType
String
Returns the client type of DRM when the DRM client is loaded successfully.

Failure callback returns

NameTypeDescription
error
Object
The JSON object containing DRM client status.
Properties
NameTypeDescription
errorCode
Number
The error code returned when the method fails.
errorText
String
The error text returned when the method fails.

Example

function isDrmLoaded() {
  drmAgent.isLoaded({
    onSuccess: function (res) {
      if (res.loadStatus === true) {
        sendDrmMessage(); // DRM already loaded
      } else {
        loadDrm(); // Load DRM first
      }
    },
    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
params
Object
The JSON object containing handlers.
Properties
NameTypeDescription
onSuccess
Function
The callback function called when the method succeeds.
onFailure
Function
The callback function called when the method fails.
Yes

Success callback returns (loadCallback)

NameTypeDescription
response
Object
The JSON object that contains the return value.
Properties
NameTypeDescription
clientId
String
If the DRM agent loaded the DRM client successfully, it returns its client ID.

Failure callback returns (failureCallback)

NameTypeDescription
error
Object
The JSON object containing DRM client status.
Properties
NameTypeDescription
errorCode
Number
The error code returned when the method fails.
errorText
String
The 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 the DRM service. After receiving the message, the DRM service starts to parse the message and perform the DRM operation.

Parameters

NameTypeDescriptionRequired
params
Object
The JSON object containing handlers.
Properties
NameTypeDescription
msg
String
The message to be provided to the underlying DRM server, which is formatted according to the DRM type.
onSuccess
Function
The callback function called when the method succeeds.
onFailure
Function
The callback function called when the method fails.
No

Success callback returns (sendDrmMessageCallback)

NameTypeDescription
response
Object
The JSON object of the result after sending messages.
Properties
NameTypeDescription
msgId
String
The unique ID of the message that led to this resulting message.
resultCode
Number
The result code, applicable only to PlayReady.
resultMsg
String
The DRM system-specific result message, applicable only to PlayReady.

Failure callback returns (failureCallback)

NameTypeDescription
error
Object
The JSON object containing DRM client status.
Properties
NameTypeDescription
errorCode
Number
The error code returned when the method fails.
errorText
String
The 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
params
Object
The JSON object containing handlers.
Properties
NameTypeDescription
onSuccess
Function
The callback function called when the method succeeds.
onFailure
Function
The callback function called when the method fails.
Yes

Success callback returns (unloadCallback)

Name

Type

Description

response

Object

Empty JSON object

Failure callback returns (failureCallback)

NameTypeDescription
error
Object
The JSON object containing DRM client status.
Properties
NameTypeDescription
errorCode
Number
The error code returned when the method fails.
errorText
String
The 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

Name

Type

Description

NOT_ERROR

Number

No error.

CLIENT_NOT_LOADED

Number

The DRM client is not loaded.

VENDOR_ERROR

Number

The vendor managed error.

API_NOT_SUPPORTED

Number

This API is not supported in the activated DRM.

WRONG_CLIENT_ID

Number

There is no process matching to the client ID.

KEY_NOT_FOUND

Number

It cannot find a key file in DRM store.

INVALID_PARAMS

Number

A part of parameters is not valid data or format.

UNSUPPORTED_DRM_TYPE

Number

It's not a supported DRM type.

INVALID_KEY_FORMAT

Number

The key file is not a valid format.

INVALID_TIME_INFO

Number

It cannot get the valid time information.

DRM_TYPE_UNMATCHED

Number

The DRM type of the currently loaded client is not matched with the DRM type that was set when the DRM agent is created.

UNKNOWN_ERROR

Number

It's an unknown error.

No Headings