Source: models/production/streams/catchup.js

define('application/models/production/streams/catchup', [
    'application/models/production/streams/base',
    'rofl/lib/utils',
    'antie/runtimecontext'
], function (
    Base,
    Utils,
    RuntimeContext
) {
    'use strict';

    var application = RuntimeContext.getCurrentApplication(),
        endpoints = {
            REPLAY: '/LIVE/{{contentId}}/{{assetId}}/?time={{startTime}}-{{endTime}}&',
            VOD: '/PROGRAM/{{contentId}}/{{assetId}}'
        },
        timeGap = 24 * 60 * 60 * 1000,
        replayBuffer = 15 * 60 * 1000;

    return Base.extend({

        /**
         * Resolves the endpoint.
         *
         * @param {Object} params - Stream params.
         * @param {Object} params.data - The content's data to request the url.
         * @returns {string} - The endpoint.
         */
        resolveEndpoint: function resolveEndpoint (params) {
            var contentData = params.data || {},
                now = application.getDate().getTime(),
                startTime = new Date(contentData.getStartTime() * 1000).getTime(),
                endTime = new Date(contentData.getEndTime() * 1000).getTime(),
                catchupEndpoint = endpoints.VOD,
                contentId,
                assetId;

            if (now - params.endTime < replayBuffer) {
                catchupEndpoint = endpoints.REPLAY;
                contentId = contentData.getChannelId();

            } else {
                contentId = contentData.getId();
            }

            assetId = contentData.getAssetId();
            startTime = (now - params.startTime < timeGap) ? (startTime - (5 * 60 * 1000)) : startTime;

            this._endpoint = Utils.formatTemplate(catchupEndpoint, {
                contentId: contentId,
                assetId: assetId,
                startTime: startTime,
                endTime: endTime
            });

            return resolveEndpoint.base.call(this, params);
        }
    });
});