@ktt45678/vidstack
Version:
UI component library for building high-quality, accessible video and audio experiences on the web.
2 lines (1 loc) • 1.97 kB
JavaScript
import{a as c,b as n,d as l}from"./vidstack-ClFi43dj.js";import{l as p}from"./vidstack-5Q7s4lUC.js";import{a as g,b as d,i,d as h,e as m,c as C,f,j as y}from"./vidstack-ERagmYfS.js";import{p as w}from"./vidstack-DgnIG4vb.js";import"./vidstack-nZNas-dv.js";class E{constructor(){this.name="google-cast"}get cast(){return g()}mediaType(){return"video"}canPlay(t){return c&&!n&&l(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:d()?.getCastDevice().friendlyName}),i()&&this.Ce(t,"connected",a)}catch(s){const r=s instanceof Error?s:this.De((s+"").toUpperCase(),"Prompt failed.");throw o=t.player.createEvent("google-cast-prompt-error",{detail:r,trigger:a??e,cancelable:!0}),t.player.dispatch(o),this.Ce(t,i()?"connected":"disconnected",o),r}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-CSSaGX1b.js")).GoogleCastProvider(this.f,t)}async Ej(t){if(h())return;const e=t.player.createEvent("google-cast-load-start");t.player.dispatch(e),await p(y()),await customElements.whenDefined("google-cast-launcher");const a=t.player.createEvent("google-cast-loaded",{trigger:e});if(t.player.dispatch(a),!m())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(),C(e))}Gj(t){this.cast?.setOptions({...f(),...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};