define('application/models/streams/pilot', [
'application/models/stream',
'rofl/lib/utils',
'application/models/configuration',
'rofl/media/source',
'rofl/devices/mediaplayer/mediaplayer',
'antie/runtimecontext',
'rofl/media/drm/item/playready'
], function (
Base,
Utils,
ApiConfig,
MediaSource,
MediaPlayer,
RuntimeContext,
PlayReadyDRMItem
) {
'use strict';
var device = RuntimeContext.getDevice(),
ENDPOINTS = {
LIVE: 'https://www.kpncdn.eu/smarttv/pilot/{{contentId}}',
VOD: 'https://www.kpncdn.eu/smarttv/pilot/{{contentId}}_{{startTime}}_{{endTime}}'
};
return Base.extend({
/**
* Resolves the endpoint.
*
* @param {Object} params - The parameters.
* @param {string} params.type - The stream type. LIVE or VOD.
* @param {string} params.contentId - The content id.
* @param {boolean} [params.stop] - True if it should stop the stream. Optional.
* @returns {string} - The endpoint.
*/
resolveEndpoint: function (params) {
var type,
endpoint;
if (!params || !params.type || !params.contentId) {
throw 'Missing type or content id.';
}
type = params.type;
endpoint = ENDPOINTS[type];
params.deviceId = device.getUdid();
this._type = type;
return Utils.formatTemplate(endpoint, params);
},
/**
* Validates the response.
*
* @param {Object} response - The response.
* @returns {boolean} - True if valid.
*/
validateResponse: function (response) {
return response.resultCode === '0'
&& Utils.hasNested(response, 'resultObj', 'url');
},
/**
* Transforms the response.
*
* @param {Object} response - The response.
* @returns {Object} - The media source.
*/
transformFrom: function (response) {
var streamUrl = Utils.getNested(response, 'resultObj', 'url'),
deviceBrand = device.getBrand(),
streamType = this._type === 'LIVE' ? MediaPlayer.TYPE.LIVE_VIDEO : MediaPlayer.TYPE.VIDEO,
mediaSource = new MediaSource(streamUrl, streamType, MediaSource.MIME_TYPES.mpd),
drmItem = new PlayReadyDRMItem();
mediaSource.setStartBitRate(2500000);
if (response.laurl) {
drmItem.setLicenseOverrideUri(response.laurl);
}
if (deviceBrand === 'hbbtv' || deviceBrand === 'lg') {
drmItem.setEmbeddedLicense(true);
}
drmItem.setProtectionHeaderUTF16(true);
mediaSource.setDrmItem(drmItem);
return mediaSource;
}
});
});