Skip to content

Commit

Permalink
fix(FEC-10806): playlist has limitation which configure cause setMedia (
Browse files Browse the repository at this point in the history
#390)

Issue: setMedia called before plugins initialize.
Solution: split the configure for one without sources and another one after with sources, as we do for sources as well.
  • Loading branch information
Yuvalke committed Dec 27, 2020
1 parent bfa458b commit c5caeda
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/common/playlist/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Playlist {
}

configure(config: KPPlaylistObject, sourcesOptions: ?PKMediaSourceOptionsObject) {
this._id = config.id;
this._poster = config.poster;
this._metadata = config.metadata;
this._id = config.id ? config.id : this._id;
this._poster = config.poster ? config.poster : this._poster;
this._metadata = config.metadata ? config.metadata : this._metadata;
if (config.items) {
this._items = [];
config.items.forEach(item => {
Expand Down
4 changes: 3 additions & 1 deletion src/kaltura-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ class KalturaPlayer extends FakeEventTarget {
this._playlistManager = new PlaylistManager(this, options);
Object.values(CoreEventType).forEach(coreEvent => this._eventManager.listen(this._localPlayer, coreEvent, e => this.dispatchEvent(e)));
this._addBindings();
this._playlistManager.configure(options.playlist);
this._playlistManager.configure(Utils.Object.mergeDeep({}, options.playlist, {items: null}));
this.configure({plugins});
//configure sources after configure finished for all components - making sure all we'll set up correctly
this._playlistManager.configure({items: (options.playlist && options.playlist.items) || []});
this._localPlayer.configure({sources: sources || {}});
}

Expand Down
82 changes: 81 additions & 1 deletion test/src/kaltura-player.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ColorsPlugin from './common/plugin/test-plugins/colors-plugin';
import NumbersPlugin from './common/plugin/test-plugins/numbers-plugin';
import {KalturaPlayer as Player} from '../../src/kaltura-player';
import SourcesConfig from './configs/sources';
import {FakeEvent, Utils} from '@playkit-js/playkit-js';
import {EventType as CoreEventType, FakeEvent, Utils, EventManager} from '@playkit-js/playkit-js';
import AsyncResolvePlugin from './common/plugin/test-plugins/async-resolve-plugin';
import AsyncRejectPlugin from './common/plugin/test-plugins/async-reject-plugin';
import {Provider} from 'playkit-js-providers';
Expand Down Expand Up @@ -626,6 +626,86 @@ describe('kaltura player api', function () {
}
});
});

it('should create the plugin before playlist source selected', function () {
const eventManager = new EventManager();
player = new Player({
ui: {},
provider: {},
playlist: {
id: '1234',
metdata: {},
items: [
{
sources: SourcesConfig.Mp4
}
]
},
plugins: {
numbers: {
size: 2,
firstCellValue: 3
}
}
});
eventManager.listen(player, CoreEventType.SOURCE_SELECTED, () => {
player._pluginManager.get('numbers').should.exist;
Object.keys(player._pluginManager._plugins).length.should.equals(1);
player.config.plugins.should.deep.equals({
numbers: {
size: 2,
firstCellValue: 3,
lastCellValue: 6
}
});
});
});

it('should create player with plugin and fail to configure other plugin after playlist source selected', function () {
player = new Player({
ui: {},
provider: {},
playlist: {
id: '1234',
metdata: {},
items: [
{
sources: SourcesConfig.Mp4
}
]
},
plugins: {
numbers: {
size: 2,
firstCellValue: 3
}
}
});
player._pluginManager.get('numbers').should.exist;
Object.keys(player._pluginManager._plugins).length.should.equals(1);
player.config.plugins.should.deep.equals({
numbers: {
size: 2,
firstCellValue: 3,
lastCellValue: 6
}
});
player.configure({
plugins: {
colors: {
size: 200
}
}
});
Object.keys(player._pluginManager._plugins).length.should.equals(1);
player.config.plugins.should.deep.equals({
numbers: {
size: 2,
firstCellValue: 3,
lastCellValue: 6
}
});
});
});

describe('async plugins loading', () => {
Expand Down

0 comments on commit c5caeda

Please sign in to comment.