@busy-app/busy-lib 0.1.1 → 0.2.0
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 +1 -1
- package/dist/index.d.ts +72 -0
- package/dist/index.js +280 -159
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var A=Object.defineProperty;var P=(e,t,i)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var u=(e,t,i)=>P(e,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("openapi-fetch");function T(e){const t=e.split(".");if(t.length!==4)return!1;for(const i of t){if(i.length===0||i.length>1&&i[0]==="0"||!/^\d+$/.test(i))return!1;const n=Number(i);if(n<0||n>255)return!1}return!0}const I=(e,t)=>{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 i;return t&&(t instanceof Headers?i=t.get("Content-Type")??t.get("content-type")??void 0:typeof t=="object"&&(i=t["Content-Type"]??t["content-type"]),i==="application/x-www-form-urlencoded")?e&&typeof e=="object"&&!(e instanceof URLSearchParams)?new URLSearchParams(e).toString():String(e):JSON.stringify(e)};let p,w,l=null;async function g(){if(!w){if(!p)throw new Error("getApiVersionFn is not set");l||(l=(async()=>{const e=await p();if(!e.api_semver)throw new Error("Empty API version");w=e.api_semver})().finally(()=>{l=null})),await l}}async function y(e){const n=(e.headers.get("content-type")||"").includes("application/json")?await e.clone().json():await e.clone().text(),o=typeof n=="object"&&n!==null?n.error||n.message:typeof n=="string"?n:void 0;return Object.assign(new Error(o||`HTTP ${e.status} ${e.statusText}`),{status:e.status,statusText:e.statusText,body:n})}let m;function b(e){m=e}const k={async onRequest({request:e,schemaPath:t}){if(t!=="/version"){if(await g(),w)return e.headers.set("X-API-Sem-Ver",w);m&&e.headers.set("X-API-Token",m)}return e},async onResponse({request:e,response:t,options:i,schemaPath:n}){if(t.ok)return t;if(n==="/version")throw await y(t);if(t.status!==405)throw await y(t);w=void 0,await g(),w&&e.headers.set("X-API-Sem-Ver",w);const o=await(i.fetch??fetch)(e);if(o.ok)return o;throw await y(o)}};let r=null;function B(e,t){p=t,r=S({baseUrl:e,bodySerializer:I}),r.use(k)}async function z(e){const{appId:t,fileName:i,file:n}=e;if(!r)throw new Error("API client is not initialized");const{data:o,error:s}=await r.POST("/assets/upload",{params:{query:{app_id:t,file:i}},headers:{"Content-Type":"application/octet-stream"},body:n});if(s)throw s;return o}async function v(e){const{appId:t}=e;if(!r)throw new Error("API client is not initialized");const{data:i,error:n}=await r.DELETE("/assets/upload",{params:{query:{app_id:t}}});if(n)throw n;return i}const O={timeout:5,x:0,y:0,display:"front"};function D(e){return{...O,...e}}async function C(e){const{appId:t,elements:i}=e;if(!r)throw new Error("API client is not initialized");const n=i.map(D),{data:o,error:s}=await r.POST("/display/draw",{body:{app_id:t,elements:n}});if(s)throw s;return o}async function L(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/display/draw");if(t)throw t;return e}async function F(e){const{appId:t,path:i}=e;if(!r)throw new Error("API client is not initialized");const{data:n,error:o}=await r.POST("/audio/play",{params:{query:{app_id:t,path:i}}});if(o)throw o;return n}async function V(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/audio/play");if(t)throw t;return e}async function $(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/enable");if(t)throw t;return e}async function _(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disable");if(t)throw t;return e}async function U(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/status");if(t)throw t;return e}async function W(e){if(!r)throw new Error("API client is not initialized");const{data:t,error:i}=await r.POST("/wifi/connect",{body:{ssid:e.ssid,password:e.password,security:e.security,ip_config:{ip_method:e.ipConfig.ipMethod,ip_type:e.ipConfig.ipType,address:e.ipConfig.address,mask:e.ipConfig.mask,gateway:e.ipConfig.gateway}}});if(i)throw i;return t}async function q(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disconnect");if(t)throw t;return e}async function G(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/networks");if(t)throw t;return e}async function N(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/forget");if(t)throw t;return e}async function j(e){if(!r)throw new Error("API client is not initialized");const{path:t,file:i}=e,{data:n,error:o}=await r.POST("/storage/write",{params:{query:{path:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(o)throw o;return n}async function R(e){if(!r)throw new Error("API client is not initialized");const{path:t,asArrayBuffer:i}=e,{data:n,error:o}=await r.GET("/storage/read",{params:{query:{path:t}},parseAs:i?"arrayBuffer":"blob"});if(o)throw o;return n}async function x(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.GET("/storage/list",{params:{query:{path:t}}});if(n)throw n;return i}async function K(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.DELETE("/storage/remove",{params:{query:{path:t}}});if(n)throw n;return i}async function H(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.POST("/storage/mkdir",{params:{query:{path:t}}});if(n)throw n;return i}async function J(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/version");if(t)throw t;return e}async function X(e){if(!r)throw new Error("API client is not initialized");const{name:t,file:i}=e,{data:n,error:o}=await r.POST("/update",{params:{query:{name:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(o)throw o;return n}async function M(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status");if(t)throw t;return e}async function Q(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/system");if(t)throw t;return e}async function Y(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/power");if(t)throw t;return e}async function Z(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/display/brightness");if(t)throw t;return e}async function tt(e){if(!r)throw new Error("API client is not initialized");const{front:t,back:i}=e,n=f=>{if(typeof f=="number"){if(f<0||f>100)throw new Error("Brightness value must be between 0 and 100 or 'auto'");return String(f)}if(f==="auto")return"auto"},o=n(t),s=n(i),{data:a,error:c}=await r.POST("/display/brightness",{params:{query:{front:o,back:s}}});if(c)throw c;return a}async function et(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/audio/volume");if(t)throw t;return e}async function it(e){if(!r)throw new Error("API client is not initialized");const{volume:t}=e;if(typeof t!="number"||t<0||t>100)throw new Error("Volume must be a number between 0 and 100");const{data:i,error:n}=await r.POST("/audio/volume",{params:{query:{volume:t}}});if(n)throw n;return i}async function rt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/access");if(t)throw t;return e}async function nt(e){if(!r)throw new Error("API client is not initialized");const{mode:t,key:i}=e;if(!/^\d{4,10}$/.test(String(i)))throw new Error("Key must be a string of 4 to 10 digits");const{data:n,error:o}=await r.POST("/access",{params:{query:{mode:t,key:i}}});if(o)throw o;return n}async function ot(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/enable");if(t)throw t;return e}async function st(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/disable");if(t)throw t;return e}class at{constructor(t="10.0.4.20"){u(this,"ip");u(this,"apiSemver");if(!T(t))throw new Error(`Incorrect IPv4: ${t}`);this.ip=t,this.apiSemver="",B(`http://${this.ip}/api/`,this.getApiVersion.bind(this))}async getApiVersion(){const t=await J();return this.apiSemver=t.api_semver,t}async updateFirmware(t){return await X(t)}async deviceStatus(){return await M()}async systemStatus(){return await Q()}async powerStatus(){return await Y()}async uploadAsset(t){return await z(t)}async deleteAssets(t){return await v(t)}async drawDisplay(t){return await C(t)}async clearDisplay(){return await L()}async playSound(t){return await F(t)}async stopSound(){return await V()}async enableWifi(){return await $()}async disableWifi(){return await _()}async statusWifi(){return await U()}async connectWifi(t){return await W(t)}async disconnectWifi(){return await q()}async networksWifi(){return await G()}async forgetWifi(){return await N()}async uploadFile(t){return await j(t)}async downloadFile(t){return await R(t)}async readDirectory(t){return await x(t)}async removeResource(t){return await K(t)}async createDirectory(t){return await H(t)}async getDisplayBrightness(){return await Z()}async setDisplayBrightness(t){return await tt(t)}async getAudioVolume(){return await et()}async setAudioVolume(t){return await it(t)}async getHttpAccess(){return await rt()}async setHttpAccess(t){const i=await nt(t);return t.mode==="key"&&t.key&&this.setApiKey(t.key),i}setApiKey(t){b(t)}async enableBle(){return await ot()}async disableBle(){return await st()}}var d=(e=>(e[e.FRONT=0]="FRONT",e[e.BACK=1]="BACK",e))(d||{});const ct=3e3,ft=new Set([1001,1006,1012,1013,1014,3008]);function E(e,t){if(t<0||t>=e.length)throw new Error(`Index ${t} is out of bounds (0…${e.length-1})`);const i=e[t];if(i===void 0)throw new Error(`Unexpected undefined at index ${t}`);return i}function ut(e,t){let i=0;const n=e.length,o=[];for(;i<n;){const s=E(e,i);if(i+=1,(s&128)!==0){const a=s&127;for(let c=0;c<a*t;c++)o.push(e[i+c]);i+=a*t}else{const a=s,c=e.slice(i,i+t);for(let f=0;f<a;f++)for(let h=0;h<t;h++)o.push(c[h]);i+=t}}return new Uint8Array(o)}function wt(e){const t=new Uint8Array(e.length*2);let i=0,n=0;for(;i<e.length;){const o=E(e,i),s=o&15,a=o>>4&15;t[n]=s,t[n+1]=a,i+=1,n+=2}return t}class lt{constructor(t){u(this,"connected",!1);u(this,"dataListeners",[]);u(this,"stopListeners",[]);u(this,"errorListeners",[]);u(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser")}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t="";this.config.mode==="cloud"?t=`${this.config.domain}/bars/${this.config.idDevice}/ws`:this.config.mode==="local"&&(t=`${this.config.barUrl}/api/screen/ws`),this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.config.mode==="cloud"?this.socket.send(JSON.stringify({token:this.config.token,display:this.config.deviceScreen})):this.config.mode==="local"&&this.socket.send(JSON.stringify({display:this.config.deviceScreen})),this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);if(this.config.mode==="cloud")this.emitData(n);else if(this.config.mode==="local"){let o;const s=this.config.deviceScreen===d.FRONT?3:2;try{const a=ut(n,s);this.config.deviceScreen===d.BACK?o=wt(a):o=a,this.emitData(o)}catch{this.emitData(n)}}}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===ct||ft.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}exports.BusyBar=at;exports.DeviceScreen=d;exports.ScreenStream=lt;
|
|
1
|
+
"use strict";var k=Object.defineProperty;var P=(e,t,i)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var o=(e,t,i)=>P(e,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("openapi-fetch");function b(e){const t=e.split(".");if(t.length!==4)return!1;for(const i of t){if(i.length===0||i.length>1&&i[0]==="0"||!/^\d+$/.test(i))return!1;const n=Number(i);if(n<0||n>255)return!1}return!0}const I=(e,t)=>{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 i;return t&&(t instanceof Headers?i=t.get("Content-Type")??t.get("content-type")??void 0:typeof t=="object"&&(i=t["Content-Type"]??t["content-type"]),i==="application/x-www-form-urlencoded")?e&&typeof e=="object"&&!(e instanceof URLSearchParams)?new URLSearchParams(e).toString():String(e):JSON.stringify(e)};let y,w,l=null;async function E(){if(!w){if(!y)throw new Error("getApiVersionFn is not set");l||(l=(async()=>{const e=await y();if(!e.api_semver)throw new Error("Empty API version");w=e.api_semver})().finally(()=>{l=null})),await l}}async function p(e){const n=(e.headers.get("content-type")||"").includes("application/json")?await e.clone().json():await e.clone().text(),s=typeof n=="object"&&n!==null?n.error||n.message:typeof n=="string"?n:void 0;return Object.assign(new Error(s||`HTTP ${e.status} ${e.statusText}`),{status:e.status,statusText:e.statusText,body:n})}let m;function v(e){m=e}const B={async onRequest({request:e,schemaPath:t}){if(t!=="/version"){if(await E(),w)return e.headers.set("X-API-Sem-Ver",w);m&&e.headers.set("X-API-Token",m)}return e},async onResponse({request:e,response:t,options:i,schemaPath:n}){if(t.ok)return t;if(n==="/version")throw await p(t);if(t.status!==405)throw await p(t);w=void 0,await E(),w&&e.headers.set("X-API-Sem-Ver",w);const s=await(i.fetch??fetch)(e);if(s.ok)return s;throw await p(s)}};let r=null;function L(e,t){y=t,r=T({baseUrl:e,bodySerializer:I}),r.use(B)}async function z(e){const{appId:t,fileName:i,file:n}=e;if(!r)throw new Error("API client is not initialized");const{data:s,error:a}=await r.POST("/assets/upload",{params:{query:{app_id:t,file:i}},headers:{"Content-Type":"application/octet-stream"},body:n});if(a)throw a;return s}async function D(e){const{appId:t}=e;if(!r)throw new Error("API client is not initialized");const{data:i,error:n}=await r.DELETE("/assets/upload",{params:{query:{app_id:t}}});if(n)throw n;return i}const O={timeout:5,x:0,y:0,display:"front"};function K(e){return{...O,...e}}async function U(e){const{appId:t,elements:i}=e;if(!r)throw new Error("API client is not initialized");const n=i.map(K),{data:s,error:a}=await r.POST("/display/draw",{body:{app_id:t,elements:n}});if(a)throw a;return s}async function C(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/display/draw");if(t)throw t;return e}async function W(e){const{appId:t,path:i}=e;if(!r)throw new Error("API client is not initialized");const{data:n,error:s}=await r.POST("/audio/play",{params:{query:{app_id:t,path:i}}});if(s)throw s;return n}async function $(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.DELETE("/audio/play");if(t)throw t;return e}async function F(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/enable");if(t)throw t;return e}async function R(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disable");if(t)throw t;return e}async function V(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/status");if(t)throw t;return e}async function _(e){if(!r)throw new Error("API client is not initialized");const{data:t,error:i}=await r.POST("/wifi/connect",{body:{ssid:e.ssid,password:e.password,security:e.security,ip_config:{ip_method:e.ipConfig.ipMethod,ip_type:e.ipConfig.ipType,address:e.ipConfig.address,mask:e.ipConfig.mask,gateway:e.ipConfig.gateway}}});if(i)throw i;return t}async function q(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/disconnect");if(t)throw t;return e}async function x(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/wifi/networks");if(t)throw t;return e}async function N(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/wifi/forget");if(t)throw t;return e}async function G(e){if(!r)throw new Error("API client is not initialized");const{path:t,file:i}=e,{data:n,error:s}=await r.POST("/storage/write",{params:{query:{path:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(s)throw s;return n}async function j(e){if(!r)throw new Error("API client is not initialized");const{path:t,asArrayBuffer:i}=e,{data:n,error:s}=await r.GET("/storage/read",{params:{query:{path:t}},parseAs:i?"arrayBuffer":"blob"});if(s)throw s;return n}async function H(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.GET("/storage/list",{params:{query:{path:t}}});if(n)throw n;return i}async function J(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.DELETE("/storage/remove",{params:{query:{path:t}}});if(n)throw n;return i}async function X(e){if(!r)throw new Error("API client is not initialized");const{path:t}=e,{data:i,error:n}=await r.POST("/storage/mkdir",{params:{query:{path:t}}});if(n)throw n;return i}async function M(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/version");if(t)throw t;return e}async function Q(e){if(!r)throw new Error("API client is not initialized");const{name:t,file:i}=e,{data:n,error:s}=await r.POST("/update",{params:{query:{name:t}},headers:{"Content-Type":"application/octet-stream"},body:i});if(s)throw s;return n}async function Y(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status");if(t)throw t;return e}async function Z(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/system");if(t)throw t;return e}async function tt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/status/power");if(t)throw t;return e}async function et(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/display/brightness");if(t)throw t;return e}async function it(e){if(!r)throw new Error("API client is not initialized");const{front:t,back:i}=e,n=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)}if(u==="auto")return"auto"},s=n(t),a=n(i),{data:c,error:f}=await r.POST("/display/brightness",{params:{query:{front:s,back:a}}});if(f)throw f;return c}async function rt(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/audio/volume");if(t)throw t;return e}async function nt(e){if(!r)throw new Error("API client is not initialized");const{volume:t}=e;if(typeof t!="number"||t<0||t>100)throw new Error("Volume must be a number between 0 and 100");const{data:i,error:n}=await r.POST("/audio/volume",{params:{query:{volume:t}}});if(n)throw n;return i}async function st(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.GET("/access");if(t)throw t;return e}async function ot(e){if(!r)throw new Error("API client is not initialized");const{mode:t,key:i}=e;if(!/^\d{4,10}$/.test(String(i)))throw new Error("Key must be a string of 4 to 10 digits");const{data:n,error:s}=await r.POST("/access",{params:{query:{mode:t,key:i}}});if(s)throw s;return n}async function at(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/enable");if(t)throw t;return e}async function ct(){if(!r)throw new Error("API client is not initialized");const{data:e,error:t}=await r.POST("/ble/disable");if(t)throw t;return e}async function ft(e){if(!r)throw new Error("API client is not initialized");const{keyName:t}=e,{data:i,error:n}=await r.POST("/input",{params:{query:{key:t}}});if(n)throw n;return i}class ut{constructor(t="10.0.4.20"){o(this,"ip");o(this,"apiSemver");if(!b(t))throw new Error(`Incorrect IPv4: ${t}`);this.ip=t,this.apiSemver="",L(`http://${this.ip}/api/`,this.getApiVersion.bind(this))}async getApiVersion(){const t=await M();return this.apiSemver=t.api_semver,t}async updateFirmware(t){return await Q(t)}async deviceStatus(){return await Y()}async systemStatus(){return await Z()}async powerStatus(){return await tt()}async uploadAsset(t){return await z(t)}async deleteAssets(t){return await D(t)}async drawDisplay(t){return await U(t)}async clearDisplay(){return await C()}async playSound(t){return await W(t)}async stopSound(){return await $()}async enableWifi(){return await F()}async disableWifi(){return await R()}async statusWifi(){return await V()}async connectWifi(t){return await _(t)}async disconnectWifi(){return await q()}async networksWifi(){return await x()}async forgetWifi(){return await N()}async uploadFile(t){return await G(t)}async downloadFile(t){return await j(t)}async readDirectory(t){return await H(t)}async removeResource(t){return await J(t)}async createDirectory(t){return await X(t)}async getDisplayBrightness(){return await et()}async setDisplayBrightness(t){return await it(t)}async getAudioVolume(){return await rt()}async setAudioVolume(t){return await nt(t)}async getHttpAccess(){return await st()}async setHttpAccess(t){const i=await ot(t);return t.mode==="key"&&t.key&&this.setApiKey(t.key),i}setApiKey(t){v(t)}async enableBle(){return await at()}async disableBle(){return await ct()}async pressButton(t){return await ft(t)}}var h=(e=>(e[e.FRONT=0]="FRONT",e[e.BACK=1]="BACK",e))(h||{});const g=3e3,S=new Set([1001,1006,1012,1013,1014,3008]);function A(e,t){if(t<0||t>=e.length)throw new Error(`Index ${t} is out of bounds (0…${e.length-1})`);const i=e[t];if(i===void 0)throw new Error(`Unexpected undefined at index ${t}`);return i}function wt(e,t){let i=0;const n=e.length,s=[];for(;i<n;){const a=A(e,i);if(i+=1,(a&128)!==0){const c=a&127;for(let f=0;f<c*t;f++)s.push(e[i+f]);i+=c*t}else{const c=a,f=e.slice(i,i+t);for(let u=0;u<c;u++)for(let d=0;d<t;d++)s.push(f[d]);i+=t}}return new Uint8Array(s)}function lt(e){const t=new Uint8Array(e.length*2);let i=0,n=0;for(;i<e.length;){const s=A(e,i),a=s&15,c=s>>4&15;t[n]=a,t[n+1]=c,i+=1,n+=2}return t}class ht{constructor(t){o(this,"connected",!1);o(this,"apiKey");o(this,"apiSemver");o(this,"dataListeners",[]);o(this,"stopListeners",[]);o(this,"errorListeners",[]);o(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser");t.apiKey&&(this.apiKey=t.apiKey),t.apiSemver&&(this.apiSemver=t.apiSemver)}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t;if(this.config.mode==="cloud"?t=new URL(`${this.config.domain}/bars/${this.config.idDevice}/ws`):this.config.mode==="local"&&(t=new URL(`${this.config.barUrl}/api/screen/ws`),this.apiKey&&t.searchParams.append("x-api-key",this.apiKey),this.apiSemver&&t.searchParams.append("x-api-sem-ver",this.apiSemver)),!t)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.config.mode==="cloud"?this.socket.send(JSON.stringify({token:this.config.token,display:this.config.deviceScreen})):this.config.mode==="local"&&this.socket.send(JSON.stringify({display:this.config.deviceScreen})),this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);if(this.config.mode==="cloud")this.emitData(n);else if(this.config.mode==="local"){let s;const a=this.config.deviceScreen===h.FRONT?3:2;try{const c=wt(n,a);this.config.deviceScreen===h.BACK?s=lt(c):s=c,this.emitData(s)}catch{this.emitData(n)}}}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===g||S.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}class dt{constructor(t){o(this,"connected",!1);o(this,"apiKey");o(this,"apiSemver");o(this,"inputEvent");o(this,"dataListeners",[]);o(this,"stopListeners",[]);o(this,"errorListeners",[]);o(this,"socket",null);if(this.config=t,!(()=>typeof window<"u"&&typeof window.document<"u"))throw new Error("not browser");t.apiKey&&(this.apiKey=t.apiKey),t.apiSemver&&(this.apiSemver=t.apiSemver),this.inputEvent={}}onData(t){this.dataListeners.push(t)}onStop(t){this.stopListeners.push(t)}onError(t){this.errorListeners.push(t)}emitData(t){for(const i of this.dataListeners)i(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const i of this.errorListeners)i(t)}async openWebsocket(){this.socket&&await this.closeWebsocket();let t;if(this.config.mode==="cloud"?t=new URL(`${this.config.domain}/bars/${this.config.idDevice}/ws`):this.config.mode==="local"&&(t=new URL(`${this.config.barUrl}/api/input`),this.apiKey&&t.searchParams.append("x-api-key",this.apiKey),this.apiSemver&&t.searchParams.append("x-api-sem-ver",this.apiSemver)),!t)throw new Error("The WebSocket URL is not specified");this.socket=new WebSocket(t),this.socket.onopen=()=>{this.socket&&(this.connected=!0)},this.socket.binaryType="arraybuffer",this.socket.onmessage=i=>{try{if(typeof i.data=="string")return;const n=new Uint8Array(i.data);this.emitData(n)}catch{this.connected=!1,this.emitStop()}},this.socket.onerror=i=>{this.connected=!1,this.emitError({code:1006,message:"WebSocket error occurred",raw:i}),this.emitStop()},this.socket.onclose=async i=>{if(this.socket=null,this.connected=!1,i.code===g||S.has(i.code)){this.emitError({code:i.code,message:i.reason,raw:i});return}this.emitStop()}}sendInput({keyName:t,value:i}){if(!this.socket||!this.connected)throw new Error("WebSocket: Not connected");this.inputEvent[t]=i,this.socket.send(JSON.stringify(this.inputEvent)),i===0&&delete this.inputEvent[t]}closeWebsocket(){return this.connected=!1,new Promise(t=>{this.socket?(this.socket.onclose=()=>{t()},this.socket.close(),this.socket=null):t(),this.emitStop()})}}exports.BusyBar=ut;exports.DeviceScreen=h;exports.Input=dt;exports.ScreenStream=ht;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
declare type ApiKey = string;
|
|
2
|
+
|
|
3
|
+
declare type ApiSemver = components["schemas"]["VersionInfo"]["api_semver"];
|
|
4
|
+
|
|
1
5
|
declare interface AudioParams {
|
|
2
6
|
appId: paths["/audio/play"]["post"]["parameters"]["query"]["app_id"];
|
|
3
7
|
path: paths["/audio/play"]["post"]["parameters"]["query"]["path"];
|
|
@@ -9,6 +13,13 @@ declare interface AudioVolumeParams {
|
|
|
9
13
|
|
|
10
14
|
declare interface BaseConfig {
|
|
11
15
|
deviceScreen: DeviceScreen;
|
|
16
|
+
apiKey?: ApiKey;
|
|
17
|
+
apiSemver?: ApiSemver;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare interface BaseConfig_2 {
|
|
21
|
+
apiKey?: ApiKey;
|
|
22
|
+
apiSemver?: ApiSemver;
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
declare type Brightness = number | "auto";
|
|
@@ -292,6 +303,18 @@ export declare class BusyBar {
|
|
|
292
303
|
* @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the disable operation.
|
|
293
304
|
*/
|
|
294
305
|
disableBle(): Promise<components["schemas"]["SuccessResponse"]>;
|
|
306
|
+
/**
|
|
307
|
+
* Sends a button press.
|
|
308
|
+
*
|
|
309
|
+
* @param params - Button press parameters:
|
|
310
|
+
* @param {InputKey['keyName']} params.keyName - Button key.
|
|
311
|
+
* @example
|
|
312
|
+
* {
|
|
313
|
+
* keyName: "ok"
|
|
314
|
+
* }
|
|
315
|
+
* @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of pressing the button.
|
|
316
|
+
*/
|
|
317
|
+
pressButton(params: InputKey): Promise<components["schemas"]["SuccessResponse"]>;
|
|
295
318
|
}
|
|
296
319
|
|
|
297
320
|
declare type BusyFile = Buffer | Blob | File | ArrayBuffer;
|
|
@@ -645,6 +668,8 @@ declare interface DeleteParams {
|
|
|
645
668
|
|
|
646
669
|
declare type DeviceConfig = LocalConfig | SiteConfig;
|
|
647
670
|
|
|
671
|
+
declare type DeviceConfig_2 = LocalConfig_2 | SiteConfig_2;
|
|
672
|
+
|
|
648
673
|
export declare enum DeviceScreen {
|
|
649
674
|
FRONT = 0,
|
|
650
675
|
BACK = 1
|
|
@@ -673,13 +698,51 @@ declare interface HttpAccess {
|
|
|
673
698
|
key: operations["setHttpAccess"]["parameters"]["query"]["key"];
|
|
674
699
|
}
|
|
675
700
|
|
|
701
|
+
export declare class Input {
|
|
702
|
+
private config;
|
|
703
|
+
connected: boolean;
|
|
704
|
+
private apiKey?;
|
|
705
|
+
private apiSemver?;
|
|
706
|
+
private inputEvent;
|
|
707
|
+
private dataListeners;
|
|
708
|
+
private stopListeners;
|
|
709
|
+
private errorListeners;
|
|
710
|
+
private socket;
|
|
711
|
+
constructor(config: DeviceConfig_2);
|
|
712
|
+
onData(listener: DataListener): void;
|
|
713
|
+
onStop(listener: StopListener): void;
|
|
714
|
+
onError(listener: ErrorListener): void;
|
|
715
|
+
protected emitData(data: Uint8Array): void;
|
|
716
|
+
protected emitStop(): void;
|
|
717
|
+
protected emitError(payload: ErrorPayload): void;
|
|
718
|
+
openWebsocket(): Promise<void>;
|
|
719
|
+
sendInput({ keyName, value }: {
|
|
720
|
+
keyName: KeyName;
|
|
721
|
+
value: KeyValue;
|
|
722
|
+
}): void;
|
|
723
|
+
closeWebsocket(): Promise<void>;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
declare interface InputKey {
|
|
727
|
+
keyName: KeyName;
|
|
728
|
+
}
|
|
729
|
+
|
|
676
730
|
declare type IPv4 = string;
|
|
677
731
|
|
|
732
|
+
export declare type KeyName = operations["setInputKey"]["parameters"]["query"]["key"];
|
|
733
|
+
|
|
734
|
+
export declare type KeyValue = 1 | 0;
|
|
735
|
+
|
|
678
736
|
declare interface LocalConfig extends BaseConfig {
|
|
679
737
|
mode: "local";
|
|
680
738
|
barUrl: string;
|
|
681
739
|
}
|
|
682
740
|
|
|
741
|
+
declare interface LocalConfig_2 extends BaseConfig_2 {
|
|
742
|
+
mode: "local";
|
|
743
|
+
barUrl: string;
|
|
744
|
+
}
|
|
745
|
+
|
|
683
746
|
declare type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
684
747
|
|
|
685
748
|
export declare type Network = components["schemas"]["Network"];
|
|
@@ -2425,6 +2488,8 @@ declare type RequireKeys<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T,
|
|
|
2425
2488
|
export declare class ScreenStream {
|
|
2426
2489
|
private config;
|
|
2427
2490
|
connected: boolean;
|
|
2491
|
+
private apiKey?;
|
|
2492
|
+
private apiSemver?;
|
|
2428
2493
|
private dataListeners;
|
|
2429
2494
|
private stopListeners;
|
|
2430
2495
|
private errorListeners;
|
|
@@ -2447,6 +2512,13 @@ declare interface SiteConfig extends BaseConfig {
|
|
|
2447
2512
|
idDevice: string;
|
|
2448
2513
|
}
|
|
2449
2514
|
|
|
2515
|
+
declare interface SiteConfig_2 extends BaseConfig_2 {
|
|
2516
|
+
mode: "cloud";
|
|
2517
|
+
domain: string;
|
|
2518
|
+
token: string;
|
|
2519
|
+
idDevice: string;
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2450
2522
|
declare type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<SnakeToCamel<Tail>>}` : S;
|
|
2451
2523
|
|
|
2452
2524
|
declare type StopListener = () => void;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var P = (e, t, i) => t in e ?
|
|
3
|
-
var
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var P = (e, t, i) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var o = (e, t, i) => P(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
4
|
import T from "openapi-fetch";
|
|
5
|
-
function
|
|
5
|
+
function b(e) {
|
|
6
6
|
const t = e.split(".");
|
|
7
7
|
if (t.length !== 4)
|
|
8
8
|
return !1;
|
|
@@ -21,13 +21,13 @@ const I = (e, t) => {
|
|
|
21
21
|
let i;
|
|
22
22
|
return t && (t instanceof Headers ? i = t.get("Content-Type") ?? t.get("content-type") ?? void 0 : typeof t == "object" && (i = t["Content-Type"] ?? t["content-type"]), i === "application/x-www-form-urlencoded") ? e && typeof e == "object" && !(e instanceof URLSearchParams) ? new URLSearchParams(e).toString() : String(e) : JSON.stringify(e);
|
|
23
23
|
};
|
|
24
|
-
let
|
|
25
|
-
async function
|
|
24
|
+
let p, w, l = null;
|
|
25
|
+
async function E() {
|
|
26
26
|
if (!w) {
|
|
27
|
-
if (!
|
|
27
|
+
if (!p)
|
|
28
28
|
throw new Error("getApiVersionFn is not set");
|
|
29
29
|
l || (l = (async () => {
|
|
30
|
-
const e = await
|
|
30
|
+
const e = await p();
|
|
31
31
|
if (!e.api_semver)
|
|
32
32
|
throw new Error("Empty API version");
|
|
33
33
|
w = e.api_semver;
|
|
@@ -36,10 +36,10 @@ async function g() {
|
|
|
36
36
|
})), await l;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
async function
|
|
40
|
-
const n = (e.headers.get("content-type") || "").includes("application/json") ? await e.clone().json() : await e.clone().text(),
|
|
39
|
+
async function d(e) {
|
|
40
|
+
const n = (e.headers.get("content-type") || "").includes("application/json") ? await e.clone().json() : await e.clone().text(), s = typeof n == "object" && n !== null ? n.error || n.message : typeof n == "string" ? n : void 0;
|
|
41
41
|
return Object.assign(
|
|
42
|
-
new Error(
|
|
42
|
+
new Error(s || `HTTP ${e.status} ${e.statusText}`),
|
|
43
43
|
{
|
|
44
44
|
status: e.status,
|
|
45
45
|
statusText: e.statusText,
|
|
@@ -47,16 +47,16 @@ async function h(e) {
|
|
|
47
47
|
}
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
let
|
|
51
|
-
function
|
|
52
|
-
|
|
50
|
+
let y;
|
|
51
|
+
function v(e) {
|
|
52
|
+
y = e;
|
|
53
53
|
}
|
|
54
|
-
const
|
|
54
|
+
const B = {
|
|
55
55
|
async onRequest({ request: e, schemaPath: t }) {
|
|
56
56
|
if (t !== "/version") {
|
|
57
|
-
if (await
|
|
57
|
+
if (await E(), w)
|
|
58
58
|
return e.headers.set("X-API-Sem-Ver", w);
|
|
59
|
-
|
|
59
|
+
y && e.headers.set("X-API-Token", y);
|
|
60
60
|
}
|
|
61
61
|
return e;
|
|
62
62
|
},
|
|
@@ -64,28 +64,28 @@ const k = {
|
|
|
64
64
|
if (t.ok)
|
|
65
65
|
return t;
|
|
66
66
|
if (n === "/version")
|
|
67
|
-
throw await
|
|
67
|
+
throw await d(t);
|
|
68
68
|
if (t.status !== 405)
|
|
69
|
-
throw await
|
|
70
|
-
w = void 0, await
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
74
|
-
throw await
|
|
69
|
+
throw await d(t);
|
|
70
|
+
w = void 0, await E(), w && e.headers.set("X-API-Sem-Ver", w);
|
|
71
|
+
const s = await (i.fetch ?? fetch)(e);
|
|
72
|
+
if (s.ok)
|
|
73
|
+
return s;
|
|
74
|
+
throw await d(s);
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
let r = null;
|
|
78
|
-
function
|
|
79
|
-
|
|
78
|
+
function L(e, t) {
|
|
79
|
+
p = t, r = T({
|
|
80
80
|
baseUrl: e,
|
|
81
81
|
bodySerializer: I
|
|
82
|
-
}), r.use(
|
|
82
|
+
}), r.use(B);
|
|
83
83
|
}
|
|
84
84
|
async function z(e) {
|
|
85
85
|
const { appId: t, fileName: i, file: n } = e;
|
|
86
86
|
if (!r)
|
|
87
87
|
throw new Error("API client is not initialized");
|
|
88
|
-
const { data:
|
|
88
|
+
const { data: s, error: a } = await r.POST("/assets/upload", {
|
|
89
89
|
params: {
|
|
90
90
|
query: {
|
|
91
91
|
app_id: t,
|
|
@@ -97,11 +97,11 @@ async function z(e) {
|
|
|
97
97
|
},
|
|
98
98
|
body: n
|
|
99
99
|
});
|
|
100
|
-
if (
|
|
101
|
-
throw
|
|
102
|
-
return
|
|
100
|
+
if (a)
|
|
101
|
+
throw a;
|
|
102
|
+
return s;
|
|
103
103
|
}
|
|
104
|
-
async function
|
|
104
|
+
async function D(e) {
|
|
105
105
|
const { appId: t } = e;
|
|
106
106
|
if (!r)
|
|
107
107
|
throw new Error("API client is not initialized");
|
|
@@ -117,24 +117,24 @@ async function v(e) {
|
|
|
117
117
|
return i;
|
|
118
118
|
}
|
|
119
119
|
const O = { timeout: 5, x: 0, y: 0, display: "front" };
|
|
120
|
-
function
|
|
120
|
+
function K(e) {
|
|
121
121
|
return { ...O, ...e };
|
|
122
122
|
}
|
|
123
|
-
async function
|
|
123
|
+
async function U(e) {
|
|
124
124
|
const { appId: t, elements: i } = e;
|
|
125
125
|
if (!r)
|
|
126
126
|
throw new Error("API client is not initialized");
|
|
127
|
-
const n = i.map(
|
|
127
|
+
const n = i.map(K), { data: s, error: a } = await r.POST("/display/draw", {
|
|
128
128
|
body: {
|
|
129
129
|
app_id: t,
|
|
130
130
|
elements: n
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
|
-
if (
|
|
134
|
-
throw
|
|
135
|
-
return
|
|
133
|
+
if (a)
|
|
134
|
+
throw a;
|
|
135
|
+
return s;
|
|
136
136
|
}
|
|
137
|
-
async function
|
|
137
|
+
async function C() {
|
|
138
138
|
if (!r)
|
|
139
139
|
throw new Error("API client is not initialized");
|
|
140
140
|
const { data: e, error: t } = await r.DELETE("/display/draw");
|
|
@@ -142,11 +142,11 @@ async function L() {
|
|
|
142
142
|
throw t;
|
|
143
143
|
return e;
|
|
144
144
|
}
|
|
145
|
-
async function
|
|
145
|
+
async function W(e) {
|
|
146
146
|
const { appId: t, path: i } = e;
|
|
147
147
|
if (!r)
|
|
148
148
|
throw new Error("API client is not initialized");
|
|
149
|
-
const { data: n, error:
|
|
149
|
+
const { data: n, error: s } = await r.POST("/audio/play", {
|
|
150
150
|
params: {
|
|
151
151
|
query: {
|
|
152
152
|
app_id: t,
|
|
@@ -154,11 +154,11 @@ async function F(e) {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
-
if (
|
|
158
|
-
throw
|
|
157
|
+
if (s)
|
|
158
|
+
throw s;
|
|
159
159
|
return n;
|
|
160
160
|
}
|
|
161
|
-
async function
|
|
161
|
+
async function $() {
|
|
162
162
|
if (!r)
|
|
163
163
|
throw new Error("API client is not initialized");
|
|
164
164
|
const { data: e, error: t } = await r.DELETE("/audio/play");
|
|
@@ -166,7 +166,7 @@ async function V() {
|
|
|
166
166
|
throw t;
|
|
167
167
|
return e;
|
|
168
168
|
}
|
|
169
|
-
async function
|
|
169
|
+
async function F() {
|
|
170
170
|
if (!r)
|
|
171
171
|
throw new Error("API client is not initialized");
|
|
172
172
|
const { data: e, error: t } = await r.POST("/wifi/enable");
|
|
@@ -174,7 +174,7 @@ async function $() {
|
|
|
174
174
|
throw t;
|
|
175
175
|
return e;
|
|
176
176
|
}
|
|
177
|
-
async function
|
|
177
|
+
async function R() {
|
|
178
178
|
if (!r)
|
|
179
179
|
throw new Error("API client is not initialized");
|
|
180
180
|
const { data: e, error: t } = await r.POST("/wifi/disable");
|
|
@@ -182,7 +182,7 @@ async function _() {
|
|
|
182
182
|
throw t;
|
|
183
183
|
return e;
|
|
184
184
|
}
|
|
185
|
-
async function
|
|
185
|
+
async function V() {
|
|
186
186
|
if (!r)
|
|
187
187
|
throw new Error("API client is not initialized");
|
|
188
188
|
const { data: e, error: t } = await r.GET("/wifi/status");
|
|
@@ -190,7 +190,7 @@ async function U() {
|
|
|
190
190
|
throw t;
|
|
191
191
|
return e;
|
|
192
192
|
}
|
|
193
|
-
async function
|
|
193
|
+
async function x(e) {
|
|
194
194
|
if (!r)
|
|
195
195
|
throw new Error("API client is not initialized");
|
|
196
196
|
const { data: t, error: i } = await r.POST("/wifi/connect", {
|
|
@@ -211,7 +211,7 @@ async function W(e) {
|
|
|
211
211
|
throw i;
|
|
212
212
|
return t;
|
|
213
213
|
}
|
|
214
|
-
async function
|
|
214
|
+
async function _() {
|
|
215
215
|
if (!r)
|
|
216
216
|
throw new Error("API client is not initialized");
|
|
217
217
|
const { data: e, error: t } = await r.POST("/wifi/disconnect");
|
|
@@ -219,7 +219,7 @@ async function G() {
|
|
|
219
219
|
throw t;
|
|
220
220
|
return e;
|
|
221
221
|
}
|
|
222
|
-
async function
|
|
222
|
+
async function N() {
|
|
223
223
|
if (!r)
|
|
224
224
|
throw new Error("API client is not initialized");
|
|
225
225
|
const { data: e, error: t } = await r.GET("/wifi/networks");
|
|
@@ -227,7 +227,7 @@ async function q() {
|
|
|
227
227
|
throw t;
|
|
228
228
|
return e;
|
|
229
229
|
}
|
|
230
|
-
async function
|
|
230
|
+
async function q() {
|
|
231
231
|
if (!r)
|
|
232
232
|
throw new Error("API client is not initialized");
|
|
233
233
|
const { data: e, error: t } = await r.POST("/wifi/forget");
|
|
@@ -235,10 +235,10 @@ async function N() {
|
|
|
235
235
|
throw t;
|
|
236
236
|
return e;
|
|
237
237
|
}
|
|
238
|
-
async function
|
|
238
|
+
async function G(e) {
|
|
239
239
|
if (!r)
|
|
240
240
|
throw new Error("API client is not initialized");
|
|
241
|
-
const { path: t, file: i } = e, { data: n, error:
|
|
241
|
+
const { path: t, file: i } = e, { data: n, error: s } = await r.POST("/storage/write", {
|
|
242
242
|
params: {
|
|
243
243
|
query: {
|
|
244
244
|
path: t
|
|
@@ -249,14 +249,14 @@ async function x(e) {
|
|
|
249
249
|
},
|
|
250
250
|
body: i
|
|
251
251
|
});
|
|
252
|
-
if (
|
|
253
|
-
throw
|
|
252
|
+
if (s)
|
|
253
|
+
throw s;
|
|
254
254
|
return n;
|
|
255
255
|
}
|
|
256
|
-
async function
|
|
256
|
+
async function j(e) {
|
|
257
257
|
if (!r)
|
|
258
258
|
throw new Error("API client is not initialized");
|
|
259
|
-
const { path: t, asArrayBuffer: i } = e, { data: n, error:
|
|
259
|
+
const { path: t, asArrayBuffer: i } = e, { data: n, error: s } = await r.GET("/storage/read", {
|
|
260
260
|
params: {
|
|
261
261
|
query: {
|
|
262
262
|
path: t
|
|
@@ -264,11 +264,11 @@ async function R(e) {
|
|
|
264
264
|
},
|
|
265
265
|
parseAs: i ? "arrayBuffer" : "blob"
|
|
266
266
|
});
|
|
267
|
-
if (
|
|
268
|
-
throw
|
|
267
|
+
if (s)
|
|
268
|
+
throw s;
|
|
269
269
|
return n;
|
|
270
270
|
}
|
|
271
|
-
async function
|
|
271
|
+
async function H(e) {
|
|
272
272
|
if (!r)
|
|
273
273
|
throw new Error("API client is not initialized");
|
|
274
274
|
const { path: t } = e, { data: i, error: n } = await r.GET("/storage/list", {
|
|
@@ -282,7 +282,7 @@ async function j(e) {
|
|
|
282
282
|
throw n;
|
|
283
283
|
return i;
|
|
284
284
|
}
|
|
285
|
-
async function
|
|
285
|
+
async function J(e) {
|
|
286
286
|
if (!r)
|
|
287
287
|
throw new Error("API client is not initialized");
|
|
288
288
|
const { path: t } = e, { data: i, error: n } = await r.DELETE("/storage/remove", {
|
|
@@ -296,7 +296,7 @@ async function K(e) {
|
|
|
296
296
|
throw n;
|
|
297
297
|
return i;
|
|
298
298
|
}
|
|
299
|
-
async function
|
|
299
|
+
async function X(e) {
|
|
300
300
|
if (!r)
|
|
301
301
|
throw new Error("API client is not initialized");
|
|
302
302
|
const { path: t } = e, { data: i, error: n } = await r.POST("/storage/mkdir", {
|
|
@@ -310,7 +310,7 @@ async function H(e) {
|
|
|
310
310
|
throw n;
|
|
311
311
|
return i;
|
|
312
312
|
}
|
|
313
|
-
async function
|
|
313
|
+
async function Q() {
|
|
314
314
|
if (!r)
|
|
315
315
|
throw new Error("API client is not initialized");
|
|
316
316
|
const { data: e, error: t } = await r.GET("/version");
|
|
@@ -318,10 +318,10 @@ async function J() {
|
|
|
318
318
|
throw t;
|
|
319
319
|
return e;
|
|
320
320
|
}
|
|
321
|
-
async function
|
|
321
|
+
async function M(e) {
|
|
322
322
|
if (!r)
|
|
323
323
|
throw new Error("API client is not initialized");
|
|
324
|
-
const { name: t, file: i } = e, { data: n, error:
|
|
324
|
+
const { name: t, file: i } = e, { data: n, error: s } = await r.POST("/update", {
|
|
325
325
|
params: {
|
|
326
326
|
query: {
|
|
327
327
|
name: t
|
|
@@ -332,11 +332,11 @@ async function X(e) {
|
|
|
332
332
|
},
|
|
333
333
|
body: i
|
|
334
334
|
});
|
|
335
|
-
if (
|
|
336
|
-
throw
|
|
335
|
+
if (s)
|
|
336
|
+
throw s;
|
|
337
337
|
return n;
|
|
338
338
|
}
|
|
339
|
-
async function
|
|
339
|
+
async function Y() {
|
|
340
340
|
if (!r)
|
|
341
341
|
throw new Error("API client is not initialized");
|
|
342
342
|
const { data: e, error: t } = await r.GET("/status");
|
|
@@ -344,7 +344,7 @@ async function Q() {
|
|
|
344
344
|
throw t;
|
|
345
345
|
return e;
|
|
346
346
|
}
|
|
347
|
-
async function
|
|
347
|
+
async function Z() {
|
|
348
348
|
if (!r)
|
|
349
349
|
throw new Error("API client is not initialized");
|
|
350
350
|
const { data: e, error: t } = await r.GET("/status/system");
|
|
@@ -352,7 +352,7 @@ async function M() {
|
|
|
352
352
|
throw t;
|
|
353
353
|
return e;
|
|
354
354
|
}
|
|
355
|
-
async function
|
|
355
|
+
async function tt() {
|
|
356
356
|
if (!r)
|
|
357
357
|
throw new Error("API client is not initialized");
|
|
358
358
|
const { data: e, error: t } = await r.GET("/status/power");
|
|
@@ -360,7 +360,7 @@ async function Y() {
|
|
|
360
360
|
throw t;
|
|
361
361
|
return e;
|
|
362
362
|
}
|
|
363
|
-
async function
|
|
363
|
+
async function et() {
|
|
364
364
|
if (!r)
|
|
365
365
|
throw new Error("API client is not initialized");
|
|
366
366
|
const { data: e, error: t } = await r.GET("/display/brightness");
|
|
@@ -368,30 +368,30 @@ async function Z() {
|
|
|
368
368
|
throw t;
|
|
369
369
|
return e;
|
|
370
370
|
}
|
|
371
|
-
async function
|
|
371
|
+
async function it(e) {
|
|
372
372
|
if (!r)
|
|
373
373
|
throw new Error("API client is not initialized");
|
|
374
|
-
const { front: t, back: i } = e, n = (
|
|
375
|
-
if (typeof
|
|
376
|
-
if (
|
|
374
|
+
const { front: t, back: i } = e, n = (u) => {
|
|
375
|
+
if (typeof u == "number") {
|
|
376
|
+
if (u < 0 || u > 100)
|
|
377
377
|
throw new Error("Brightness value must be between 0 and 100 or 'auto'");
|
|
378
|
-
return String(
|
|
378
|
+
return String(u);
|
|
379
379
|
}
|
|
380
|
-
if (
|
|
380
|
+
if (u === "auto")
|
|
381
381
|
return "auto";
|
|
382
|
-
},
|
|
382
|
+
}, s = n(t), a = n(i), { data: c, error: f } = await r.POST("/display/brightness", {
|
|
383
383
|
params: {
|
|
384
384
|
query: {
|
|
385
|
-
front:
|
|
386
|
-
back:
|
|
385
|
+
front: s,
|
|
386
|
+
back: a
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
});
|
|
390
|
-
if (
|
|
391
|
-
throw
|
|
392
|
-
return
|
|
390
|
+
if (f)
|
|
391
|
+
throw f;
|
|
392
|
+
return c;
|
|
393
393
|
}
|
|
394
|
-
async function
|
|
394
|
+
async function rt() {
|
|
395
395
|
if (!r)
|
|
396
396
|
throw new Error("API client is not initialized");
|
|
397
397
|
const { data: e, error: t } = await r.GET("/audio/volume");
|
|
@@ -399,7 +399,7 @@ async function et() {
|
|
|
399
399
|
throw t;
|
|
400
400
|
return e;
|
|
401
401
|
}
|
|
402
|
-
async function
|
|
402
|
+
async function nt(e) {
|
|
403
403
|
if (!r)
|
|
404
404
|
throw new Error("API client is not initialized");
|
|
405
405
|
const { volume: t } = e;
|
|
@@ -416,7 +416,7 @@ async function it(e) {
|
|
|
416
416
|
throw n;
|
|
417
417
|
return i;
|
|
418
418
|
}
|
|
419
|
-
async function
|
|
419
|
+
async function st() {
|
|
420
420
|
if (!r)
|
|
421
421
|
throw new Error("API client is not initialized");
|
|
422
422
|
const { data: e, error: t } = await r.GET("/access");
|
|
@@ -424,13 +424,13 @@ async function rt() {
|
|
|
424
424
|
throw t;
|
|
425
425
|
return e;
|
|
426
426
|
}
|
|
427
|
-
async function
|
|
427
|
+
async function ot(e) {
|
|
428
428
|
if (!r)
|
|
429
429
|
throw new Error("API client is not initialized");
|
|
430
430
|
const { mode: t, key: i } = e;
|
|
431
431
|
if (!/^\d{4,10}$/.test(String(i)))
|
|
432
432
|
throw new Error("Key must be a string of 4 to 10 digits");
|
|
433
|
-
const { data: n, error:
|
|
433
|
+
const { data: n, error: s } = await r.POST("/access", {
|
|
434
434
|
params: {
|
|
435
435
|
query: {
|
|
436
436
|
mode: t,
|
|
@@ -438,11 +438,11 @@ async function nt(e) {
|
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
});
|
|
441
|
-
if (
|
|
442
|
-
throw
|
|
441
|
+
if (s)
|
|
442
|
+
throw s;
|
|
443
443
|
return n;
|
|
444
444
|
}
|
|
445
|
-
async function
|
|
445
|
+
async function at() {
|
|
446
446
|
if (!r)
|
|
447
447
|
throw new Error("API client is not initialized");
|
|
448
448
|
const { data: e, error: t } = await r.POST("/ble/enable");
|
|
@@ -450,7 +450,7 @@ async function ot() {
|
|
|
450
450
|
throw t;
|
|
451
451
|
return e;
|
|
452
452
|
}
|
|
453
|
-
async function
|
|
453
|
+
async function ct() {
|
|
454
454
|
if (!r)
|
|
455
455
|
throw new Error("API client is not initialized");
|
|
456
456
|
const { data: e, error: t } = await r.POST("/ble/disable");
|
|
@@ -458,6 +458,20 @@ async function st() {
|
|
|
458
458
|
throw t;
|
|
459
459
|
return e;
|
|
460
460
|
}
|
|
461
|
+
async function ft(e) {
|
|
462
|
+
if (!r)
|
|
463
|
+
throw new Error("API client is not initialized");
|
|
464
|
+
const { keyName: t } = e, { data: i, error: n } = await r.POST("/input", {
|
|
465
|
+
params: {
|
|
466
|
+
query: {
|
|
467
|
+
key: t
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
if (n)
|
|
472
|
+
throw n;
|
|
473
|
+
return i;
|
|
474
|
+
}
|
|
461
475
|
class dt {
|
|
462
476
|
/**
|
|
463
477
|
* Creates an instance of BUSY Bar.
|
|
@@ -472,12 +486,12 @@ class dt {
|
|
|
472
486
|
* @type {IPv4}
|
|
473
487
|
* @readonly
|
|
474
488
|
*/
|
|
475
|
-
|
|
489
|
+
o(this, "ip");
|
|
476
490
|
// @ts-ignore
|
|
477
|
-
|
|
478
|
-
if (!
|
|
491
|
+
o(this, "apiSemver");
|
|
492
|
+
if (!b(t))
|
|
479
493
|
throw new Error(`Incorrect IPv4: ${t}`);
|
|
480
|
-
this.ip = t, this.apiSemver = "",
|
|
494
|
+
this.ip = t, this.apiSemver = "", L(`http://${this.ip}/api/`, this.getApiVersion.bind(this));
|
|
481
495
|
}
|
|
482
496
|
/**
|
|
483
497
|
* Retrieves the API semantic version.
|
|
@@ -485,7 +499,7 @@ class dt {
|
|
|
485
499
|
* @returns A promise that resolves to an object containing the `api_semver` string.
|
|
486
500
|
*/
|
|
487
501
|
async getApiVersion() {
|
|
488
|
-
const t = await
|
|
502
|
+
const t = await Q();
|
|
489
503
|
return this.apiSemver = t.api_semver, t;
|
|
490
504
|
}
|
|
491
505
|
/**
|
|
@@ -497,7 +511,7 @@ class dt {
|
|
|
497
511
|
* @returns Result of the update operation.
|
|
498
512
|
*/
|
|
499
513
|
async updateFirmware(t) {
|
|
500
|
-
return await
|
|
514
|
+
return await M(t);
|
|
501
515
|
}
|
|
502
516
|
/**
|
|
503
517
|
* Gets the current status of the device, including system and power information.
|
|
@@ -505,7 +519,7 @@ class dt {
|
|
|
505
519
|
* @returns Current status of the device.
|
|
506
520
|
*/
|
|
507
521
|
async deviceStatus() {
|
|
508
|
-
return await
|
|
522
|
+
return await Y();
|
|
509
523
|
}
|
|
510
524
|
/**
|
|
511
525
|
* Gets the current system status.
|
|
@@ -513,7 +527,7 @@ class dt {
|
|
|
513
527
|
* @returns Current system status.
|
|
514
528
|
*/
|
|
515
529
|
async systemStatus() {
|
|
516
|
-
return await
|
|
530
|
+
return await Z();
|
|
517
531
|
}
|
|
518
532
|
/**
|
|
519
533
|
* Gets the current power status.
|
|
@@ -521,7 +535,7 @@ class dt {
|
|
|
521
535
|
* @returns Current power status.
|
|
522
536
|
*/
|
|
523
537
|
async powerStatus() {
|
|
524
|
-
return await
|
|
538
|
+
return await tt();
|
|
525
539
|
}
|
|
526
540
|
/**
|
|
527
541
|
* Uploads an asset to the device.
|
|
@@ -543,7 +557,7 @@ class dt {
|
|
|
543
557
|
* @returns {Promise<{ result: string }>} Result of the delete operation.
|
|
544
558
|
*/
|
|
545
559
|
async deleteAssets(t) {
|
|
546
|
-
return await
|
|
560
|
+
return await D(t);
|
|
547
561
|
}
|
|
548
562
|
/**
|
|
549
563
|
* Draws elements on the device display.
|
|
@@ -554,7 +568,7 @@ class dt {
|
|
|
554
568
|
* @returns {Promise<{ result: string }>} Result of the draw operation.
|
|
555
569
|
*/
|
|
556
570
|
async drawDisplay(t) {
|
|
557
|
-
return await
|
|
571
|
+
return await U(t);
|
|
558
572
|
}
|
|
559
573
|
/**
|
|
560
574
|
* Clears the device display and stops the Canvas application if running.
|
|
@@ -562,7 +576,7 @@ class dt {
|
|
|
562
576
|
* @returns {Promise<{ result: string }>} Result of the clear operation.
|
|
563
577
|
*/
|
|
564
578
|
async clearDisplay() {
|
|
565
|
-
return await
|
|
579
|
+
return await C();
|
|
566
580
|
}
|
|
567
581
|
/**
|
|
568
582
|
* Plays an audio file from the assets directory.
|
|
@@ -573,7 +587,7 @@ class dt {
|
|
|
573
587
|
* @returns {Promise<{ result: string }>} Result of the play operation.
|
|
574
588
|
*/
|
|
575
589
|
async playSound(t) {
|
|
576
|
-
return await
|
|
590
|
+
return await W(t);
|
|
577
591
|
}
|
|
578
592
|
/**
|
|
579
593
|
* Stops any currently playing audio on the device.
|
|
@@ -581,7 +595,7 @@ class dt {
|
|
|
581
595
|
* @returns {Promise<{ result: string }>} Result of the stop operation.
|
|
582
596
|
*/
|
|
583
597
|
async stopSound() {
|
|
584
|
-
return await
|
|
598
|
+
return await $();
|
|
585
599
|
}
|
|
586
600
|
/**
|
|
587
601
|
* Enables the device's Wi-Fi module.
|
|
@@ -589,7 +603,7 @@ class dt {
|
|
|
589
603
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the enable operation.
|
|
590
604
|
*/
|
|
591
605
|
async enableWifi() {
|
|
592
|
-
return await
|
|
606
|
+
return await F();
|
|
593
607
|
}
|
|
594
608
|
/**
|
|
595
609
|
* Disables the device's Wi-Fi module.
|
|
@@ -597,7 +611,7 @@ class dt {
|
|
|
597
611
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the disable operation.
|
|
598
612
|
*/
|
|
599
613
|
async disableWifi() {
|
|
600
|
-
return await
|
|
614
|
+
return await R();
|
|
601
615
|
}
|
|
602
616
|
/**
|
|
603
617
|
* Gets the current status of the Wi-Fi module.
|
|
@@ -605,7 +619,7 @@ class dt {
|
|
|
605
619
|
* @returns {Promise<components['schemas']['StatusResponse']>} Current Wi-Fi status.
|
|
606
620
|
*/
|
|
607
621
|
async statusWifi() {
|
|
608
|
-
return await
|
|
622
|
+
return await V();
|
|
609
623
|
}
|
|
610
624
|
/**
|
|
611
625
|
* Connects the device to a Wi-Fi network with the specified parameters.
|
|
@@ -623,7 +637,7 @@ class dt {
|
|
|
623
637
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the connect operation.
|
|
624
638
|
*/
|
|
625
639
|
async connectWifi(t) {
|
|
626
|
-
return await
|
|
640
|
+
return await x(t);
|
|
627
641
|
}
|
|
628
642
|
/**
|
|
629
643
|
* Disconnects the device from the current Wi-Fi network.
|
|
@@ -631,7 +645,7 @@ class dt {
|
|
|
631
645
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the disconnect operation.
|
|
632
646
|
*/
|
|
633
647
|
async disconnectWifi() {
|
|
634
|
-
return await
|
|
648
|
+
return await _();
|
|
635
649
|
}
|
|
636
650
|
/**
|
|
637
651
|
* Scans for available Wi-Fi networks near your device.
|
|
@@ -639,7 +653,7 @@ class dt {
|
|
|
639
653
|
* @returns {Promise<components['schemas']['NetworkResponse']>} List of discovered networks.
|
|
640
654
|
*/
|
|
641
655
|
async networksWifi() {
|
|
642
|
-
return await
|
|
656
|
+
return await N();
|
|
643
657
|
}
|
|
644
658
|
/**
|
|
645
659
|
* Removes the saved Wi-Fi configuration (forgets the network).
|
|
@@ -647,7 +661,7 @@ class dt {
|
|
|
647
661
|
* @returns {Promise<never>} Result of the forget operation.
|
|
648
662
|
*/
|
|
649
663
|
async forgetWifi() {
|
|
650
|
-
return await
|
|
664
|
+
return await q();
|
|
651
665
|
}
|
|
652
666
|
/**
|
|
653
667
|
* Uploads a file to the device's internal storage.
|
|
@@ -658,7 +672,7 @@ class dt {
|
|
|
658
672
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the upload operation.
|
|
659
673
|
*/
|
|
660
674
|
async uploadFile(t) {
|
|
661
|
-
return await
|
|
675
|
+
return await G(t);
|
|
662
676
|
}
|
|
663
677
|
/**
|
|
664
678
|
* Downloads a file from the device's internal storage.
|
|
@@ -669,7 +683,7 @@ class dt {
|
|
|
669
683
|
* @returns {Promise<ArrayBuffer | Blob>} The file data.
|
|
670
684
|
*/
|
|
671
685
|
async downloadFile(t) {
|
|
672
|
-
return await
|
|
686
|
+
return await j(t);
|
|
673
687
|
}
|
|
674
688
|
/**
|
|
675
689
|
* Reads the contents of a directory (files and subdirectories) at the specified path.
|
|
@@ -679,7 +693,7 @@ class dt {
|
|
|
679
693
|
* @returns {Promise<components["schemas"]["StorageList"]>} List of files and directories.
|
|
680
694
|
*/
|
|
681
695
|
async readDirectory(t) {
|
|
682
|
-
return await
|
|
696
|
+
return await H(t);
|
|
683
697
|
}
|
|
684
698
|
/**
|
|
685
699
|
* Removes a file or a directory from the device's internal storage.
|
|
@@ -689,7 +703,7 @@ class dt {
|
|
|
689
703
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the remove operation.
|
|
690
704
|
*/
|
|
691
705
|
async removeResource(t) {
|
|
692
|
-
return await
|
|
706
|
+
return await J(t);
|
|
693
707
|
}
|
|
694
708
|
/**
|
|
695
709
|
* Creates a new directory in the device's internal storage.
|
|
@@ -699,7 +713,7 @@ class dt {
|
|
|
699
713
|
* @returns {Promise<components['schemas']['SuccessResponse']>} Result of the create operation.
|
|
700
714
|
*/
|
|
701
715
|
async createDirectory(t) {
|
|
702
|
-
return await
|
|
716
|
+
return await X(t);
|
|
703
717
|
}
|
|
704
718
|
/**
|
|
705
719
|
* Gets the current display brightness settings for the device.
|
|
@@ -707,7 +721,7 @@ class dt {
|
|
|
707
721
|
* @returns {Promise<components["schemas"]["DisplayBrightnessInfo"]>} Current brightness information for front and back panels.
|
|
708
722
|
*/
|
|
709
723
|
async getDisplayBrightness() {
|
|
710
|
-
return await
|
|
724
|
+
return await et();
|
|
711
725
|
}
|
|
712
726
|
/**
|
|
713
727
|
* Sets the display brightness for the device.
|
|
@@ -719,7 +733,7 @@ class dt {
|
|
|
719
733
|
* @throws {Error} If brightness value is outside the range 0-100 or not "auto".
|
|
720
734
|
*/
|
|
721
735
|
async setDisplayBrightness(t) {
|
|
722
|
-
return await
|
|
736
|
+
return await it(t);
|
|
723
737
|
}
|
|
724
738
|
/**
|
|
725
739
|
* Gets the current audio volume value.
|
|
@@ -727,7 +741,7 @@ class dt {
|
|
|
727
741
|
* @returns {Promise<components["schemas"]["AudioVolumeInfo"]>} Current audio volume (0-100).
|
|
728
742
|
*/
|
|
729
743
|
async getAudioVolume() {
|
|
730
|
-
return await
|
|
744
|
+
return await rt();
|
|
731
745
|
}
|
|
732
746
|
/**
|
|
733
747
|
* Sets the audio volume value.
|
|
@@ -738,7 +752,7 @@ class dt {
|
|
|
738
752
|
* @throws {Error} If volume is outside the range 0-100 or request fails.
|
|
739
753
|
*/
|
|
740
754
|
async setAudioVolume(t) {
|
|
741
|
-
return await
|
|
755
|
+
return await nt(t);
|
|
742
756
|
}
|
|
743
757
|
/**
|
|
744
758
|
* Gets the current HTTP API access configuration.
|
|
@@ -746,7 +760,7 @@ class dt {
|
|
|
746
760
|
* @returns {Promise<components["schemas"]["HttpAccessInfo"]>} Current HTTP access info.
|
|
747
761
|
*/
|
|
748
762
|
async getHttpAccess() {
|
|
749
|
-
return await
|
|
763
|
+
return await st();
|
|
750
764
|
}
|
|
751
765
|
/**
|
|
752
766
|
* Sets the HTTP API access configuration.
|
|
@@ -757,7 +771,7 @@ class dt {
|
|
|
757
771
|
* @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the set operation.
|
|
758
772
|
*/
|
|
759
773
|
async setHttpAccess(t) {
|
|
760
|
-
const i = await
|
|
774
|
+
const i = await ot(t);
|
|
761
775
|
return t.mode === "key" && t.key && this.setApiKey(t.key), i;
|
|
762
776
|
}
|
|
763
777
|
/**
|
|
@@ -765,26 +779,40 @@ class dt {
|
|
|
765
779
|
* @param {string} key - API key to use in "X-API-Key" header.
|
|
766
780
|
*/
|
|
767
781
|
setApiKey(t) {
|
|
768
|
-
|
|
782
|
+
v(t);
|
|
769
783
|
}
|
|
770
784
|
/**
|
|
771
785
|
* Enables BLE module.
|
|
772
786
|
* @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the enable operation.
|
|
773
787
|
*/
|
|
774
788
|
async enableBle() {
|
|
775
|
-
return await
|
|
789
|
+
return await at();
|
|
776
790
|
}
|
|
777
791
|
/**
|
|
778
792
|
* Disables BLE module.
|
|
779
793
|
* @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of the disable operation.
|
|
780
794
|
*/
|
|
781
795
|
async disableBle() {
|
|
782
|
-
return await
|
|
796
|
+
return await ct();
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Sends a button press.
|
|
800
|
+
*
|
|
801
|
+
* @param params - Button press parameters:
|
|
802
|
+
* @param {InputKey['keyName']} params.keyName - Button key.
|
|
803
|
+
* @example
|
|
804
|
+
* {
|
|
805
|
+
* keyName: "ok"
|
|
806
|
+
* }
|
|
807
|
+
* @returns {Promise<components["schemas"]["SuccessResponse"]>} Result of pressing the button.
|
|
808
|
+
*/
|
|
809
|
+
async pressButton(t) {
|
|
810
|
+
return await ft(t);
|
|
783
811
|
}
|
|
784
812
|
}
|
|
785
813
|
var m = /* @__PURE__ */ ((e) => (e[e.FRONT = 0] = "FRONT", e[e.BACK = 1] = "BACK", e))(m || {});
|
|
786
|
-
const
|
|
787
|
-
function
|
|
814
|
+
const g = 3e3, S = /* @__PURE__ */ new Set([1001, 1006, 1012, 1013, 1014, 3008]);
|
|
815
|
+
function A(e, t) {
|
|
788
816
|
if (t < 0 || t >= e.length)
|
|
789
817
|
throw new Error(`Index ${t} is out of bounds (0…${e.length - 1})`);
|
|
790
818
|
const i = e[t];
|
|
@@ -792,44 +820,49 @@ function E(e, t) {
|
|
|
792
820
|
throw new Error(`Unexpected undefined at index ${t}`);
|
|
793
821
|
return i;
|
|
794
822
|
}
|
|
795
|
-
function
|
|
823
|
+
function ut(e, t) {
|
|
796
824
|
let i = 0;
|
|
797
|
-
const n = e.length,
|
|
825
|
+
const n = e.length, s = [];
|
|
798
826
|
for (; i < n; ) {
|
|
799
|
-
const
|
|
800
|
-
if (i += 1, (
|
|
801
|
-
const
|
|
802
|
-
for (let
|
|
803
|
-
|
|
804
|
-
i +=
|
|
827
|
+
const a = A(e, i);
|
|
828
|
+
if (i += 1, (a & 128) !== 0) {
|
|
829
|
+
const c = a & 127;
|
|
830
|
+
for (let f = 0; f < c * t; f++)
|
|
831
|
+
s.push(e[i + f]);
|
|
832
|
+
i += c * t;
|
|
805
833
|
} else {
|
|
806
|
-
const
|
|
807
|
-
for (let
|
|
808
|
-
for (let
|
|
809
|
-
|
|
834
|
+
const c = a, f = e.slice(i, i + t);
|
|
835
|
+
for (let u = 0; u < c; u++)
|
|
836
|
+
for (let h = 0; h < t; h++)
|
|
837
|
+
s.push(f[h]);
|
|
810
838
|
i += t;
|
|
811
839
|
}
|
|
812
840
|
}
|
|
813
|
-
return new Uint8Array(
|
|
841
|
+
return new Uint8Array(s);
|
|
814
842
|
}
|
|
815
|
-
function
|
|
843
|
+
function wt(e) {
|
|
816
844
|
const t = new Uint8Array(e.length * 2);
|
|
817
845
|
let i = 0, n = 0;
|
|
818
846
|
for (; i < e.length; ) {
|
|
819
|
-
const
|
|
820
|
-
t[n] =
|
|
847
|
+
const s = A(e, i), a = s & 15, c = s >> 4 & 15;
|
|
848
|
+
t[n] = a, t[n + 1] = c, i += 1, n += 2;
|
|
821
849
|
}
|
|
822
850
|
return t;
|
|
823
851
|
}
|
|
824
|
-
class
|
|
852
|
+
class pt {
|
|
825
853
|
constructor(t) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
854
|
+
o(this, "connected", !1);
|
|
855
|
+
// @ts-ignore
|
|
856
|
+
o(this, "apiKey");
|
|
857
|
+
// @ts-ignore
|
|
858
|
+
o(this, "apiSemver");
|
|
859
|
+
o(this, "dataListeners", []);
|
|
860
|
+
o(this, "stopListeners", []);
|
|
861
|
+
o(this, "errorListeners", []);
|
|
862
|
+
o(this, "socket", null);
|
|
831
863
|
if (this.config = t, !(() => typeof window < "u" && typeof window.document < "u"))
|
|
832
864
|
throw new Error("not browser");
|
|
865
|
+
t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver);
|
|
833
866
|
}
|
|
834
867
|
onData(t) {
|
|
835
868
|
this.dataListeners.push(t);
|
|
@@ -854,8 +887,10 @@ class ht {
|
|
|
854
887
|
}
|
|
855
888
|
async openWebsocket() {
|
|
856
889
|
this.socket && await this.closeWebsocket();
|
|
857
|
-
let t
|
|
858
|
-
this.config.mode === "cloud" ? t = `${this.config.domain}/bars/${this.config.idDevice}/ws` : this.config.mode === "local" && (t = `${this.config.barUrl}/api/screen/ws`), this.
|
|
890
|
+
let t;
|
|
891
|
+
if (this.config.mode === "cloud" ? t = new URL(`${this.config.domain}/bars/${this.config.idDevice}/ws`) : this.config.mode === "local" && (t = new URL(`${this.config.barUrl}/api/screen/ws`), this.apiKey && t.searchParams.append("x-api-key", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver)), !t)
|
|
892
|
+
throw new Error("The WebSocket URL is not specified");
|
|
893
|
+
this.socket = new WebSocket(t), this.socket.onopen = () => {
|
|
859
894
|
this.socket && (this.config.mode === "cloud" ? this.socket.send(
|
|
860
895
|
JSON.stringify({
|
|
861
896
|
token: this.config.token,
|
|
@@ -870,11 +905,11 @@ class ht {
|
|
|
870
905
|
if (this.config.mode === "cloud")
|
|
871
906
|
this.emitData(n);
|
|
872
907
|
else if (this.config.mode === "local") {
|
|
873
|
-
let
|
|
874
|
-
const
|
|
908
|
+
let s;
|
|
909
|
+
const a = this.config.deviceScreen === m.FRONT ? 3 : 2;
|
|
875
910
|
try {
|
|
876
|
-
const
|
|
877
|
-
this.config.deviceScreen === m.BACK ?
|
|
911
|
+
const c = ut(n, a);
|
|
912
|
+
this.config.deviceScreen === m.BACK ? s = wt(c) : s = c, this.emitData(s);
|
|
878
913
|
} catch {
|
|
879
914
|
this.emitData(n);
|
|
880
915
|
}
|
|
@@ -890,7 +925,87 @@ class ht {
|
|
|
890
925
|
raw: i
|
|
891
926
|
}), this.emitStop();
|
|
892
927
|
}, this.socket.onclose = async (i) => {
|
|
893
|
-
if (this.socket = null, this.connected = !1, i.code ===
|
|
928
|
+
if (this.socket = null, this.connected = !1, i.code === g || S.has(i.code)) {
|
|
929
|
+
this.emitError({
|
|
930
|
+
code: i.code,
|
|
931
|
+
message: i.reason,
|
|
932
|
+
raw: i
|
|
933
|
+
});
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
this.emitStop();
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
closeWebsocket() {
|
|
940
|
+
return this.connected = !1, new Promise((t) => {
|
|
941
|
+
this.socket ? (this.socket.onclose = () => {
|
|
942
|
+
t();
|
|
943
|
+
}, this.socket.close(), this.socket = null) : t(), this.emitStop();
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
class yt {
|
|
948
|
+
constructor(t) {
|
|
949
|
+
o(this, "connected", !1);
|
|
950
|
+
// @ts-ignore
|
|
951
|
+
o(this, "apiKey");
|
|
952
|
+
// @ts-ignore
|
|
953
|
+
o(this, "apiSemver");
|
|
954
|
+
o(this, "inputEvent");
|
|
955
|
+
o(this, "dataListeners", []);
|
|
956
|
+
o(this, "stopListeners", []);
|
|
957
|
+
o(this, "errorListeners", []);
|
|
958
|
+
o(this, "socket", null);
|
|
959
|
+
if (this.config = t, !(() => typeof window < "u" && typeof window.document < "u"))
|
|
960
|
+
throw new Error("not browser");
|
|
961
|
+
t.apiKey && (this.apiKey = t.apiKey), t.apiSemver && (this.apiSemver = t.apiSemver), this.inputEvent = {};
|
|
962
|
+
}
|
|
963
|
+
onData(t) {
|
|
964
|
+
this.dataListeners.push(t);
|
|
965
|
+
}
|
|
966
|
+
onStop(t) {
|
|
967
|
+
this.stopListeners.push(t);
|
|
968
|
+
}
|
|
969
|
+
onError(t) {
|
|
970
|
+
this.errorListeners.push(t);
|
|
971
|
+
}
|
|
972
|
+
emitData(t) {
|
|
973
|
+
for (const i of this.dataListeners)
|
|
974
|
+
i(t);
|
|
975
|
+
}
|
|
976
|
+
emitStop() {
|
|
977
|
+
for (const t of this.stopListeners)
|
|
978
|
+
t();
|
|
979
|
+
}
|
|
980
|
+
emitError(t) {
|
|
981
|
+
for (const i of this.errorListeners)
|
|
982
|
+
i(t);
|
|
983
|
+
}
|
|
984
|
+
async openWebsocket() {
|
|
985
|
+
this.socket && await this.closeWebsocket();
|
|
986
|
+
let t;
|
|
987
|
+
if (this.config.mode === "cloud" ? t = new URL(`${this.config.domain}/bars/${this.config.idDevice}/ws`) : this.config.mode === "local" && (t = new URL(`${this.config.barUrl}/api/input`), this.apiKey && t.searchParams.append("x-api-key", this.apiKey), this.apiSemver && t.searchParams.append("x-api-sem-ver", this.apiSemver)), !t)
|
|
988
|
+
throw new Error("The WebSocket URL is not specified");
|
|
989
|
+
this.socket = new WebSocket(t), this.socket.onopen = () => {
|
|
990
|
+
this.socket && (this.connected = !0);
|
|
991
|
+
}, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (i) => {
|
|
992
|
+
try {
|
|
993
|
+
if (typeof i.data == "string")
|
|
994
|
+
return;
|
|
995
|
+
const n = new Uint8Array(i.data);
|
|
996
|
+
this.emitData(n);
|
|
997
|
+
} catch {
|
|
998
|
+
this.connected = !1, this.emitStop();
|
|
999
|
+
}
|
|
1000
|
+
}, this.socket.onerror = (i) => {
|
|
1001
|
+
this.connected = !1, this.emitError({
|
|
1002
|
+
code: 1006,
|
|
1003
|
+
// Standard «abnormal closure» code per RFC-6455
|
|
1004
|
+
message: "WebSocket error occurred",
|
|
1005
|
+
raw: i
|
|
1006
|
+
}), this.emitStop();
|
|
1007
|
+
}, this.socket.onclose = async (i) => {
|
|
1008
|
+
if (this.socket = null, this.connected = !1, i.code === g || S.has(i.code)) {
|
|
894
1009
|
this.emitError({
|
|
895
1010
|
code: i.code,
|
|
896
1011
|
message: i.reason,
|
|
@@ -901,6 +1016,11 @@ class ht {
|
|
|
901
1016
|
this.emitStop();
|
|
902
1017
|
};
|
|
903
1018
|
}
|
|
1019
|
+
sendInput({ keyName: t, value: i }) {
|
|
1020
|
+
if (!this.socket || !this.connected)
|
|
1021
|
+
throw new Error("WebSocket: Not connected");
|
|
1022
|
+
this.inputEvent[t] = i, this.socket.send(JSON.stringify(this.inputEvent)), i === 0 && delete this.inputEvent[t];
|
|
1023
|
+
}
|
|
904
1024
|
closeWebsocket() {
|
|
905
1025
|
return this.connected = !1, new Promise((t) => {
|
|
906
1026
|
this.socket ? (this.socket.onclose = () => {
|
|
@@ -912,5 +1032,6 @@ class ht {
|
|
|
912
1032
|
export {
|
|
913
1033
|
dt as BusyBar,
|
|
914
1034
|
m as DeviceScreen,
|
|
915
|
-
|
|
1035
|
+
yt as Input,
|
|
1036
|
+
pt as ScreenStream
|
|
916
1037
|
};
|