Skip to content

Commit

Permalink
feat(FEC-8816): support the new captions API structure in getPlayback…
Browse files Browse the repository at this point in the history
…Context (#78)

* remove caption list service

use the new caption object that returns as part of the getPlaybackContext

* fix typo

* change flag name & change default to true & fix flow

* fix tests
  • Loading branch information
odedhutzler authored Jan 24, 2019
1 parent 16fcba7 commit 15db3de
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### Description of the Changes

Please add a detailed description of the change, weather it's an enhancement or a bugfix.
Please add a detailed description of the change, whether it's an enhancement or a bugfix.
If the PR is related to an open issue please link to it.

### CheckLists

- [ ] changes have been done against master branch, and PR does not conflict
- [ ] new unit / functional tests have been added (whenever applicable)
- [ ] test are passing in local environment
- [ ] test are passing in local environment
- [ ] Travis tests are passing (or test results are not worse than on master branch :))
- [ ] Docs have been updated
2 changes: 1 addition & 1 deletion flow-typed/types/env-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
declare type ProviderEnvConfigObject = {
serviceUrl: string,
cdnUrl?: string,
experimentalLoadApiCaptions?: boolean
useApiCaptions?: boolean
};
2 changes: 1 addition & 1 deletion src/k-provider/ovp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const defaultConfig: Object = {
apiVersion: '3.3.0',
format: 1
},
experimentalLoadApiCaptions: false
useApiCaptions: true
};

export default class OVPConfiguration {
Expand Down
34 changes: 10 additions & 24 deletions src/k-provider/ovp/external-captions-builder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @flow
import OVPConfiguration from './config';

const KalturaCaptionType: CaptionType = {
SRT: '1',
Expand All @@ -8,36 +7,23 @@ const KalturaCaptionType: CaptionType = {
CAP: '4'
};

const CaptionsFormats: {[format: string]: string} = {
WEBVTT: 'vtt'
const CaptionsFormatsMap: {[format: string]: string} = {
'3': 'vtt',
'1': 'srt'
};

const BASE_URL: string = 'index.php/service/caption_captionasset/action/serveWebVTT/captionAssetId/ASSET_ID/segmentIndex/-1/version/2/captions.vtt';

const ASSET_ID_INDEX: number = 6;
const VERSION_INDEX: number = 10;

class ExternalCaptionsBuilder {
static createConfig(metadata: Object, ks: string): Array<PKExternalCaptionObject> {
return metadata.filter(meta => [KalturaCaptionType.WEBVTT, KalturaCaptionType.SRT].includes(meta.format)).map(meta => {
static createConfig(captions: Array<Object>): Array<PKExternalCaptionObject> {
return captions.filter(caption => [KalturaCaptionType.WEBVTT, KalturaCaptionType.SRT].includes(caption.format)).map(caption => {
return {
type: CaptionsFormats.WEBVTT,
language: meta.language,
label: meta.label,
url: ExternalCaptionsBuilder.createUrl(meta, ks)
default: caption.isDefault,
type: CaptionsFormatsMap[caption.format],
language: caption.language,
label: caption.label,
url: caption.url
};
});
}

static createUrl(metadata: Object, ks: string): string {
const config = OVPConfiguration.get();
let path = BASE_URL.split('/');
path[ASSET_ID_INDEX] = metadata.id;
path[VERSION_INDEX] = metadata.version;
path = path.join('/');
ks = ks ? `/ks/${ks}` : ``;
return `${config.serviceUrl}/${path}${ks}`;
}
}

export {ExternalCaptionsBuilder};
12 changes: 1 addition & 11 deletions src/k-provider/ovp/loaders/media-entry-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ 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';
import OVPCaptionService from '../services/captions-service';
import KalturaCaptionAssetListResponse from '../response-types/kaltura-caption-list';

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

Expand Down Expand Up @@ -46,14 +43,10 @@ export default class OVPMediaEntryLoader implements ILoader {
}

set response(response: any) {
const config = OVPConfiguration.get();
let mediaEntryResponse: KalturaBaseEntryListResponse = new KalturaBaseEntryListResponse(response[0].data);
this._response.entry = mediaEntryResponse.entries[0];
this._response.playBackContextResult = new KalturaPlaybackContext(response[1].data);
this._response.metadataListResult = new KalturaMetadataListResponse(response[2].data);
if (config.experimentalLoadApiCaptions) {
this._response.captionResult = new KalturaCaptionAssetListResponse(response[3].data);
}
}

get response(): OVPMediaEntryLoaderResponse {
Expand All @@ -73,9 +66,6 @@ export default class OVPMediaEntryLoader implements ILoader {
requests.push(OVPBaseEntryService.list(config.serviceUrl, params.ks, params.entryId, params.redirectFromEntryId));
requests.push(OVPBaseEntryService.getPlaybackContext(config.serviceUrl, params.ks, params.entryId));
requests.push(OVPMetadataService.list(config.serviceUrl, params.ks, params.entryId));
if (config.experimentalLoadApiCaptions) {
requests.push(OVPCaptionService.list(config.serviceUrl, params.ks, params.entryId));
}
return requests;
}

Expand Down
4 changes: 2 additions & 2 deletions src/k-provider/ovp/provider-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export default class OVPProviderParser {
const kalturaSources = playbackContext.sources;

mediaEntry.sources = OVPProviderParser._getParsedSources(kalturaSources, ks, partnerId, uiConfId, entry, playbackContext);
if (mediaEntryResponse.captionResult) {
mediaEntry.sources.captions = ExternalCaptionsBuilder.createConfig(mediaEntryResponse.captionResult.data, ks);
if (OVPConfiguration.get().useApiCaptions && playbackContext.data.playbackCaptions) {
mediaEntry.sources.captions = ExternalCaptionsBuilder.createConfig(playbackContext.data.playbackCaptions);
}
OVPProviderParser._fillBaseData(mediaEntry, entry, metadataList);
return mediaEntry;
Expand Down
20 changes: 0 additions & 20 deletions src/k-provider/ovp/response-types/kaltura-caption-list.js

This file was deleted.

28 changes: 0 additions & 28 deletions src/k-provider/ovp/services/captions-service.js

This file was deleted.

3 changes: 2 additions & 1 deletion test/src/k-provider/ovp/provider-parser-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const youtubeMediaEntryResult = {
}
],
dash: [],
hls: []
hls: [],
captions: []
},
duration: 0,
metadata: {
Expand Down

0 comments on commit 15db3de

Please sign in to comment.