UNPKG

@ktt45678/vidstack

Version:

UI component library for building high-quality, accessible video and audio experiences on the web.

2 lines (1 loc) 2.01 kB
import{c}from"./vidstack-_YlOvjKd.js";import{l as n}from"./vidstack-Ds9fx5AB.js";import{a as l,b as p}from"./vidstack-BC0sXP__.js";import{a as g,b as h,i,d as m,e as d,c as f,f as C,j as y}from"./vidstack-D7a9zsAz.js";import{p as w}from"./vidstack-B1PqmCkk.js";import"./vidstack-DaFtTE-M.js";class E{constructor(){this.name="google-cast"}get cast(){return g()}mediaType(){return"video"}canPlay(t){return l&&!p&&c(t)}async prompt(t){let e,a,o;try{e=await this.Ej(t),this.f||(this.f=new cast.framework.RemotePlayer,new cast.framework.RemotePlayerController(this.f)),a=t.player.createEvent("google-cast-prompt-open",{trigger:e}),t.player.dispatchEvent(a),this.Ce(t,"connecting",a),await this.Fj(w(t.$props.googleCast)),t.$state.remotePlaybackInfo.set({deviceName:h()?.getCastDevice().friendlyName}),i()&&this.Ce(t,"connected",a)}catch(r){const s=r instanceof Error?r:this.De((r+"").toUpperCase(),"Prompt failed.");throw o=t.player.createEvent("google-cast-prompt-error",{detail:s,trigger:a??e,cancelable:!0}),t.player.dispatch(o),this.Ce(t,i()?"connected":"disconnected",o),s}finally{t.player.dispatch("google-cast-prompt-close",{trigger:o??a??e})}}async load(t){if(!this.f)throw Error("[vidstack] google cast player was not initialized");return new(await import("../providers/vidstack-google-cast-ZYiIAydz.js")).GoogleCastProvider(this.f,t)}async Ej(t){if(m())return;const e=t.player.createEvent("google-cast-load-start");t.player.dispatch(e),await n(y()),await customElements.whenDefined("google-cast-launcher");const a=t.player.createEvent("google-cast-loaded",{trigger:e});if(t.player.dispatch(a),!d())throw this.De("CAST_NOT_AVAILABLE","Google Cast not available on this platform.");return a}async Fj(t){this.Gj(t);const e=await this.cast.requestSession();if(e)throw this.De(e.toUpperCase(),f(e))}Gj(t){this.cast?.setOptions({...C(),...t})}Ce(t,e,a){const o={type:"google-cast",state:e};t.delegate.c("remote-playback-change",o,a)}De(t,e){const a=Error(e);return a.code=t,a}}export{E as GoogleCastLoader};