Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: lazy validators (ME-15925) #606

Merged
merged 8 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/plugins/ima/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default async function imaPlugin(player, playerOptions) {

if (playerOptions.ads && (!loaded.contribAdsLoaded || !loaded.imaAdsLoaded)) {
if (!loaded.contribAdsLoaded) {
console.log('contribAds is not loaded');
console.warn('contribAds is not loaded');
}
if (!loaded.imaAdsLoaded) {
console.log('imaSdk is not loaded');
console.warn('imaSdk is not loaded');
}
return false;
}
Expand All @@ -33,6 +33,8 @@ export default async function imaPlugin(player, playerOptions) {
debug: playerOptions.ads.denug
});

debugger; // eslint-disable-line

if (Object.keys(playerOptions.ads).length > 0 && typeof player.ima === 'object') {
if (playerOptions.ads.adsInPlaylist === 'first-video') {
player.one(PLAYER_EVENT.SOURCE_CHANGED, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class SourceMenuButton extends MenuButton {
}

// Bind update to qualityLevels changes
// Todo: switch to Function.prototype.bind
this.player_.qualityLevels().on(['change', 'addqualitylevel', 'removequalitylevel'], videojs.bind(this, this.update));
this.player_.qualityLevels().on(['change', 'addqualitylevel', 'removequalitylevel'], this.update.bind(this));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppress a deprecation console warning regarding videojs.bind

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsi is it riksy? because our assumption was that this PR would be focusing on very minimal risk stuff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, but let's wait with it till next release

}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/utils/cloudinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const setError = (that, res) => {
};

const setVideoSrc = (that, srcs) => {
console.log('Trying sources: ', srcs);
if (that.options.playerOptions.debug) {
console.log('Trying sources: ', srcs);
}
srcs.forEach(s => {
s.try = true;
});
Expand Down
22 changes: 22 additions & 0 deletions src/validators/validators-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,25 @@ export const isValidConfig = (config, validators) => {

return true;
};

/**
* check if a configuration object is valid or not
* @param {object} config - a config object
* @returns boolean - true is the configuration object is valid and false if it is not
*/
export const isValidPlayerConfig = async (config) => {
return import(/* webpackChunkName: "validators" */ './validators').then(({playerValidators}) => {
return isValidConfig(config, playerValidators);
});
};

/**
* check if a configuration object is valid or not
* @param {object} config - a config object
* @returns boolean - true is the configuration object is valid and false if it is not
*/
export const isValidSourceConfig = (config) => {
return import(/* webpackChunkName: "validators" */ './validators').then(({sourceValidators}) => {
return isValidConfig(config, sourceValidators);
});
};
1 change: 1 addition & 0 deletions src/validators/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const playerValidators = {
}
},
playerOptions: {
debug: validator.isBoolean,
queryParams: validator.isPlainObject,
publicId: validator.isString,
fluid: validator.isBoolean,
Expand Down
1 change: 1 addition & 0 deletions src/video-player.const.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const CLOUDINARY_PARAMS = [
];

export const PLAYER_PARAMS = CLOUDINARY_PARAMS.concat([
'debug',
'publicId',
'source',
'autoplayMode',
Expand Down
31 changes: 16 additions & 15 deletions src/video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
overrideDefaultVideojsComponents
} from './video-player.utils';
import { FLOATING_TO, FLUID_CLASS_NAME } from './video-player.const';
import { isValidConfig } from './validators/validators-functions';
import { playerValidators, sourceValidators } from './validators/validators';
import { isValidPlayerConfig, isValidSourceConfig } from './validators/validators-functions';
import { PLAYER_EVENT, SOURCE_TYPE } from './utils/consts';
import { getAnalyticsFromPlayerOptions } from './utils/get-analytics-player-options';
import { extendCloudinaryConfig, normalizeOptions, isRawUrl } from './plugins/cloudinary/common';
Expand Down Expand Up @@ -72,14 +71,15 @@ class VideoPlayer extends Utils.mixin(Eventable) {

this.videojs = videojs(this.videoElement, this._videojsOptions);

// to do, should be change by isValidConfig
this._isPlayerConfigValid = true;

isValidConfig(this.options, playerValidators);

if (!this._isPlayerConfigValid) {
this.videojs.error('invalid player configuration');
return;
if (this.playerOptions.debug) {
isValidPlayerConfig(this.options).then((valid) => {
if (!valid) {
this._isPlayerConfigValid = valid;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not set it directly to false?

this.videojs.error('invalid player configuration');
return;
}
});
}

if (this._videojsOptions.muted) {
Expand Down Expand Up @@ -390,7 +390,7 @@ class VideoPlayer extends Utils.mixin(Eventable) {
_initAnalytics() {
const analyticsOpts = this.playerOptions.analytics;

if (!window.ga && analyticsOpts) {
if (!window.ga && analyticsOpts && this.playerOptions.debug) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For later i think it is better to create an abstract that wraps the console.error statement and considers the debug mode.

console.error('Google Analytics script is missing');
return;
}
Expand Down Expand Up @@ -528,11 +528,12 @@ class VideoPlayer extends Utils.mixin(Eventable) {
return;
}

const isSourceConfigValid = isValidConfig(options, sourceValidators);

if (!isSourceConfigValid) {
this.videojs.error('invalid source configuration');
return;
if (this.playerOptions.debug) {
isValidSourceConfig(options).then((valid) => {
if (!valid) {
this.videojs.error('invalid source configuration');
}
});
}

this._sendInternalAnalytics({ source: options });
Expand Down
Loading