Skip to main content
Skip table of contents

DAS Web Client Integration Guide

Prerequisites

Download the SDK, which provides all the files to integrate into your JavaScript applications.

  • dasc-sdk-js-5.3.x-production.zip

  • dasc-sdk-js-5.3.x-sample_application.zip

HTML page

Your web page needs to include <script> tags to reference the following items:

  • dasWebSDK.js included in the production.zip file

  • jquery-3.3.1.min.js from a suitable CDN location

It is no longer required to supplement the SDK with various other libraries that were provided in the production.zip file.  The necessary dependencies are wholly contained within the dasWebSDK.js file.

The example below also refers to dasWebClient JavaScript code which implements the demonstration application's calls to the various APIs.

XML
...
    <script src="dasWebSDK.js"></script>
    <script src="dasWebClient.es5.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
...

The demonstration application's JS code is transpiled to be ES 2015 compatible to ensure a wider range of devices can be supported.  Both the source code and its transpiled variant are available in the sample_application.zip file.
See the  DAS Web Client Demo Application for a more detailed explanation of the layout and workflow of the demo application.

Version API

The dasc.version API provides details of the product version and revision numbers.  For example:

JS
let versionString = "DAS Web Client v" + dasc.version.product + "." + dasc.version.revision;

TVKey Support

In an HbbTV environment with TVKey supported, the SDK can use the TVKey security features provided by the OS and hardware to authenticate, secure messages, and encrypt or decrypt data. The DAS Client SDK makes use of the TVKey security if the application provides a non-null Operator UUID using:

JS
setOperatorUUID(operatorUUID)
;

Detection of HbbTV and TVKey environment

The same application may be run on various devices, of which only a few can provide the necessary support. TV sets providing HbbTV support provide access to the OIPF framework through which the application can set TVKey operator parameters by sending a formatted DRM message.

The following code segment shows how to combine detection of the TVKey environment and setting up initial parameters.
JS
function setTvkeyOperatorParams() {
    const MSG_TYPE = "application/vnd.tvkey.cloud-json";
	const DRM_SYSTEM_ID = "urn:dvb:casystemid:19300";	
	const REPONSE_TYPE = "SetOperatorResponse";
	const ERROR_TYPE = "ErrorResponse";

	var SetOperatorParametersMsg = {
	    "type": "SetOperatorParameters",
		"OperatorCertificates": [
		    "AAAAK3H+8SujnOX2AP5RAAAAAAAAAAAAAAACEQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEZRtbg7m7zB0Aga/bl36NbNJF0Xh57rOuDGvTyJ+12Z/I/E8qR/TcBK19JK+yOYn94d2fgqgCqBFlPne5zRH+=",
            "AAAAK2rRUaueCCySAAAAAAAAAhEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEQAAAAAAAAIRAAACEYCXE+Svnwi1m2hCbraVocouDHbKs5JIlKSAEgqnRc7FTNEtAnlCEXGKC47SY9V4HYMLfQ0PL6+MfMDp4RZRg2EAAAAAAAAA="
		],
		"OperatorUUID": "a3e5335e-c3e0-41f8-b380-d85d55faea69",
		"OperatorName": "OpName",
		"BroadcastType": ["DVB-C"],
	    "OperatorProfile": 2
	}

	var messageId;
  
	return new Promise(function resolveSetOperatorParam(resolve,reject) {
	    function toHexString(str) {
		    var buf = [];
			for (var n = 0, l = str.length; l > n; n++) {
			    buf.push(Number(str.charCodeAt(n)).toString(16));
			}
		    return buf.join('');
		}
		  
		function fromHexString(hexStr) {
			var hex = hexStr.toString();
			var str = '';
			for (var n = 0;(n < hex.length && hex.substr(n, 2) !== '00'); n += 2) {
			    str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
			}
			return str;
		} 	

        function onOipfDrmMessageResult(msgID,hexResultMsg,resultCode) {
	        console.log("Get DRM Message result - msgID : " + msgID + " resultCode: " + resultCode);
	        if(msgID === messageId) {
			    if(resultCode === 0) {
				    //successful
				    try {
                        //the response message is an encoded HEX string
				        let resultMsg = fromHexString(hexResultMsg);
				        console.log("host response message: " + resultMsg);
                        var response = JSON.parse(resultMsg);
				        if(response.type === REPONSE_TYPE) {
					        if(response.Success) {
					            resolve(true);
	                        } else {
					            //failed
						        reject(JSON.stringify(response.Result));
					        }
				        } else if(response.type === ERROR_TYPE) {
					        console.error("Get errro response: " + resultMsg);
				            reject(resultMsg);
				        }
                    } catch (error) {
				        console.error("Parse JSon object failed: " + error.message);
			            reject(error);
			        }				
		        } else {
			        console.error("Get Drm error code: " + resultCode);
			        reject("resultCode: " + resultCode);
                }
	        }		  
        }
        let oipfDrmAgent = window.oipfObjectFactory.createDrmAgentObject();
        //Register callback
        oipfDrmAgent.onDRMMessageResult = onOipfDrmMessageResult;
        //Send activation request message to host.
        //the message is an encoded HEX string
        messageId = oipfDrmAgent.sendDRMMessage(MSG_TYPE,toHexString(JSON.stringify(SetOperatorParametersMsg)),DRM_SYSTEM_ID);
        console.log("setOperatorParameters message: " + JSON.stringify(SetOperatorParametersMsg));
    });
}
    
function checkTvkeyDrmEngine() {
    return new Promise((resolve , reject) => {
	    let config = [
		    {
			     initDataTypes: ["keyids", "cenc"],
				 videoCapabilities : [
				     { contentType: 'video/mp4;codecs="avc1.640028"' }
				 ]
			}
		];
		
		if (navigator.requestMediaKeySystemAccess !== undefined) {
		    navigator
			    .requestMediaKeySystemAccess("com.tvkey.drm", config)
			    .then(() => {
				    console.log("Instantiate tvkey system successfully.");
				    resolve();
			    })
			    .catch(() => {
				    console.error("Unable to Instantiate tvkey system.");
				    reject();
			    });
		} else {
		    reject();
	    }
    });
}

function checkTvkeyAndSetOperatorParameters() {
    checkTvkeyDrmEngine().then(setTvkeyOperatorParams)
	                       .then(() => {
                             console.log("set tvkey operator parameter successfully");
						    })
						    .catch(() => { console.log("The device does not support tvkey"); });
}

window.checkTvkeyAndSetOperatorParameters(); 

Adjust the code to match your parameters.

JavaScript errors detected

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

If this problem persists, please contact our support.