define('application/models/production/streams/base', [
'rofl/models/api/abstract',
'rofl/lib/utils',
'antie/runtimecontext',
'application/helpers/playerproperties'
], function (
Abstract,
Utils,
RuntimeContext,
PlayerProperties
) {
'use strict';
var device = RuntimeContext.getDevice(),
PROFILES = {
DASH: 'M21',
SMOOTH: 'S22'
},
webkitBrowserUrl = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
baseUrl = '101/1.2.0/A/nld/smarttv/kpn/CONTENT/VIDEOURL',
Base = Abstract.extend({
/**
* Resolves the endpoint.
*
* @returns {string} - The endpoint url.
*/
resolveEndpoint: function () {
if (!this._queries) {
this._queries = {};
}
this._queries.deviceId = device.getUdid();
this._queries.profile = this._profile || PROFILES.DASH;
return Utils.addToQueryStringOfURL(baseUrl + this._endpoint, this._queries);
},
/**
* Transforms the response.
*
* @param {Object} response - The response.
* @returns {Object} - The media source data to be built.
*/
transformFrom: function (response) {
var data = Utils.getNested(response, 'resultObj', 'src', 'sources'),
url = data.src,
licenseUrl = Utils.getNested(data, 'contentProtection', 'playready', 'licenseAcquisitionURL'),
mimeType;
// Use local video for pc browser.
if (device.getModel() === 'webkit') {
url = webkitBrowserUrl;
licenseUrl = null;
mimeType = PlayerProperties.MIME_TYPES.mp4;
}
return {
url: url,
licenseUrl: licenseUrl,
mimeType: mimeType
};
},
/**
* Validates the response.
*
* @param {Object} response - The response.
* @returns {boolean} - True if valid.
*/
validateResponse: function (response) {
return response.resultCode === 'OK'
&& Utils.hasNested(response, 'resultObj', 'src', 'sources');
},
/**
* Return true in case failed request should be repeated.
*
* @param {Object} response - Response.
* @returns {boolean} True if retry.
*/
shouldRetry: function (response) {
return response.errorDescription !== '403-10146';
}
});
Base.PROFILES = PROFILES;
return Base;
});