Skip to content

Commit

Permalink
feat(FEC-9156): getting bumper from playback context (#91)
Browse files Browse the repository at this point in the history
* Parse the bumper comes from the provider (OTT only)
* Add it to the plugins passed to the player 

Depends on kaltura/kaltura-player-js#252
  • Loading branch information
yairans authored Jul 10, 2019
1 parent 093bfcd commit de7c668
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/entities/bumper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@flow

export default class Bumper {
/**
* @member - bumper url
* @type {string}
*/
url: string;

/**
* @constructor
* @param {Object} data - The bumper response
*/
constructor(data: Object) {
this.url = data.url;
}
}
20 changes: 20 additions & 0 deletions src/k-provider/ott/provider-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import Drm from '../../entities/drm';
import MediaSource from '../../entities/media-source';
import MediaSources from '../../entities/media-sources';
import EntryList from '../../entities/entry-list';
import Bumper from '../../entities/bumper';
import {SupportedStreamFormat, isProgressiveSource} from '../../entities/media-format';
import KalturaDrmPlaybackPluginData from '../common/response-types/kaltura-drm-playback-plugin-data';
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';
import KalturaBumpersPlaybackPluginData from './response-types/kaltura-bumper-playback-plugin-data';

const LIVE_ASST_OBJECT_TYPE: string = 'KalturaLiveAsset';

Expand Down Expand Up @@ -81,6 +83,24 @@ export default class OTTProviderParser {
return entryList;
}

/**
* Returns parsed bumper by given OTT response objects.
* @function getBumper
* @param {any} assetResponse - The asset response.
* @returns {?Bumper} - The bumper
* @static
* @public
*/
static getBumper(assetResponse: any): ?Bumper {
const playbackContext = assetResponse.playBackContextResult;
const progressiveBumper = playbackContext.plugins.find(
bumper => bumper.streamertype === KalturaBumpersPlaybackPluginData.StreamerType.PROGRESSIVE
);
if (progressiveBumper) {
return new Bumper(progressiveBumper);
}
}

static _fillBaseData(mediaEntry: MediaEntry, assetResponse: any) {
const mediaAsset = assetResponse.mediaDataResult;
const metaData = OTTProviderParser.reconstructMetadata(mediaAsset);
Expand Down
4 changes: 4 additions & 0 deletions src/k-provider/ott/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export default class OTTProvider extends BaseProvider<OTTProviderMediaInfoObject
const mediaEntry = OTTProviderParser.getMediaEntry(response, requestData);
Object.assign(mediaConfig.sources, this._getSourcesObject(mediaEntry));
this._verifyHasSources(mediaConfig.sources);
const bumper = OTTProviderParser.getBumper(response);
if (bumper) {
Object.assign(mediaConfig.plugins, {bumper});
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@flow
export default class KalturaBumpersPlaybackPluginData {
static StreamerType: {[type: string]: string} = {
HLS: 'hls',
DASH: 'dash',
PROGRESSIVE: 'progressive'
};

/**
* @member - The streamer type
* @type {string}
*/
streamertype: string;
/**
* @member - The url
* @type {string}
*/
url: string;

/**
* @constructor
* @param {Object} data - The response
*/
constructor(data: Object) {
this.streamertype = data.streamertype;
this.url = data.url;
}
}
12 changes: 11 additions & 1 deletion src/k-provider/ott/response-types/kaltura-playback-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 {
static Type: {[type: string]: string} = {
Expand All @@ -22,10 +23,15 @@ export default class KalturaPlaybackContext extends ServiceResult {
*/
actions: Array<KalturaRuleAction> = [];
/**
* @member - Array of actions as received from the rules that invalidated
* @member - Array of access control massages
* @type {Array<KalturaAccessControlMessage>}
*/
messages: Array<KalturaAccessControlMessage> = [];
/**
* @member - Array of bumper plugins
* @type {Array<KalturaBumpersPlaybackPluginData>}
*/
plugins: Array<KalturaBumpersPlaybackPluginData> = [];

/**
* @constructor
Expand All @@ -46,6 +52,10 @@ export default class KalturaPlaybackContext extends ServiceResult {
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)));
}
}
}

Expand Down
75 changes: 74 additions & 1 deletion test/src/k-provider/ott/be-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3061,4 +3061,77 @@ const AnonymousPlaylistByEntryList = {
}
};

export {AnonymousEntryWithoutUIConfWithDrmData, LiveEntryNoDrmData, BlockActionEntry, PlaylistByEntryList, AnonymousPlaylistByEntryList};
const EntryWithBumper = {
response: {
result: [
{
objectType: 'KalturaMediaAsset',
createDate: 1559544691,
description: 'avichay VOD',
enableCatchUp: false,
enableCdvr: false,
enableStartOver: false,
enableTrickPlay: false,
endDate: 1572451200,
id: 324284,
metas: {},
name: 'avichay series1 VOD',
startDate: 1558022400,
tags: {},
type: 340,
updateDate: 1560668342,
catchUpBuffer: 0,
enableRecordingPlaybackNonEntitledChannel: false,
entryId: '0_tle49uqr',
externalIds: '0',
status: true,
trickPlayBuffer: 0,
typeDescription: 'Episode'
},
{
objectType: 'KalturaPlaybackContext',
actions: [],
messages: [{objectType: 'KalturaAccessControlMessage', code: 'OK', message: 'OK'}],
playbackCaptions: [],
plugins: [
{
objectType: 'KalturaBumpersPlaybackPluginData',
streamertype: 'progressive',
url: 'bumper_url.mp4'
}
],
sources: [
{
objectType: 'KalturaPlaybackSource',
assetId: 324284,
duration: 60,
externalId: 'DASH_WIDEVINE_90a80eff-c6e9-4ff7-b15f-1538384786b0',
fileSize: 0,
id: 630312,
url: 'dash_url',
drm: [
{
objectType: 'KalturaCustomDrmPlaybackPluginData',
licenseURL: 'license_url',
scheme: 'WIDEVINE_CENC'
}
],
format: 'mpegdash',
isTokenized: true,
protocols: 'https'
}
]
}
],
executionTime: 1.09587932
}
};

export {
AnonymousEntryWithoutUIConfWithDrmData,
LiveEntryNoDrmData,
BlockActionEntry,
PlaylistByEntryList,
AnonymousPlaylistByEntryList,
EntryWithBumper
};
40 changes: 39 additions & 1 deletion test/src/k-provider/ott/media-config-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,4 +728,42 @@ const LiveEntryNoDrm = {
plugins: {}
};

export {NoPluginsWithDrm, FilteredSourcesByDeviceType, LiveEntryNoDrm};
const EntryWithBumper = {
session: {
isAnonymous: false,
partnerId: 147,
ks: 'ks'
},
sources: {
hls: [],
dash: [
{
id: '630312,mpegdash',
url: 'dash_url',
mimetype: 'application/dash+xml',
drmData: [
{
licenseUrl: 'license_url',
scheme: 'com.widevine.alpha'
}
]
}
],
progressive: [],
id: 324284,
duration: 60,
type: 'Vod',
poster: '',
dvr: false,
vr: null,
metadata: {
name: 'avichay series1 VOD',
description: 'avichay VOD',
tags: {},
metas: {}
}
},
plugins: {bumper: {url: 'bumper_url.mp4'}}
};

export {NoPluginsWithDrm, FilteredSourcesByDeviceType, LiveEntryNoDrm, EntryWithBumper};
38 changes: 38 additions & 0 deletions test/src/k-provider/ott/provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,44 @@ describe('getEntryListConfig', function() {
});
});

describe('getEntryWithBumper', function() {
let provider, sandbox;
const partnerId = 147;
const ks = 'ks';
const playerVersion = '1.2.3';

beforeEach(() => {
sandbox = sinon.sandbox.create();
provider = new OTTProvider({partnerId: partnerId}, playerVersion);
});

afterEach(() => {
sandbox.restore();
MultiRequestBuilder.prototype.execute.restore();
});

it('should load the entry with bumper', done => {
sinon.stub(MultiRequestBuilder.prototype, 'execute').callsFake(function() {
return new Promise(resolve => {
resolve({response: new MultiRequestResult(BE_DATA.EntryWithBumper.response)});
});
});
provider.getMediaConfig({entryId: '324284', fileIds: '630312', ks}).then(
mediaConfig => {
try {
mediaConfig.should.deep.equal(MEDIA_CONFIG_DATA.EntryWithBumper);
done();
} catch (err) {
done(err);
}
},
err => {
done(err);
}
);
});
});

describe('logger', () => {
const provider = new OTTProvider({partnerId: partnerId}, playerVersion);

Expand Down

0 comments on commit de7c668

Please sign in to comment.