Skip to content

Commit

Permalink
fix(FEC-8739): block action is not fired from OTT provider (#71)
Browse files Browse the repository at this point in the history
OTT BE rule action enum is a string equal to BLOCK while in OVP it is an int equal to 1.
We are currently using a base enum, which is incorrect as the enums are different, so need to separate the enum.
I also moved the base provider parser utility functions to more appropriate places, as having a base with shared enums between providers is not manageable.
  • Loading branch information
OrenMe authored Dec 4, 2018
1 parent bb3a9da commit 2a318db
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 65 deletions.
12 changes: 12 additions & 0 deletions src/entities/media-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ export const SupportedStreamFormat: Map<string, ProviderMediaFormatType> = new M
['applehttp', MediaFormat.HLS],
['url', MediaFormat.MP4]
]);

/**
* returns a boolean whether a source is progressive or not
* @param {string} formatName - the format name
* @returns {boolean} - if source is progressive or not
*/
function isProgressiveSource(formatName: string): boolean {
const sourceFormat = SupportedStreamFormat.get(formatName);
return !!sourceFormat && sourceFormat.name === MediaFormat.MP4.name;
}

export {isProgressiveSource};
47 changes: 0 additions & 47 deletions src/k-provider/common/base-provider-parser.js

This file was deleted.

5 changes: 4 additions & 1 deletion src/k-provider/ott/loaders/asset-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import RequestBuilder from '../../../util/request-builder';
import KalturaPlaybackContext from '../response-types/kaltura-playback-context';
import KalturaAsset from '../response-types/kaltura-asset';

type OTTAssetLoaderResponse = {mediaDataResult: KalturaAsset, playBackContextResult: KalturaPlaybackContext};
export type {OTTAssetLoaderResponse};

export default class OTTAssetLoader implements ILoader {
_entryId: string;
_requests: Array<RequestBuilder>;
Expand Down Expand Up @@ -36,7 +39,7 @@ export default class OTTAssetLoader implements ILoader {
this._response.playBackContextResult = new KalturaPlaybackContext(response[1].data);
}

get response(): any {
get response(): OTTAssetLoaderResponse {
return this._response;
}

Expand Down
24 changes: 19 additions & 5 deletions src/k-provider/ott/provider-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import MediaEntry from '../../entities/media-entry';
import Drm from '../../entities/drm';
import MediaSource from '../../entities/media-source';
import MediaSources from '../../entities/media-sources';
import {SupportedStreamFormat} from '../../entities/media-format';
import {SupportedStreamFormat, isProgressiveSource} from '../../entities/media-format';
import KalturaDrmPlaybackPluginData from '../common/response-types/kaltura-drm-playback-plugin-data';
import BaseProviderParser from '../common/base-provider-parser';
import KalturaRuleAction from './response-types/kaltura-rule-action';
import KalturaAccessControlMessage from '../common/response-types/kaltura-access-control-message';
import type {OTTAssetLoaderResponse} from './loaders/asset-loader';

const LIVE_ASST_OBJECT_TYPE: string = 'KalturaLiveAsset';

Expand All @@ -32,7 +34,7 @@ const MediaTypeCombinations: {[mediaType: string]: Object} = {
}
};

export default class OTTProviderParser extends BaseProviderParser {
export default class OTTProviderParser {
static _logger = getLogger('OTTProviderParser');

/**
Expand Down Expand Up @@ -159,10 +161,10 @@ export default class OTTProviderParser extends BaseProviderParser {
sources.map(parsedSource, sourceFormat);
};
const parseAdaptiveSources = () => {
kalturaSources.filter(source => !OTTProviderParser._isProgressiveSource(source)).forEach(addAdaptiveSource);
kalturaSources.filter(source => !isProgressiveSource(source.format)).forEach(addAdaptiveSource);
};
const parseProgressiveSources = () => {
kalturaSources.filter(source => OTTProviderParser._isProgressiveSource(source)).forEach(addAdaptiveSource);
kalturaSources.filter(source => isProgressiveSource(source.format)).forEach(addAdaptiveSource);
};
if (kalturaSources && kalturaSources.length > 0) {
parseAdaptiveSources();
Expand Down Expand Up @@ -205,4 +207,16 @@ export default class OTTProviderParser extends BaseProviderParser {
}
return mediaSource;
}

static hasBlockAction(response): boolean {
return response.playBackContextResult.hasBlockAction();
}

static getBlockAction(response): ?KalturaRuleAction {
return response.playBackContextResult.getBlockAction();
}

static getErrorMessages(response: OTTAssetLoaderResponse): Array<KalturaAccessControlMessage> {
return response.playBackContextResult.getErrorMessages();
}
}
2 changes: 1 addition & 1 deletion src/k-provider/ott/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class OTTProvider extends BaseProvider<OTTProviderMediaInfoObject
if (data.has(OTTAssetLoader.id)) {
const assetLoader = data.get(OTTAssetLoader.id);
if (assetLoader && assetLoader.response && Object.keys(assetLoader.response).length) {
const response = assetLoader.response;
const response = (assetLoader: OTTAssetLoader).response;
if (OTTProviderParser.hasBlockAction(response)) {
throw new Error(Error.Severity.CRITICAL, Error.Category.SERVICE, Error.Code.BLOCK_ACTION, {
action: OTTProviderParser.getBlockAction(response),
Expand Down
14 changes: 13 additions & 1 deletion src/k-provider/ott/response-types/kaltura-playback-context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@flow
import ServiceResult from '../../common/base-service-result';
import KalturaAccessControlMessage from '../../common/response-types/kaltura-access-control-message';
import KalturaRuleAction from '../../common/response-types/kaltura-rule-action';
import KalturaRuleAction from './kaltura-rule-action';
import KalturaPlaybackSource from './kaltura-playback-source';

export default class KalturaPlaybackContext extends ServiceResult {
Expand Down Expand Up @@ -48,4 +48,16 @@ export default class KalturaPlaybackContext extends ServiceResult {
}
}
}

hasBlockAction(): boolean {
return this.getBlockAction() !== undefined;
}

getBlockAction(): ?KalturaRuleAction {
return this.actions.find(action => action.type === KalturaRuleAction.Type.BLOCK);
}

getErrorMessages(): Array<KalturaAccessControlMessage> {
return this.messages;
}
}
26 changes: 26 additions & 0 deletions src/k-provider/ott/response-types/kaltura-rule-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//@flow
export default class KalturaRuleAction {
static Type: {[type: string]: string | number} = {
BLOCK: 'BLOCK',
START_DATE_OFFSET: 'START_DATE_OFFSET',
END_DATE_OFFSET: 'END_DATE_OFFSET',
USER_BLOCK: 'USER_BLOCK',
ALLOW_PLAYBACK: 'ALLOW_PLAYBACK',
BLOCK_PLAYBACK: 'BLOCK_PLAYBACK',
APPLY_DISCOUNT_MODULE: 'APPLY_DISCOUNT_MODULE'
};

/**
* @member - The type of the action
* @type {string|number}
*/
type: string | number;

/**
* @constructor
* @param {Object} data - The response
*/
constructor(data: Object) {
this.type = data.type;
}
}
10 changes: 9 additions & 1 deletion src/k-provider/ovp/loaders/media-entry-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import OVPConfiguration from '../config';
import KalturaPlaybackContext from '../response-types/kaltura-playback-context';
import KalturaMetadataListResponse from '../response-types/kaltura-metadata-list-response';
import KalturaBaseEntryListResponse from '../response-types/kaltura-base-entry-list-response';
import KalturaMediaEntry from '../response-types/kaltura-media-entry';

type OVPMediaEntryLoaderResponse = {
entry: KalturaMediaEntry,
playBackContextResult: KalturaPlaybackContext,
metadataListResult: KalturaMetadataListResponse
};
export type {OVPMediaEntryLoaderResponse};

export default class OVPMediaEntryLoader implements ILoader {
_entryId: string;
Expand Down Expand Up @@ -40,7 +48,7 @@ export default class OVPMediaEntryLoader implements ILoader {
this._response.metadataListResult = new KalturaMetadataListResponse(response[2].data);
}

get response(): any {
get response(): OVPMediaEntryLoaderResponse {
return this._response;
}

Expand Down
24 changes: 19 additions & 5 deletions src/k-provider/ovp/provider-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import MediaEntry from '../../entities/media-entry';
import Drm from '../../entities/drm';
import MediaSource from '../../entities/media-source';
import MediaSources from '../../entities/media-sources';
import {SupportedStreamFormat} from '../../entities/media-format';
import BaseProviderParser from '../common/base-provider-parser';
import {SupportedStreamFormat, isProgressiveSource} from '../../entities/media-format';
import Playlist from '../../entities/playlist';
import EntryList from '../../entities/entry-list';
import KalturaRuleAction from './response-types/kaltura-rule-action';
import KalturaAccessControlMessage from '../common/response-types/kaltura-access-control-message';
import type {OVPMediaEntryLoaderResponse} from './loaders/media-entry-loader';

export default class OVPProviderParser extends BaseProviderParser {
export default class OVPProviderParser {
static _logger = getLogger('OVPProviderParser');

/**
Expand Down Expand Up @@ -156,10 +158,10 @@ export default class OVPProviderParser extends BaseProviderParser {
sources.map(parsedSource, sourceFormat);
};
const parseAdaptiveSources = () => {
kalturaSources.filter(source => !OVPProviderParser._isProgressiveSource(source)).forEach(addAdaptiveSource);
kalturaSources.filter(source => !isProgressiveSource(source.format)).forEach(addAdaptiveSource);
};
const parseProgressiveSources = () => {
const progressiveSource = kalturaSources.find(OVPProviderParser._isProgressiveSource);
const progressiveSource = kalturaSources.find(source => isProgressiveSource(source.format));
sources.progressive = OVPProviderParser._parseProgressiveSources(progressiveSource, playbackContext, ks, partnerId, uiConfId, entry.id);
};
if (kalturaSources && kalturaSources.length > 0) {
Expand Down Expand Up @@ -339,6 +341,18 @@ export default class OVPProviderParser extends BaseProviderParser {
return 'https';
}

static hasBlockAction(response: OVPMediaEntryLoaderResponse): boolean {
return response.playBackContextResult.hasBlockAction();
}

static getBlockAction(response: OVPMediaEntryLoaderResponse): ?KalturaRuleAction {
return response.playBackContextResult.getBlockAction();
}

static getErrorMessages(response: OVPMediaEntryLoaderResponse): Array<KalturaAccessControlMessage> {
return response.playBackContextResult.getErrorMessages();
}

/**
* Applies the request host regex on the url
* @function _applyRegexAction
Expand Down
2 changes: 1 addition & 1 deletion src/k-provider/ovp/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class OVPProvider extends BaseProvider<ProviderMediaInfoObject> {
if (data.has(OVPMediaEntryLoader.id)) {
const mediaLoader = data.get(OVPMediaEntryLoader.id);
if (mediaLoader && mediaLoader.response) {
const response = mediaLoader.response;
const response = (mediaLoader: OVPMediaEntryLoader).response;
if (OVPProviderParser.hasBlockAction(response)) {
throw new Error(Error.Severity.CRITICAL, Error.Category.SERVICE, Error.Code.BLOCK_ACTION, {
action: OVPProviderParser.getBlockAction(response),
Expand Down
16 changes: 14 additions & 2 deletions src/k-provider/ovp/response-types/kaltura-playback-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import ServiceResult from '../../common/base-service-result';
import KalturaAccessControlMessage from '../../common/response-types/kaltura-access-control-message';
import KalturaPlaybackSource from './kaltura-playback-source';
import KalturaRuleAction from '../../common/response-types/kaltura-rule-action';
import KalturaAccessControlModifyRequestHostRegexAction from '../../common/response-types/kaltura-access-control-modify-request-host-regex-action';
import KalturaAccessControlModifyRequestHostRegexAction from './kaltura-access-control-modify-request-host-regex-action';
import KalturaRuleAction from './kaltura-rule-action';
import KalturaFlavorAsset from './kaltura-flavor-asset';

export default class KalturaPlaybackContext extends ServiceResult {
Expand Down Expand Up @@ -60,6 +60,18 @@ export default class KalturaPlaybackContext extends ServiceResult {
}
}

hasBlockAction(): boolean {
return this.getBlockAction() !== undefined;
}

getBlockAction(): ?KalturaRuleAction {
return this.actions.find(action => action.type === KalturaRuleAction.Type.BLOCK);
}

getErrorMessages(): Array<KalturaAccessControlMessage> {
return this.messages;
}

/**
* Get the KalturaAccessControlModifyRequestHostRegexAction action
* @function getRequestHostRegexAction
Expand Down
44 changes: 43 additions & 1 deletion test/src/k-provider/ott/be-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,4 +1165,46 @@ const LiveEntryNoDrmData = {
}
};

export {AnonymousEntryWithoutUIConfWithDrmData, LiveEntryNoDrmData};
const BlockActionEntry = {
response: {
result: [
{
ks:
'djJ8MTk4fEiDJqfTA_nqary8_jB-U-W0ne3JNVaZW5JmZDufdRcmcTGy3pAquXoMvFbANe6h63lEhxCo7mMZTsMTP5k4QDmOq99dRsPEsHUwOknv_9wvR_J2pbNzdXmlZ4JlYgO0ZcUr9_7tsZhqrHRfIcgrSj4=',
refreshToken: 'b07f74dfe6584790b272eb742577369b',
objectType: 'KalturaLoginSession'
},
{
externalIds: '1234',
catchUpBuffer: 4320,
trickPlayBuffer: 0,
enableRecordingPlaybackNonEntitledChannel: false,
entryId: '',
id: 1234,
type: 549,
name: 'test',
description: 'test',
images: [],
mediaFiles: [],
metas: {},
tags: {},
startDate: 1509545700,
endDate: 4070908800,
enableCdvr: false,
enableCatchUp: true,
enableStartOver: true,
enableTrickPlay: true,
objectType: 'KalturaMediaAsset'
},
{
sources: [],
actions: [{type: 'BLOCK', objectType: 'KalturaAccessControlBlockAction'}],
messages: [{message: 'Concurrency limitation', code: 'ConcurrencyLimitation', objectType: 'KalturaAccessControlMessage'}],
objectType: 'KalturaPlaybackContext'
}
],
executionTime: 0.2346709
}
};

export {AnonymousEntryWithoutUIConfWithDrmData, LiveEntryNoDrmData, BlockActionEntry};
Loading

0 comments on commit 2a318db

Please sign in to comment.