Skip to content

Commit

Permalink
fix(FEC-10729): forceRedirectExternalStreams is reset in playlist (#381)
Browse files Browse the repository at this point in the history
* Update the sources after `forceRedirectExternalStreams` is set by `loadMedia`
* Save the `player.config.sources.options` for all item unless configured for an item specifically (needed for when the app wants to config the `sources.options` for all playlist items)

Solves FEC-10729

Cont. of #370
  • Loading branch information
yairans committed Dec 23, 2020
1 parent 6a061de commit 77e86ec
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/common/playlist/playlist-item.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
// @flow
import {Utils} from '@playkit-js/playkit-js';
const formats = ['hls', 'dash', 'progressive'];
/**
* @class PlaylistItem
* @param {ProviderMediaConfigSourcesObject} [sources] - The item sources
* @param {PKSourcesConfigObject} [sources] - The item sources
* @param {KPPlaylistItemConfigObject} [config] - The item config
*/
class PlaylistItem {
_sources: ?ProviderMediaConfigSourcesObject;
_sources: ?PKSourcesConfigObject;
_config: ?KPPlaylistItemConfigObject;

constructor(sources: ?ProviderMediaConfigSourcesObject, config: ?KPPlaylistItemConfigObject) {
constructor(sources: ?PKSourcesConfigObject, config: ?KPPlaylistItemConfigObject) {
this._sources = sources;
this._config = config;
}

/**
* Update the playlist item sources
* @param {ProviderMediaConfigSourcesObject} sourcesObject - The sources
* @param {PKSourcesConfigObject} sourcesObject - The sources
* @returns {void}
* @instance
* @memberof PlaylistItem
*/
updateSources(sourcesObject: ProviderMediaConfigSourcesObject): void {
formats.forEach(format => {
this._sources && (this._sources[format] = sourcesObject[format]);
});
updateSources(sourcesObject: PKSourcesConfigObject): void {
this._sources = Utils.Object.mergeDeep({}, sourcesObject);
}

/**
* Playlist item sources
* @type {?ProviderMediaConfigSourcesObject}
* @type {?PKSourcesConfigObject}
* @instance
* @memberof PlaylistItem
*/
get sources(): ?ProviderMediaConfigSourcesObject {
get sources(): ?PKSourcesConfigObject {
formats.forEach((format: string) => {
if (this._sources && this._sources[format] && this._sources[format].length === 0) {
delete this._sources[format];
Expand Down
6 changes: 3 additions & 3 deletions src/common/playlist/playlist-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlaylistManager {
*/
configure(config: ?KPPlaylistObject, entryList: ?ProviderEntryListObject) {
if (config) {
this._playlist.configure(config);
this._playlist.configure(config, Utils.Object.getPropertyPath(this._player.config, 'sources.options'));
Utils.Object.mergeDeep(this._options, config.options);
Utils.Object.mergeDeep(this._countdown, config.countdown);
if (config.items && config.items.find(item => !!item.sources)) {
Expand Down Expand Up @@ -273,8 +273,8 @@ class PlaylistManager {
this._player.configure({
sources: activeItem.sources
});
return this._player.loadMedia(this._mediaInfoList[index]).then(mediaConfig => {
this._playlist.updateItemSources(index, mediaConfig.sources);
return this._player.loadMedia(this._mediaInfoList[index]).then(() => {
this._playlist.updateItemSources(index, this._player.config.sources);
this._player.dispatchEvent(new FakeEvent(PlaylistEventType.PLAYLIST_ITEM_CHANGED, {index, activeItem}));
});
}
Expand Down
10 changes: 8 additions & 2 deletions src/common/playlist/playlist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import {PlaylistItem} from './playlist-item';
import {Utils} from '@playkit-js/playkit-js';

class Playlist {
_id: string;
Expand All @@ -16,19 +17,24 @@ class Playlist {
this._activeItemIndex = -1;
}

configure(config: KPPlaylistObject) {
configure(config: KPPlaylistObject, sourcesOptions: ?PKMediaSourceOptionsObject) {
this._id = config.id;
this._poster = config.poster;
this._metadata = config.metadata;
if (config.items) {
this._items = [];
config.items.forEach(item => {
if (item.sources) {
const configSourcesOptions = Utils.Object.mergeDeep({}, sourcesOptions);
const itemSourcesOptions = item.sources.options || {};
item.sources.options = Utils.Object.mergeDeep(configSourcesOptions, itemSourcesOptions);
}
this._items.push(new PlaylistItem(item.sources, item.config));
});
}
}

updateItemSources(index: number, sourcesObject: ProviderMediaConfigSourcesObject) {
updateItemSources(index: number, sourcesObject: PKSourcesConfigObject) {
this._items[index].updateSources(sourcesObject);
}

Expand Down
18 changes: 18 additions & 0 deletions test/src/common/playlist/playlist-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@ describe('PlaylistManager', function () {
});
playlistManager.configure(PlaylistMockData.playlistByConfig);
});

it('should set the configured sources.options for all items', function () {
kalturaPlayer.configure({sources: {options: {forceRedirectExternalStreams: true, redirectExternalStreamsHandler: () => 1}}});
playlistManager.configure({items: [{sources: {}}, {sources: {}}]});
playlistManager.items.forEach(item => item.sources.options.forceRedirectExternalStreams.should.be.true);
playlistManager.items.forEach(item => (item.sources.options.redirectExternalStreamsHandler() === 1).should.be.true);
});

it('should prefer the item configuration before the sources.options', function () {
kalturaPlayer.configure({sources: {options: {forceRedirectExternalStreams: true, redirectExternalStreamsHandler: () => 1}}});
playlistManager.configure({
items: [{sources: {options: {forceRedirectExternalStreams: false}}}, {sources: {options: {redirectExternalStreamsHandler: () => 2}}}]
});
playlistManager.items[0].sources.options.forceRedirectExternalStreams.should.be.false;
playlistManager.items[1].sources.options.forceRedirectExternalStreams.should.be.true;
(playlistManager.items[0].sources.options.redirectExternalStreamsHandler() === 1).should.be.true;
(playlistManager.items[1].sources.options.redirectExternalStreamsHandler() === 2).should.be.true;
});
});

describe('load', function () {
Expand Down

0 comments on commit 77e86ec

Please sign in to comment.