src/register.js
/**
 * Register contrib-ads with Video.js, but provide protection for duplicate
 * copies of the plugin. This could happen if, for example, a stitched ads
 * plugin and a client-side ads plugin are included simultaneously with their
 * own copies of contrib-ads.
 *
 * If contrib-ads detects a pre-existing duplicate, it will not register
 * itself.
 *
 * Ad plugins using contrib-ads and anticipating that this could come into
 * effect should verify that the contrib-ads they are using is of a compatible
 * version.
 *
 * @param  {Function} contribAdsPlugin
 *         The plugin function.
 *
 * @return {boolean}
 *         When `true`, the plugin was registered. When `false`, the plugin
 *         was not registered.
 */
Register contrib-ads with Video.js, but provide protection for duplicate
copies of the plugin. This could happen if, for example, a stitched ads
plugin and a client-side ads plugin are included simultaneously with their
own copies of contrib-ads.

If contrib-ads detects a pre-existing duplicate, it will not register
itself.

Ad plugins using contrib-ads and anticipating that this could come into
effect should verify that the contrib-ads they are using is of a compatible
version.

@param  {Function} contribAdsPlugin
The plugin function.

@return {boolean}
When `true`, the plugin was registered. When `false`, the plugin
was not registered.
Register contrib - ads with Video . js but provide protection for duplicate copies of the plugin . This could happen if for example a stitched ads plugin and a client - side ads plugin are included simultaneously with their own copies of contrib - ads . If contrib - ads detects a pre - existing duplicate it will not register itself . Ad plugins using contrib - ads and anticipating that this could come into effect should verify that the contrib - ads they are using is of a compatible version . @param { Function } contribAdsPlugin The plugin function . @return { boolean } When ` true ` the plugin was registered . When ` false ` the plugin was not registered .
function register(contribAdsPlugin) {
  if (hasAdsPlugin(videojs)) {
    return false;
  }
  const registerPlugin = videojs.registerPlugin || videojs.plugin;
  registerPlugin('ads', contribAdsPlugin);
  if (isMiddlewareMediatorSupported() && !videojs.usingContribAdsMiddleware_) {
    videojs.use('*', playMiddleware);
    videojs.usingContribAdsMiddleware_ = true;
    videojs.log.debug('Play middleware has been registered with videojs');
  }
  return true;
}
function register ( contribAdsPlugin ) { if ( hasAdsPlugin ( videojs ) ) { return false ; } const registerPlugin = videojs . registerPlugin || videojs . plugin ; registerPlugin ( 'ads' , contribAdsPlugin ) ; if ( isMiddlewareMediatorSupported ( ) && ! videojs . usingContribAdsMiddleware_ ) { videojs . use ( '*' , playMiddleware ) ; videojs . usingContribAdsMiddleware_ = true ; videojs . log . debug ( 'Play middleware has been registered with videojs' ) ; } return true ; }
Register contrib-ads with Video.js, but provide protection for duplicate
 copies of the plugin.
Register contrib - ads with Video . js but provide protection for duplicate copies of the plugin .
// If the ads plugin already exists, do not overwrite it. // Cross-compatibility with Video.js 6/7 and 5. // Register this plugin with Video.js. // Register the play middleware with Video.js on script execution, // to avoid a new playMiddleware factory being added for each player. // The `usingContribAdsMiddleware_` flag is used to ensure that we only ever // register the middleware once - despite the ability to de-register and // re-register the plugin itself. // Register the play middleware