import ServiceResult from '../../common/base-service-result'; import {KalturaAccessControlMessage} from '../../common/response-types/kaltura-access-control-message'; import KalturaRuleAction from './kaltura-rule-action'; import KalturaPlaybackSource from './kaltura-playback-source'; import KalturaBumpersPlaybackPluginData from './kaltura-bumper-playback-plugin-data'; export default class KalturaPlaybackContext extends ServiceResult { public static Type: {[type: string]: string} = { DOWNLOAD: 'DOWNLOAD', TRAILER: 'TRAILER', CATCHUP: 'CATCHUP', START_OVER: 'START_OVER', PLAYBACK: 'PLAYBACK' }; /** * @member - The playback sources * @type {Array} */ public sources: Array = []; /** * @member - Array of actions as received from the rules that invalidated * @type {Array} */ public actions: KalturaRuleAction[] = []; /** * @member - Array of access control massages * @type {Array} */ public messages: Array = []; /** * @member - Array of bumper plugins * @type {Array} */ public plugins: Array = []; /** * @constructor * @param {Object} response The response */ constructor(response: any) { super(response); if (!this.hasError) { const messages = response.messages; if (messages) { messages.map(message => this.messages.push(new KalturaAccessControlMessage(message))); } const actions = response.actions; if (actions) { actions.map(action => this.actions.push(new KalturaRuleAction(action))); } const sources = response.sources; if (sources) { sources.map(source => this.sources.push(new KalturaPlaybackSource(source))); } const plugins = response.plugins; if (plugins) { plugins.map(plugin => this.plugins.push(new KalturaBumpersPlaybackPluginData(plugin))); } } } public hasBlockAction(): boolean { return this.getBlockAction() !== undefined; } public getBlockAction(): KalturaRuleAction | undefined { return this.actions.find(action => action.type === KalturaRuleAction.Type.BLOCK); } public getErrorMessages(): Array { return this.messages; } }