Entitlement and DRM
What you learn​
You're instantiating DIVA Player in your web front-end and relying on DIVA Back Office as the video streaming source.
The goal of this article is to build the simplest front-end to stream a video from the DIVA Back Office with entitlement check and DRM.
Before starting​
- Ensure the DIVA Back Office instance you rely on is up and running.
- Ask your video engineers team the
<video id>
and<settings URL>
. - Ensure the settings file contains:
- The
entitlementCheck
section:Note: Consider"entitlementCheck": {
"entitlementUrl": "<yourEntitlementBaseURL>/tokenize",
"heartbeatUrl": "<yourEntitlementBaseURL>/heartbeat",
"heartbeatPollingInterval": 180000,
"heartbeatSeekInterval": 10000,
"other": "{<sessionId>}|{<platform>}",
"fairPlayCertificateUrl": "<yourFairPlayCertificateBaseURL>/fairplay.cer",
"queryParams": ["VideoSourceName", "VideoId", "VideoKind"],
"data": {
"sessionId": "{Run.SessionID}",
"platform": "webTV custom/Amidala",
"idfa": "{Run.idfa}",
"p.adsParams.paln":"{diva_pal_nonce}"
}
}other
deprecated and replaced bydata
. - The
videoPlatformsPriority
section:"videoPlatformsPriority": {
"default": [
{
"type": "DASH"
"sourceName": "Desktop-DASH",
"drmType": "playready"
},
{
"type": "DASH",
"sourceName": "Desktop-DASH",
"drmType": "widevine"
},
{
"type": "HLS",
"sourceName": "Desktop-V4",
"drmType": "fairplay"
}
],
"chromecast": [
{
"type": "DASH",
"sourceName": "Chromecast-DASH",
"drmType": "widevine"
}
]
}
- The
Instantiation​
DRM code​
There's no code to add to the Basic instantiation code.
Entitlement code​
Enrich the Basic instantiation code with the entitlement configuration:
entitlementUser
: It returns the token that entitles a video player user to stream a specific video.version
: If valued, the entitlement payload usesdata
, otherwiseother
— Note:other
is a legacy and deprecated field: usedata
entitlementPayloadMap
: Callback function that receives the entitlement payload as parameter and returns a Promise with the payload eventially modified.entitlementPayloadMap
can change the entitlement payload before DIVA Player sends it to the entitlement service.entitlementPayloadMap
input parameters are:type
: It can valuetoken
orheartbeat
token
: It indicates the entitlement initialization call.heartBeat
: It indicates the entitlement check call.
payload
: Created every time DIVA Player calls the entitlement service, ifversion
is valued, it usesdata
, otherwiseother
. E.g.:Note: If{
"Type": 1, // 1 = 'token', 2 = 'heartbeat'
"User": "<userID>", //user identifier
"VideoId": "<videoID>",
"VideoSource": "<video source>",
"VideoKind": "replay", //possible values depend on the video production
"AssetState": "3", //2 = 'live', 3 = 'VOD'
"PlayerType": "<player type>",
"VideoSourceFormat": "DASH",
"VideoSourceName": "Desktop-DASH",
"DRMType": "widevine",
"AuthType": "Token",
"ContentKeyData": "<content key data>",
"SessionId": "<sessionID>",
"PlaybackSessionId": "<PlaybackSessionId>",
"Other": "{\"<sessionId>\"}|{\"<platform>\"}",
"Data": "{\"sessionId\":\"<sessionID>\",\"platform\":\"webTV custom/Amidala\",\"idfa\":\"{Run.idfa}\",\"offsetFromLiveEdge\":\"0\",\"p.adsParams.paln\":\"{diva_pal_nonce}\"}",
"Version": "1"
}AssetState = "1"
there's something wrong: "1" means 'scheduled', which is a not yet existing video that DIVA Player cannot manage.
Entitlement code sample​
Write the entitlement configuration:
const token = "<entitlement token of the video player user>";
const entitlementPayloadMap: (entitlementType: 'token' | 'heartbeat', payload: any) => Promise<any> = (
entitlementType,
payload
) => {
// Modify the payload
payload.PlayerType = 'myPlayer'
return Promise.resolve(payload);
};
const entitlementConfiguration = {
entitlementUser: () => token,
entitlementPayloadMap: entitlementPayloadMap,
version: "1"
};
Finally, add the entitlementConfiguration
to the DIVA Player instantiation.
Working sample code (.tsx)​
import React from "react";
import { DivaWebBoAdapter } from "@deltatre-vxp/diva-sdk/diva-web-bo-adapter";
import "@deltatre-vxp/diva-sdk/diva-web-sdk/index.min.css";
const videoId = "<videoId";
const libs = {
mux: "https://cdnjs.cloudflare.com/ajax/libs/mux.js/6.2.0/mux.min.js",
shaka: "https://cdnjs.cloudflare.com/ajax/libs/shaka-player/4.11.2/shaka-player.compiled.js",
hlsJs: "https://cdn.jsdelivr.net/npm/hls.js@1.5.7",
googleIMA: false,
googleDAI: false,
googleCast: false,
threeJs: false
};
const config = {
videoId: videoId,
libs: libs,
};
const token = "<entitlement token of the video player user>";
const entitlementPayloadMap: (entitlementType: 'token' | 'heartbeat', payload: any) => Promise<any> = (
entitlementType,
payload
) => {
// Modify the payload
payload.PlayerType = 'myPlayer'
return Promise.resolve(payload);
};
const entitlementConfiguration = {
entitlementUser: () => token,
entitlementPayloadMap: entitlementPayloadMap,
version: "1"
};
const props = {
settingsUrl: "<Settings URL>",
languageCode: "en-US",
languageDictionary: "en-US",
onDivaBoAdapterError: console.error,
config: config,
entitlementConfiguration: entitlementConfiguration
function App() {
return (
<DivaWebBoAdapter
{
...props
}
/>
);
}
export default App;