Skip to content

Commit

Permalink
Merge pull request #518 from cloudinary/ME-14384-lazy-recommendations
Browse files Browse the repository at this point in the history
ME-14384-lazy-recommendations
  • Loading branch information
tsi authored Jan 23, 2024
2 parents c113584 + 0c54b10 commit cd13389
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import JumpForwardButton from './jumpButtons/jump-10-plus';
import JumpBackButton from './jumpButtons/jump-10-minus';
import LogoButton from './logoButton/logo-button';
import ProgressControlEventsBlocker from './progress-control-events-blocker/progress-control-events-blocker';
import RecommendationsOverlay from './recommendations-overlay';
import ShoppablePanel from './shoppable-bar/panel/shoppable-panel';
import TitleBar from './title-bar/title-bar';

Expand All @@ -11,7 +10,6 @@ export {
JumpBackButton,
LogoButton,
ProgressControlEventsBlocker,
RecommendationsOverlay,
ShoppablePanel,
TitleBar
};
14 changes: 11 additions & 3 deletions src/components/recommendations-overlay/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import RecommendationsOverlay from './recommendations-overlay';

export default RecommendationsOverlay;
export default async function lazyRecommendationsOverlayComponent(player) {
try {
if (!player.getChild('recommendationsOverlay')) {
await import(/* webpackChunkName: "recommendations-overlay" */ './recommendations-overlay');
player.addChild('recommendationsOverlay');
}
return player;
} catch (error) {
console.error('Failed to load plugin:', error);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import videojs from 'video.js';
import RecommendationsOverlayItem from './recommendations-overlay-item';
import componentUtils from '../component-utils';
import componentUtils from 'components/component-utils';

// support VJS5 & VJS6 at the same time
const dom = videojs.dom || videojs;
Expand Down
14 changes: 9 additions & 5 deletions src/plugins/cloudinary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import VideoSource from './models/video-source/video-source';
import EventHandlerRegistry from './event-handler-registry';
import AudioSource from './models/audio-source/audio-source';

import recommendationsOverlay from 'components/recommendations-overlay';

const DEFAULT_PARAMS = {
transformation: {},
sourceTypes: [],
Expand All @@ -27,9 +29,7 @@ export const CONSTRUCTOR_PARAMS = ['cloudinaryConfig', 'transformation',
'sourceTypes', 'sourceTransformation', 'posterOptions', 'autoShowRecommendations'];

class CloudinaryContext {

constructor(player, options = {}) {

setupCloudinaryMiddleware();

this.player = player;
Expand Down Expand Up @@ -74,7 +74,11 @@ class CloudinaryContext {
if (options.recommendationOptions) {
({ disableAutoShow, itemBuilder } = sliceAndUnsetProperties(options.recommendationOptions, 'disableAutoShow', 'itemBuilder'));
}
setRecommendations(recommendations, { disableAutoShow, itemBuilder });

recommendationsOverlay(player).then(() => {
setRecommendations(recommendations, { disableAutoShow, itemBuilder });
});

} else {
unsetRecommendations();
}
Expand Down Expand Up @@ -227,7 +231,7 @@ class CloudinaryContext {
}
};

this.one('cldsourcechanged', _recommendations.sourceChangedHandler);
_recommendations.sourceChangedHandler();

_recommendations.endedHandler = () => {
if (!disableAutoShow && this.autoShowRecommendations()) {
Expand Down Expand Up @@ -364,7 +368,7 @@ class CloudinaryContext {
}
}

export default function(options = {}) {
export default function (options = {}) {
options.chainTarget = options.chainTarget || this;
this.cloudinary = new CloudinaryContext(this, options);
}
1 change: 0 additions & 1 deletion src/video-player.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const overrideDefaultVideojsComponents = () => {

// Add TitleBar as default
children.push('titleBar');
children.push('recommendationsOverlay');

const ControlBar = videojs.getComponent('ControlBar');
if (ControlBar) {
Expand Down

0 comments on commit cd13389

Please sign in to comment.