!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VideoPressIframeApi=t():e.VideoPressIframeApi=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function n(e){return n="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},n(e)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);nc});const c=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o="channel_init",s=i((function e(t){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a(this,"initListener",(function(){var e=0,t=Math.random().toString(36),r=function(){window.removeEventListener("message",o),clearInterval(i)},o=function(e){e.source===n.iframe.contentWindow&&e.data&&e.data.uid===t&&"iframe_ack_response"===e.data.event&&(r(),n.onIframeLoaded())};window.addEventListener("message",o);var i=setInterval((function(){e>40?r():n.iframe.contentWindow&&(n.iframe.contentWindow.postMessage({event:"iframe_ack",uid:t},"*"),e++)}),300);n.iframe.addEventListener("load",(function(){r(),n.onIframeLoaded()}))})),a(this,"onIframeLoaded",(function(){n.channel||(n.channel=new MessageChannel,n.channel.port1.onmessage=function(e){return n.onMessageReceived(e)},n.iframe.contentWindow.postMessage({event:o},"*",[n.channel.port2]))})),a(this,"onChannelInitialized",(function(){n.onReadyCallback&&n.onReadyCallback()})),a(this,"postMessage",(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(null!==n.channel){var o={event:e};null!==t&&Array.isArray(t)&&(o.args=t),null!==r&&(o.xchgId=r),n.channel.port1.postMessage(o)}})),a(this,"generateXchgId",(function(){return++n.currentXchgId})),a(this,"generateListenerId",(function(){return++n.currentEventListenerId})),a(this,"callMethod",(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=n.generateXchgId();return new Promise((function(o,i){n.pendingResolvers[r]={resolve:o,reject:i},n.postMessage(e,t,r)}))})),a(this,"listen",(function(e,t){if(!n.eventListenersByEvent[e])return!1;var r=n.generateListenerId();return n.eventListenersById[r]={event:e,callback:t},n.eventListenersByEvent[e].push(r),r})),a(this,"stopListening",(function(e){if(e=Number(e),n.eventListenersById[e]){var t=n.eventListenersById[e],r=n.eventListenersByEvent[t.event].findIndex((function(t){return e===t}));void 0!==r&&n.eventListenersByEvent[t.event].splice(r,1),delete n.eventListenersById[e]}})),a(this,"onMessageReceived",(function(e){var t,r,i=null!==(t=e.data.event)&&void 0!==t&&t;if(i)if(o!==i){var a=null!==(r=e.data.xchgId)&&void 0!==r?r:0;a?n.onMessageReceivedWithXchgId(a,i,e):"event"===i&&n.onEventReceived(e)}else n.onChannelInitialized()})),a(this,"onEventReceived",(function(e){var t,o,i=null!==(t=e.data.type)&&void 0!==t?t:"";if(i&&n.eventListenersByEvent[i]){var a=null!==(o=e.data.args)&&void 0!==o?o:[];n.eventListenersByEvent[i].forEach((function(e){var t,o,i=null!==(t=n.eventListenersById[e])&&void 0!==t?t:null;i&&i.callback.apply(i,function(e){if(Array.isArray(e))return r(e)}(o=a)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(o)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(o)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())}))}})),a(this,"onMessageReceivedWithXchgId",(function(e,t,r){if(n.pendingResolvers[e]){var o=n.pendingResolvers[e];delete n.pendingResolvers[e],"error"===t?o.reject(r.data.code,r.data.message):"result"===t&&o.resolve(r.data.message.result)}})),this.currentXchgId=0,this.currentEventListenerId=0,this.pendingResolvers={},this.eventListenersById={},this.eventListenersByEvent={"info.infoUpdated":[],"status.fullscreenChanged":[],"status.playerStatusChanged":[],"status.playbackTimeUpdated":[],"status.timeUpdate":[],"status.chaptersChapterChange":[],"status.chaptersTrackChange":[],"status.borderColorsChanged":[],"status.error":[],"status.segmentsWatched":[],"status.playbackRateUpdate":[]},this.onReadyCallback=i,this.channel=null,this.iframe=t,this.initListener()})),c=new s(e,t);return{controls:{play:function(){return new Promise((function(e,t){return c.callMethod("controls.play",[]).then(e).catch(t)}))},pause:function(){return new Promise((function(e,t){return c.callMethod("controls.pause",[]).then(e).catch(t)}))},seek:function(e){return new Promise((function(t,n){if(e=Number(e),!isNaN(e))return c.callMethod("controls.seek",[e]).then(t).catch(n);n("Invalid argument provided for timeMs")}))},volume:function(e){return new Promise((function(t,n){if(e=Number(e),!isNaN(e))return c.callMethod("controls.volume",[e]).then(t).catch(n);n("Invalid argument provided for volume")}))},mute:function(e){return new Promise((function(t,n){return e=(!("toLowerCase"in Object(e))||"false"!==e.toLowerCase()&&"0"!==e)&&Boolean(e),c.callMethod("controls.mute",[e]).then(t).catch(n)}))},fullscreen:function(e){return new Promise((function(t,n){return e=(!("toLowerCase"in Object(e))||"false"!==e.toLowerCase()&&"0"!==e)&&Boolean(e),c.callMethod("controls.fullscreen",[e]).then(t).catch(n)}))},setChapters:function(e){return new Promise((function(t,n){if(Array.isArray(e))return c.callMethod("controls.setChapters",[e]).then(t).catch(n);n("Invalid argument provided for chapters")}))}},customize:{get:function(e){return new Promise((function(t,n){return e=String(e),c.callMethod("customize.get",[e]).then(t).catch(n)}))},set:function(e){return new Promise((function(t,r){if("object"===n(e))return c.callMethod("customize.set",[e]).then(t).catch(r);r("Invalid argument provided for options")}))}},info:{onInfoUpdated:function(e){return c.listen("info.infoUpdated",e)},offInfoUpdated:function(e){return c.stopListening(e)},duration:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:JSON.parse(!1);return new Promise((function(t,n){return e=(!("toLowerCase"in Object(e))||"false"!==e.toLowerCase()&&"0"!==e)&&Boolean(e),c.callMethod("info.duration",[e]).then(t).catch(n)}))},guid:function(){return new Promise((function(e,t){return c.callMethod("info.guid",[]).then(e).catch(t)}))},title:function(){return new Promise((function(e,t){return c.callMethod("info.title",[]).then(e).catch(t)}))},poster:function(){return new Promise((function(e,t){return c.callMethod("info.poster",[]).then(e).catch(t)}))},privacy:function(){return new Promise((function(e,t){return c.callMethod("info.privacy",[]).then(e).catch(t)}))},getThumbnailSample:function(e){return new Promise((function(t,n){if(e=Number(e),!isNaN(e))return c.callMethod("info.getThumbnailSample",[e]).then(t).catch(n);n("Invalid argument provided for count")}))},enableWatchedSegments:function(){return new Promise((function(e,t){return c.callMethod("info.enableWatchedSegments",[]).then(e).catch(t)}))},disableWatchedSegments:function(){return new Promise((function(e,t){return c.callMethod("info.disableWatchedSegments",[]).then(e).catch(t)}))},toggleWatchedSegments:function(){return new Promise((function(e,t){return c.callMethod("info.toggleWatchedSegments",[]).then(e).catch(t)}))},watched:function(){return new Promise((function(e,t){return c.callMethod("info.watched",[]).then(e).catch(t)}))},resetWatched:function(){return new Promise((function(e,t){return c.callMethod("info.resetWatched",[]).then(e).catch(t)}))}},status:{fullscreen:function(){return new Promise((function(e,t){return c.callMethod("status.fullscreen",[]).then(e).catch(t)}))},onFullscreenChanged:function(e){return c.listen("status.fullscreenChanged",e)},offFullscreenChanged:function(e){return c.stopListening(e)},player:function(){return new Promise((function(e,t){return c.callMethod("status.player",[]).then(e).catch(t)}))},onPlayerStatusChanged:function(e){return c.listen("status.playerStatusChanged",e)},offPlayerStatusChanged:function(e){return c.stopListening(e)},audio:function(){return new Promise((function(e,t){return c.callMethod("status.audio",[]).then(e).catch(t)}))},playbackTime:function(){return new Promise((function(e,t){return c.callMethod("status.playbackTime",[]).then(e).catch(t)}))},onPlaybackTimeUpdated:function(e){return c.listen("status.playbackTimeUpdated",e)},offPlaybackTimeUpdated:function(e){return c.stopListening(e)},onTimeUpdate:function(e){return c.listen("status.timeUpdate",e)},offTimeUpdate:function(e){return c.stopListening(e)},onChaptersChapterChange:function(e){return c.listen("status.chaptersChapterChange",e)},offChaptersChapterChange:function(e){return c.stopListening(e)},onChaptersTrackChange:function(e){return c.listen("status.chaptersTrackChange",e)},offChaptersTrackChange:function(e){return c.stopListening(e)},onBorderColorsChanged:function(e){return c.listen("status.borderColorsChanged",e)},offBorderColorsChanged:function(e){return c.stopListening(e)},borderColors:function(){return new Promise((function(e,t){return c.callMethod("status.borderColors",[]).then(e).catch(t)}))},onError:function(e){return c.listen("status.error",e)},offError:function(e){return c.stopListening(e)},onSegmentsWatched:function(e){return c.listen("status.segmentsWatched",e)},offSegmentsWatched:function(e){return c.stopListening(e)},onPlaybackRateUpdate:function(e){return c.listen("status.playbackRateUpdate",e)},offPlaybackRateUpdate:function(e){return c.stopListening(e)}}}};return t.default})()));; // listen for rlt authentication events and pass them to children of this document. ( function() { var currentToken; var parentOrigin; var iframeOrigins; var registeredIframes = []; var initializationListeners = []; var hasBeenInitialized = false; var RLT_KEY = 'jetpack:wpcomRLT'; // should we inject RLT into this iframe? function rltShouldAuthorizeIframe( frameOrigin ) { if ( ! Array.isArray( iframeOrigins ) ) { return false; } return iframeOrigins.includes( frameOrigin ); } function rltInvalidateWindowToken( token, target, origin ) { if ( target && typeof target.postMessage === 'function' ) { try { target.postMessage( JSON.stringify( { type: 'rltMessage', data: { event: 'invalidate', token: token, sourceOrigin: window.location.origin, }, } ), origin ); } catch ( err ) { return; } } } /** * PUBLIC METHODS */ window.rltInvalidateToken = function( token, sourceOrigin ) { // invalidate in current context if ( token === currentToken ) { currentToken = null; } // remove from localstorage, but only if in a top level window, not iframe try { if ( window.location === window.parent.location && window.localStorage ) { if ( window.localStorage.getItem(RLT_KEY) === token ) { window.localStorage.removeItem(RLT_KEY); } } } catch( e ) { console.info("localstorage access for invalidate denied - probably blocked third-party access", window.location.href); } // invalidate in registered iframes for ( const [ frameOrigin, frameWindow ] of registeredIframes ) { if ( frameOrigin !== sourceOrigin ) { rltInvalidateWindowToken( token, frameWindow, frameOrigin ); } } // invalidate in parent if ( parentOrigin && parentOrigin !== sourceOrigin && window.parent ) { rltInvalidateWindowToken( token, window.parent, parentOrigin ); } } window.rltInjectToken = function( token, target, origin ) { if ( target && typeof target.postMessage === 'function' ) { try { target.postMessage( JSON.stringify( { type: 'loginMessage', data: { event: 'login', success: true, type: 'rlt', token: token, sourceOrigin: window.location.origin, }, } ), origin ); } catch ( err ) { return; } } }; window.rltIsAuthenticated = function() { return !! currentToken; }; window.rltGetToken = function() { return currentToken; }; window.rltAddInitializationListener = function( listener ) { // if RLT is already initialized, call the listener immediately if ( hasBeenInitialized ) { listener( currentToken ); } else { initializationListeners.push( listener ); } }; // store the token in localStorage window.rltStoreToken = function( token ) { currentToken = token; try { if ( window.location === window.parent.location && window.localStorage ) { window.localStorage.setItem( RLT_KEY, token ); } } catch( e ) { console.info("localstorage access denied - probably blocked third-party access", window.location.href); } } window.rltInitialize = function( config ) { if ( ! config || typeof window.postMessage !== 'function' ) { return; } currentToken = config.token; iframeOrigins = config.iframeOrigins; parentOrigin = config.parentOrigin; // needed? // load token from localStorage if possible, but only in top level window try { if ( ! currentToken && window.location === window.parent.location && window.localStorage ) { currentToken = window.localStorage.getItem(RLT_KEY); } } catch( e ) { console.info("localstorage access denied - probably blocked third-party access", window.location.href); } // listen for RLT events from approved origins window.addEventListener( 'message', function( e ) { var message = e && e.data; if ( typeof message === 'string' ) { try { message = JSON.parse( message ); } catch ( err ) { return; } } var type = message && message.type; var data = message && message.data; if ( type === 'loginMessage' ) { if ( data && data.type === 'rlt' && data.token !== currentToken ) { // put into localStorage if running in top-level window (not iframe) rltStoreToken( data.token ); // send to registered iframes for ( const [ frameOrigin, frameWindow ] of registeredIframes ) { rltInjectToken( currentToken, frameWindow, frameOrigin ); } // send to the parent, unless the event was sent _by_ the parent if ( parentOrigin && parentOrigin !== data.sourceOrigin && window.parent ) { rltInjectToken( currentToken, window.parent, parentOrigin ); } } } if ( type === 'rltMessage' ) { if ( data && data.event === 'invalidate' && data.token === currentToken ) { rltInvalidateToken( data.token ); } if ( data && data.event === 'register' ) { if ( rltShouldAuthorizeIframe( e.origin ) ) { registeredIframes.push( [ e.origin, e.source ] ); if ( currentToken ) { rltInjectToken( currentToken, e.source, e.origin ); } } } } } ); initializationListeners.forEach( function( listener ) { listener( currentToken ); } ); initializationListeners = []; // inform the parent that we are ready to receive the RLT token window.parent.postMessage( { type: 'rltMessage', data: { event: 'register' }, }, '*' ); hasBeenInitialized = true; }; } )(); ;