Skip to content

Commit

Permalink
fix(FEC-14362): add disableChapters api (#49)
Browse files Browse the repository at this point in the history
**the issue:**
when playkit-unisphere plugin loads summary & chapters widget, but the chapters data is empty, "regular" chapters are not shown on timeline (if exist).

**root cause:**
when fetching VOD data, we exclude Chapter cuepoints from the request in case Summary cuepoint was registered.

**solution:**
- remove Summary cuepoint type
- do not exclude Chapter cuepoints from the filter request

Resolves FEC-14362
  • Loading branch information
lianbenjamin authored Feb 24, 2025
1 parent c4e0fe6 commit f5983d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/timeline-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TimelineManager {
_resolveTimelineDurationPromise = () => {};
_timelineDurationPromise: Promise<void>;
_getThumbnailInfoFn: (virtualTime: number) => ThumbnailInfo | Array<ThumbnailInfo>;
_shouldIncludeChapters: boolean;

/**
* @constructor
Expand All @@ -52,6 +53,7 @@ class TimelineManager {
this._cuePointsMap = new Map();
this._timelineDurationPromise = this._makeTimelineDurationPromise();
this._getThumbnailInfoFn = this._player.getThumbnail.bind(this._player);
this._shouldIncludeChapters = true;
}

get _uiManager() {
Expand All @@ -61,6 +63,12 @@ class TimelineManager {
return this._store.getState();
}

public disableChapters() {
this._shouldIncludeChapters = false;
// if there are chapters, reset the array
this._chapters = [];
}

public get timelineManagerAPI() {
return {
loadMedia: this.loadMedia,
Expand All @@ -75,6 +83,7 @@ class TimelineManager {
},
addSeekBarPreview: this._addSeekBarPreview,
reset: () => this.reset(),
disableChapters: () => this.disableChapters(),
// Expose entire timelineManager for testing purposes
...((window as any)._TEST_ENV ? {timelineManager: this} : {})
};
Expand Down Expand Up @@ -122,8 +131,12 @@ class TimelineManager {
// @ts-ignore
const {clipTo, seekFrom} = this._player.sources;
let duration = this._player.sources.duration;
if (clipTo && typeof seekFrom === 'number') {
duration = clipTo - seekFrom;
if (clipTo) {
if (typeof seekFrom === 'number' && seekFrom > 0) {
duration = clipTo - seekFrom;
} else {
duration = clipTo;
}
} else if (!clipTo && seekFrom && duration) {
duration = duration - seekFrom;
}
Expand Down Expand Up @@ -201,12 +214,16 @@ class TimelineManager {
title?: string,
cuePointData?: QuizQuestionData | NavigationChapterData | any
) => {
if (this._state.shell.playerSize === PLAYER_SIZE.TINY || this._uiManager.store.getState().seekbar.isPreventSeek) {
if (
this._state.shell.playerSize === PLAYER_SIZE.TINY ||
this._uiManager.store.getState().seekbar.isPreventSeek ||
(type === ItemTypes.Chapter && !this._shouldIncludeChapters)
) {
return;
}
// wait for the duration to be correct and stable
this._timelineDurationPromise.then(() => {
if (type === ItemTypes.Chapter) {
if (type === ItemTypes.Chapter || type === ItemTypes.SummaryAndChapters) {
const chapter: Chapter = {
type: ItemTypes.Chapter,
id: cuePointId,
Expand Down Expand Up @@ -439,6 +456,7 @@ class TimelineManager {
this._store.dispatch(actions.updateSeekbarSegments([]));
this._chapters = [];
}
this._shouldIncludeChapters = true;
};

private _getThumbnailInfo(virtualTime: number): ThumbnailInfo | Array<ThumbnailInfo> {
Expand Down
3 changes: 2 additions & 1 deletion src/types/timelineTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ export enum ItemTypes {
AnswerOnAir = 'AnswerOnAir',
Chapter = 'Chapter',
Hotspot = 'Hotspot',
QuizQuestion = 'QuizQuestion'
QuizQuestion = 'QuizQuestion',
SummaryAndChapters = 'SummaryAndChapters',
}

0 comments on commit f5983d4

Please sign in to comment.