Skip to content

Commit

Permalink
feat(FEC-8875): when an external caption format is DFXP return the we…
Browse files Browse the repository at this point in the history
…bvtt url (#81)

* use webvtt url when the caption format is DFXP or CAP
* add tests + fix pr
  • Loading branch information
odedhutzler authored Jan 31, 2019
1 parent 817111b commit 49581ad
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/k-provider/ovp/external-captions-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ const CaptionsFormatsMap: {[format: string]: string} = {

class ExternalCaptionsBuilder {
static createConfig(captions: Array<Object>): Array<PKExternalCaptionObject> {
return captions.filter(caption => [KalturaCaptionType.WEBVTT, KalturaCaptionType.SRT].includes(caption.format)).map(caption => {
return captions.map(caption => {
let url = caption.url;
let type = CaptionsFormatsMap[caption.format];
if ([KalturaCaptionType.DFXP, KalturaCaptionType.CAP].includes(caption.format)) {
url = caption.webVttUrl;
type = CaptionsFormatsMap[KalturaCaptionType.WEBVTT];
}
return {
default: caption.isDefault,
type: CaptionsFormatsMap[caption.format],
default: !!caption.isDefault,
type: type,
language: caption.languageCode,
label: caption.label,
url: caption.url
url: url
};
});
}
Expand Down
59 changes: 59 additions & 0 deletions test/src/k-provider/ovp/external-captions-builder.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {ExternalCaptionsBuilder} from '../../../../src/k-provider/ovp/external-captions-builder';

describe('external captions parser', function() {
const playbackCaptions = [
{
format: '1',
label: 'Eng',
language: 'English',
languageCode: 'EN',
objectType: 'KalturaCaptionPlaybackPluginData',
url: 'regularUrl',
webVttUrl: 'webVttUrl'
},
{
format: '3',
label: 'FRA',
language: 'FRENCH',
languageCode: 'FR',
objectType: 'KalturaCaptionPlaybackPluginData',
url: 'regularUrl',
webVttUrl: 'webVttUrl'
},
{
format: '2',
label: 'RUS',
language: 'Russian',
languageCode: 'RU',
objectType: 'KalturaCaptionPlaybackPluginData',
url: 'regularUrl',
webVttUrl: 'webVttUrl'
}
];

describe('createConfig', () => {
it('should return an empty config', () => {
const captions = ExternalCaptionsBuilder.createConfig([]);
captions.length.should.equal(0);
});
it('should return an array with 3 captions', () => {
const captions = ExternalCaptionsBuilder.createConfig(playbackCaptions);
captions.length.should.equal(3);
});
it('should return a caption with regular url with srt type', () => {
const captions = ExternalCaptionsBuilder.createConfig([playbackCaptions[0]]);
captions[0].url.should.equal('regularUrl');
captions[0].type.should.equal('srt');
});
it('should return a caption with regular url with vtt type', () => {
const captions = ExternalCaptionsBuilder.createConfig([playbackCaptions[1]]);
captions[0].url.should.equal('regularUrl');
captions[0].type.should.equal('vtt');
});
it('should return a caption with url : webvtturl with a vtt type', () => {
const captions = ExternalCaptionsBuilder.createConfig([playbackCaptions[2]]);
captions[0].url.should.equal('webVttUrl');
captions[0].type.should.equal('vtt');
});
});
});

0 comments on commit 49581ad

Please sign in to comment.