Dash-Industry-Forum / IOPv5

IOP v5 editing for tracking issues
1 stars 1 forks source link

Part 11: Query and token mechanism in dash.js - Action item from call 15-02-2022 #30

Open dsilhavy opened 2 years ago

dsilhavy commented 2 years ago

For the action item "Query and Token mechanism (from Daniel)" from the IOP call on 16.02.2022 please find a description below

dash.js allows applications to define callback functions to modify the URLs and the headers for all requests to the CDN and to the license server(s).  To modify the requests to the CDN the RequestModifier class of dash.js must be extended. A basic example can be found below:

/* Extend RequestModifier class and implement our own behaviour */
player.extend("RequestModifier", function () {
    return {
        modifyRequestHeader: function (xhr) {
            xhr.setRequestHeader('DASH-CUSTOM-HEADER', 'MyValue'); 
            return xhr;
        },
        modifyRequestURL: function (url) {
            return url + '?customQuery=value';
        }
    };
});

In this case, a custom header DASH-CUSTOM-HEADER with the value MyValue is added to all requests. In addition, a query parameter customQuery=value is appended to the request URL. The current implementation of the RequestModifier class is limited to synchronous functions, the modifyRequestHeader and the modifyRequestURL functions cannot be implemented asynchronously (i.e. are not allowed to return a promise).

Similar to the approach described above, the request to the DRM license server can be modified:

var filterLicenseRequest = function (request) {
    request.headers = {
        "X-AxDRM-Message":"somepayload"
    }
    return Promise.resolve();
}

player.registerLicenseRequestFilter(filterLicenseRequest);

In this example, a new header X-AxDRM-Message is added to the license request. In contrast to the RequestModifier implementation, the function to modify license requests must be implemented asynchronously (i.e. must return a promise)

Complete examples can be found here: