@busy-app/busy-lib 0.13.1 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +22 -8
- package/dist/index.d.ts +326 -514
- package/dist/index.js +917 -1053
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var M=Object.defineProperty;var V=(r,e,n)=>e in r?M(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n;var l=(r,e,n)=>V(r,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("openapi-fetch"),W=(r,e)=>{if(typeof FormData<"u"&&r instanceof FormData||typeof Buffer<"u"&&typeof Buffer.isBuffer=="function"&&Buffer.isBuffer(r)||typeof File<"u"&&r instanceof File||typeof Blob<"u"&&r instanceof Blob||typeof ArrayBuffer<"u"&&r instanceof ArrayBuffer||typeof ArrayBuffer<"u"&&ArrayBuffer.isView&&ArrayBuffer.isView(r))return r;let n;return e&&(e instanceof Headers?n=e.get("Content-Type")??e.get("content-type")??void 0:typeof e=="object"&&(n=e["Content-Type"]??e["content-type"]),n==="application/x-www-form-urlencoded")?r&&typeof r=="object"&&!(r instanceof URLSearchParams)?new URLSearchParams(r).toString():String(r):JSON.stringify(r)};async function A(r){const t=(r.headers.get("content-type")||"").includes("application/json")?await r.clone().json():await r.clone().text(),i=typeof t=="object"&&t!==null?t.error||t.message:typeof t=="string"?t:void 0;return Object.assign(new Error(i||`HTTP ${r.status} ${r.statusText}`),{status:r.status,statusText:r.statusText,body:t})}async function s(r,e=3e3){if(e<=0)return await r();const n=new AbortController,t=setTimeout(()=>n.abort(),e);try{return await r(n.signal)}catch(i){throw i instanceof DOMException&&i.name==="AbortError"?new Error(`Request timed out after ${e}ms`):i}finally{clearTimeout(t)}}function G(r,e,n){let t,i=n??void 0,o,a=null;const c=async()=>{t||(a||(a=(async()=>{const f=await e();if(!f.api_semver)throw new Error("Empty API version");t=f.api_semver})().finally(()=>{a=null})),await a)},u={async onRequest({request:f,schemaPath:y}){return i&&f.headers.set("Authorization",`Bearer ${i}`),y!=="/version"&&(await c(),t&&f.headers.set("X-API-Sem-Ver",t),o&&f.headers.set("X-API-Token",o)),f},async onResponse({request:f,response:y,options:B,schemaPath:F}){if(y.ok)return y;if(F==="/version")throw await A(y);if(y.status!==405)throw await A(y);t=void 0,await c(),t&&f.headers.set("X-API-Sem-Ver",t),i&&f.headers.set("Authorization",`Bearer ${i}`);const T=await(B.fetch??fetch)(f);if(T.ok)return T;throw await A(T)}},v=q({baseUrl:r,bodySerializer:W});return v.use(u),{client:v,setApiKey:f=>{o=f},setToken:f=>{i=f}}}async function $(r,e){const{data:n,error:t}=await s(i=>r.GET("/version",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function z(r,e){const{data:n,error:t}=await s(i=>r.GET("/status",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function J(r,e){const{data:n,error:t}=await s(i=>r.GET("/status/system",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function H(r,e){const{data:n,error:t}=await s(i=>r.GET("/status/power",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function K(r,e){const{data:n,error:t}=await s(i=>r.GET("/status/device",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function X(r,e){const{data:n,error:t}=await s(i=>r.GET("/status/firmware",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}class Y{async SystemVersionGet(e){const n=await $(this.apiClient,e);return this.apiSemver=n.api_semver,n}async SystemStatusGet(e){return await z(this.apiClient,e)}async SystemInfoGet(e){return await J(this.apiClient,e)}async SystemStatusPowerGet(e){return await H(this.apiClient,e)}async SystemStatusDeviceGet(e){return await K(this.apiClient,e)}async SystemStatusFirmwareGet(e){return await X(this.apiClient,e)}}async function Z(r,e){const{file:n}=e,{data:t,error:i}=await s(o=>r.POST("/update",{headers:{"Content-Type":"application/octet-stream"},body:n,signal:o}),e.timeout);if(i)throw i;return t}async function Q(r,e){const{data:n,error:t}=await s(i=>r.POST("/update/check",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ee(r,e){const{data:n,error:t}=await s(i=>r.GET("/update/status",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ne(r,e){const{version:n}=e,{data:t,error:i}=await s(o=>r.GET("/update/changelog",{params:{query:{version:n}},signal:o}),e.timeout);if(i)throw i;return t}async function te(r,e){const{version:n}=e,{data:t,error:i}=await s(o=>r.POST("/update/install",{params:{query:{version:n}},signal:o}),e.timeout);if(i)throw i;return t}async function re(r,e){const{data:n,error:t}=await s(i=>r.POST("/update/abort_download",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ie(r,e){const{data:n,error:t}=await s(i=>r.GET("/update/autoupdate",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function oe(r,e){const{is_enabled:n,interval_start:t,interval_end:i}=e,{data:o,error:a}=await s(c=>r.POST("/update/autoupdate",{body:{is_enabled:n,interval_start:t,interval_end:i},signal:c}),e.timeout);if(a)throw a;return o}class se{async UpdateFromFile(e){return await Z(this.apiClient,e)}async UpdateCheck(e){return await Q(this.apiClient,e)}async UpdateStatusGet(e){return await ee(this.apiClient,e)}async UpdateChangelogGet(e){return await ne(this.apiClient,e)}async UpdateInstall(e){return await te(this.apiClient,e)}async UpdateAbort(e){return await re(this.apiClient,e)}async UpdateAutoUpdateGet(e){return await ie(this.apiClient,e)}async UpdateAutoUpdateSet(e){return await oe(this.apiClient,e)}}async function ae(r,e){const{data:n,error:t}=await s(i=>r.GET("/time",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ue(r,e){const{timestamp:n}=e,{data:t,error:i}=await s(o=>r.POST("/time/timestamp",{params:{query:{timestamp:n}},signal:o}),e.timeout);if(i)throw i;return t}async function le(r,e){const{data:n,error:t}=await s(i=>r.GET("/time/timezone",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ce(r,e){const{timezone:n}=e,{data:t,error:i}=await s(o=>r.POST("/time/timezone",{params:{query:{timezone:n}},signal:o}),e.timeout);if(i)throw i;return t}async function fe(r,e){const{data:n,error:t}=await s(i=>r.GET("/time/tzlist",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}class de{async TimeGet(e){return await ae(this.apiClient,e)}async TimeTimestampSet(e){return await ue(this.apiClient,e)}async TimeTimezoneGet(e){return await le(this.apiClient,e)}async TimeTimezoneSet(e){return await ce(this.apiClient,e)}async TimeTzListGet(e){return await fe(this.apiClient,e)}}async function pe(r,e){const{data:n,error:t}=await s(i=>r.GET("/account/status",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function he(r,e){const{data:n,error:t}=await s(i=>r.GET("/account/info",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ye(r,e){const{data:n,error:t}=await s(i=>r.GET("/account/profile",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function me(r,e){const{profile:n,custom_url:t}=e,{data:i,error:o}=await s(a=>r.POST("/account/profile",{params:{query:{profile:n,custom_url:t}},signal:a}),e.timeout);if(o)throw o;return i}async function ve(r,e){const{data:n,error:t}=await s(i=>r.DELETE("/account",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ge(r,e){const{data:n,error:t}=await s(i=>r.POST("/account/link",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}class be{async AccountInfoGet(e){return await he(this.apiClient,e)}async AccountStateGet(e){return await pe(this.apiClient,e)}async AccountProfileGet(e){return await ye(this.apiClient,e)}async AccountProfileSet(e){return await me(this.apiClient,e)}async AccountUnlink(e){return await ve(this.apiClient,e)}async AccountLink(e){return await ge(this.apiClient,e)}}async function Ee(r,e){const{application_name:n,elements:t,priority:i=50,timeout:o}=e,{data:a,error:c}=await s(u=>r.POST("/display/draw",{body:{application_name:n,priority:i,elements:t},signal:u}),o);if(c)throw c;return a}async function _e(r,e){const{data:n,error:t}=await s(i=>r.DELETE("/display/draw",{params:{query:{application_name:e==null?void 0:e.application_name}},signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Oe(r,e){const{display:n,timeout:t}=e,{data:i,error:o}=await s(a=>r.GET("/screen",{params:{query:{display:n}},parseAs:"blob",signal:a}),t);if(o)throw o;return i}async function we(r,e){const{data:n,error:t}=await s(i=>r.GET("/display/brightness",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Re(r,e){const{value:n}=e,i=(c=>{if(typeof c=="number"){if(c<0||c>100)throw new Error("Brightness value must be between 0 and 100 or 'auto'");return String(c)}return"auto"})(n),{data:o,error:a}=await s(c=>r.POST("/display/brightness",{params:{query:{value:i}},signal:c}),e.timeout);if(a)throw a;return o}class Te{async DisplayDraw(e){return await Ee(this.apiClient,e)}async DisplayClear(e){return await _e(this.apiClient,e)}async DisplayScreenFrameGet(e){return await Oe(this.apiClient,e)}async DisplayBrightnessGet(e){return await we(this.apiClient,e)}async DisplayBrightnessSet(e){return await Re(this.apiClient,e)}}async function Ae(r,e){const{application_name:n,path:t}=e,{data:i,error:o}=await s(a=>r.POST("/audio/play",{params:{query:{application_name:n,path:t}},signal:a}),e.timeout);if(o)throw o;return i}async function Se(r,e){const{data:n,error:t}=await s(i=>r.DELETE("/audio/play",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Ne(r,e){const{data:n,error:t}=await s(i=>r.GET("/audio/volume",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function ke(r,e){const{volume:n}=e;if(typeof n!="number"||n<0||n>100)throw new Error("Volume must be a number between 0 and 100");const{data:t,error:i}=await s(o=>r.POST("/audio/volume",{params:{query:{volume:n}},signal:o}),e.timeout);if(i)throw i;return t}class Ce{async AudioPlay(e){return await Ae(this.apiClient,e)}async AudioStop(e){return await Se(this.apiClient,e)}async AudioVolumeGet(e){return await Ne(this.apiClient,e)}async AudioVolumeSet(e){return await ke(this.apiClient,e)}}async function Ie(r,e){const{data:n,error:t}=await s(i=>r.GET("/wifi/status",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function qe(r,e){const{ssid:n,password:t,security:i,ip_config:o}=e,{data:a,error:c}=await s(u=>r.POST("/wifi/connect",{body:{ssid:n,password:t,security:i,ip_config:o},signal:u}),e.timeout);if(c)throw c;return a}async function je(r,e){const{data:n,error:t}=await s(i=>r.POST("/wifi/disconnect",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Pe(r,e){const{data:n,error:t}=await s(i=>r.GET("/wifi/networks",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}class De{async WifiStatusGet(e){return await Ie(this.apiClient,e)}async WifiConnect(e){return await qe(this.apiClient,e)}async WifiDisconnect(e){return await je(this.apiClient,e)}async WifiNetworksGet(e){return await Pe(this.apiClient,e)}}async function Le(r,e){const{path:n,file:t}=e,{data:i,error:o}=await s(a=>r.POST("/storage/write",{params:{query:{path:n}},headers:{"Content-Type":"application/octet-stream"},body:t,signal:a}),e.timeout);if(o)throw o;return i}async function Ue(r,e){const{path:n,as_array_buffer:t}=e,{data:i,error:o}=await s(a=>r.GET("/storage/read",{params:{query:{path:n}},parseAs:t?"arrayBuffer":"blob",signal:a}),e.timeout);if(o)throw o;return i}async function xe(r,e){const{path:n}=e,{data:t,error:i}=await s(o=>r.GET("/storage/list",{params:{query:{path:n}},signal:o}),e.timeout);if(i)throw i;return t}async function Be(r,e){const{path:n}=e,{data:t,error:i}=await s(o=>r.DELETE("/storage/remove",{params:{query:{path:n}},signal:o}),e.timeout);if(i)throw i;return t}async function Fe(r,e){const{path:n}=e,{data:t,error:i}=await s(o=>r.POST("/storage/mkdir",{params:{query:{path:n}},signal:o}),e.timeout);if(i)throw i;return t}async function Me(r,e){const{data:n,error:t}=await s(i=>r.GET("/storage/status",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Ve(r,e){const{path:n,new_path:t}=e,{data:i,error:o}=await s(a=>r.POST("/storage/rename",{params:{query:{path:n,new_path:t}},signal:a}),e.timeout);if(o)throw o;return i}class We{async StorageWrite(e){return await Le(this.apiClient,e)}async StorageRead(e){return await Ue(this.apiClient,e)}async StorageListGet(e){return await xe(this.apiClient,e)}async StorageRemove(e){return await Be(this.apiClient,e)}async StorageMkdir(e){return await Fe(this.apiClient,e)}async StorageStatusGet(e){return await Me(this.apiClient,e)}async StorageRename(e){return await Ve(this.apiClient,e)}}async function Ge(r,e){const{data:n,error:t}=await s(i=>r.GET("/access",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function $e(r,e){const{mode:n,key:t}=e,i=t??"";if(String(i).trim()&&!/^\d{4,10}$/.test(String(i)))throw new Error("Key must be a string of 4 to 10 digits");const{data:o,error:a}=await s(c=>r.POST("/access",{params:{query:{mode:n,key:i}},signal:c}),e.timeout);if(a)throw a;return o}async function ze(r,e){const{data:n,error:t}=await s(i=>r.GET("/name",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Je(r,e){const{name:n}=e,{data:t,error:i}=await s(o=>r.POST("/name",{body:{name:n},signal:o}),e.timeout);if(i)throw i;return t}class He{async SettingsAccessGet(e){return await Ge(this.apiClient,e)}async SettingsAccessSet(e){const n=await $e(this.apiClient,e);return e.mode==="key"&&e.key&&this.setApiKey(e.key),n}async SettingsNameGet(e){return await ze(this.apiClient,e)}async SettingsNameSet(e){return await Je(this.apiClient,e)}}async function Ke(r,e){const{data:n,error:t}=await s(i=>r.POST("/ble/enable",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Xe(r,e){const{data:n,error:t}=await s(i=>r.POST("/ble/disable",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Ye(r,e){const{data:n,error:t}=await s(i=>r.DELETE("/ble/pairing",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function Ze(r,e){const{data:n,error:t}=await s(i=>r.GET("/ble/status",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}class Qe{async BleEnable(e){return await Ke(this.apiClient,e)}async BleDisable(e){return await Xe(this.apiClient,e)}async BleUnpair(e){return await Ye(this.apiClient,e)}async BleStatusGet(e){return await Ze(this.apiClient,e)}}async function en(r,e){const{key:n}=e,{data:t,error:i}=await s(o=>r.POST("/input",{params:{query:{key:n}},signal:o}),e.timeout);if(i)throw i;return t}class nn{async InputSend(e){return await en(this.apiClient,e)}}async function tn(r,e){const{data:n,error:t}=await s(i=>r.GET("/smart_home/pairing",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function rn(r,e){const{data:n,error:t}=await s(i=>r.POST("/smart_home/pairing",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function on(r,e){const{data:n,error:t}=await s(i=>r.DELETE("/smart_home/pairing",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function sn(r,e){const{data:n,error:t}=await s(i=>r.GET("/smart_home/switch",{signal:i}),e==null?void 0:e.timeout);if(t)throw t;return n}async function an(r,e){const{timeout:n,...t}=e,{data:i,error:o}=await s(a=>r.POST("/smart_home/switch",{body:t,signal:a}),n);if(o)throw o;return i}class un{async SmartHomePairingGet(e){return await tn(this.apiClient,e)}async SmartHomePair(e){return await rn(this.apiClient,e)}async SmartHomeErase(e){return await on(this.apiClient,e)}async SmartHomeSwitchStateGet(e){return await sn(this.apiClient,e)}async SmartHomeSwitchStateSet(e){return await an(this.apiClient,e)}async MatterStatusGet(e){return await this.SmartHomePairingGet(e)}async MatterPair(e){return await this.SmartHomePair(e)}async MatterErase(e){return await this.SmartHomeErase(e)}}async function ln(r,e){const{application_name:n,file:t,data:i}=e,{data:o,error:a}=await s(c=>r.POST("/assets/upload",{params:{query:{application_name:n,file:t}},headers:{"Content-Type":"application/octet-stream"},body:i,signal:c}),e.timeout);if(a)throw a;return o}async function cn(r,e){const{application_name:n}=e,{data:t,error:i}=await s(o=>r.DELETE("/assets/upload",{params:{query:{application_name:n}},signal:o}),e.timeout);if(i)throw i;return t}class fn{async AssetsUpload(e){return await ln(this.apiClient,e)}async AssetsDelete(e){return await cn(this.apiClient,e)}}const N="http://10.0.4.20",dn="https://proxy.busy.app",pn=/^https?:\/\/proxy(?:\.(?:dev|test|stage))?\.busy\.app$/i;function k(r){const e=r.split(".");if(e.length!==4)return!1;for(const n of e){if(n.length===0||n.length>1&&n[0]==="0"||!/^\d+$/.test(n))return!1;const t=Number(n);if(t<0||t>255)return!1}return!0}function C(r){return/\.local$/i.test(r)}class j{constructor(e){l(this,"addr");l(this,"apiSemver");l(this,"apiClient");l(this,"setApiKeyFn");l(this,"setTokenFn");l(this,"connectionType","unknown");if(!e||!e.addr&&!e.token)this.addr=N;else if(!e.addr)this.addr=dn;else{let o=e.addr.trim();if(/^https?:\/\//i.test(o)||(o=`http://${o}`),pn.test(o)&&!e.token)throw new Error("Token is required. Please provide it.");this.addr=o}this.apiSemver="";const{client:n,setApiKey:t,setToken:i}=G(`${this.addr}/api/`,this.SystemVersionGet.bind(this),e==null?void 0:e.token);this.apiClient=n,this.setApiKeyFn=t,this.setTokenFn=i,this.detectConnectionType()}async detectConnectionType(){const e=new URL(this.addr).hostname;if(!k(e)&&!C(e)){this.connectionType="wifi";return}const n=q({baseUrl:`${this.addr}/api/`});try{const{response:t}=await n.GET("/name");if(t.status===401||t.status===403)this.connectionType="wifi";else if(t.ok)this.connectionType="usb";else throw new Error(`Failed to detect connection type. Status: ${t.status}`)}catch(t){throw t}}setApiKey(e){this.setApiKeyFn(e)}setToken(e){this.setTokenFn(e)}}function hn(r,e){e.forEach(n=>{Object.getOwnPropertyNames(n.prototype).forEach(t=>{Object.defineProperty(r.prototype,t,Object.getOwnPropertyDescriptor(n.prototype,t)||Object.create(null))})})}hn(j,[Y,se,de,be,Te,Ce,De,We,He,Qe,nn,un,fn]);var w=(r=>(r[r.FRONT=0]="FRONT",r[r.BACK=1]="BACK",r))(w||{});const P=3e3,D=new Set([1001,1006,1012,1013,1014,3008]);function L(r,e){if(e<0||e>=r.length)throw new Error(`Index ${e} is out of bounds (0…${r.length-1})`);const n=r[e];if(n===void 0)throw new Error(`Unexpected undefined at index ${e}`);return n}function yn(r,e){let n=0;const t=r.length,i=[];for(;n<t;){const o=L(r,n);if(n+=1,(o&128)!==0){const a=o&127;for(let c=0;c<a*e;c++)i.push(r[n+c]);n+=a*e}else{const a=o,c=r.slice(n,n+e);for(let u=0;u<a;u++)for(let v=0;v<e;v++)i.push(c[v]);n+=e}}return new Uint8Array(i)}function mn(r){const e=new Uint8Array(r.length*2);let n=0,t=0;for(;n<r.length;){const i=L(r,n),o=i&15,a=i>>4&15;e[t]=o,e[t+1]=a,n+=1,t+=2}return e}const U=()=>typeof window<"u"&&typeof window.document<"u";class vn{constructor(e){l(this,"addr");l(this,"connected",!1);l(this,"apiKey");l(this,"apiSemver");l(this,"dataListeners",[]);l(this,"stopListeners",[]);l(this,"errorListeners",[]);l(this,"socket",null);if(this.config=e,!U())throw new Error("not browser");if(e.apiKey&&(this.apiKey=e.apiKey),e.apiSemver&&(this.apiSemver=e.apiSemver),!e||!e.addr)this.addr=N;else{let n=e.addr.trim();/^https?:\/\//i.test(n)||(n=`http://${n}`);try{const i=new URL(n).hostname;if(!k(i)&&!C(i))throw new Error(`Invalid address: "${e.addr}". Only IP addresses and mDNS names (ending in .local) are supported.`)}catch(t){throw t instanceof Error&&t.message.startsWith("Invalid address")?t:new Error(`Invalid URL format: "${e.addr}"`)}this.addr=n}}onData(e){this.dataListeners.push(e)}onStop(e){this.stopListeners.push(e)}onError(e){this.errorListeners.push(e)}emitData(e){for(const n of this.dataListeners)n(e)}emitStop(){for(const e of this.stopListeners)e()}emitError(e){for(const n of this.errorListeners)n(e)}async openWebsocket(){this.socket&&await this.closeWebsocket();const e=new URL(`${this.addr}/api/screen/ws`);if(this.apiKey&&e.searchParams.append("x-api-token",this.apiKey),this.apiSemver&&e.searchParams.append("x-api-sem-ver",this.apiSemver),!e)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(e),this.socket.onopen=()=>{this.socket&&(this.socket.send(JSON.stringify({display:this.config.deviceScreen})),this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=n=>{try{if(typeof n.data=="string")return;const t=new Uint8Array(n.data);let i;const o=this.config.deviceScreen===w.FRONT?3:2;try{const a=yn(t,o);this.config.deviceScreen===w.BACK?i=mn(a):i=a,this.emitData(i)}catch{this.emitData(t)}}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=n=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:n}),this.emitStop()},this.socket.onclose=async n=>{if(this.socket=null,this.connected=!1,n.code===P||D.has(n.code)){this.emitError({code:n.code,message:n.reason,raw:n});return}this.emitStop()}}closeWebsocket(){return this.connected=!1,new Promise(e=>{this.socket?(this.socket.onclose=()=>{e()},this.socket.close(),this.socket=null):e(),this.emitStop()})}}class gn{constructor(e){l(this,"addr");l(this,"connected",!1);l(this,"apiKey");l(this,"apiSemver");l(this,"inputEvent");l(this,"dataListeners",[]);l(this,"stopListeners",[]);l(this,"errorListeners",[]);l(this,"socket",null);if(!U())throw new Error("not browser");if(e!=null&&e.apiKey&&(this.apiKey=e.apiKey),e!=null&&e.apiSemver&&(this.apiSemver=e.apiSemver),!e||!e.addr)this.addr=N;else{let n=e.addr.trim();/^https?:\/\//i.test(n)||(n=`http://${n}`);try{const i=new URL(n).hostname;if(!k(i)&&!C(i))throw new Error(`Invalid address: "${e.addr}". Only IP addresses and mDNS names (ending in .local) are supported.`)}catch(t){throw t instanceof Error&&t.message.startsWith("Invalid address")?t:new Error(`Invalid URL format: "${e.addr}"`)}this.addr=n}this.inputEvent={}}onData(e){this.dataListeners.push(e)}onStop(e){this.stopListeners.push(e)}onError(e){this.errorListeners.push(e)}emitData(e){for(const n of this.dataListeners)n(e)}emitStop(){for(const e of this.stopListeners)e()}emitError(e){for(const n of this.errorListeners)n(e)}async openWebsocket(){this.socket&&await this.closeWebsocket();const e=new URL(`${this.addr}/api/input`);if(this.apiKey&&e.searchParams.append("x-api-token",this.apiKey),this.apiSemver&&e.searchParams.append("x-api-sem-ver",this.apiSemver),!e)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(e),this.socket.onopen=()=>{this.socket&&(this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=n=>{try{if(typeof n.data=="string")return;const t=new Uint8Array(n.data);this.emitData(t)}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=n=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:n}),this.emitStop()},this.socket.onclose=async n=>{if(this.socket=null,this.connected=!1,n.code===P||D.has(n.code)){this.emitError({code:n.code,message:n.reason,raw:n});return}this.emitStop()}}sendInput({keyName:e,value:n}){if(!this.socket||!this.connected)throw new Error("WebSocket: Not connected");this.inputEvent[e]=n,this.socket.send(JSON.stringify(this.inputEvent)),n===0&&delete this.inputEvent[e]}closeWebsocket(){return this.connected=!1,new Promise(e=>{this.socket?(this.socket.onclose=()=>{e()},this.socket.close(),this.socket=null):e(),this.emitStop()})}}var d=(r=>(r.CONNECTION_FAILED="CONNECTION_FAILED",r.RECONNECT_FAILED="RECONNECT_FAILED",r.CONNECTION_LOST="CONNECTION_LOST",r.CONNECTION_TIMEOUT="CONNECTION_TIMEOUT",r.AUTH_FAILED="AUTH_FAILED",r.AUTH_REFRESH_FAILED="AUTH_REFRESH_FAILED",r.DEVICE_ERROR="DEVICE_ERROR",r.DECODE_ERROR="DECODE_ERROR",r.FRAME_PROCESS_ERROR="FRAME_PROCESS_ERROR",r.STREAM_ALREADY_STARTED="STREAM_ALREADY_STARTED",r.WORKER_INIT_FAILED="WORKER_INIT_FAILED",r.UNKNOWN_ERROR="UNKNOWN_ERROR",r))(d||{});class h extends Error{constructor(e,n,t){super(n),this.code=e,this.data=t,this.name="StateStreamError"}}var p=(r=>(r.IDLE="IDLE",r.STARTING="STARTING",r.RUNNING="RUNNING",r.STOPPED="STOPPED",r.FAILED="FAILED",r))(p||{}),m=(r=>(r.DISCONNECTED="DISCONNECTED",r.CONNECTING="CONNECTING",r.CONNECTED="CONNECTED",r.RECONNECTING="RECONNECTING",r))(m||{}),g=(r=>(r.UNAUTHENTICATED="UNAUTHENTICATED",r.AUTHENTICATING="AUTHENTICATING",r.AUTHENTICATED="AUTHENTICATED",r.FAILED="FAILED",r))(g||{}),b=(r=>(r.NONE="NONE",r.ACTIVE="ACTIVE",r.STALE="STALE",r))(b||{}),E=(r=>(r.OFF="OFF",r.INITIALIZING="INITIALIZING",r.READY="READY",r.ERROR="ERROR",r))(E||{});const x=`var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, src = { exports: {} }, indexLight = { exports: {} }, indexMinimal = {}, minimal = {}, aspromise, hasRequiredAspromise;
|
|
1
|
+
"use strict";var P=Object.defineProperty;var j=(e,n,t)=>n in e?P(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var l=(e,n,t)=>j(e,typeof n!="symbol"?n+"":n,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("openapi-fetch"),D=(e,n)=>{if(typeof FormData<"u"&&e instanceof FormData||typeof Buffer<"u"&&typeof Buffer.isBuffer=="function"&&Buffer.isBuffer(e)||typeof File<"u"&&e instanceof File||typeof Blob<"u"&&e instanceof Blob||typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer||typeof ArrayBuffer<"u"&&ArrayBuffer.isView&&ArrayBuffer.isView(e))return e;let t;return n&&(n instanceof Headers?t=n.get("Content-Type")??n.get("content-type")??void 0:typeof n=="object"&&(t=n["Content-Type"]??n["content-type"]),t==="application/x-www-form-urlencoded")?e&&typeof e=="object"&&!(e instanceof URLSearchParams)?new URLSearchParams(e).toString():String(e):JSON.stringify(e)};async function w(e){const r=(e.headers.get("content-type")||"").includes("application/json")?await e.clone().json():await e.clone().text(),i=typeof r=="object"&&r!==null?r.error||r.message:typeof r=="string"?r:void 0;return Object.assign(new Error(i||`HTTP ${e.status} ${e.statusText}`),{status:e.status,statusText:e.statusText,body:r})}function L(e,n,t,r=3e3){let i,o=t??void 0,s,u=null;const a=async()=>{i||(u||(u=(async()=>{const f=await n();if(!f.api_semver)throw new Error("Empty API version");i=f.api_semver})().finally(()=>{u=null})),await u)},q={async onRequest({request:f,schemaPath:p}){return o&&f.headers.set("Authorization",`Bearer ${o}`),p!=="/version"&&(await a(),i&&f.headers.set("X-API-Sem-Ver",i),s&&f.headers.set("X-API-Token",s)),f},async onResponse({request:f,response:p,options:T,schemaPath:A}){if(p.ok)return p;if(A==="/version")throw await w(p);if(p.status!==405)throw await w(p);i=void 0,await a(),i&&f.headers.set("X-API-Sem-Ver",i),o&&f.headers.set("Authorization",`Bearer ${o}`);const y=await(T.fetch??fetch)(f);if(y.ok)return y;throw await w(y)}},R=I({baseUrl:e,bodySerializer:D});return R.withTimeout=async(f,p=r)=>{if(p<=0)return await f();const T=new AbortController,A=setTimeout(()=>T.abort(),p);try{return await f(T.signal)}catch(y){throw y instanceof DOMException&&y.name==="AbortError"?new Error(`Request timed out after ${p}ms`):y}finally{clearTimeout(A)}},R.use(q),{client:R,setApiKey:f=>{s=f},setToken:f=>{o=f}}}async function F(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/version",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function x(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/status",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function U(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/status/system",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function B(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/status/power",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function M(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/status/device",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function G(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/status/firmware",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function V(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/transport",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}class W{async SystemVersionGet(n){const t=await F(this.apiClient,n);return this.apiSemver=t.api_semver,t}async SystemStatusGet(n){return await x(this.apiClient,n)}async SystemInfoGet(n){return await U(this.apiClient,n)}async SystemStatusPowerGet(n){return await B(this.apiClient,n)}async SystemStatusDeviceGet(n){return await M(this.apiClient,n)}async SystemStatusFirmwareGet(n){return await G(this.apiClient,n)}async SystemTransportGet(n){return await V(this.apiClient,n)}}async function $(e,n){const{file:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/update",{headers:{"Content-Type":"application/octet-stream"},body:t,signal:o}),n.timeout);if(i)throw i;return r}async function z(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/update/check",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function H(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/update/status",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function J(e,n){const{version:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.GET("/update/changelog",{params:{query:{version:t}},signal:o}),n.timeout);if(i)throw i;return r}async function K(e,n){const{version:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/update/install",{params:{query:{version:t}},signal:o}),n.timeout);if(i)throw i;return r}async function Y(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/update/abort_download",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function X(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/update/autoupdate",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Z(e,n){const{is_enabled:t,interval_start:r,interval_end:i}=n,{data:o,error:s}=await e.withTimeout(u=>e.POST("/update/autoupdate",{body:{is_enabled:t,interval_start:r,interval_end:i},signal:u}),n.timeout);if(s)throw s;return o}class Q{async UpdateFromFile(n){return await $(this.apiClient,n)}async UpdateCheck(n){return await z(this.apiClient,n)}async UpdateStatusGet(n){return await H(this.apiClient,n)}async UpdateChangelogGet(n){return await J(this.apiClient,n)}async UpdateInstall(n){return await K(this.apiClient,n)}async UpdateAbort(n){return await Y(this.apiClient,n)}async UpdateAutoUpdateGet(n){return await X(this.apiClient,n)}async UpdateAutoUpdateSet(n){return await Z(this.apiClient,n)}}async function nn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/time",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function en(e,n){const{timestamp:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/time/timestamp",{params:{query:{timestamp:t}},signal:o}),n.timeout);if(i)throw i;return r}async function tn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/time/timezone",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function rn(e,n){const{timezone:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/time/timezone",{params:{query:{timezone:t}},signal:o}),n.timeout);if(i)throw i;return r}async function on(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/time/tzlist",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}class sn{async TimeGet(n){return await nn(this.apiClient,n)}async TimeTimestampSet(n){return await en(this.apiClient,n)}async TimeTimezoneGet(n){return await tn(this.apiClient,n)}async TimeTimezoneSet(n){return await rn(this.apiClient,n)}async TimeTzListGet(n){return await on(this.apiClient,n)}}async function an(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/account/status",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function un(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/account/info",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function ln(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/account/profile",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function fn(e,n){const{profile:t,custom_url:r}=n,{data:i,error:o}=await e.withTimeout(s=>e.POST("/account/profile",{params:{query:{profile:t,custom_url:r}},signal:s}),n.timeout);if(o)throw o;return i}async function cn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.DELETE("/account",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function dn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/account/link",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}class pn{async AccountInfoGet(n){return await un(this.apiClient,n)}async AccountStateGet(n){return await an(this.apiClient,n)}async AccountProfileGet(n){return await ln(this.apiClient,n)}async AccountProfileSet(n){return await fn(this.apiClient,n)}async AccountUnlink(n){return await cn(this.apiClient,n)}async AccountLink(n){return await dn(this.apiClient,n)}}async function hn(e,n){const{application_name:t,elements:r,priority:i=50,timeout:o}=n,{data:s,error:u}=await e.withTimeout(a=>e.POST("/display/draw",{body:{application_name:t,priority:i,elements:r},signal:a}),o);if(u)throw u;return s}async function yn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.DELETE("/display/draw",{params:{query:{application_name:n==null?void 0:n.application_name}},signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function mn(e,n){const{display:t,timeout:r}=n,{data:i,error:o}=await e.withTimeout(s=>e.GET("/screen",{params:{query:{display:t}},parseAs:"blob",signal:s}),r);if(o)throw o;return i}async function vn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/display/brightness",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function gn(e,n){const{value:t}=n,i=(u=>{if(typeof u=="number"){if(u<0||u>100)throw new Error("Brightness value must be between 0 and 100 or 'auto'");return String(u)}return"auto"})(t),{data:o,error:s}=await e.withTimeout(u=>e.POST("/display/brightness",{params:{query:{value:i}},signal:u}),n.timeout);if(s)throw s;return o}class bn{async DisplayDraw(n){return await hn(this.apiClient,n)}async DisplayClear(n){return await yn(this.apiClient,n)}async DisplayScreenFrameGet(n){return await mn(this.apiClient,n)}async DisplayBrightnessGet(n){return await vn(this.apiClient,n)}async DisplayBrightnessSet(n){return await gn(this.apiClient,n)}}async function En(e,n){const{application_name:t,path:r}=n,{data:i,error:o}=await e.withTimeout(s=>e.POST("/audio/play",{params:{query:{application_name:t,path:r}},signal:s}),n.timeout);if(o)throw o;return i}async function _n(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.DELETE("/audio/play",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Tn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/audio/volume",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function On(e,n){const{volume:t,silent:r}=n;if(typeof t!="number"||t<0||t>100)throw new Error("Volume must be a number between 0 and 100");const{data:i,error:o}=await e.withTimeout(s=>e.POST("/audio/volume",{params:{query:{volume:t,silent:r}},signal:s}),n.timeout);if(o)throw o;return i}class Rn{async AudioPlay(n){return await En(this.apiClient,n)}async AudioStop(n){return await _n(this.apiClient,n)}async AudioVolumeGet(n){return await Tn(this.apiClient,n)}async AudioVolumeSet(n){return await On(this.apiClient,n)}}async function An(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/wifi/status",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function wn(e,n){const{ssid:t,password:r,security:i,ip_config:o}=n,{data:s,error:u}=await e.withTimeout(a=>e.POST("/wifi/connect",{body:{ssid:t,password:r,security:i,ip_config:o},signal:a}),n.timeout);if(u)throw u;return s}async function Sn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/wifi/disconnect",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Nn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/wifi/networks",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}class In{async WifiStatusGet(n){return await An(this.apiClient,n)}async WifiConnect(n){return await wn(this.apiClient,n)}async WifiDisconnect(n){return await Sn(this.apiClient,n)}async WifiNetworksGet(n){return await Nn(this.apiClient,n)}}async function Cn(e,n){const{path:t,file:r}=n,{data:i,error:o}=await e.withTimeout(s=>e.POST("/storage/write",{params:{query:{path:t}},headers:{"Content-Type":"application/octet-stream"},body:r,signal:s}),n.timeout);if(o)throw o;return i}async function kn(e,n){const{path:t,as_array_buffer:r}=n,{data:i,error:o}=await e.withTimeout(s=>e.GET("/storage/read",{params:{query:{path:t}},parseAs:r?"arrayBuffer":"blob",signal:s}),n.timeout);if(o)throw o;return i}async function qn(e,n){const{path:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.GET("/storage/list",{params:{query:{path:t}},signal:o}),n.timeout);if(i)throw i;return r}async function Pn(e,n){const{path:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.DELETE("/storage/remove",{params:{query:{path:t}},signal:o}),n.timeout);if(i)throw i;return r}async function jn(e,n){const{path:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/storage/mkdir",{params:{query:{path:t}},signal:o}),n.timeout);if(i)throw i;return r}async function Dn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/storage/status",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Ln(e,n){const{path:t,new_path:r}=n,{data:i,error:o}=await e.withTimeout(s=>e.POST("/storage/rename",{params:{query:{path:t,new_path:r}},signal:s}),n.timeout);if(o)throw o;return i}class Fn{async StorageWrite(n){return await Cn(this.apiClient,n)}async StorageRead(n){return await kn(this.apiClient,n)}async StorageListGet(n){return await qn(this.apiClient,n)}async StorageRemove(n){return await Pn(this.apiClient,n)}async StorageMkdir(n){return await jn(this.apiClient,n)}async StorageStatusGet(n){return await Dn(this.apiClient,n)}async StorageRename(n){return await Ln(this.apiClient,n)}}async function xn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/access",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Un(e,n){const{mode:t,key:r}=n,i=r??"";if(String(i).trim()&&!/^\d{4,10}$/.test(String(i)))throw new Error("Key must be a string of 4 to 10 digits");const{data:o,error:s}=await e.withTimeout(u=>e.POST("/access",{params:{query:{mode:t,key:i}},signal:u}),n.timeout);if(s)throw s;return o}async function Bn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/name",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Mn(e,n){const{name:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/name",{body:{name:t},signal:o}),n.timeout);if(i)throw i;return r}class Gn{async SettingsAccessGet(n){return await xn(this.apiClient,n)}async SettingsAccessSet(n){const t=await Un(this.apiClient,n);return n.mode==="key"&&n.key&&this.setApiKey(n.key),t}async SettingsNameGet(n){return await Bn(this.apiClient,n)}async SettingsNameSet(n){return await Mn(this.apiClient,n)}}async function Vn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/ble/enable",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Wn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/ble/disable",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function $n(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.DELETE("/ble/pairing",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function zn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/ble/status",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}class Hn{async BleEnable(n){return await Vn(this.apiClient,n)}async BleDisable(n){return await Wn(this.apiClient,n)}async BleUnpair(n){return await $n(this.apiClient,n)}async BleStatusGet(n){return await zn(this.apiClient,n)}}async function Jn(e,n){const{key:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.POST("/input",{params:{query:{key:t}},signal:o}),n.timeout);if(i)throw i;return r}class Kn{async InputSend(n){return await Jn(this.apiClient,n)}}async function Yn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/smart_home/pairing",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Xn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.POST("/smart_home/pairing",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Zn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.DELETE("/smart_home/pairing",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function Qn(e,n){const{data:t,error:r}=await e.withTimeout(i=>e.GET("/smart_home/switch",{signal:i}),n==null?void 0:n.timeout);if(r)throw r;return t}async function ne(e,n){const{timeout:t,...r}=n,{data:i,error:o}=await e.withTimeout(s=>e.POST("/smart_home/switch",{body:r,signal:s}),t);if(o)throw o;return i}class ee{async SmartHomePairingGet(n){return await Yn(this.apiClient,n)}async SmartHomePair(n){return await Xn(this.apiClient,n)}async SmartHomeErase(n){return await Zn(this.apiClient,n)}async SmartHomeSwitchStateGet(n){return await Qn(this.apiClient,n)}async SmartHomeSwitchStateSet(n){return await ne(this.apiClient,n)}async MatterStatusGet(n){return await this.SmartHomePairingGet(n)}async MatterPair(n){return await this.SmartHomePair(n)}async MatterErase(n){return await this.SmartHomeErase(n)}}async function te(e,n){const{application_name:t,file:r,data:i}=n,{data:o,error:s}=await e.withTimeout(u=>e.POST("/assets/upload",{params:{query:{application_name:t,file:r}},headers:{"Content-Type":"application/octet-stream"},body:i,signal:u}),n.timeout);if(s)throw s;return o}async function re(e,n){const{application_name:t}=n,{data:r,error:i}=await e.withTimeout(o=>e.DELETE("/assets/upload",{params:{query:{application_name:t}},signal:o}),n.timeout);if(i)throw i;return r}class ie{async AssetsUpload(n){return await te(this.apiClient,n)}async AssetsDelete(n){return await re(this.apiClient,n)}}const oe="http://10.0.4.20",se="https://proxy.busy.app",ae=/^https?:\/\/proxy(?:\.(?:dev|test|stage))?\.busy\.app$/i;function ue(e){const n=e.split(".");if(n.length!==4)return!1;for(const t of n){if(t.length===0||t.length>1&&t[0]==="0"||!/^\d+$/.test(t))return!1;const r=Number(t);if(r<0||r>255)return!1}return!0}function le(e){return/\.local$/i.test(e)}class C{constructor(n){l(this,"addr");l(this,"apiSemver");l(this,"apiClient");l(this,"setApiKeyFn");l(this,"setTokenFn");l(this,"connectionType","unknown");if(!n||!n.addr&&!n.token)this.addr=oe;else if(!n.addr)this.addr=se;else{let o=n.addr.trim();if(/^https?:\/\//i.test(o)||(o=`http://${o}`),ae.test(o)&&!n.token)throw new Error("Token is required. Please provide it.");this.addr=o}this.apiSemver="";const{client:t,setApiKey:r,setToken:i}=L(`${this.addr}/api/`,this.SystemVersionGet.bind(this),n==null?void 0:n.token,n==null?void 0:n.timeout);this.apiClient=t,this.setApiKeyFn=r,this.setTokenFn=i,this.detectConnectionType()}async detectConnectionType(){const n=new URL(this.addr).hostname;if(!ue(n)&&!le(n)){this.connectionType="wifi";return}const t=I({baseUrl:`${this.addr}/api/`});try{const{response:r}=await t.GET("/name");if(r.status===401||r.status===403)this.connectionType="wifi";else if(r.ok)this.connectionType="usb";else throw new Error(`Failed to detect connection type. Status: ${r.status}`)}catch(r){throw r}}setApiKey(n){this.setApiKeyFn(n)}setToken(n){this.setTokenFn(n)}}function fe(e,n){n.forEach(t=>{Object.getOwnPropertyNames(t.prototype).forEach(r=>{Object.defineProperty(e.prototype,r,Object.getOwnPropertyDescriptor(t.prototype,r)||Object.create(null))})})}fe(C,[W,Q,sn,pn,bn,Rn,In,Fn,Gn,Hn,Kn,ee,ie]);var c=(e=>(e.CONNECTION_FAILED="CONNECTION_FAILED",e.RECONNECT_FAILED="RECONNECT_FAILED",e.CONNECTION_LOST="CONNECTION_LOST",e.CONNECTION_TIMEOUT="CONNECTION_TIMEOUT",e.AUTH_FAILED="AUTH_FAILED",e.AUTH_REFRESH_FAILED="AUTH_REFRESH_FAILED",e.DEVICE_ERROR="DEVICE_ERROR",e.DECODE_ERROR="DECODE_ERROR",e.FRAME_PROCESS_ERROR="FRAME_PROCESS_ERROR",e.STREAM_ALREADY_STARTED="STREAM_ALREADY_STARTED",e.WORKER_INIT_FAILED="WORKER_INIT_FAILED",e.UNKNOWN_ERROR="UNKNOWN_ERROR",e))(c||{});class h extends Error{constructor(n,t,r){super(t),this.code=n,this.data=r,this.name="StateStreamError"}}var d=(e=>(e.IDLE="IDLE",e.STARTING="STARTING",e.RUNNING="RUNNING",e.STOPPED="STOPPED",e.FAILED="FAILED",e))(d||{}),m=(e=>(e.DISCONNECTED="DISCONNECTED",e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.RECONNECTING="RECONNECTING",e))(m||{}),v=(e=>(e.UNAUTHENTICATED="UNAUTHENTICATED",e.AUTHENTICATING="AUTHENTICATING",e.AUTHENTICATED="AUTHENTICATED",e.FAILED="FAILED",e))(v||{}),g=(e=>(e.NONE="NONE",e.ACTIVE="ACTIVE",e.STALE="STALE",e))(g||{}),b=(e=>(e.OFF="OFF",e.INITIALIZING="INITIALIZING",e.READY="READY",e.ERROR="ERROR",e))(b||{});const k=`var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, src = { exports: {} }, indexLight = { exports: {} }, indexMinimal = {}, minimal = {}, aspromise, hasRequiredAspromise;
|
|
2
2
|
function requireAspromise() {
|
|
3
3
|
if (hasRequiredAspromise) return aspromise;
|
|
4
4
|
hasRequiredAspromise = 1, aspromise = u;
|
|
@@ -3905,10 +3905,12 @@ function connect(u, f, h = !0, c = "local") {
|
|
|
3905
3905
|
code: StateStreamErrorCode.DEVICE_ERROR,
|
|
3906
3906
|
message: \`Server reported \${E}: \${y}\`,
|
|
3907
3907
|
data: l.error
|
|
3908
|
-
}), a === p.values.FATAL
|
|
3908
|
+
}), a === p.values.FATAL) {
|
|
3909
3909
|
stopAndCleanup();
|
|
3910
3910
|
return;
|
|
3911
3911
|
}
|
|
3912
|
+
if (a === p.values.ERROR)
|
|
3913
|
+
return;
|
|
3912
3914
|
} else
|
|
3913
3915
|
broadcast({
|
|
3914
3916
|
type: "ERROR",
|
|
@@ -3939,7 +3941,12 @@ function connect(u, f, h = !0, c = "local") {
|
|
|
3939
3941
|
} : { type: "DATA", data: l });
|
|
3940
3942
|
}
|
|
3941
3943
|
} catch (e) {
|
|
3942
|
-
broadcast({
|
|
3944
|
+
broadcast({
|
|
3945
|
+
type: "ERROR",
|
|
3946
|
+
code: StateStreamErrorCode.DECODE_ERROR,
|
|
3947
|
+
message: \`Decode error: \${String(e)}\`,
|
|
3948
|
+
data: n.data
|
|
3949
|
+
});
|
|
3943
3950
|
}
|
|
3944
3951
|
}).catch(console.error);
|
|
3945
3952
|
}, socket.onerror = () => {
|
|
@@ -4023,7 +4030,7 @@ if ("SharedWorkerGlobalScope" in self) {
|
|
|
4023
4030
|
handleCommand(f.data, u);
|
|
4024
4031
|
};
|
|
4025
4032
|
}
|
|
4026
|
-
`,
|
|
4033
|
+
`,N=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",k],{type:"text/javascript;charset=utf-8"});function ce(e){let n;try{if(n=N&&(self.URL||self.webkitURL).createObjectURL(N),!n)throw"";const t=new Worker(n,{type:"module",name:e==null?void 0:e.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(n)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(k),{type:"module",name:e==null?void 0:e.name})}}const de=`var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, src = { exports: {} }, indexLight = { exports: {} }, indexMinimal = {}, minimal = {}, aspromise, hasRequiredAspromise;
|
|
4027
4034
|
function requireAspromise() {
|
|
4028
4035
|
if (hasRequiredAspromise) return aspromise;
|
|
4029
4036
|
hasRequiredAspromise = 1, aspromise = u;
|
|
@@ -7930,10 +7937,12 @@ function connect(u, f, h = !0, c = "local") {
|
|
|
7930
7937
|
code: StateStreamErrorCode.DEVICE_ERROR,
|
|
7931
7938
|
message: \`Server reported \${E}: \${y}\`,
|
|
7932
7939
|
data: l.error
|
|
7933
|
-
}), a === p.values.FATAL
|
|
7940
|
+
}), a === p.values.FATAL) {
|
|
7934
7941
|
stopAndCleanup();
|
|
7935
7942
|
return;
|
|
7936
7943
|
}
|
|
7944
|
+
if (a === p.values.ERROR)
|
|
7945
|
+
return;
|
|
7937
7946
|
} else
|
|
7938
7947
|
broadcast({
|
|
7939
7948
|
type: "ERROR",
|
|
@@ -7964,7 +7973,12 @@ function connect(u, f, h = !0, c = "local") {
|
|
|
7964
7973
|
} : { type: "DATA", data: l });
|
|
7965
7974
|
}
|
|
7966
7975
|
} catch (e) {
|
|
7967
|
-
broadcast({
|
|
7976
|
+
broadcast({
|
|
7977
|
+
type: "ERROR",
|
|
7978
|
+
code: StateStreamErrorCode.DECODE_ERROR,
|
|
7979
|
+
message: \`Decode error: \${String(e)}\`,
|
|
7980
|
+
data: n.data
|
|
7981
|
+
});
|
|
7968
7982
|
}
|
|
7969
7983
|
}).catch(console.error);
|
|
7970
7984
|
}, socket.onerror = () => {
|
|
@@ -8048,7 +8062,7 @@ if ("SharedWorkerGlobalScope" in self) {
|
|
|
8048
8062
|
handleCommand(f.data, u);
|
|
8049
8063
|
};
|
|
8050
8064
|
}
|
|
8051
|
-
`;function _n(r){return new SharedWorker("data:text/javascript;charset=utf-8,"+encodeURIComponent(En),{type:"module",name:r==null?void 0:r.name})}const _=class _{constructor(e,n){l(this,"addr");l(this,"token");l(this,"isBinary");l(this,"connectTimeout");l(this,"dataTimeout");l(this,"worker",null);l(this,"connectionTimer",null);l(this,"dataTimer",null);l(this,"_status");l(this,"dataCallback");l(this,"rawDataCallback");l(this,"errorCallback");l(this,"statusCallback");this.addr=e.addr||"",this.token=e.token,this.isBinary=e.isBinary??!0,this.connectTimeout=(n==null?void 0:n.timeout)??5e3,this.dataTimeout=(n==null?void 0:n.dataTimeout)??15e3,this._status={main:{status:p.IDLE},connection:{status:m.DISCONNECTED},auth:{status:g.UNAUTHENTICATED},data:{status:b.NONE},worker:{status:E.OFF}}}get status(){return this._status}resolveProtocol(e){let n=e.trim();if(n.startsWith("https://"))return n.replace("https://","wss://");if(n.startsWith("http://"))return n.replace("http://","ws://");if(n.startsWith("wss://")||n.startsWith("ws://"))return n;let t="ws:";return typeof window<"u"&&window.location.protocol==="https:"&&(t="wss:"),`${t}//${n}`}start({dataCallback:e,rawDataCallback:n,errorCallback:t,statusCallback:i}){if(this._status.main.status===p.STARTING||this._status.main.status===p.RUNNING){const o=new h(d.STREAM_ALREADY_STARTED,"StateStream is already running. Call stop() before starting again.");if(i&&i({...this._status,main:{...this._status.main,lastError:o}}),t)t(o);else throw o;return}this.dataCallback=e,this.rawDataCallback=n,this.errorCallback=t,this.statusCallback=i,this.updateStatusComponent("main",{status:p.STARTING,lastError:void 0});try{this.ensureWorker(),this.sendCommand({type:"START",addr:this.normalizeUrl(this.addr),token:this.token,isBinary:this.isBinary,mode:this.streamMode}),this.clearConnectionTimer(),this.connectionTimer=setTimeout(()=>{const o=new h(d.CONNECTION_TIMEOUT,`Connection timed out after ${this.connectTimeout}ms`);this.mapErrorToStatus(o),this.errorCallback&&this.errorCallback(o),this.stop()},this.connectTimeout)}catch(o){const a=o instanceof h?o:new h(d.UNKNOWN_ERROR,String(o));this.errorCallback&&this.errorCallback(a)}}stop(){this.clearConnectionTimer(),this.clearDataTimer(),!(this._status.main.status===p.IDLE||this._status.main.status===p.STOPPED)&&(this.updateStatusComponent("main",{status:p.STOPPED}),this.updateStatusComponent("connection",{status:m.DISCONNECTED}),this.sendCommand({type:"STOP"}),this.clearCallbacks())}destroy(){this.stop(),this.worker&&(this.worker.terminate?this.worker.terminate():"close"in this.worker.port&&this.worker.port.close(),this.worker=null)}clearCallbacks(){this.dataCallback=void 0,this.rawDataCallback=void 0,this.errorCallback=void 0,this.statusCallback=void 0}sendToken(e){this.token=e,this.sendCommand({type:"UPDATE_TOKEN",token:e})}sendCommand(e){this.worker&&this.worker.port.postMessage(e)}ensureWorker(){if(this.worker||typeof window>"u")return;const e=btoa(this.addr);try{if(this.updateStatusComponent("worker",{status:E.INITIALIZING,lastError:void 0}),window.SharedWorker){const n=new _n({name:e});this.worker={port:n.port},n.port.onmessage=t=>{this.handleWorkerMessage(t.data)},n.port.start()}else{const n=new bn;this.worker={port:n,terminate:()=>n.terminate()},n.onmessage=t=>{this.handleWorkerMessage(t.data)}}this.updateStatusComponent("worker",{status:E.READY})}catch(n){const t=new h(d.WORKER_INIT_FAILED,`Failed to initialize worker: ${String(n)}`);throw this.updateStatusComponent("worker",{status:E.ERROR,lastError:t}),this.updateStatusComponent("main",{status:p.FAILED,lastError:t}),t}}handleWorkerMessage(e){switch(e.type){case"DATA":this.resetDataTimer(),this.dataCallback&&this.dataCallback(this.normalizeState(e.data));break;case"RAW_DATA":this.resetDataTimer(),this.rawDataCallback&&this.rawDataCallback(e.data);break;case"CONNECTED":this.clearConnectionTimer(),this.updateStatusComponent("connection",{status:m.CONNECTED}),this.streamMode==="local"&&this.updateStatusComponent("main",{status:p.RUNNING});break;case"STATUS_UPDATE":e.connection&&this.updateStatusComponent("connection",{status:e.connection}),e.auth&&(this.updateStatusComponent("auth",{status:e.auth}),e.auth===g.AUTHENTICATED&&this.updateStatusComponent("main",{status:p.RUNNING}));break;case"ERROR":{this.clearConnectionTimer();const n=new h(e.code,e.message,e.data);this.mapErrorToStatus(n),this.errorCallback&&this.errorCallback(n);break}case"TOKEN_EXPIRED":this.updateStatusComponent("auth",{status:g.AUTHENTICATING}),this.handleTokenExpiredInternal();break;case"DISCONNECTED":this.updateStatusComponent("connection",{status:m.DISCONNECTED});break}}mapErrorToStatus(e){const n=e.code;(n===d.CONNECTION_FAILED||n===d.CONNECTION_LOST||n===d.RECONNECT_FAILED||n===d.CONNECTION_TIMEOUT)&&(this.updateStatusComponent("connection",{status:m.DISCONNECTED,lastError:e}),this.updateStatusComponent("main",{status:p.FAILED,lastError:e})),(n===d.AUTH_FAILED||n===d.AUTH_REFRESH_FAILED)&&(this.updateStatusComponent("auth",{status:g.FAILED,lastError:e}),this.updateStatusComponent("main",{status:p.FAILED,lastError:e})),(n===d.DEVICE_ERROR||n===d.DECODE_ERROR)&&this.updateStatusComponent("main",{lastError:e})}updateStatusComponent(e,n){const t=this._status[e];this._status[e]={...t,...n},this.statusCallback&&this.statusCallback({...this._status})}clearConnectionTimer(){this.connectionTimer&&(clearTimeout(this.connectionTimer),this.connectionTimer=null)}resetDataTimer(){this.clearDataTimer(),this._status.data.status!==b.ACTIVE?this.updateStatusComponent("data",{status:b.ACTIVE,lastActivity:Date.now()}):this._status.data.lastActivity=Date.now(),this.dataTimer=setTimeout(()=>{this.updateStatusComponent("data",{status:b.STALE})},this.dataTimeout)}clearDataTimer(){this.dataTimer&&(clearTimeout(this.dataTimer),this.dataTimer=null)}normalizeState(e){let n,t;"bar_id"in e&&"state"in e?(n=e.state,t=e.bar_id):n=e;let i=n.updates;return i&&(i=i.map(o=>{const a=Object.keys(o).find(c=>o[c]!=null);return{...o,state:a}})),{...n,updates:i,bar_id:t}}async handleTokenExpiredInternal(){const e=this.addr;let n=_.tokenRefreshPromises.get(e);if(!n&&this.onTokenExpired&&(n=(async()=>{try{const i=this.onTokenExpired();return i instanceof Promise?await i:""}finally{_.tokenRefreshPromises.delete(e)}})(),_.tokenRefreshPromises.set(e,n)),n){const t=await n;t&&this.sendToken(t)}}};l(_,"tokenRefreshPromises",new Map);let R=_;class On extends R{constructor(n={},t){let i=n.addr;i||(typeof window<"u"?i=window.location.origin:i="10.0.4.20");super({isBinary:!0,...n,addr:i},t);l(this,"streamMode","local")}normalizeUrl(n){const t=this.resolveProtocol(n),i=new URL(t);return(i.pathname==="/"||!i.pathname)&&(i.pathname="/api/status/ws"),i.toString()}}class wn extends R{constructor(n,t){super({isBinary:!1,...n},t);l(this,"streamMode","remote");l(this,"tokenProvider");this.tokenProvider=n.tokenProvider}subscribe(n){this.sendCommand({type:"SUBSCRIBE",guid:n})}unsubscribe(n){this.sendCommand({type:"UNSUBSCRIBE",guid:n})}normalizeUrl(n){return this.resolveProtocol(n)}onTokenExpired(){if(this.tokenProvider)return this.tokenProvider().then(n=>(this.sendToken(n),n)).catch(n=>{const t=`Failed to refresh token: ${n.message}`;throw this.errorCallback&&this.errorCallback(new h(d.AUTH_REFRESH_FAILED,t)),n})}}const O=class O{constructor(){l(this,"gl",null);l(this,"program",null);l(this,"texture",null);l(this,"vs",`#version 300 es
|
|
8065
|
+
`;function pe(e){return new SharedWorker("data:text/javascript;charset=utf-8,"+encodeURIComponent(de),{type:"module",name:e==null?void 0:e.name})}const E=class E{constructor(n,t){l(this,"addr");l(this,"token");l(this,"isBinary");l(this,"connectTimeout");l(this,"dataTimeout");l(this,"worker",null);l(this,"connectionTimer",null);l(this,"dataTimer",null);l(this,"_status");l(this,"dataCallback");l(this,"rawDataCallback");l(this,"errorCallback");l(this,"statusCallback");this.addr=n.addr||"",this.token=n.token,this.isBinary=n.isBinary??!0,this.connectTimeout=(t==null?void 0:t.timeout)??5e3,this.dataTimeout=(t==null?void 0:t.dataTimeout)??15e3,this._status={main:{status:d.IDLE},connection:{status:m.DISCONNECTED},auth:{status:v.UNAUTHENTICATED},data:{status:g.NONE},worker:{status:b.OFF}}}get status(){return this._status}resolveProtocol(n){let t=n.trim();if(t.startsWith("https://"))return t.replace("https://","wss://");if(t.startsWith("http://"))return t.replace("http://","ws://");if(t.startsWith("wss://")||t.startsWith("ws://"))return t;let r="ws:";return typeof window<"u"&&window.location.protocol==="https:"&&(r="wss:"),`${r}//${t}`}start({dataCallback:n,rawDataCallback:t,errorCallback:r,statusCallback:i}){if(this._status.main.status===d.STARTING||this._status.main.status===d.RUNNING){const o=new h(c.STREAM_ALREADY_STARTED,"StateStream is already running. Call stop() before starting again.");if(i&&i({...this._status,main:{...this._status.main,lastError:o}}),r)r(o);else throw o;return}this.dataCallback=n,this.rawDataCallback=t,this.errorCallback=r,this.statusCallback=i,this.updateStatusComponent("main",{status:d.STARTING,lastError:void 0});try{this.ensureWorker(),this.sendCommand({type:"START",addr:this.normalizeUrl(this.addr),token:this.token,isBinary:this.isBinary,mode:this.streamMode}),this.clearConnectionTimer(),this.connectionTimer=setTimeout(()=>{const o=new h(c.CONNECTION_TIMEOUT,`Connection timed out after ${this.connectTimeout}ms`);this.mapErrorToStatus(o),this.errorCallback&&this.errorCallback(o),this.stop()},this.connectTimeout)}catch(o){const s=o instanceof h?o:new h(c.UNKNOWN_ERROR,String(o));this.errorCallback&&this.errorCallback(s)}}stop(){this.clearConnectionTimer(),this.clearDataTimer(),!(this._status.main.status===d.IDLE||this._status.main.status===d.STOPPED)&&(this.updateStatusComponent("main",{status:d.STOPPED}),this.updateStatusComponent("connection",{status:m.DISCONNECTED}),this.sendCommand({type:"STOP"}),this.clearCallbacks())}destroy(){this.stop(),this.worker&&(this.worker.terminate?this.worker.terminate():"close"in this.worker.port&&this.worker.port.close(),this.worker=null)}clearCallbacks(){this.dataCallback=void 0,this.rawDataCallback=void 0,this.errorCallback=void 0,this.statusCallback=void 0}sendToken(n){this.token=n,this.sendCommand({type:"UPDATE_TOKEN",token:n})}sendCommand(n){this.worker&&this.worker.port.postMessage(n)}ensureWorker(){if(this.worker||typeof window>"u")return;const n=btoa(this.addr);try{if(this.updateStatusComponent("worker",{status:b.INITIALIZING,lastError:void 0}),window.SharedWorker){const t=new pe({name:n});this.worker={port:t.port},t.port.onmessage=r=>{this.handleWorkerMessage(r.data)},t.port.start()}else{const t=new ce;this.worker={port:t,terminate:()=>t.terminate()},t.onmessage=r=>{this.handleWorkerMessage(r.data)}}this.updateStatusComponent("worker",{status:b.READY})}catch(t){const r=new h(c.WORKER_INIT_FAILED,`Failed to initialize worker: ${String(t)}`);throw this.updateStatusComponent("worker",{status:b.ERROR,lastError:r}),this.updateStatusComponent("main",{status:d.FAILED,lastError:r}),r}}handleWorkerMessage(n){switch(n.type){case"DATA":this.resetDataTimer(),this.dataCallback&&this.dataCallback(this.normalizeState(n.data));break;case"RAW_DATA":this.resetDataTimer(),this.rawDataCallback&&this.rawDataCallback(n.data);break;case"CONNECTED":this.clearConnectionTimer(),this.updateStatusComponent("connection",{status:m.CONNECTED}),this.streamMode==="local"&&this.updateStatusComponent("main",{status:d.RUNNING});break;case"STATUS_UPDATE":n.connection&&this.updateStatusComponent("connection",{status:n.connection}),n.auth&&(this.updateStatusComponent("auth",{status:n.auth}),n.auth===v.AUTHENTICATED&&this.updateStatusComponent("main",{status:d.RUNNING}));break;case"ERROR":{this.clearConnectionTimer();const t=new h(n.code,n.message,n.data);this.mapErrorToStatus(t),this.errorCallback&&this.errorCallback(t);break}case"TOKEN_EXPIRED":this.updateStatusComponent("auth",{status:v.AUTHENTICATING}),this.handleTokenExpiredInternal();break;case"DISCONNECTED":this.updateStatusComponent("connection",{status:m.DISCONNECTED});break}}mapErrorToStatus(n){const t=n.code;(t===c.CONNECTION_FAILED||t===c.CONNECTION_LOST||t===c.RECONNECT_FAILED||t===c.CONNECTION_TIMEOUT)&&(this.updateStatusComponent("connection",{status:m.DISCONNECTED,lastError:n}),this.updateStatusComponent("main",{status:d.FAILED,lastError:n})),(t===c.AUTH_FAILED||t===c.AUTH_REFRESH_FAILED)&&(this.updateStatusComponent("auth",{status:v.FAILED,lastError:n}),this.updateStatusComponent("main",{status:d.FAILED,lastError:n})),(t===c.DEVICE_ERROR||t===c.DECODE_ERROR)&&this.updateStatusComponent("main",{lastError:n})}updateStatusComponent(n,t){const r=this._status[n];this._status[n]={...r,...t},this.statusCallback&&this.statusCallback({...this._status})}clearConnectionTimer(){this.connectionTimer&&(clearTimeout(this.connectionTimer),this.connectionTimer=null)}resetDataTimer(){this.clearDataTimer(),this._status.data.status!==g.ACTIVE?this.updateStatusComponent("data",{status:g.ACTIVE,lastActivity:Date.now()}):this._status.data.lastActivity=Date.now(),this.dataTimer=setTimeout(()=>{this.updateStatusComponent("data",{status:g.STALE})},this.dataTimeout)}clearDataTimer(){this.dataTimer&&(clearTimeout(this.dataTimer),this.dataTimer=null)}normalizeState(n){let t,r;"bar_id"in n&&"state"in n?(t=n.state,r=n.bar_id):t=n;let i=t.updates;return i&&(i=i.map(o=>{const s=Object.keys(o).find(u=>o[u]!=null);return{...o,state:s}})),{...t,updates:i,bar_id:r}}async handleTokenExpiredInternal(){const n=this.addr;let t=E.tokenRefreshPromises.get(n);if(!t&&this.onTokenExpired&&(t=(async()=>{try{const i=this.onTokenExpired();return i instanceof Promise?await i:""}finally{E.tokenRefreshPromises.delete(n)}})(),E.tokenRefreshPromises.set(n,t)),t){const r=await t;r&&this.sendToken(r)}}};l(E,"tokenRefreshPromises",new Map);let O=E;class he extends O{constructor(t={},r){let i=t.addr;i||(typeof window<"u"?i=window.location.origin:i="10.0.4.20");super({isBinary:!0,...t,addr:i},r);l(this,"streamMode","local")}normalizeUrl(t){const r=this.resolveProtocol(t),i=new URL(r);return(i.pathname==="/"||!i.pathname)&&(i.pathname="/api/status/ws"),i.toString()}}class ye extends O{constructor(t,r){super({isBinary:!1,...t},r);l(this,"streamMode","remote");l(this,"tokenProvider");this.tokenProvider=t.tokenProvider}subscribe(t){this.sendCommand({type:"SUBSCRIBE",guid:t})}unsubscribe(t){this.sendCommand({type:"UNSUBSCRIBE",guid:t})}normalizeUrl(t){return this.resolveProtocol(t)}onTokenExpired(){if(this.tokenProvider)return this.tokenProvider().then(t=>(this.sendToken(t),t)).catch(t=>{const r=`Failed to refresh token: ${t.message}`;throw this.errorCallback&&this.errorCallback(new h(c.AUTH_REFRESH_FAILED,r)),t})}}exports.BSB_State=void 0;(e=>{(n=>{n[n.DISCHARGING=0]="DISCHARGING",n[n.CHARGING=1]="CHARGING",n[n.CHARGED=2]="CHARGED"})(e.BatteryStatus||(e.BatteryStatus={})),(n=>{n[n.CONNECTED=0]="CONNECTED",n[n.CONNECTING=1]="CONNECTING",n[n.DISCONNECTING=2]="DISCONNECTING",n[n.RECONNECTING=3]="RECONNECTING"})(e.WifiConnectionStatus||(e.WifiConnectionStatus={})),(n=>{n[n.UNKNOWN=0]="UNKNOWN",n[n.OPEN=1]="OPEN",n[n.WPA=2]="WPA",n[n.WPA2=3]="WPA2",n[n.WEP=4]="WEP",n[n.WPA_WPA2=5]="WPA_WPA2",n[n.WPA3=6]="WPA3",n[n.WPA2_WPA3=7]="WPA2_WPA3"})(e.WifiSecurity||(e.WifiSecurity={})),(n=>{n[n.DHCP=0]="DHCP",n[n.STATIC=1]="STATIC"})(e.IpConfigurationMethod||(e.IpConfigurationMethod={})),(n=>{n[n.IPV4=0]="IPV4",n[n.IPV6=1]="IPV6"})(e.IpProtocol||(e.IpProtocol={})),(n=>{n[n.NEVER_STARTED=0]="NEVER_STARTED",n[n.STARTED=1]="STARTED",n[n.COMPLETED_SUCCESSFULLY=2]="COMPLETED_SUCCESSFULLY",n[n.FAILED=3]="FAILED"})(e.MatterCommissioningStatus||(e.MatterCommissioningStatus={})),(n=>{(t=>{t[t.RESET=0]="RESET",t[t.INITIALIZATION=1]="INITIALIZATION",t[t.READY=2]="READY",t[t.ADVERTISING=3]="ADVERTISING",t[t.CONNECTABLE=4]="CONNECTABLE",t[t.CONNECTED=5]="CONNECTED",t[t.ERROR=6]="ERROR"})(n.ServiceStatus||(n.ServiceStatus={}))})(e.Ble||(e.Ble={}))})(exports.BSB_State||(exports.BSB_State={}));exports.BSB_Update=void 0;(e=>{(n=>{n[n.SESSION_START=0]="SESSION_START",n[n.SESSION_STOP=1]="SESSION_STOP",n[n.ACTION_BEGIN=2]="ACTION_BEGIN",n[n.ACTION_DONE=3]="ACTION_DONE",n[n.DETAIL_CHANGE=4]="DETAIL_CHANGE",n[n.ACTION_PROGRESS=5]="ACTION_PROGRESS",n[n.EVENT_NONE=6]="EVENT_NONE"})(e.UpdateEvent||(e.UpdateEvent={})),(n=>{n[n.DOWNLOAD=0]="DOWNLOAD",n[n.SHA_VERIFICATION=1]="SHA_VERIFICATION",n[n.UNPACK=2]="UNPACK",n[n.INSTALLATION_PREPARE=3]="INSTALLATION_PREPARE",n[n.INSTALLATION_APPLY=4]="INSTALLATION_APPLY",n[n.ACTION_NONE=5]="ACTION_NONE"})(e.UpdateAction||(e.UpdateAction={})),(n=>{n[n.OK=0]="OK",n[n.BATTERY_LOW=1]="BATTERY_LOW",n[n.BUSY=2]="BUSY",n[n.DOWNLOAD_FAILURE=3]="DOWNLOAD_FAILURE",n[n.DOWNLOAD_ABORT=4]="DOWNLOAD_ABORT",n[n.SHA_MISMATCH=5]="SHA_MISMATCH",n[n.UNPACK_CREATE_STAGING_DIRECTORY_FAILURE=6]="UNPACK_CREATE_STAGING_DIRECTORY_FAILURE",n[n.UNPACK_ARCHIVE_OPEN_FAILURE=7]="UNPACK_ARCHIVE_OPEN_FAILURE",n[n.UNPACK_ARCHIVE_UNPACK_FAILURE=8]="UNPACK_ARCHIVE_UNPACK_FAILURE",n[n.INSTALLATION_PREPARE_MANIFEST_NOT_FOUND=9]="INSTALLATION_PREPARE_MANIFEST_NOT_FOUND",n[n.INSTALLATION_PREPARE_MANIFEST_INVALID=10]="INSTALLATION_PREPARE_MANIFEST_INVALID",n[n.INSTALLATION_PREPARE_SESSION_CONFIG_SETUP_FAILURE=11]="INSTALLATION_PREPARE_SESSION_CONFIG_SETUP_FAILURE",n[n.INSTALLATION_PREPARE_POINTER_SETUP_FAILURE=12]="INSTALLATION_PREPARE_POINTER_SETUP_FAILURE",n[n.UNKNOWN_FAILURE=13]="UNKNOWN_FAILURE"})(e.UpdateStatus||(e.UpdateStatus={})),(n=>{n[n.NOT_AVAILABLE=0]="NOT_AVAILABLE",n[n.FAILURE=1]="FAILURE",n[n.IDLE=2]="IDLE"})(e.CheckError||(e.CheckError={}))})(exports.BSB_Update||(exports.BSB_Update={}));exports.BSB_Frame=void 0;(e=>{(n=>{n[n.PLAIN=0]="PLAIN",n[n.RUN_LENGTH=1]="RUN_LENGTH",n[n.DEFLATE=2]="DEFLATE",n[n.DEFLATE_RUN_LENGTH=3]="DEFLATE_RUN_LENGTH"})(e.Encoding||(e.Encoding={})),(n=>{n[n.RGB888=0]="RGB888",n[n.L8=1]="L8",n[n.L4=2]="L4"})(e.PixelFormat||(e.PixelFormat={})),(n=>{n[n.FRONT=0]="FRONT",n[n.BACK=1]="BACK"})(e.Screen||(e.Screen={}))})(exports.BSB_Frame||(exports.BSB_Frame={}));exports.BSB_Util=void 0;(e=>{(n=>{n[n.PLAIN=0]="PLAIN",n[n.GZIP=1]="GZIP"})(e.Compression||(e.Compression={}))})(exports.BSB_Util||(exports.BSB_Util={}));exports.BSB_Input=void 0;(e=>{(n=>{n[n.OK=0]="OK",n[n.BACK=1]="BACK",n[n.START=2]="START"})(e.Button||(e.Button={})),(n=>{n[n.PRESS=0]="PRESS",n[n.RELEASE=1]="RELEASE"})(e.ButtonAction||(e.ButtonAction={})),(n=>{n[n.BUSY=0]="BUSY",n[n.CUSTOM=1]="CUSTOM",n[n.OFF=2]="OFF",n[n.APPS=3]="APPS",n[n.SETTINGS=4]="SETTINGS"})(e.SwitchPosition||(e.SwitchPosition={}))})(exports.BSB_Input||(exports.BSB_Input={}));exports.BSB_Error=void 0;(e=>{(n=>{n[n.RESOURCE_LIMIT=0]="RESOURCE_LIMIT"})(e.Cause||(e.Cause={})),(n=>{n[n.FATAL=0]="FATAL",n[n.ERROR=1]="ERROR",n[n.WARNING=2]="WARNING"})(e.Severity||(e.Severity={}))})(exports.BSB_Error||(exports.BSB_Error={}));const _=class _{constructor(){l(this,"gl",null);l(this,"program",null);l(this,"texture",null);l(this,"vs",`#version 300 es
|
|
8052
8066
|
in vec2 position;
|
|
8053
8067
|
out vec2 v_uv;
|
|
8054
8068
|
void main() {
|
|
@@ -8088,4 +8102,4 @@ if ("SharedWorkerGlobalScope" in self) {
|
|
|
8088
8102
|
if (mask < 0.001) discard;
|
|
8089
8103
|
outColor = vec4(finalColor, color.a * mask);
|
|
8090
8104
|
}
|
|
8091
|
-
`);if(
|
|
8105
|
+
`);if(_.instance)return _.instance;_.instance=this}init(){if(this.gl||typeof window>"u")return;const t=document.createElement("canvas").getContext("webgl2",{antialias:!0,alpha:!0,preserveDrawingBuffer:!0});if(!t)throw new Error("WebGL 2.0 not supported");this.gl=t,this.program=this.createProgram(this.vs,this.fs);const r=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW);const i=t.getAttribLocation(this.program,"position");t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0),this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}render(n,t,r,i){const{pixelSize:o=.85,radius:s=.5,darkThreshold:u=.04}=i,a=this.gl;a.viewport(0,0,a.canvas.width,a.canvas.height),a.useProgram(this.program),a.bindTexture(a.TEXTURE_2D,this.texture),a.texImage2D(a.TEXTURE_2D,0,a.RGBA8,t,r,0,a.RGBA,a.UNSIGNED_BYTE,n),a.uniform2f(a.getUniformLocation(this.program,"u_dataRes"),t,r),a.uniform2f(a.getUniformLocation(this.program,"u_canvasRes"),a.canvas.width,a.canvas.height),a.uniform1f(a.getUniformLocation(this.program,"u_pixelSize"),o),a.uniform1f(a.getUniformLocation(this.program,"u_radius"),s),a.uniform1f(a.getUniformLocation(this.program,"u_darkThreshold"),u),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT),a.enable(a.BLEND),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.drawArrays(a.TRIANGLES,0,6)}renderFrame(n,t,r,i,o={}){if(this.init(),typeof window>"u"||!this.gl)return;(this.gl.canvas.width!==n.width||this.gl.canvas.height!==n.height)&&(this.gl.canvas.width=n.width,this.gl.canvas.height=n.height),this.render(t,r,i,o);const s=n.getContext("2d");s&&(s.clearRect(0,0,n.width,n.height),s.drawImage(this.gl.canvas,0,0))}createProgram(n,t){const r=this.gl,i=(s,u)=>{const a=r.createShader(s);if(r.shaderSource(a,u),r.compileShader(a),!r.getShaderParameter(a,r.COMPILE_STATUS))throw new Error(r.getShaderInfoLog(a)||"Shader Error");return a},o=r.createProgram();return r.attachShader(o,i(r.VERTEX_SHADER,n)),r.attachShader(o,i(r.FRAGMENT_SHADER,t)),r.linkProgram(o),o}};l(_,"instance",null);let S=_;const me=new S;exports.AuthStatus=v;exports.BusyBar=C;exports.ConnectionStatus=m;exports.DataStatus=g;exports.LEDRenderer=me;exports.LocalStateStream=he;exports.RemoteStateStream=ye;exports.StateStreamError=h;exports.StateStreamErrorCode=c;exports.StreamLifecycle=d;exports.WorkerStatus=b;
|