2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
import"./engine-DDeQk6Ow.js";import{c as ye}from"./presentations-Cv1n4E0C.js";import{_ as be}from"./DeckViewer.vue_vue_type_style_index_0_lang-BaDQ_ebp.js";import{A as Z,d as ke,o as Ee,aH as Se,aN as ae,c as F,s as Me,f as te,b as J,F as _e,r as Y,aO as ie,n as A,aM as Re,aP as Ce,Z as Te}from"./index-DbE8VwcP.js";import{C as ne,f as le,a as Le,c as Ae,r as Ne,b as Pe}from"./log-Xlt5jeld.js";import{b as De,R as Ie}from"./remote-aOKX75Mt.js";const Fe=/^U\+(0-FF|100-2BA)\b/i;function Oe(e){return e.status==="unloaded"&&Fe.test(e.unicodeRange.trim())}async function je(e){const r=[...e].filter(Oe);return await Promise.allSettled(r.map(a=>a.load())),r.length}async function Be(e,r){const a=e.filter(d=>d.classList.contains("on"));try{for(const d of e){for(const s of e)s.classList.toggle("on",s===d);d.offsetHeight,await r()}}finally{for(const d of e)d.classList.toggle("on",a.includes(d))}return e.length}async function ze(e,r,a=50){const d=Date.now()+r;for(;;){if(e())return!0;if(Date.now()>=d)return!1;await new Promise(s=>setTimeout(s,a))}}function ue(){return{raf:e=>requestAnimationFrame(()=>e()),cancelRaf:e=>cancelAnimationFrame(e),setTimeout:(e,r)=>window.setTimeout(e,r),clearTimeout:e=>window.clearTimeout(e),now:()=>performance.now()}}async function Ue(e,r=ue()){return(await fe(Number.POSITIVE_INFINITY,e,r)).frames}function fe(e,r,a=ue()){return new Promise(d=>{const s=a.now();let u=0,g=0,v=0,y=!1;const p=l=>{y||(y=!0,a.cancelRaf(g),a.clearTimeout(v),d({frames:u,ms:Math.round(a.now()-s),ok:l}))},E=()=>{y||(u++,u>=e?p(!0):g=a.raf(E))};v=a.setTimeout(()=>p(!1),r),g=a.raf(E)})}const We="https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js",se="bm-caf",de=["READY","SENDER_CONNECTED","SENDER_DISCONNECTED","SHUTDOWN","VISIBILITY_CHANGED","STANDBY_CHANGED","ERROR"];function O(){const r=globalThis.cast?.framework;return r&&typeof r.CastReceiverContext?.getInstance=="function"?r:null}function $e(){return O()!==null}function He(e=1e4){return O()?Promise.resolve(!0):new Promise(r=>{let a=document.getElementById(se);a||(a=document.createElement("script"),a.id=se,a.src=We,document.head.appendChild(a));const d=a;let s=!1;const u=E=>{s||(s=!0,window.clearInterval(y),window.clearTimeout(p),d.removeEventListener("load",g),d.removeEventListener("error",v),r(E))},g=()=>u(O()!==null),v=()=>u(!1);d.addEventListener("load",g),d.addEventListener("error",v);const y=window.setInterval(()=>{O()&&u(!0)},50),p=window.setTimeout(()=>u(O()!==null),e)})}function Ve(e){const r=O();if(!r)throw new Error("cast: the receiver SDK is not loaded");const a=r.CastReceiverContext.getInstance(),d=()=>{try{return a.getSenders().length}catch{return 0}},s=new r.CastReceiverOptions;s.customNamespaces={[ne]:r.system.MessageType.JSON},s.skipPlayersLoad=!0,s.disableIdleTimeout=!0,s.maxInactivity=3600,s.statusText=e.statusText;for(const u of de){const g=r.system.EventType[u];g!==void 0&&a.addEventListener(g,v=>{e.onEvent(u,{reason:v?.reason,senderId:v?.senderId,isVisible:v?.isVisible,isStandby:v?.isStandby,senders:d()})})}return a.addCustomMessageListener(ne,u=>e.onMessage(u?.data,u?.senderId)),a.start(s),{send(u,g){if(!le(u))return e.onEvent("send-dropped",{type:u.type}),!1;try{return a.sendCustomMessage(ne,g,u),!0}catch(v){return e.onEvent("send-failed",{type:u.type,error:v instanceof Error?v.message:String(v)}),!1}},senders:d,setStatusText(u){try{a.setApplicationState(u)}catch{}},deviceCapabilities(){try{return a.getDeviceCapabilities?.()??null}catch{return null}}}}const Ge=2e3,qe=5e3,xe=/data-deck-image="([^"]+)"/g;function Je(e){const r=new Set,a=s=>{if(s)for(const u of s.matchAll(xe))r.add(u[1])},d=s=>{a(s.body_html),a(s.comment_html),a(s.sources_html),s.special&&d(s.special)};for(const s of e.slides??[])d(s);return[...r]}function H(e){return e instanceof Z?e.status:0}function K(e){return e instanceof Z?`${e.status} ${e.message}`:e instanceof Error?e.message:String(e)}function Ye(e){const r=e.now??(()=>Date.now());let a=null,d=null,s=null,u=null,g="waiting",v="off",y="",p=0,E=-1/0,l=!1,S,M=-1/0,w=null,j=!1,C=[],B="",z=0,U=0,V=0;function T(){const t=e.view.current();return{type:"status",phase:g,ws:v,number:t?.number??0,special:t?.special??!1,title:y}}function W(){const t=T();e.onStatus?.(t),e.send(t)}function N(t){g!==t&&(g=t,e.log("phase",t),W())}function P(t){if(v===t)return;const n=v;n==="connected"&&t==="connecting"&&V++,v=t,e.log("ws",`${n} -> ${t}`),W()}function D(t){const n=r();n-E<Ge||(E=n,e.log("ticket","need-ticket",{why:t}),e.send({type:"need-ticket"}))}async function I(t,n,o=a){if(!o)throw new Z(401,"no ticket");try{return await n(o)}catch(f){throw H(f)===401&&o===a&&D(t),f}}async function $(t){const n=r();try{const o=await I(t,e.api.realtime);return e.log("token",`${t} ok`,{kind:t,outcome:"ok",ms:Math.round(r()-n)}),o}catch(o){const f=H(o),m=f===401||f===403||f===404?"refused":"failed";throw e.log("token",`${t} ${m}`,{kind:t,outcome:m,status:f,ms:Math.round(r()-n)}),o}}function G(){e.realtime.setTokenSource({connection:async()=>(await $("connection")).token,subscription:async t=>{const n=await $("subscription");if(n.channel!==t)throw e.log("token","subscription channel mismatch"),new Z(403,"cast: channel mismatch");return n.channel_token}})}function q(t=C){for(const n of t)e.revokeURL(n);t===C&&(C=[])}async function Q(t,n,o){const f={};return await Promise.all(Je(t).map(async m=>{try{const L=await I("image",k=>e.api.image(k,m),n);if(o!==p||l)return;const R=e.objectURL(L);C.push(R),f[m]=R}catch(L){e.log("image","image skipped",{name:m,status:H(L)})}})),f}function i(){u?.close(),u=null}function c(t){const n=()=>t===p&&!l;return{onPublication(o){if(!n())return;const f=De(o);if(!f||f.event!==Ie)return;const m=f.payload;if(m.tab!==d){U++,e.log("foreign","state from another tab",{tab:m.tab});return}z++,e.view.show(m.number,m.special,m.panel==="notes"||m.panel==="srcs"?m.panel:null),e.log("state","applied",{number:m.number,special:m.special})},onSubscribed(){n()&&(e.log("ws","subscribed"),g==="ready"&&W())},onConnection(o){n()&&P(o)},onDenied(o){n()&&(e.log("ws","subscription denied",{code:o}),o===401&&D("subscription denied"))},onUnavailable(){n()&&(P("off"),D("realtime unavailable"))}}}async function h(t,n){const o=await e.realtime.openChannel(n,c(t));if(t!==p||l){o.close();return}u=o}async function b(t,n){const o=++p,f=a,m=r();i(),e.realtime.disconnect(),s=null,B="",N("loading");const L=C;C=[];let R;try{if(R=n??await I("deck",e.api.deck,f),o!==p||l)return;y=R.title??"";const k=r(),re=await Q(R,f??"",o);if(o!==p||l)return;const oe=r();if(await e.view.load(R,re),o!==p||l)return;B=JSON.stringify(R),e.log("perf","deck up",{fetchMs:Math.round(k-m),imagesMs:Math.round(oe-k),images:Object.keys(re).length,loadMs:Math.round(r()-oe),totalMs:Math.round(r()-m),slides:R.slides?.length??0})}catch(k){if(o!==p||l)return;e.log("error","deck load failed",{error:K(k)}),N("error");return}finally{q(L)}try{G();const k=t??await I("realtime",e.api.realtime,f);if(o!==p||l)return;s=k.channel,await h(o,k.channel)}catch(k){if(o!==p||l)return;e.log("error","channel join failed",{error:K(k)}),P("off")}o!==p||l||N("ready")}async function _(){if(!s)return;const t=p;i(),e.realtime.disconnect();try{await h(t,s)}catch(n){e.log("error","channel reopen failed",{error:K(n)})}}async function x(t,n,o){if(!a){a=t,d=n,e.log("ticket","first hello",{tab:n}),await b(),a===t&&g==="ready"&&(S=o);return}if(t===a){if(d!==n&&e.log("tab","casting tab switched",{tab:n}),d=n,S=o,g==="error"||g==="ready"&&!u){await b();return}e.send(T(),o);return}let f;try{f=await e.api.realtime(t)}catch(m){e.log("ticket","refused",{status:H(m)}),e.send(T(),o);return}if(!l){if(a=t,d=n,S=o,E=-1/0,s&&f.channel===s&&g==="ready"){let m=null;try{m=await e.api.deck(t)}catch(L){e.log("ticket","deck check failed",{status:H(L)})}if(l)return;if(m&&JSON.stringify(m)!==B){e.log("ticket","deck changed",{tab:n}),await b(f,m);return}if(e.log("ticket","swapped",{tab:n}),await _(),l)return;e.send(T(),o);return}e.log("ticket","new deck",{tab:n}),await b(f)}}function X(t){const n=e.report?.()??{summary:null,device:null,events:[],previousRun:[]},o=Ae(JSON.stringify(Ne(n)));e.log("log","sending",{parts:o.length,senderId:t});for(const f of o){if(!le(f)){e.log("log","part dropped",{part:f.part});continue}e.send(f,t)}}function ee(t){const n=e.view.current();e.send({type:"position",number:n?.number??0,special:n?.special??!1},t)}async function me(t,n){if(l)return;const o=Le(t);if(!o){e.log("foreign","unknown message",{senderId:n});return}if(e.log("rx",o.type,{senderId:n}),o.type==="where"){ee(n);return}if(o.type==="log"){X(n);return}const f=S!==void 0&&n===S||o.ticket===a;if(!f&&S!==void 0){if(r()<M){e.log("foreign","hello throttled",{senderId:n});return}M=r()+qe}await we(o.ticket,o.tab,n,f)}function we(t,n,o,f){return new Promise(m=>{if(w){if(w.trusted&&!f){e.log("foreign","hello dropped behind a trusted one",{senderId:o}),m();return}e.log("rx","hello superseded",{senderId:w.senderId}),w.settle()}w={ticket:t,tab:n,senderId:o,trusted:f,settle:m},j||ge()})}async function ge(){j=!0;try{for(;w&&!l;){const t=w;w=null;try{await x(t.ticket,t.tab,t.senderId)}catch(n){e.log("error","hello failed",{error:K(n)})}finally{t.settle()}}}finally{j=!1,w?.settle(),w=null}}function ve(t){t===void 0||t!==S||(S=void 0,e.log("rx","pinned sender left",{senderId:t}))}function he(){l=!0,p++,i(),e.realtime.setTokenSource(null),q()}function pe(){return{ws:v,applied:z,foreign:U,reconnects:V}}return{handle:me,senderLeft:ve,status:T,stats:pe,close:he}}const Ke={key:1,class:"cast-screen cast-cover",role:"status"},Ze={key:2,class:"cast-screen"},Qe={key:0,class:"cast-hint"},Xe={key:3,class:"cast-screen"},et={key:4,class:"cast-screen"},tt=6e4,ce=1e3,ct=ke({__name:"CastReceiverView",setup(e){const r=Y("boot"),a=ie(null),d=ie({}),s=Y("pending"),u=Y(null),g=Y(!1);let v=null,y=null,p=0;const E=new Set(de),l=Pe("bm.cast.log"),S=Date.now();let M={};function w(i,c,h){l.note(i,c,h),i==="error"&&l.persist()}function j(){const i=performance.memory;return i?Math.round(i.usedJSHeapSize/1048576):null}function C(){const i=navigator;return{ua:navigator.userAgent,screen:`${window.screen.width}x${window.screen.height}`,viewport:`${window.innerWidth}x${window.innerHeight}`,dpr:window.devicePixelRatio,cores:navigator.hardwareConcurrency,memoryGB:i.deviceMemory??null}}function B(i,c){if(!E.has(i)){w("send",i,c);return}i==="READY"&&v?(M={...M,capabilities:v.deviceCapabilities()},w("caf",i,{...c,capabilities:M.capabilities})):w("caf",i,c),i==="SENDER_DISCONNECTED"&&typeof c?.senderId=="string"&&y?.senderLeft(c.senderId),l.persist()}function z(){return"serviceWorker"in navigator&&navigator.serviceWorker.controller!==null}function U(){return{screen:r.value,covered:g.value,coverInDom:document.querySelector(".cast-cover")!==null,visibility:document.visibilityState,focus:document.hasFocus(),sw:z()}}async function V(){const i=await Ue(ce),c=y?.stats();w("beat","heartbeat",{uptimeMin:+((Date.now()-S)/6e4).toFixed(1),ws:c?.ws??"off",applied:c?.applied??0,foreign:c?.foreign??0,reconnects:c?.reconnects??0,heapMB:j(),frames:i,frameSampleMs:ce,...U()}),l.persist(),y&&v?.send(y.status())}async function T(){const i=await fe(3,3e3);w("paint",i.ok?"frames after the cover":"no frames after the cover",{...i,...U()}),l.persist()}async function W(){if(!("serviceWorker"in navigator))return;const i=navigator.serviceWorker;try{const c=await i.getRegistrations(),h=i.controller!==null;if(c.length===0&&!h)return;const b=await Promise.all(c.map(_=>_.unregister().catch(()=>!1)));w("boot","service worker unregistered",{controlled:h,scopes:c.map(_=>_.scope),unregistered:b.filter(Boolean).length})}catch(c){w("boot","service worker check failed",String(c))}l.persist()}function N(i){w("error","window error",{message:String(i.message),source:i.filename,line:i.lineno})}function P(i){const c=i.reason instanceof Error?i.reason.message:String(i.reason);w("error","unhandled rejection",{reason:c})}function D(){w("boot","pagehide"),l.persist()}function I(i){return new Promise(c=>window.setTimeout(c,i))}function $(){return new Promise(i=>requestAnimationFrame(()=>i()))}function G(){return u.value?.sections()??[]}async function q(i,c){g.value=!0;const h=performance.now();try{a.value=i,d.value=c,s.value="ready",r.value="deck",await Te(),await ze(()=>G().some(ee=>ee.classList.contains("on")),2e4)||w("error","the first slide did not show in 20 s"),await document.fonts.ready,await I(50);const b=performance.now(),_=await je(document.fonts),x=performance.now(),X=await Be(G(),$);await $(),w("perf","warm-up",{stageMs:Math.round(b-h),faces:_,warmMs:Math.round(x-b),sections:X,prerenderMs:Math.round(performance.now()-x),totalMs:Math.round(performance.now()-h)})}finally{g.value=!1,T()}v?.setStatusText(`BM · ${i.title}`)}function Q(i){i.phase==="loading"?g.value=!0:i.phase==="error"?(g.value=!1,r.value="error"):i.phase==="ready"&&a.value&&(r.value="deck")}return Ee(async()=>{M=C();const i=l.previous[l.previous.length-1];if(w("boot","receiver loaded",{...M,cafAtBoot:$e(),sw:z(),previousRunEvents:l.previous.length,lastPrevious:i??null}),l.persist(),W(),window.addEventListener("error",N),window.addEventListener("unhandledrejection",P),window.addEventListener("pagehide",D),p=window.setInterval(()=>{V()},tt),document.documentElement.classList.add("deck-public"),!document.querySelector('meta[data-deck-public="1"]')){const h=document.createElement("meta");h.name="robots",h.content="noindex",h.dataset.deckPublic="1",document.head.appendChild(h)}if(!await He()){r.value="unsupported",w("boot","no CAF SDK");return}r.value="waiting",y=Ye({api:ye,realtime:{setTokenSource:Ce,openChannel:Re,disconnect:ae},view:{load:q,show:(h,b,_)=>{u.value?.showSlide(h,b,_)},current:()=>u.value?.current()??null},send:(h,b)=>{v?.send(h,b)},log:w,objectURL:h=>URL.createObjectURL(h),revokeURL:h=>URL.revokeObjectURL(h),onStatus:Q,report:()=>({summary:l.summary(),device:M,events:l.events,previousRun:l.previous})});const c=y;try{v=Ve({statusText:"BM · prezentacja",onMessage:(h,b)=>{c.handle(h,b)},onEvent:B}),w("caf","started")}catch(h){w("error","receiver start failed",String(h)),r.value="unsupported"}}),Se(()=>{window.clearInterval(p),window.removeEventListener("error",N),window.removeEventListener("unhandledrejection",P),window.removeEventListener("pagehide",D),l.persist(),y?.close(),ae(),document.documentElement.classList.remove("deck-public"),document.querySelector('meta[data-deck-public="1"]')?.remove()}),(i,c)=>(A(),F(_e,null,[a.value?(A(),Me(be,{key:0,ref_key:"viewer",ref:u,phase:s.value,deck:a.value,error:"",mode:"public","no-toolbar":"","extra-css":a.value.css,theme:a.value.theme,images:d.value},null,8,["phase","deck","extra-css","theme","images"])):te("",!0),g.value?(A(),F("div",Ke,[...c[0]||(c[0]=[J("p",null,"Przygotowuję slajdy…",-1)])])):r.value==="boot"||r.value==="waiting"?(A(),F("div",Ze,[c[1]||(c[1]=J("p",null,"BM · czekam na pilota…",-1)),r.value==="waiting"?(A(),F("p",Qe,"Na telefonie otwórz pilota prezentacji i wybierz Wyświetl na TV.")):te("",!0)])):r.value==="unsupported"?(A(),F("div",Xe,[...c[2]||(c[2]=[J("p",null,"Ta strona działa tylko na urządzeniu Google Cast.",-1)])])):r.value==="error"?(A(),F("div",et,[...c[3]||(c[3]=[J("p",null,"Nie mogę wczytać prezentacji. Połącz ponownie z telefonu.",-1)])])):te("",!0)],64))}});export{ct as default};
|