UNPKG

@brightcove/player-loader

Version:

An asynchronous script loader for the Brightcove Player.

4 lines (3 loc) 8.46 kB
/*! @name @brightcove/player-loader @version 1.8.0 @license Apache-2.0 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("global/document"),require("global/window")):"function"==typeof define&&define.amd?define(["global/document","global/window"],t):(e=e||self).brightcovePlayerLoader=t(e.document,e.window)}(this,function(e,t){"use strict";function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=["catalogSearch","catalogSequence"],i=["adConfigId","applicationId","catalogSearch","catalogSequence","playlistId","playlistVideoId","videoId"],a=function(e){return Object.keys(e).filter(function(e){return-1!==i.indexOf(e)}).reduce(function(t,n){var r=function(e,t){if(e&&void 0!==e[t]){if("string"!=typeof e[t]&&-1!==o.indexOf(t))try{return encodeURIComponent(JSON.stringify(e[t]))}catch(e){return}return encodeURIComponent(String(e[t]).trim())||void 0}}(e,n);return void 0!==r&&(t+=t?"&":"?",t+=encodeURIComponent(n)+"="+r),t},"")},d=function(e){var t=e.accountId,n=e.base,o=void 0===n?"https://players.brightcove.net":n,i=e.playerId,d=void 0===i?"default":i,c=e.embedId,l=void 0===c?"default":c,u=e.iframe,s=void 0!==u&&u,f=e.minified,p=void 0===f||f,m=e.queryParams,y=void 0===m?null:m,b="";s?b+="html":(p&&(b+="min."),b+="js"),"/"===o.charAt(o.length-1)&&(o=o.substring(0,o.length-1));var v="";return s&&y&&"object"===(void 0===y?"undefined":r(y))&&(v=a(y)),o+"/"+(t=encodeURIComponent(t))+"/"+(d=encodeURIComponent(d))+"_"+(l=encodeURIComponent(l))+"/index."+b+v}; /*! @name @brightcove/player-url @version 1.2.0 @license Apache-2.0 */d.VERSION="1.2.0";var c={embedId:"default",embedType:"in-page",playerId:"default",Promise:t.Promise,refNodeInsert:"append"},l="video",u="video-js",s="in-page",f="iframe",p="append",m="prepend",y="before",b="after",v="replace",E=["catalogSearch","catalogSequence"],h="https://players.brightcove.net/",g=function(e){if(e.playerUrl)return e.playerUrl;var t=e.accountId,n=e.playerId,r=e.embedId,o=e.embedOptions,i=e.embedType===f;return d({accountId:t,playerId:n,embedId:r,iframe:i,base:h,minified:!o||!o.unminified,queryParams:e})},I=function(){return h},N=function(e){h=e},O=function(e){return Boolean(e&&1===e.nodeType)},w=function(e){return Boolean(O(e)&&e.parentNode)},_=function(t,r,o){return r?function(t,n){if(!t.pip)return n;var r=e.createElement("div");return r.classList.add("vjs-pip-container"),r.appendChild(n),r}(r,function(t,r,o){if(!r.responsive)return o;o.style.position="absolute",o.style.top="0px",o.style.right="0px",o.style.bottom="0px",o.style.left="0px",o.style.width="100%",o.style.height="100%";var i=n({aspectRatio:"16:9",iframeHorizontalPlaylist:!1,maxWidth:"100%"},r.responsive),a=i.aspectRatio.split(":").map(Number),d=e.createElement("div"),c=a[1]/a[0]*100;t===f&&i.iframeHorizontalPlaylist&&(c*=1.25),d.style.paddingTop=c+"%",d.appendChild(o);var l=e.createElement("div");return l.style.position="relative",l.style.display="block",l.style.maxWidth=i.maxWidth,l.appendChild(d),l}(t,r,o)):o},R=function(t){return function(t,n){var r=t.refNode,o=t.refNodeInsert,i=r.parentNode,a=_(t.embedType,t.embedOptions,n);if(o===y?i.insertBefore(a,r):o===b?i.insertBefore(a,r.nextElementSibling||null):o===v?i.replaceChild(a,r):o===m?r.insertBefore(a,r.firstChild||null):r.appendChild(a),t.embedOptions&&t.embedOptions.playlist){var d=t.embedOptions.playlist.legacy?"ul":"div",c=e.createElement(d);c.classList.add("vjs-playlist"),n.parentNode.insertBefore(c,n.nextElementSibling||null)}return t.refNode=null,n}(t,function(e,t){if("function"!=typeof e.onEmbedCreated)return t;var n=e.onEmbedCreated(t);return O(n)?n:t}(t,t.embedType===f?function(t){var n=e.createElement("iframe");return n.setAttribute("allow","autoplay;encrypted-media;fullscreen"),n.setAttribute("allowfullscreen","allowfullscreen"),n.src=g(t),n}(t):function(t){var n=t.embedOptions,r={adConfigId:"data-ad-config-id",applicationId:"data-application-id",catalogSearch:"data-catalog-search",catalogSequence:"data-catalog-sequence",deliveryConfigId:"data-delivery-config-id",playlistId:"data-playlist-id",playlistVideoId:"data-playlist-video-id",poster:"poster",videoId:"data-video-id"},o=n&&n.tagName||u,i=e.createElement(o);return Object.keys(r).filter(function(e){return t[e]}).forEach(function(e){var n;if("string"!=typeof t[e]&&-1!==E.indexOf(e))try{n=JSON.stringify(t[e])}catch(e){return}else n=String(t[e]).trim();i.setAttribute(r[e],n)}),i.setAttribute("controls","controls"),i.classList.add("video-js"),i}(t)))},S=new t.Map,P=function(e){return(e.accountId||"*")+"_"+e.playerId+"_"+e.embedId},C=function(){S.clear()},A=function(e){S.forEach(e)},j=function(e){return S.has(P(e))},T=function(e){S.set(P(e),e.accountId?g(e):"")},x=/^([A-Za-z0-9]+)_([A-Za-z0-9]+)$/,D=function(){return t.bc?Object.keys(t.bc).filter(function(e){return x.test(e)}):[]},B=function(e){e&&Object.keys(e.players).forEach(function(t){var n=e.players[t];n&&n.dispose()})},q=function(){A(function(t,n){t&&Array.prototype.slice.call(e.querySelectorAll('script[src="'+t+'"]')).forEach(function(e){return e.parentNode.removeChild(e)})}),C(),B(t.videojs),D().forEach(function(e){return B(t.bc[e].videojs)}),Object.keys(t).filter(function(e){return/^videojs/i.test(e)||/^(bc)$/.test(e)}).forEach(function(e){delete t[e]})};(function(){D().forEach(function(e){var t=e.match(x),n={playerId:t[1],embedId:t[2]};j(n)||T(n)})})();var U=function(e){return"function"==typeof e},F=function(e){var t,n=e.accountId,r=e.embedOptions,o=e.embedType,i=e.options,a=e.refNode,d=e.refNodeInsert;if(!n)throw new Error("accountId is required");if(!w(a))throw new Error("refNode must resolve to a node attached to the DOM");if(!function(e){return e===s||e===f}(o))throw new Error("embedType is missing or invalid");if(o===f&&i)throw new Error("cannot use options with an iframe embed");if(r&&void 0!==r.tagName&&((t=r.tagName)!==u&&t!==l))throw new Error('embedOptions.tagName is invalid (value: "'+r.tagName+'")');if(r&&r.responsive&&r.responsive.aspectRatio&&!/^\d+\:\d+$/.test(r.responsive.aspectRatio))throw new Error('embedOptions.responsive.aspectRatio must be in the "n:n" format (value: "'+r.responsive.aspectRatio+'")');if(!function(e){return e===p||e===m||e===y||e===b||e===v}(d))throw new Error("refNodeInsert is missing or invalid")},M=function(e,n,r,o){var i,a=e.embedId,d=e.playerId,c=t.bc[d+"_"+a]||t.bc;if(!c)return o(new Error("missing bc function for "+d));T(e);try{(i=c(n,e.options)).bcinfo&&(i.bcinfo.PLAYER_LOADER=!0)}catch(t){var l="Could not initialize the Brightcove Player.";return e.embedOptions.tagName===u&&(l+=' You are attempting to embed using a "video-js" element. Please ensure that your Player is v6.11.0 or newer in order to support this embed type. Alternatively, pass `"video"` for `embedOptions.tagName`.'),o(new Error(l))}r({type:s,ref:i})},L=function(t,n,r){t.refNode=function(t){return w(t)?t:"string"==typeof t?e.querySelector(t):null}(t.refNode),F(t);var o=t.refNode,i=t.refNodeInsert,a=o.parentNode,d=R(t);if(t.embedType!==f){if(j(t))return M(t,d,n,r);var c=e.createElement("script");c.onload=function(){return M(t,d,n,r)},c.onerror=function(){r(new Error("player script could not be downloaded"))},c.async=!0,c.charset="utf-8",c.src=g(t),i===v?a.appendChild(c):o.appendChild(c)}else n({type:f,ref:d})},k=function(e){var t=n({},c,e),r=t.Promise,o=t.onSuccess,i=t.onFailure;return!U(r)||U(o)||U(i)?L(t,U(o)?o:function(){},U(i)?i:function(e){throw e}):new r(function(e,n){return L(t,e,n)})},V=function(e,t){Object.defineProperty(k,e,{configurable:!1,enumerable:!0,value:t,writable:!1})};return V("getBaseUrl",function(){return I()}),V("setBaseUrl",function(e){N(e)}),V("getUrl",function(e){return g(e)}),V("reset",function(){return q()}),[["EMBED_TAG_NAME_VIDEO",l],["EMBED_TAG_NAME_VIDEOJS",u],["EMBED_TYPE_IN_PAGE",s],["EMBED_TYPE_IFRAME",f],["REF_NODE_INSERT_APPEND",p],["REF_NODE_INSERT_PREPEND",m],["REF_NODE_INSERT_BEFORE",y],["REF_NODE_INSERT_AFTER",b],["REF_NODE_INSERT_REPLACE",v],["VERSION","1.8.0"]].forEach(function(e){V(e[0],e[1])}),k});