Skip to content

Commit

Permalink
feat(FEC-8661): support youtube engine playback (#205)
Browse files Browse the repository at this point in the history
support adding youtube to streamPrioirty list if video mimetype is youtube.
  • Loading branch information
OrenMe authored Jan 15, 2019
1 parent f1f6392 commit 63f1a3b
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 94 deletions.
30 changes: 29 additions & 1 deletion src/common/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,33 @@ function isIos(): boolean {
return Env.os.name === 'iOS';
}
/**
* set stream priority according to playerConfig
* @param {Player} player - player
* @param {PartialKPOptionsObject} playerConfig - player config
* @return {void}
*/
function maybeSetStreamPriority(player: Player, playerConfig: PartialKPOptionsObject): void {
const source = playerConfig.sources && playerConfig.sources.progressive;
if (source && source[0] && source[0].mimetype === 'video/youtube') {
const playbackConfig = player.config.playback;
let hasYoutube = false;
playbackConfig.streamPriority.forEach(sp => {
if (sp.engine === 'youtube') {
hasYoutube = true;
}
});
if (!hasYoutube) {
playbackConfig.streamPriority.push({
engine: 'youtube',
format: 'progressive'
});
}

playerConfig.playback = playbackConfig;
}
}

export {
printSetupMessages,
supportLegacyOptions,
Expand All @@ -399,5 +426,6 @@ export {
checkNativeHlsSupport,
getDefaultOptions,
isSafari,
isIos
isIos,
maybeSetStreamPriority
};
3 changes: 2 additions & 1 deletion src/kaltura-player.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import {EventType as UIEventType} from '@playkit-js/playkit-js-ui';
import {Provider} from 'playkit-js-providers';
import {supportLegacyOptions} from './common/utils/setup-helpers';
import {supportLegacyOptions, maybeSetStreamPriority} from './common/utils/setup-helpers';
import getLogger from './common/utils/logger';
import {addKalturaParams} from './common/utils/kaltura-params';
import {evaluatePluginsConfig} from './common/plugins/plugins-config';
Expand Down Expand Up @@ -76,6 +76,7 @@ class KalturaPlayer extends FakeEventTarget {
});
addKalturaPoster(playerConfig.sources, mediaConfig.sources, this._localPlayer.dimensions);
addKalturaParams(this, playerConfig);
maybeSetStreamPriority(this, playerConfig);
this._uiWrapper.setSeekbarConfig(mediaConfig, this._localPlayer.config.ui);
this.configure(playerConfig);
}
Expand Down
73 changes: 69 additions & 4 deletions test/src/kaltura-player.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ describe('kaltura player api', function() {

beforeEach(function() {
kalturaPlayer = setup(config);
sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function(playlistInfo) {
return playlistInfo.playlistId
? Promise.resolve(MediaMockData.MediaConfig)
: Promise.reject({success: false, data: 'Missing mandatory parameter'});
sinon.stub(kalturaPlayer._provider, 'getMediaConfig').callsFake(function(info) {
const id = info.playlistId || info.entryId;
return id ? Promise.resolve(MediaMockData.MediaConfig[id]) : Promise.reject({success: false, data: 'Missing mandatory parameter'});
});
});

Expand All @@ -66,6 +65,72 @@ describe('kaltura player api', function() {
done();
});
});

describe('maybeSetStreamPriority', function() {
describe('media source mime type is video/youtube', function() {
it('should add youtube to stream priority if not already set', function(done) {
kalturaPlayer.loadMedia({entryId: 'Youtube'}).then(() => {
let hasYoutube = false;
kalturaPlayer.config.playback.streamPriority.forEach(sp => {
if (sp.engine === 'youtube') {
hasYoutube = true;
}
});
try {
hasYoutube.should.be.true;
done();
} catch (e) {
done("youtube engine wasn't added to stream priority list");
}
});
});
it('should not add youtube to stream priority if already set', function(done) {
kalturaPlayer.configure({
playback: {
streamPriority: [
{
engine: 'youtube',
format: 'progressive'
}
]
}
});
kalturaPlayer.loadMedia({entryId: 'Youtube'}).then(() => {
let hasYoutube = false;
kalturaPlayer.config.playback.streamPriority.length.should.equal(1);
kalturaPlayer.config.playback.streamPriority.forEach(sp => {
if (sp.engine === 'youtube') {
hasYoutube = true;
}
});
try {
hasYoutube.should.be.true;
done();
} catch (e) {
done("youtube engine wasn't added to stream priority list");
}
});
});
});
describe('media source mime type is not video/youtube', function() {
it('should not add youtube to stream priority', function(done) {
kalturaPlayer.loadMedia({entryId: entryId}).then(() => {
let hasYoutube = false;
kalturaPlayer.config.playback.streamPriority.forEach(sp => {
if (sp.engine === 'youtube') {
hasYoutube = true;
}
});
try {
hasYoutube.should.be.false;
done();
} catch (e) {
done('youtube engine was added to stream priority list');
}
});
});
});
});
});
});

Expand Down
212 changes: 124 additions & 88 deletions test/src/mock-data/media.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,130 @@
const MediaConfig = {
session: {
isAnonymous: true,
partnerId: 1091,
uiConfId: 15215933,
ks: 'OGViNDhkZGI4ZTM1ODAzYWVhYTk0OTZlMzcwMmZmZjUzMjZkNGFkMnwxMDkxOzEwOTE7MTU0NDY5MTMwODswOzE1NDQ2MDQ5MDguNTg4NDswO3ZpZXc6Kix3aWRnZXQ6MTs7'
},
sources: {
hls: [
{
id: '0_wifqaipd_861,applehttp',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/applehttp/flavorIds/0_h65mfj7f,0_3flmvnwc,0_m131krws,0_5407xm9j,0_xcrwyk2n/a.m3u8?uiConfId=15215933',
mimetype: 'application/x-mpegURL'
}
],
dash: [
{
id: '0_wifqaipd_911,mpegdash',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/mpegdash/flavorIds/0_m131krws,0_5407xm9j,0_xcrwyk2n/a.mpd?uiConfId=15215933',
mimetype: 'application/dash+xml'
'0_wifqaipd': {
session: {
isAnonymous: true,
partnerId: 1091,
uiConfId: 15215933,
ks: 'OGViNDhkZGI4ZTM1ODAzYWVhYTk0OTZlMzcwMmZmZjUzMjZkNGFkMnwxMDkxOzEwOTE7MTU0NDY5MTMwODswOzE1NDQ2MDQ5MDguNTg4NDswO3ZpZXc6Kix3aWRnZXQ6MTs7'
},
sources: {
hls: [
{
id: '0_wifqaipd_861,applehttp',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/applehttp/flavorIds/0_h65mfj7f,0_3flmvnwc,0_m131krws,0_5407xm9j,0_xcrwyk2n/a.m3u8?uiConfId=15215933',
mimetype: 'application/x-mpegURL'
}
],
dash: [
{
id: '0_wifqaipd_911,mpegdash',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/mpegdash/flavorIds/0_m131krws,0_5407xm9j,0_xcrwyk2n/a.mpd?uiConfId=15215933',
mimetype: 'application/dash+xml'
}
],
progressive: [
{
id: '0_h65mfj7f261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_h65mfj7f/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 480256,
width: 480,
height: 272,
label: 'Undefined'
},
{
id: '0_3flmvnwc261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_3flmvnwc/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 686080,
width: 640,
height: 360,
label: 'Undefined'
},
{
id: '0_m131krws261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_m131krws/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 987136,
width: 640,
height: 360,
label: 'Undefined'
},
{
id: '0_5407xm9j261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_5407xm9j/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 1667072,
width: 1280,
height: 720,
label: 'Undefined'
},
{
id: '0_xcrwyk2n261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_xcrwyk2n/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 2691072,
width: 1280,
height: 720,
label: 'Undefined'
}
],
id: '0_wifqaipd',
duration: 741,
type: 'Vod',
poster: 'http://cdntesting.qa.mkaltura.com/p/1091/sp/109100/thumbnail/entry_id/0_wifqaipd/version/100042',
dvr: false,
vr: null,
metadata: {
name: 'MPEG Dash with MultiAudio New Transcoding',
description: '',
tags: '',
MediaType: 'Movie',
WatchPermissionRule: 'Parrent Allowed'
}
],
progressive: [
{
id: '0_h65mfj7f261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_h65mfj7f/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 480256,
width: 480,
height: 272,
label: 'Undefined'
},
{
id: '0_3flmvnwc261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_3flmvnwc/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 686080,
width: 640,
height: 360,
label: 'Undefined'
},
{
id: '0_m131krws261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_m131krws/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 987136,
width: 640,
height: 360,
label: 'Undefined'
},
{
id: '0_5407xm9j261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_5407xm9j/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 1667072,
width: 1280,
height: 720,
label: 'Undefined'
},
{
id: '0_xcrwyk2n261,url',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1091/sp/109100/playManifest/entryId/0_wifqaipd/protocol/http/format/url/flavorIds/0_xcrwyk2n/a.mp4?uiConfId=15215933',
mimetype: 'video/mp4',
bandwidth: 2691072,
width: 1280,
height: 720,
label: 'Undefined'
}
],
id: '0_wifqaipd',
duration: 741,
type: 'Vod',
poster: 'http://cdntesting.qa.mkaltura.com/p/1091/sp/109100/thumbnail/entry_id/0_wifqaipd/version/100042',
dvr: false,
vr: null,
metadata: {
name: 'MPEG Dash with MultiAudio New Transcoding',
description: '',
tags: '',
MediaType: 'Movie',
WatchPermissionRule: 'Parrent Allowed'
}
},
plugins: {}
},
plugins: {}
Youtube: {
session: {
isAnonymous: true,
partnerId: 1234,
uiConfId: 1234567,
ks: 'ABCDEFGHIJKLMNOP'
},
sources: {
hls: [],
dash: [],
progressive: [
{
id: '1111',
url:
'http://qa-apache-php7.dev.kaltura.com/p/1234/sp/123400/playManifest/entryId/1111/protocol/http/format/url/flavorIds/1111/a.mp4?uiConfId=15215933',
mimetype: 'video/youtube'
}
],
id: '0_wifqaipd',
duration: 741,
type: 'Vod',
poster: 'http://cdntesting.qa.mkaltura.com/p/1234/sp/123400/thumbnail/entry_id/1111/version/100042',
dvr: false,
vr: null,
metadata: {
name: 'MPEG Dash with MultiAudio New Transcoding',
description: '',
tags: '',
MediaType: 'Movie',
WatchPermissionRule: 'Parrent Allowed'
}
},
plugins: {}
}
};

export {MediaConfig};

0 comments on commit 63f1a3b

Please sign in to comment.