bluetooth-buzzer/_app/immutable/nodes/2.beca72a0.js

6 lines
78 KiB
JavaScript
Raw Normal View History

2024-01-20 11:19:44 +01:00
var lt=Object.defineProperty;var st=(t,e,r)=>e in t?lt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Te=(t,e,r)=>(st(t,typeof e!="symbol"?e+"":e,r),r);import{s as he,e as H,i as A,d as _,A as Z,B as Sr,C as L,D as J,r as Q,f as D,g as G,h as F,E as tr,F as ct,G as U,u as $,v as ee,w as re,H as Wr,I as hr,J as O,p as Hr,K as dt,L as ut,M as ft,N as Zr,a as Be,c as Ue,O as ke,x as K,l as q,m as W,j,n as or,P as Ar,Q as Tr,R as bt,y as zr,z as Yr,o as gt,S as ht,k as Nr}from"../chunks/scheduler.2f27f277.js";import{S as xe,i as Ce,a as y,t as x,g as Me,c as Ie,b as ie,d as ne,m as ae,e as le,f as Or}from"../chunks/index.d9978d1c.js";import{w as Xr}from"../chunks/index.6e61dc83.js";function me(t,e){const r={},o={},i={$$scope:1};let n=t.length;for(;n--;){const a=t[n],l=e[n];if(l){for(const s in a)s in l||(o[s]=1);for(const s in l)i[s]||(r[s]=l[s],i[s]=1);t[n]=l}else for(const s in a)i[s]=1}for(const a in o)a in r||(r[a]=void 0);return r}function ir(t){return typeof t=="object"&&t!==null?t:{}}const mt=!1,pt=!1,mi=Object.freeze(Object.defineProperty({__proto__:null,prerender:mt,ssr:pt},Symbol.toStringTag,{value:"Module"})),Re=Xr("DISCONNECTED");let mr=Xr({});class wt{constructor(){Te(this,"__currentOffset");Te(this,"__currentFluctuation");Te(this,"__currentAcceptanceRate");Te(this,"__acceptedFluctuationFactor",4n);Te(this,"__latestOffsets",[]);Te(this,"__latestFluctuations",[]);Te(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,r,o){let i=r-e,n=o+i/2n-r;this.__handleNewOffset(n)}__handleNewOffset(e){const r=this.__isOffsetInMargin(e);this.__handleAcceptanceResult(r),r&&(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 r=this.__currentOffset-e;return r<0&&(r=-r),this.__currentFluctuation&&this.__latestFluctuations.length>5&&r>this.__currentFluctuation*this.__acceptedFluctuationFactor?!1:(this.__currentFluctuation=this.__pushValueAndCaluclateAverage(this.__latestFluctuations,r),this.__latestFluctuations.length<10?!0:r<this.__currentFluctuation*2n)}__pushValueAndCaluclateAverage(e,r){e.push(r),e.length>10&&e.shift();let o=0n;for(let i=0;i<e.length;i++)o+=e[i];return o/BigInt(e.length)}}const _t="deea3136-d728-4f23-823a-104290",ur=_t+"00",sr=ur+"0000";let Oe,rr,Fe={currentTime:void 0,lastTriggerTime:void 0},Pe,Kr,fr;function yt(){return navigator.bluetooth?(Re.set("DISCONNECTED"),!0):(Re.set("UNAVAILABLE"),!1)}async function kt(){Re.set("CONNECTING");try{Oe=await navigator.bluetooth.requestDevice({filters:[{services:[sr]}],optionalServices:[sr]})}catch(e){console.error(e),Re.set("DISCONNECTED");return}console.log("> Requested "+Oe.name+" ("+Oe.id+")");let t;try{t=await Oe.gatt.connect()}catch{console.log("> Error connecting to "+Oe.name+" ("+Oe.id+")"),Re.set("DISCONNECTED");return}Oe.addEventListener("gattserverdisconnected",vt),rr=await t.getPrimaryService(sr),Fe.currentTime=await rr.getCharacteristic(ur+"0001"),Fe.lastTriggerTime=await rr.getCharacteristic(ur+"0002"),await Fe.lastTriggerTime.startNotifications(),Fe.lastTriggerTime.addEventListener("characteristicvaluechanged",xt),Pe=new wt,fr=setInterval(Ct,1e3),Re.set("CONNECTED")}function vt(){console.log("> Bluetooth Device disconnected"),Oe=void 0,rr=void 0,Pe=void 0,Kr=void 0,fr!==void 0&&clearInterval(fr),Re.set("DISCONNECTED")}function xt(t){var r;if(!t.target)return;const e=t.target;e.uuid==((r=Fe.lastTriggerTime)==null?void 0:r.uu
`),c.c(),u=q("."),this.h()},l(b){e=G(b,"SPAN",{class:!0});var m=F(e);r=W(m,"Your Browser is not compatible with this website, as it does not support "),ne(o.$$.fragment,m),i=W(m,"."),m.forEach(_),n=Ue(b),a=G(b,"SPAN",{class:!0});var z=F(a);l=W(z,`Please use a browser which supports web bluetooth, for example
`),c.l(z),u=W(z,"."),z.forEach(_),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(a,"class","text-xl mt-3")},m(b,m){A(b,e,m),K(e,r),ae(o,e,null),K(e,i),A(b,n,m),A(b,a,m),K(a,l),f[s].m(a,null),K(a,u),h=!0},p(b,m){const z={};m&1024&&(z.$$scope={dirty:m,ctx:b}),o.$set(z)},i(b){h||(y(o.$$.fragment,b),y(c),h=!0)},o(b){x(o.$$.fragment,b),x(c),h=!1},d(b){b&&(_(e),_(n),_(a)),le(o),f[s].d()}}}function Qo(t){let e,r;return e=new ot({props:{$$slots:{default:[ci]},$$scope:{ctx:t}}}),e.$on("click",t[6]),{c(){ie(e.$$.fragment)},l(o){ne(e.$$.fragment,o)},m(o,i){ae(e,o,i),r=!0},p(o,i){const n={};i&1024&&(n.$$scope={dirty:i,ctx:o}),e.$set(n)},i(o){r||(y(e.$$.fragment,o),r=!0)},o(o){x(e.$$.fragment,o),r=!1},d(o){le(e,o)}}}function $o(t){let e;return{c(){e=q("Connecting...")},l(r){e=W(r,"Connecting...")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function ei(t){let e;return{c(){e=q("Wait ...")},l(r){e=W(r,"Wait ...")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function ri(t){let e;return{c(){e=q("Reset!")},l(r){e=W(r,"Reset!")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function ti(t){let e;return{c(){e=q("Start!")},l(r){e=W(r,"Start!")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function oi(t){let e;function r(n,a){return n[1]=="idle"?ti:n[1]=="running"?ri:ei}let o=r(t),i=o(t);return{c(){i.c(),e=H()},l(n){i.l(n),e=H()},m(n,a){i.m(n,a),A(n,e,a)},p(n,a){o!==(o=r(n))&&(i.d(1),i=o(n),i&&(i.c(),i.m(e.parentNode,e)))},d(n){n&&_(e),i.d(n)}}}function ii(t){let e;return{c(){e=q(`web bluetooth
`)},l(r){e=W(r,`web bluetooth
`)},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function ni(t){let e,r,o;return e=new wr({props:{href:"https://www.google.com/chrome/",$$slots:{default:[li]},$$scope:{ctx:t}}}),{c(){ie(e.$$.fragment),r=Be()},l(i){ne(e.$$.fragment,i),r=Ue(i)},m(i,n){ae(e,i,n),A(i,r,n),o=!0},i(i){o||(y(e.$$.fragment,i),o=!0)},o(i){x(e.$$.fragment,i),o=!1},d(i){i&&_(r),le(e,i)}}}function ai(t){let e,r,o;return e=new wr({props:{href:"https://apps.apple.com/us/app/bluefy-web-ble-browser/id1492822055",$$slots:{default:[si]},$$scope:{ctx:t}}}),{c(){ie(e.$$.fragment),r=Be()},l(i){ne(e.$$.fragment,i),r=Ue(i)},m(i,n){ae(e,i,n),A(i,r,n),o=!0},i(i){o||(y(e.$$.fragment,i),o=!0)},o(i){x(e.$$.fragment,i),o=!1},d(i){i&&_(r),le(e,i)}}}function li(t){let e;return{c(){e=q("Google Chrome")},l(r){e=W(r,"Google Chrome")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function si(t){let e;return{c(){e=q("Bluefy")},l(r){e=W(r,"Bluefy")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function ci(t){let e;return{c(){e=q("Connect")},l(r){e=W(r,"Connect")},m(r,o){A(r,e,o)},d(r){r&&_(e)}}}function di(t){let e,r,o,i;const n=[Qo,Jo,Ko,Xo],a=[];function l(s,c){return s[2]=="DISCONNECTED"?0:s[2]=="UNAVAILABLE"?1:s[2]=="CONNECTED"?2:3}return r=l(t),o=a[r]=n[r](t),{c(){e=D("div"),o.c(),this.h()},l(s){e=G(s,"DIV",{class:!0});var c=F(e);o.l(c),c.forEach(_),this.h()},h(){j(e,"class","p-8 flex flex-col")},m(s,c){A(s,e,c),a[r].m(e,null),i=!0},p(s,[c]){let u=r;r=l(s),r===u?a[r].p(s,c):(Me(),x(a[u],1,1,()=>{a[u]=null}),Ie(),o=a[r],o?o.p(s,c):(o=a[r]=n[r](s),o.c()),y(o,1),o.m(e,null))},i(s){i||(y(o),i=!0)},o(s){x(o),i=!1},d(s){s&&_(e),a[r].d()}}}function ui(t,e,r){let o;Yr(t,Re,f=>r(2,o=f));const i=new jo.UAParser;let n,a="idle";const l=f=>new Promise(g=>setTimeout(g,f)),s=async()=>{r(1,a="wait"),await l(3e3),r(1,a="ready");const f=new Audio("/sound/ok-ready-go.mp3"),g=new Promise(b=>{f.onended=()=>{b()}});await f.play(),await g,n.start(200n),r(1,a="running")},c={idle:"Press start!",wait:"At your marks!",ready:"Ready!",running:""},u=()=>{kt()};function h(f){Hr[f?"unshift":"push"](()=>{n=f,r(0,n)})}const d=()=>{a=="idle"?s():a=="running"&&(n.reset(),r(1,a="idle"))};return yt(),[n,a,o,i,s,c,u,h,d]}class pi extends xe{constructor(e){super(),Ce(this,e,ui,di,he,{})}}export{pi as component,mi as universal};