@vime/core
Version:
Customizable, extensible, accessible and framework agnostic media player.
1 lines • 6.87 kB
JavaScript
import{r as t,c as i,h as s}from"./p-aa8acb66.js";import{d as e}from"./p-e3b0430a.js";import{c as a,k as o,h}from"./p-b018976f.js";import{M as n}from"./p-8b74fa0e.js";import{V as r}from"./p-415151d7.js";import{w as c,c as d}from"./p-17652948.js";import{w as u}from"./p-ad08a3bd.js";import"./p-d84b1c8a.js";import"./p-121aab6e.js";import"./p-8acb8eb5.js";import"./p-cbbce638.js";import"./p-152748b8.js";var l=function(t,i,s,e){return new(s||(s=Promise))((function(a,o){function h(t){try{r(e.next(t))}catch(t){o(t)}}function n(t){try{r(e.throw(t))}catch(t){o(t)}}function r(t){var i;t.done?a(t.value):(i=t.value,i instanceof s?i:new s((function(t){t(i)}))).then(h,n)}r((e=e.apply(t,i||[])).next())}))};const m=new Map,p=class{constructor(s){t(this,s),this.vmLoadStart=i(this,"vmLoadStart",7),this.vmError=i(this,"vmError",7),this.defaultInternalState={},this.internalState={currentTime:0,volume:0,muted:!1,isAdsPlaying:!1,playbackReady:!1},this.embedSrc="",this.mediaTitle="",this.shouldAutoplayQueue=!1,this.showUpNextQueue=!1,this.showShareButtons=!1,this.showDailymotionLogo=!1,this.showVideoInfo=!0,this.language="en",this.autoplay=!1,this.controls=!1,this.loop=!1,this.muted=!1,this.playsinline=!1,a(this),c(this),u(this)}onVideoIdChange(){this.internalState=Object.assign({},this.defaultInternalState),this.videoId?(this.embedSrc=`${this.getOrigin()}/embed/video/${this.videoId}?api=1`,this.fetchVideoInfo=this.getVideoInfo(),this.pendingMediaTitleCall=o()):this.embedSrc=""}onControlsChange(){this.internalState.playbackReady&&this.remoteControl("controls",this.controls)}onCustomPosterChange(){this.dispatch("currentPoster",this.poster)}connectedCallback(){this.dispatch=d(this),this.dispatch("viewType",r.Video),this.onVideoIdChange(),this.internalState.muted=this.muted,this.defaultInternalState=Object.assign({},this.internalState)}componentWillLoad(){this.initialMuted=this.muted}getOrigin(){return"https://www.dailymotion.com"}getPreconnections(){return[this.getOrigin(),"https://static1.dmcdn.net"]}remoteControl(t,i){return this.embed.postMessage({command:t,parameters:i?[i]:[]})}buildParams(){return{autoplay:this.autoplay,mute:this.initialMuted,controls:this.controls,"queue-autoplay-next":this.shouldAutoplayQueue,"queue-enable":this.showUpNextQueue,"sharing-enable":this.showShareButtons,syndication:this.syndication,"ui-highlight":this.color,"ui-logo":this.showDailymotionLogo,"ui-start-screen-info":this.showVideoInfo}}getVideoInfo(){return l(this,void 0,void 0,(function*(){return m.has(this.videoId)?m.get(this.videoId):window.fetch(`https://api.dailymotion.com/video/${this.videoId}?fields=duration,thumbnail_1080_url`).then((t=>t.json())).then((t=>{const i=t.thumbnail_1080_url,s=parseFloat(t.duration);return m.set(this.videoId,{poster:i,duration:s}),{poster:i,duration:s}}))}))}onEmbedSrcChange(){this.vmLoadStart.emit(),this.dispatch("viewType",r.Video)}onEmbedMessage(t){var i,s;const e=t.detail;switch(e.event){case"playback_ready":this.onControlsChange(),this.dispatch("currentSrc",this.embedSrc),this.dispatch("mediaType",n.Video),Promise.all([this.fetchVideoInfo,null===(i=this.pendingMediaTitleCall)||void 0===i?void 0:i.promise]).then((([t,i])=>{var s,e;this.dispatch("duration",null!==(s=null==t?void 0:t.duration)&&void 0!==s?s:-1),this.dispatch("currentPoster",null!==(e=this.poster)&&void 0!==e?e:null==t?void 0:t.poster),this.dispatch("mediaTitle",i),this.dispatch("playbackReady",!0)}));break;case"videochange":null===(s=this.pendingMediaTitleCall)||void 0===s||s.resolve(e.title);break;case"start":this.dispatch("paused",!1),this.dispatch("playbackStarted",!0),this.dispatch("buffering",!0);break;case"video_start":this.remoteControl("muted",this.internalState.muted),this.remoteControl("volume",this.internalState.volume),this.internalState.currentTime>0&&this.remoteControl("seek",this.internalState.currentTime);break;case"play":this.dispatch("paused",!1);break;case"pause":this.dispatch("paused",!0),this.dispatch("playing",!1),this.dispatch("buffering",!1);break;case"playing":this.dispatch("playing",!0),this.dispatch("buffering",!1);break;case"video_end":this.loop?setTimeout((()=>{this.remoteControl("play")}),300):this.dispatch("playbackEnded",!0);break;case"timeupdate":this.dispatch("currentTime",parseFloat(e.time));break;case"volumechange":this.dispatch("muted","true"===e.muted),this.dispatch("volume",Math.floor(100*parseFloat(e.volume)));break;case"seeking":this.dispatch("currentTime",parseFloat(e.time)),this.dispatch("seeking",!0);break;case"seeked":this.dispatch("currentTime",parseFloat(e.time)),this.dispatch("seeking",!1);break;case"waiting":this.dispatch("buffering",!0);break;case"progress":this.dispatch("buffered",parseFloat(e.time));break;case"durationchange":this.dispatch("duration",parseFloat(e.duration));break;case"qualitiesavailable":this.dispatch("playbackQualities",e.qualities.map((t=>`${t}p`)));break;case"qualitychange":this.dispatch("playbackQuality",`${e.quality}p`);break;case"fullscreenchange":this.dispatch("isFullscreenActive","true"===e.fullscreen);break;case"error":this.vmError.emit(e.error)}}getAdapter(){return l(this,void 0,void 0,(function*(){const t=/(?:dai\.ly|dailymotion|dailymotion\.com)\/(?:video\/|embed\/|)(?:video\/|)((?:\w)+)/;return{getInternalPlayer:()=>l(this,void 0,void 0,(function*(){return this.embed})),play:()=>l(this,void 0,void 0,(function*(){this.remoteControl("play")})),pause:()=>l(this,void 0,void 0,(function*(){this.remoteControl("pause")})),canPlay:i=>l(this,void 0,void 0,(function*(){return h(i)&&t.test(i)})),setCurrentTime:t=>l(this,void 0,void 0,(function*(){t!==this.internalState.currentTime&&(this.internalState.currentTime=t,this.remoteControl("seek",t))})),setMuted:t=>l(this,void 0,void 0,(function*(){this.internalState.muted=t,this.remoteControl("muted",t)})),setVolume:t=>l(this,void 0,void 0,(function*(){this.internalState.volume=t/100,this.dispatch("volume",t),this.remoteControl("volume",t/100)})),canSetPlaybackQuality:()=>l(this,void 0,void 0,(function*(){return!0})),setPlaybackQuality:t=>l(this,void 0,void 0,(function*(){this.remoteControl("quality",t.slice(0,-1))})),canSetFullscreen:()=>l(this,void 0,void 0,(function*(){return!0})),enterFullscreen:()=>l(this,void 0,void 0,(function*(){this.remoteControl("fullscreen",!0)})),exitFullscreen:()=>l(this,void 0,void 0,(function*(){this.remoteControl("fullscreen",!1)}))}}))}render(){return s("vm-embed",{embedSrc:this.embedSrc,mediaTitle:this.mediaTitle,origin:this.getOrigin(),params:this.buildParams(),decoder:e,preconnections:this.getPreconnections(),onVmEmbedMessage:this.onEmbedMessage.bind(this),onVmEmbedSrcChange:this.onEmbedSrcChange.bind(this),ref:t=>{this.embed=t}})}static get watchers(){return{videoId:["onVideoIdChange"],controls:["onControlsChange"],poster:["onCustomPosterChange"]}}};p.style=":host{z-index:var(--vm-media-z-index)}";export{p as vm_dailymotion}