Skip to content

Commit

Permalink
feat(FEC-8623): playlist countdown (#164)
Browse files Browse the repository at this point in the history
* handle auto continue only when the ui countdown doesn't exist 
* expose `playlist.countdown getter`
  • Loading branch information
yairans authored Nov 5, 2018
1 parent 6ae6253 commit bc7eb33
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
41 changes: 33 additions & 8 deletions src/common/playlist/playlist-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class PlaylistManager {

_player: KalturaPlayer;
_playlist: Playlist;
_playerOptions: KPOptionsObject;
_options: KPPlaylistOptions;
_countdown: KPPlaylistCountdownOptions;

Expand All @@ -19,7 +20,8 @@ class PlaylistManager {
this._playlist = new Playlist();
this._options = {autoContinue: true};
this._countdown = {duration: 10, showing: true};
this.configure(options.playlist);
this._playerOptions = options;
this.configure(this._playerOptions.playlist);
this.addBindings();
}

Expand All @@ -39,13 +41,15 @@ class PlaylistManager {
}

addBindings() {
this._player.addEventListener(
this._player.Event.Core.PLAYBACK_ENDED,
() =>
this._playlist.next
? this._options.autoContinue && this.playNext()
: this._player.dispatchEvent(new FakeEvent(PlaylistEventType.PLAYLIST_ENDED))
);
this._player.addEventListener(this._player.Event.Core.PLAYBACK_ENDED, () => this._onPlaybackEnded());
}

_onPlaybackEnded(): void {
if (this._playerOptions.ui.disable || !this.countdown.showing) {
this._playlist.next
? this._options.autoContinue && this.playNext()
: this._player.dispatchEvent(new FakeEvent(PlaylistEventType.PLAYLIST_ENDED));
}
}

_setItem(activeItem: PlaylistItem, index: number): Promise<*> {
Expand Down Expand Up @@ -107,6 +111,27 @@ class PlaylistManager {
return this._playlist.prev.item;
}

get id(): string {
return this._playlist.id;
}

get metadata(): KPPlaylistMetadata {
return this._playlist.metadata;
}

get countdown(): KPPlaylistCountdownOptions {
if (this._playlist.current.item && this._playlist.current.item.config) {
const mergedConfig: KPPlaylistCountdownOptions = {duration: 10, showing: true};
Utils.Object.mergeDeep(mergedConfig, this._countdown, this._playlist.current.item.config.countdown);
return mergedConfig;
}
return this._countdown;
}

get options(): KPPlaylistOptions {
return this._options;
}

reset() {
this._playlist = new Playlist();
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/playlist/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Playlist {
return this._metadata;
}

get current(): {item: ?PlaylistItem, index: number} {
return {item: this.items[this._activeItemIndex] || null, index: this._activeItemIndex};
}

get next(): {item: ?PlaylistItem, index: number} {
return {item: this.items[this._activeItemIndex + 1] || null, index: this._activeItemIndex + 1};
}
Expand Down
29 changes: 13 additions & 16 deletions src/kaltura-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ class KalturaPlayer extends FakeEventTarget {
);
}

// $FlowFixMe
_mergePlaylistConfigAndSet(playlistConfigFromAPI: KPPlaylistConfigObject, playlistOptions: KPPlaylistConfigObject = {}): void {
playlistOptions.items = playlistConfigFromAPI.items.map((item, index) => {
return {
sources: item.sources,
config: playlistOptions.items && playlistOptions.items[index] && playlistOptions.items[index].config
};
});
Utils.Object.mergeDeep(playlistConfigFromAPI, playlistOptions);
this.setPlaylist(playlistConfigFromAPI);
}

setPlaylist(playlistConfig: KPPlaylistConfigObject): void {
this._logger.debug('setPlaylist', playlistConfig);
const config = {playlist: playlistConfig, plugins: this._localPlayer.config.plugins};
Expand All @@ -130,10 +118,6 @@ class KalturaPlayer extends FakeEventTarget {
this._playlistManager.configure(config.playlist);
}

get playlist(): PlaylistManager {
return this._playlistManager;
}

getMediaInfo(): ?ProviderMediaInfoObject {
return Utils.Object.copyDeep(this._mediaInfo);
}
Expand Down Expand Up @@ -408,6 +392,10 @@ class KalturaPlayer extends FakeEventTarget {
return this._localPlayer.plugins;
}

get playlist(): PlaylistManager {
return this._playlistManager;
}

get Event(): KPEventTypes {
return {
Cast: CastEventType,
Expand Down Expand Up @@ -458,6 +446,15 @@ class KalturaPlayer extends FakeEventTarget {
get Error(): typeof Error {
return this._localPlayer.Error;
}

// $FlowFixMe
_mergePlaylistConfigAndSet(playlistConfigFromAPI: KPPlaylistConfigObject, playlistOptions: KPPlaylistConfigObject = {}): void {
playlistOptions.items = playlistConfigFromAPI.items.map((item, index) => {
return {sources: item.sources, config: playlistOptions.items && playlistOptions.items[index] && playlistOptions.items[index].config};
});
Utils.Object.mergeDeep(playlistConfigFromAPI, playlistOptions);
this.setPlaylist(playlistConfigFromAPI);
}
}

export {KalturaPlayer};

0 comments on commit bc7eb33

Please sign in to comment.