DRMAgent Class
DRMAgent is a class provided for the webOSDev API.
Methods
| Type | Name | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
type | String | The type of DRM.
|
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
| Name | Type | Description |
|---|---|---|
type | String | The DRM type.
|
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
| Name | Type | Description | Required | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | The JSON object containing handlers Properties
| Yes |
Success callback returns
| Name | Type | Description | Required |
|---|---|---|---|
returnValue | Boolean | Flag that indicates success/failure of the request.
| Yes |
subscribed | Boolean | Flag that indicates whether the subscription is enabled or not.
| 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
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
error | Object | The JSON object containing DRM client status. Properties
|
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
| Name | Type | Description | Required | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | The JSON object containing handlers. Properties
| Yes |
Success callback returns
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
response | Object | The JSON object containing DRM client status. Properties
|
Failure callback returns
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
error | Object | The JSON object containing DRM client status. Properties
|
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
| Name | Type | Description | Required | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | The JSON object containing handlers. Properties
| Yes |
Success callback returns (loadCallback)
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
response | Object | The JSON object that contains the return value. Properties
|
Failure callback returns (failureCallback)
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
error | Object | The JSON object containing DRM client status. Properties
|
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
| Name | Type | Description | Required | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | The JSON object containing handlers. Properties
| No |
Success callback returns (sendDrmMessageCallback)
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
response | Object | The JSON object of the result after sending messages. Properties
|
Failure callback returns (failureCallback)
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
error | Object | The JSON object containing DRM client status. Properties
|
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
| Name | Type | Description | Required | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | The JSON object containing handlers. Properties
| Yes |
Success callback returns (unloadCallback)
Name | Type | Description |
|---|---|---|
response | Object | Empty JSON object |
Failure callback returns (failureCallback)
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
error | Object | The JSON object containing DRM client status. Properties
|
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. |