-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwwIframeApi.min.js
2 lines (2 loc) · 7.91 KB
/
wwIframeApi.min.js
1
2
/** @version 1.0.0 */
!function(t,e,a){function r(){for(var t="",e=0;e<32;e++)t+=Math.floor(16*Math.random()).toString(16);return t}function n(t,a){var r={frame:e.querySelector("[ww-id-"+t+"]"),contentFrame:e.querySelector("[ww-id-"+t+"]").contentWindow,muted:!1,volume:1,rate:1,availableRates:[1],loadedValue:0,state:-1,time:0,sessionStart:-1,sessionStartGranular:-1,duration:-1,url:"",title:"",analytics:{},captions:[]},n=!1;"undefined"!=typeof a&&Object.keys(a).forEach(function(t,e){r[t]=a[t]});var o={onReady:function(t){},onStateChange:function(t){},onPlaybackRateChange:function(t){},onError:function(t){}},i={unstarted:-1,ended:0,playing:1,paused:2,buffering:3},u={NOT_LOADED:-1,BAD_REQUEST:400},d=function(){var t=Date.now();setTimeout(function(){if(r.state!=i.playing)return!1;var e=r.time+(Date.now()-t)/r.rate/1e3;r.time=e,r.analytics[r.sessionStart].endTime=r.time,d()},250)},s={ready:function(){n=!0},_throwError:function(t){return s.onError({target:this,data:t}),!1},play:function(){return n?void r.contentFrame.postMessage({event:"play",frameId:t},"*"):this._throwError(u.NOT_LOADED)},pause:function(){return n?void r.contentFrame.postMessage({event:"pause",frameId:t},"*"):this._throwError(u.NOT_LOADED)},seekTo:function(e){return n?isNaN(parseFloat(e))?this._throwError(u.BAD_REQUEST):void r.contentFrame.postMessage({event:"seekTo",frameId:t,payload:e},"*"):this._throwError(u.NOT_LOADED)},mute:function(){return n?void r.contentFrame.postMessage({event:"mute",frameId:t},"*"):this._throwError(u.NOT_LOADED)},unMute:function(){return n?void r.contentFrame.postMessage({event:"unmute",frameId:t},"*"):this._throwError(u.NOT_LOADED)},isMuted:function(){return n?r.muted:this._throwError(u.NOT_LOADED)},setVolume:function(e){return n?isNaN(parseFloat(e))?this._throwError(u.BAD_REQUEST):void r.contentFrame.postMessage({event:"setVolume",frameId:t,payload:e},"*"):this._throwError(u.NOT_LOADED)},getVolume:function(){return n?r.volume:this._throwError(u.NOT_LOADED)},getPlaybackRate:function(){return n?r.rate:this._throwError(u.NOT_LOADED)},setPlaybackRate:function(e){return n?isNaN(parseFloat(e))?this._throwError(u.BAD_REQUEST):void r.contentFrame.postMessage({event:"setPlaybackRate",frameId:t,payload:e},"*"):this._throwError(u.NOT_LOADED)},getAvailablePlaybackRates:function(){return n?r.availableRates:this._throwError(u.NOT_LOADED)},getMediaLoadedValue:function(){return n?r.loadedValue:this._throwError(u.NOT_LOADED)},getPlayerState:function(){return n?r.state:this._throwError(u.NOT_LOADED)},getCurrentTime:function(){return n?r.time:this._throwError(u.NOT_LOADED)},getId:function(){return n?r.frameId:this._throwError(u.NOT_LOADED)},getTitle:function(){return n?r.title:this._throwError(u.NOT_LOADED)},getDuration:function(){return n?r.duration:this._throwError(u.NOT_LOADED)},getMediaUrl:function(){return n?r.url:this._throwError(u.NOT_LOADED)},getSessionAnalytics:function(){return n?r.analytics:this._throwError(u.NOT_LOADED)},getCaptions:function(){return n?r.captions:this._throwError(u.NOT_LOADED)},setCaption:function(e){return n?void r.contentFrame.postMessage({event:"setCaption",frameId:t,payload:e},"*"):this._throwError(u.NOT_LOADED)},getIframe:function(){return n?r.frame:this._throwError(u.NOT_LOADED)},destroy:function(){return n?(r.frame.remove(),void delete _playerApis(t)):this._throwError(u.NOT_LOADED)},updateData:function(t){"undefined"==typeof t&&retun(!1),Object.keys(t).forEach(function(e,a){r[e]=t[e]})},updateMuted:function(t){r.muted=t.muted},updateVolume:function(t){r.volume=t.volume},updatePlaybackRate:function(t){r.rate=t.playbackRate},updateMediaLoadedValue:function(t){r.loadedValue=t.end/r.duration},updatePlayerState:function(t){return r.state=t.state,t.state!=i.playing?(r.time=t.currentTime,r.analytics[t.sessionStart].endTime=t.currentTime,!0):(r.sessionStartGranular=t.sessionStartGranular,r.sessionStart=t.sessionStart,r.analytics[t.sessionStart]={startTime:t.currentTime,endTime:t.currentTime},r.time=t.currentTime,"undefined"!=typeof r.sessionStartGranular&&Date.now()>r.sessionStartGranular&&(r.time=t.currentTime+(Date.now()-r.sessionStartGranular)/1e3),void d())},updateSeeking:function(t){return r.state!=i.playing||(r.analytics[t.sessionStart].endTime=t.currentTime,void(r.time=t.currentTime))},updateSeeked:function(t){return r.state!=i.playing||(r.analytics[t.sessionStart]={startTime:t.currentTime,endTime:t.currentTime},r.time=t.currentTime,void(r.sessionStart=t.sessionStart))},updateTime:function(t){r.time=t.currentTime},updateDuration:function(t){r.duration=t.duration},updateCaptions:function(t){for(var e=0;e<r.captions.length;e++)r.captions[e].label==t.label?r.captions[e].enabled=!0:r.captions[e].enabled=!1},onReady:function(t){return o.onReady(t)},onStateChange:function(t){return o.onStateChange(t)},onPlaybackRateChange:function(t){return o.onPlaybackRateChange(t)},onError:function(t){return o.onError(t)},getAnalyticsToken:function(){if(!n)return this._throwError(u.NOT_LOADED)}};return Object.defineProperty(s,"onReady",{get:function(){return o.onReady},set:function(t){o.onReady=t,n&&t({target:this})},configurable:!1}),s}function o(a){function o(){var t=this;t.contentWindow.postMessage({event:"setup",frameId:t.getAttribute("data-ww-id")},"*")}for(var i={},u=e.getElementsByTagName("iframe"),d=0;d<u.length;d++){if("undefined"!=typeof a){for(var s=!1,c=0;c<a.length;c++)u[d].getAttribute("src").indexOf(a[c])>-1&&(s=!0);if(!s)continue}(null==u[d].getAttribute("data-ww-id")||u[d].getAttribute("data-ww-id").trim().length<=0)&&u[d].setAttribute("data-ww-id",r()),u[d].setAttribute("ww-id-"+u[d].getAttribute("data-ww-id"),!0),i[u[d].getAttribute("data-ww-id").trim()]=new n(u[d].getAttribute("data-ww-id").trim()),o.apply(u[d]),u[d].onload=function(){i[this.getAttribute("data-ww-id").trim()].ready()||o.apply(this)}}var f=function(t){return"undefined"!=typeof i[t]?i[t]:null};f.add=function(t,e){i[t]=new n(t,e)},f.list=function(){var t=[];return Object.keys(i).forEach(function(e,a){t.push(i[e])}),t},f.getByUrl=function(){return Object.keys(i).forEach(function(t,e){if(i[t].getMediaUrl()==url)return i[t]}),null};var l=function(t){if("undefined"==typeof t.data.event)return!1;switch(t.data.event){case"setup":"undefined"!=typeof f(t.data.frameId)?f(t.data.frameId).updateData(t.data.payload):f.add(t.data.frameId,t.data.payload),f(t.data.frameId).ready(),f(t.data.frameId).onReady({target:f(t.data.frameId)});break;case"error":f(t.data.frameId).onError({target:f(t.data.frameId),data:t.data.payload.code});break;case"captionChange":f(t.data.frameId).updateCaptions(t.data.payload);break;case"mute":f(t.data.frameId).updateMuted(t.data.payload);break;case"volume":f(t.data.frameId).updateVolume(t.data.payload);break;case"playbackRate":f(t.data.frameId).updatePlaybackRate(t.data.payload),f(t.data.frameId).onPlaybackRateChange({target:f(t.data.frameId),data:t.data.payload.playbackRate});break;case"seeked":f(t.data.frameId).updateSeeked(t.data.payload);break;case"seeking":f(t.data.frameId).updateSeeking(t.data.payload);break;case"state":f(t.data.frameId).updatePlayerState(t.data.payload),f(t.data.frameId).onStateChange({target:f(t.data.frameId),data:t.data.payload.state});break;case"duration":f(t.data.frameId).updateDuration(t.data.payload);break;case"progress":f(t.data.frameId).updateMediaLoadedValue(t.data.payload)}};return t.addEventListener("message",l,!1),f}Object.keys||(Object.keys=function(){"use strict";var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),a=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],r=a.length;return function(n){if("function"!=typeof n&&("object"!=typeof n||null===n))throw new TypeError("Object.keys called on non-object");var o,i,u=[];for(o in n)t.call(n,o)&&u.push(o);if(e)for(i=0;i<r;i++)t.call(n,a[i])&&u.push(a[i]);return u}}());t.wwIframeApi=o,t.WWIRE={PLAYERSTATES:{UNSTARTED:-1,ENDED:0,PLAYING:1,PAUSED:2,BUFFERING:3},CODES:{NOT_LOADED:-1,BAD_REQUEST:400}},"undefined"!=typeof t.onWarpwirePlayerAPIReady&&t.onWarpwirePlayerAPIReady()}(window,document);