bluetooth-buzzer/_app/immutable/nodes/2.17f77c00.js

12 lines
93 KiB
JavaScript
Raw Permalink Normal View History

2024-01-20 15:14:30 +01:00
var sr=Object.defineProperty;var cr=(r,e,A)=>e in r?sr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:A}):r[e]=A;var Qe=(r,e,A)=>(cr(r,typeof e!="symbol"?e+"":e,A),A);import{s as be,e as U,i as I,d as w,A as q,B as QA,C as G,D as H,r as K,f as z,g as N,h as F,E as rA,F as dr,G as D,u as $,v as ee,w as Ae,H as qA,I as mA,J as M,p as LA,K as ur,L as fr,M as gr,N as jA,a as Ze,c as De,O as ye,x as P,l as X,m as W,j as J,n as tA,P as SA,Q as xA,R as br,y as MA,z as PA,o as hr,S as mr,k as OA}from"../chunks/scheduler.2f27f277.js";import{S as ve,i as Ee,a as k,t as v,g as Ve,c as Te,b as oe,d as ie,m as ne,e as ae,f as VA}from"../chunks/index.d9978d1c.js";import{w as HA}from"../chunks/index.6e61dc83.js";function he(r,e){const A={},t={},o={$$scope:1};let i=r.length;for(;i--;){const n=r[i],a=e[i];if(a){for(const l in n)l in a||(t[l]=1);for(const l in a)o[l]||(A[l]=a[l],o[l]=1);r[i]=a}else for(const l in n)o[l]=1}for(const n in t)n in A||(A[n]=void 0);return A}function oA(r){return typeof r=="object"&&r!==null?r:{}}const pr=!1,wr=!1,Co=Object.freeze(Object.defineProperty({__proto__:null,prerender:pr,ssr:wr},Symbol.toStringTag,{value:"Module"})),Oe=HA("DISCONNECTED");let pA=HA({});class kr{constructor(){Qe(this,"__currentOffset");Qe(this,"__currentFluctuation");Qe(this,"__currentAcceptanceRate");Qe(this,"__acceptedFluctuationFactor",4n);Qe(this,"__latestOffsets",[]);Qe(this,"__latestFluctuations",[]);Qe(this,"__latestAcceptanceResults",[]);this.__currentOffset=void 0,this.__currentFluctuation=void 0,this.__latestOffsets=[],this.__latestFluctuations=[],this.__latestAcceptanceResults=[]}currentOffset(){return this.__currentOffset}currentAcceptanceRate(){return this.__currentAcceptanceRate}handleTimeSync(e,A,t){let o=A-e,i=t+o/2n-A;this.__handleNewOffset(i)}__handleNewOffset(e){const A=this.__isOffsetInMargin(e);this.__handleAcceptanceResult(A),A&&(this.__currentOffset=this.__pushValueAndCaluclateAverage(this.__latestOffsets,e))}__handleAcceptanceResult(e){this.__currentAcceptanceRate=this.__pushValueAndCaluclateAverage(this.__latestAcceptanceResults,e?100n:0n),this.__currentAcceptanceRate>90n?this.__acceptedFluctuationFactor=4n:this.__currentAcceptanceRate>80n?this.__acceptedFluctuationFactor=6n:this.__currentAcceptanceRate>50n?this.__acceptedFluctuationFactor=10n:this.__acceptedFluctuationFactor=100n}__isOffsetInMargin(e){if(!this.__currentOffset)return!0;let A=this.__currentOffset-e;return A<0&&(A=-A),this.__currentFluctuation&&this.__latestFluctuations.length>5&&A>this.__currentFluctuation*this.__acceptedFluctuationFactor?!1:(this.__currentFluctuation=this.__pushValueAndCaluclateAverage(this.__latestFluctuations,A),this.__latestFluctuations.length<10?!0:A<this.__currentFluctuation*2n)}__pushValueAndCaluclateAverage(e,A){e.push(A),e.length>10&&e.shift();let t=0n;for(let o=0;o<e.length;o++)t+=e[o];return t/BigInt(e.length)}}const yr="deea3136-d728-4f23-823a-104290",fA=yr+"00",lA=fA+"0000";let Me,AA,Fe={currentTime:void 0,lastTriggerTime:void 0},Re,KA,gA;function _r(){return navigator.bluetooth?(Oe.set("DISCONNECTED"),!0):(Oe.set("UNAVAILABLE"),!1)}async function vr(){Oe.set("CONNECTING");try{Me=await navigator.bluetooth.requestDevice({filters:[{services:[lA]}],optionalServices:[lA]})}catch(e){console.error(e),Oe.set("DISCONNECTED");return}console.log("> Requested "+Me.name+" ("+Me.id+")");let r;try{r=await Me.gatt.connect()}catch{console.log("> Error connecting to "+Me.name+" ("+Me.id+")"),Oe.set("DISCONNECTED");return}Me.addEventListener("gattserverdisconnected",Er),AA=await r.getPrimaryService(lA),Fe.currentTime=await AA.getCharacteristic(fA+"0001"),Fe.lastTriggerTime=await AA.getCharacteristic(fA+"0002"),await Fe.lastTriggerTime.startNotifications(),Fe.lastTriggerTime.addEventListener("characteristicvaluechanged",Cr),Re=new kr,gA=setInterval(Br,1e3),Oe.set("CONNECTED")}function Er(){console.log("> Bluetooth Device disconnected"),Me=void 0,AA=void 0,Re=void 0,KA=void 0,gA!==void 0&&clearInterval(gA),Oe.set("DISCONNECTED")}function Cr(r){var A;if(!r.target)return;const e=r.target;e.uuid==((A=Fe.lastTriggerTime)==null?void 0
NoSleep enabled for older iOS devices. This can interrupt
active or long-running network requests from completing successfully.
See https://github.com/richtr/NoSleep.js/issues/15 for more details.
`),this.noSleepTimer=window.setInterval(()=>{document.hidden||(window.location.href=window.location.href.split("#")[0],window.setTimeout(window.stop,0))},15e3),this.enabled=!0,Promise.resolve()):this.noSleepVideo.play().then(A=>(this.enabled=!0,A)).catch(A=>{throw this.enabled=!1,A})}disable(){uA()?(this._wakeLock&&this._wakeLock.release(),this._wakeLock=null):dA()?this.noSleepTimer&&(console.warn(`
NoSleep now disabled for older iOS devices.
`),window.clearInterval(this.noSleepTimer),this.noSleepTimer=null):this.noSleepVideo.pause(),this.enabled=!1}}var Ao=eo;const ro=Xt(Ao);function to(r){let e,A;return e=new Rt({props:{color:"yellow",$$slots:{default:[ao]},$$scope:{ctx:r}}}),{c(){oe(e.$$.fragment)},l(t){ie(e.$$.fragment,t)},m(t,o){ne(e,t,o),A=!0},p(t,o){const i={};o&2048&&(i.$$scope={dirty:o,ctx:t}),e.$set(i)},i(t){A||(k(e.$$.fragment,t),A=!0)},o(t){v(e.$$.fragment,t),A=!1},d(t){ae(e,t)}}}function oo(r){let e,A,t,o,i={placeholder:r[5][r[1]]};return e=new Pt({props:i}),r[7](e),t=new ir({props:{disabled:r[1]=="wait"||r[1]=="ready",$$slots:{default:[uo]},$$scope:{ctx:r}}}),t.$on("click",r[8]),{c(){oe(e.$$.fragment),A=Ze(),oe(t.$$.fragment)},l(n){ie(e.$$.fragment,n),A=De(n),ie(t.$$.fragment,n)},m(n,a){ne(e,n,a),I(n,A,a),ne(t,n,a),o=!0},p(n,a){const l={};a&2&&(l.placeholder=n[5][n[1]]),e.$set(l);const s={};a&2&&(s.disabled=n[1]=="wait"||n[1]=="ready"),a&2050&&(s.$$scope={dirty:a,ctx:n}),t.$set(s)},i(n){o||(k(e.$$.fragment,n),k(t.$$.fragment,n),o=!0)},o(n){v(e.$$.fragment,n),v(t.$$.fragment,n),o=!1},d(n){n&&w(A),r[7](null),ae(e,n),ae(t,n)}}}function io(r){let e,A,t,o,i,n,a,l,s,d,b;t=new kA({props:{class:"font-bold",href:"https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API#browser_compatibility",$$slots:{default:[fo]},$$scope:{ctx:r}}});const c=[bo,go],u=[];function g(f,h){return f[3].getOS().name==="iOS"?0:1}return l=g(r),s=u[l]=c[l](r),{c(){e=z("span"),A=X("Your Browser is not compatible with this website, as it does not support "),oe(t.$$.fragment),o=X("."),i=Ze(),n=z("span"),a=X(`Please use a browser which supports web bluetooth, for example
`),s.c(),d=X("."),this.h()},l(f){e=N(f,"SPAN",{class:!0});var h=F(e);A=W(h,"Your Browser is not compatible with this website, as it does not support "),ie(t.$$.fragment,h),o=W(h,"."),h.forEach(w),i=De(f),n=N(f,"SPAN",{class:!0});var S=F(n);a=W(S,`Please use a browser which supports web bluetooth, for example
`),s.l(S),d=W(S,"."),S.forEach(w),this.h()},h(){J(e,"class","text-xl text-white rounded-md font-bold border-primary-600 border-4 border-r-4 p-3"),J(n,"class","text-xl mt-3")},m(f,h){I(f,e,h),P(e,A),ne(t,e,null),P(e,o),I(f,i,h),I(f,n,h),P(n,a),u[l].m(n,null),P(n,d),b=!0},p(f,h){const S={};h&2048&&(S.$$scope={dirty:h,ctx:f}),t.$set(S)},i(f){b||(k(t.$$.fragment,f),k(s),b=!0)},o(f){v(t.$$.fragment,f),v(s),b=!1},d(f){f&&(w(e),w(i),w(n)),ae(t),u[l].d()}}}function no(r){let e,A;return e=new ir({props:{$$slots:{default:[po]},$$scope:{ctx:r}}}),e.$on("click",r[6]),{c(){oe(e.$$.fragment)},l(t){ie(e.$$.fragment,t)},m(t,o){ne(e,t,o),A=!0},p(t,o){const i={};o&2048&&(i.$$scope={dirty:o,ctx:t}),e.$set(i)},i(t){A||(k(e.$$.fragment,t),A=!0)},o(t){v(e.$$.fragment,t),A=!1},d(t){ae(e,t)}}}function ao(r){let e;return{c(){e=X("Connecting...")},l(A){e=W(A,"Connecting...")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function lo(r){let e;return{c(){e=X("Wait ...")},l(A){e=W(A,"Wait ...")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function so(r){let e;return{c(){e=X("Reset!")},l(A){e=W(A,"Reset!")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function co(r){let e;return{c(){e=X("Start!")},l(A){e=W(A,"Start!")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function uo(r){let e;function A(i,n){return i[1]=="idle"?co:i[1]=="running"?so:lo}let t=A(r),o=t(r);return{c(){o.c(),e=U()},l(i){o.l(i),e=U()},m(i,n){o.m(i,n),I(i,e,n)},p(i,n){t!==(t=A(i))&&(o.d(1),o=t(i),o&&(o.c(),o.m(e.parentNode,e)))},d(i){i&&w(e),o.d(i)}}}function fo(r){let e;return{c(){e=X(`web bluetooth
`)},l(A){e=W(A,`web bluetooth
`)},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function go(r){let e,A,t;return e=new kA({props:{href:"https://www.google.com/chrome/",$$slots:{default:[ho]},$$scope:{ctx:r}}}),{c(){oe(e.$$.fragment),A=Ze()},l(o){ie(e.$$.fragment,o),A=De(o)},m(o,i){ne(e,o,i),I(o,A,i),t=!0},i(o){t||(k(e.$$.fragment,o),t=!0)},o(o){v(e.$$.fragment,o),t=!1},d(o){o&&w(A),ae(e,o)}}}function bo(r){let e,A,t;return e=new kA({props:{href:"https://apps.apple.com/us/app/bluefy-web-ble-browser/id1492822055",$$slots:{default:[mo]},$$scope:{ctx:r}}}),{c(){oe(e.$$.fragment),A=Ze()},l(o){ie(e.$$.fragment,o),A=De(o)},m(o,i){ne(e,o,i),I(o,A,i),t=!0},i(o){t||(k(e.$$.fragment,o),t=!0)},o(o){v(e.$$.fragment,o),t=!1},d(o){o&&w(A),ae(e,o)}}}function ho(r){let e;return{c(){e=X("Google Chrome")},l(A){e=W(A,"Google Chrome")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function mo(r){let e;return{c(){e=X("Bluefy")},l(A){e=W(A,"Bluefy")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function po(r){let e;return{c(){e=X("Connect")},l(A){e=W(A,"Connect")},m(A,t){I(A,e,t)},d(A){A&&w(e)}}}function wo(r){let e,A,t,o;const i=[no,io,oo,to],n=[];function a(l,s){return l[2]=="DISCONNECTED"?0:l[2]=="UNAVAILABLE"?1:l[2]=="CONNECTED"?2:3}return A=a(r),t=n[A]=i[A](r),{c(){e=z("div"),t.c(),this.h()},l(l){e=N(l,"DIV",{class:!0});var s=F(e);t.l(s),s.forEach(w),this.h()},h(){J(e,"class","p-8 flex flex-col")},m(l,s){I(l,e,s),n[A].m(e,null),o=!0},p(l,[s]){let d=A;A=a(l),A===d?n[A].p(l,s):(Ve(),v(n[d],1,1,()=>{n[d]=null}),Te(),t=n[A],t?t.p(l,s):(t=n[A]=i[A](l),t.c()),k(t,1),t.m(e,null))},i(l){o||(k(t),o=!0)},o(l){v(t),o=!1},d(l){l&&w(e),n[A].d()}}}function ko(r,e,A){let t;PA(r,Oe,g=>A(2,t=g));const o=new Wt.UAParser,i=new ro;let n,a="idle";const l=g=>new Promise(f=>setTimeout(f,g)),s=async()=>{i.isEnabled||i.enable(),A(1,a="wait"),await l(3e3),A(1,a="ready");const g=new Audio("/sound/ok-ready-go.mp3"),f=new Promise(h=>{g.onended=()=>{h()}});await g.play(),await f,n.start(200n),A(1,a="running")},d={idle:"Press start!",wait:"At your marks!",ready:"Ready!",running:""},b=()=>{vr()};function c(g){LA[g?"unshift":"push"](()=>{n=g,A(0,n)})}const u=()=>{a=="idle"?s():a=="running"&&(n.reset(),A(1,a="idle"))};return _r(),[n,a,t,o,s,d,b,c,u]}class Bo extends ve{constructor(e){super(),Ee(this,e,ko,wo,be,{})}}export{Bo as component,Co as universal};