@busy-app/busy-lib 0.0.3 → 0.0.4
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 +2 -3
- package/dist/index.js +45 -46
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var w=(e,t,n)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var a=(e,t,n)=>w(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("openapi-fetch");function m(e){const t=e.split(".");if(t.length!==4)return!1;for(const n of t){if(n.length===0||n.length>1&&n[0]==="0"||!/^\d+$/.test(n))return!1;const r=Number(n);if(r<0||r>255)return!1}return!0}const g=(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 n;return t&&(t instanceof Headers?n=t.get("Content-Type")??t.get("content-type")??void 0:typeof t=="object"&&(n=t["Content-Type"]??t["content-type"]),n==="application/x-www-form-urlencoded")?e&&typeof e=="object"&&!(e instanceof URLSearchParams)?new URLSearchParams(e).toString():String(e):JSON.stringify(e)};let o=null;function
|
|
1
|
+
"use strict";var d=Object.defineProperty;var w=(e,t,n)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var a=(e,t,n)=>w(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("openapi-fetch");function m(e){const t=e.split(".");if(t.length!==4)return!1;for(const n of t){if(n.length===0||n.length>1&&n[0]==="0"||!/^\d+$/.test(n))return!1;const r=Number(n);if(r<0||r>255)return!1}return!0}const g=(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 n;return t&&(t instanceof Headers?n=t.get("Content-Type")??t.get("content-type")??void 0:typeof t=="object"&&(n=t["Content-Type"]??t["content-type"]),n==="application/x-www-form-urlencoded")?e&&typeof e=="object"&&!(e instanceof URLSearchParams)?new URLSearchParams(e).toString():String(e):JSON.stringify(e)};let o=null;function E(e){o=y({baseUrl:e,bodySerializer:g})}async function S(e){const{appId:t,fileName:n,file:r}=e;if(!o)throw new Error("API client is not initialized");const{data:i,error:s}=await o.POST("/v0/assets/upload",{params:{query:{app_id:t,file:n}},headers:{"Content-Type":"application/octet-stream"},body:r});if(s)throw s;return i}async function A(e){const{appId:t}=e;if(!o)throw new Error("API client is not initialized");const{data:n,error:r}=await o.DELETE("/v0/assets/upload",{params:{query:{app_id:t}}});if(r)throw r;return n}const B={timeout:5,x:0,y:0,display:"front"};function k(e){return{...B,...e}}async function D(e){const{appId:t,elements:n}=e;if(!o)throw new Error("API client is not initialized");const r=n.map(k),{data:i,error:s}=await o.POST("/v0/display/draw",{body:{app_id:t,elements:r}});if(s)throw s;return i}async function T(){if(!o)throw new Error("API client is not initialized");const{data:e,error:t}=await o.DELETE("/v0/display/draw");if(t)throw t;return e}async function L(e){const{appId:t,path:n}=e;if(!o)throw new Error("API client is not initialized");const{data:r,error:i}=await o.POST("/v0/audio/play",{params:{query:{app_id:t,path:n}}});if(i)throw i;return r}async function P(){if(!o)throw new Error("API client is not initialized");const{data:e,error:t}=await o.DELETE("/v0/audio/play");if(t)throw t;return e}class I{constructor(t="10.0.4.20"){a(this,"ip");if(!m(t))throw new Error(`Incorrect IPv4: ${t}`);this.ip=t,console.log(this.ip),E(`http://${this.ip}/api/`)}async uploadAsset(t){return await S(t)}async deleteAssets(t){return await A(t)}async drawDisplay(t){return await D(t)}async clearDisplay(){return await T()}async playSound(t){return await L(t)}async stopSound(){return await P()}}var l=(e=>(e[e.FRONT=0]="FRONT",e[e.BACK=1]="BACK",e))(l||{});const v=3e3,C=new Set([1001,1006,1012,1013,1014,3008]);function h(e,t){if(t<0||t>=e.length)throw new Error(`Index ${t} is out of bounds (0…${e.length-1})`);const n=e[t];if(n===void 0)throw new Error(`Unexpected undefined at index ${t}`);return n}function O(e,t){let n=0;const r=e.length,i=[];for(;n<r;){const s=h(e,n);if(n+=1,(s&128)!==0){const c=s&127;for(let f=0;f<c*t;f++)i.push(e[n+f]);n+=c*t}else{const c=s,f=e.slice(n,n+t);for(let p=0;p<c;p++)for(let u=0;u<t;u++)i.push(f[u]);n+=t}}return new Uint8Array(i)}function U(e){const t=new Uint8Array(e.length*2);let n=0,r=0;for(;n<e.length;){const i=h(e,n),s=i&15,c=i>>4&15;t[r]=s,t[r+1]=c,n+=1,r+=2}return t}class N{constructor(t){a(this,"connected",!1);a(this,"dataListeners",[]);a(this,"stopListeners",[]);a(this,"errorListeners",[]);a(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 n of this.dataListeners)n(t)}emitStop(){for(const t of this.stopListeners)t()}emitError(t){for(const n of this.errorListeners)n(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/v0/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=n=>{try{if(typeof n.data=="string")return;const r=new Uint8Array(n.data);if(this.config.mode==="cloud")this.emitData(r);else if(this.config.mode==="local"){let i;const s=this.config.deviceScreen===l.FRONT?3:2;try{const c=O(r,s);this.config.deviceScreen===l.BACK?i=U(c):i=c,this.emitData(i)}catch{this.emitData(r)}}}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===v||C.has(n.code)){this.emitError({code:n.code,message:n.reason,raw:n});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=I;exports.DeviceScreen=l;exports.ScreenStream=N;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare interface AudioParams {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
declare interface BaseConfig {
|
|
7
|
-
deviceScreen:
|
|
7
|
+
deviceScreen: DeviceScreen;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -270,7 +270,7 @@ declare interface DeleteParams {
|
|
|
270
270
|
|
|
271
271
|
declare type DeviceConfig = LocalConfig | SiteConfig;
|
|
272
272
|
|
|
273
|
-
declare enum DeviceScreen {
|
|
273
|
+
export declare enum DeviceScreen {
|
|
274
274
|
FRONT = 0,
|
|
275
275
|
BACK = 1
|
|
276
276
|
}
|
|
@@ -829,7 +829,6 @@ export declare class ScreenStream {
|
|
|
829
829
|
private stopListeners;
|
|
830
830
|
private errorListeners;
|
|
831
831
|
private socket;
|
|
832
|
-
private deviceScreen;
|
|
833
832
|
constructor(config: DeviceConfig);
|
|
834
833
|
onData(listener: DataListener): void;
|
|
835
834
|
onStop(listener: StopListener): void;
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,8 @@ function m(e) {
|
|
|
9
9
|
for (const n of t) {
|
|
10
10
|
if (n.length === 0 || n.length > 1 && n[0] === "0" || !/^\d+$/.test(n))
|
|
11
11
|
return !1;
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
12
|
+
const i = Number(n);
|
|
13
|
+
if (i < 0 || i > 255)
|
|
14
14
|
return !1;
|
|
15
15
|
}
|
|
16
16
|
return !0;
|
|
@@ -28,11 +28,11 @@ function E(e) {
|
|
|
28
28
|
bodySerializer: g
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
async function
|
|
32
|
-
const { appId: t, fileName: n, file:
|
|
31
|
+
async function A(e) {
|
|
32
|
+
const { appId: t, fileName: n, file: i } = e;
|
|
33
33
|
if (!o)
|
|
34
34
|
throw new Error("API client is not initialized");
|
|
35
|
-
const { data:
|
|
35
|
+
const { data: r, error: s } = await o.POST("/v0/assets/upload", {
|
|
36
36
|
params: {
|
|
37
37
|
query: {
|
|
38
38
|
app_id: t,
|
|
@@ -42,25 +42,25 @@ async function S(e) {
|
|
|
42
42
|
headers: {
|
|
43
43
|
"Content-Type": "application/octet-stream"
|
|
44
44
|
},
|
|
45
|
-
body:
|
|
45
|
+
body: i
|
|
46
46
|
});
|
|
47
47
|
if (s)
|
|
48
48
|
throw s;
|
|
49
|
-
return
|
|
49
|
+
return r;
|
|
50
50
|
}
|
|
51
|
-
async function
|
|
51
|
+
async function S(e) {
|
|
52
52
|
const { appId: t } = e;
|
|
53
53
|
if (!o)
|
|
54
54
|
throw new Error("API client is not initialized");
|
|
55
|
-
const { data: n, error:
|
|
55
|
+
const { data: n, error: i } = await o.DELETE("/v0/assets/upload", {
|
|
56
56
|
params: {
|
|
57
57
|
query: {
|
|
58
58
|
app_id: t
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
if (
|
|
63
|
-
throw
|
|
62
|
+
if (i)
|
|
63
|
+
throw i;
|
|
64
64
|
return n;
|
|
65
65
|
}
|
|
66
66
|
const B = { timeout: 5, x: 0, y: 0, display: "front" };
|
|
@@ -71,15 +71,15 @@ async function D(e) {
|
|
|
71
71
|
const { appId: t, elements: n } = e;
|
|
72
72
|
if (!o)
|
|
73
73
|
throw new Error("API client is not initialized");
|
|
74
|
-
const
|
|
74
|
+
const i = n.map(k), { data: r, error: s } = await o.POST("/v0/display/draw", {
|
|
75
75
|
body: {
|
|
76
76
|
app_id: t,
|
|
77
|
-
elements:
|
|
77
|
+
elements: i
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
if (s)
|
|
81
81
|
throw s;
|
|
82
|
-
return
|
|
82
|
+
return r;
|
|
83
83
|
}
|
|
84
84
|
async function L() {
|
|
85
85
|
if (!o)
|
|
@@ -93,7 +93,7 @@ async function T(e) {
|
|
|
93
93
|
const { appId: t, path: n } = e;
|
|
94
94
|
if (!o)
|
|
95
95
|
throw new Error("API client is not initialized");
|
|
96
|
-
const { data:
|
|
96
|
+
const { data: i, error: r } = await o.POST("/v0/audio/play", {
|
|
97
97
|
params: {
|
|
98
98
|
query: {
|
|
99
99
|
app_id: t,
|
|
@@ -101,11 +101,11 @@ async function T(e) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
});
|
|
104
|
-
if (
|
|
105
|
-
throw
|
|
106
|
-
return
|
|
104
|
+
if (r)
|
|
105
|
+
throw r;
|
|
106
|
+
return i;
|
|
107
107
|
}
|
|
108
|
-
async function
|
|
108
|
+
async function I() {
|
|
109
109
|
if (!o)
|
|
110
110
|
throw new Error("API client is not initialized");
|
|
111
111
|
const { data: e, error: t } = await o.DELETE("/v0/audio/play");
|
|
@@ -142,7 +142,7 @@ class $ {
|
|
|
142
142
|
* @returns {Promise<{ result: string }>} Result of the upload operation.
|
|
143
143
|
*/
|
|
144
144
|
async uploadAsset(t) {
|
|
145
|
-
return await
|
|
145
|
+
return await A(t);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Deletes all assets for a specific application from the device.
|
|
@@ -152,7 +152,7 @@ class $ {
|
|
|
152
152
|
* @returns {Promise<{ result: string }>} Result of the delete operation.
|
|
153
153
|
*/
|
|
154
154
|
async deleteAssets(t) {
|
|
155
|
-
return await
|
|
155
|
+
return await S(t);
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Draws elements on the device display.
|
|
@@ -190,11 +190,11 @@ class $ {
|
|
|
190
190
|
* @returns {Promise<{ result: string }>} Result of the stop operation.
|
|
191
191
|
*/
|
|
192
192
|
async stopSound() {
|
|
193
|
-
return await
|
|
193
|
+
return await I();
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
var
|
|
197
|
-
const
|
|
196
|
+
var u = /* @__PURE__ */ ((e) => (e[e.FRONT = 0] = "FRONT", e[e.BACK = 1] = "BACK", e))(u || {});
|
|
197
|
+
const P = 3e3, C = /* @__PURE__ */ new Set([1001, 1006, 1012, 1013, 1014, 3008]);
|
|
198
198
|
function h(e, t) {
|
|
199
199
|
if (t < 0 || t >= e.length)
|
|
200
200
|
throw new Error(`Index ${t} is out of bounds (0…${e.length - 1})`);
|
|
@@ -203,32 +203,32 @@ function h(e, t) {
|
|
|
203
203
|
throw new Error(`Unexpected undefined at index ${t}`);
|
|
204
204
|
return n;
|
|
205
205
|
}
|
|
206
|
-
function
|
|
206
|
+
function O(e, t) {
|
|
207
207
|
let n = 0;
|
|
208
|
-
const
|
|
209
|
-
for (; n <
|
|
208
|
+
const i = e.length, r = [];
|
|
209
|
+
for (; n < i; ) {
|
|
210
210
|
const s = h(e, n);
|
|
211
211
|
if (n += 1, (s & 128) !== 0) {
|
|
212
212
|
const c = s & 127;
|
|
213
213
|
for (let f = 0; f < c * t; f++)
|
|
214
|
-
|
|
214
|
+
r.push(e[n + f]);
|
|
215
215
|
n += c * t;
|
|
216
216
|
} else {
|
|
217
217
|
const c = s, f = e.slice(n, n + t);
|
|
218
218
|
for (let p = 0; p < c; p++)
|
|
219
|
-
for (let
|
|
220
|
-
|
|
219
|
+
for (let l = 0; l < t; l++)
|
|
220
|
+
r.push(f[l]);
|
|
221
221
|
n += t;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
return new Uint8Array(
|
|
224
|
+
return new Uint8Array(r);
|
|
225
225
|
}
|
|
226
226
|
function U(e) {
|
|
227
227
|
const t = new Uint8Array(e.length * 2);
|
|
228
|
-
let n = 0,
|
|
228
|
+
let n = 0, i = 0;
|
|
229
229
|
for (; n < e.length; ) {
|
|
230
|
-
const
|
|
231
|
-
t[
|
|
230
|
+
const r = h(e, n), s = r & 15, c = r >> 4 & 15;
|
|
231
|
+
t[i] = s, t[i + 1] = c, n += 1, i += 2;
|
|
232
232
|
}
|
|
233
233
|
return t;
|
|
234
234
|
}
|
|
@@ -239,10 +239,8 @@ class F {
|
|
|
239
239
|
a(this, "stopListeners", []);
|
|
240
240
|
a(this, "errorListeners", []);
|
|
241
241
|
a(this, "socket", null);
|
|
242
|
-
a(this, "deviceScreen");
|
|
243
242
|
if (this.config = t, !(() => typeof window < "u" && typeof window.document < "u"))
|
|
244
243
|
throw new Error("not browser");
|
|
245
|
-
this.deviceScreen = l[this.config.deviceScreen.toUpperCase()];
|
|
246
244
|
}
|
|
247
245
|
onData(t) {
|
|
248
246
|
this.dataListeners.push(t);
|
|
@@ -272,24 +270,24 @@ class F {
|
|
|
272
270
|
this.socket && (this.config.mode === "cloud" ? this.socket.send(
|
|
273
271
|
JSON.stringify({
|
|
274
272
|
token: this.config.token,
|
|
275
|
-
display: this.deviceScreen
|
|
273
|
+
display: this.config.deviceScreen
|
|
276
274
|
})
|
|
277
|
-
) : this.config.mode === "local" && this.socket.send(JSON.stringify({ display: this.deviceScreen })), this.connected = !0);
|
|
275
|
+
) : this.config.mode === "local" && this.socket.send(JSON.stringify({ display: this.config.deviceScreen })), this.connected = !0);
|
|
278
276
|
}, this.socket.binaryType = "arraybuffer", this.socket.onmessage = (n) => {
|
|
279
277
|
try {
|
|
280
278
|
if (typeof n.data == "string")
|
|
281
279
|
return;
|
|
282
|
-
const
|
|
280
|
+
const i = new Uint8Array(n.data);
|
|
283
281
|
if (this.config.mode === "cloud")
|
|
284
|
-
this.emitData(
|
|
282
|
+
this.emitData(i);
|
|
285
283
|
else if (this.config.mode === "local") {
|
|
286
|
-
let
|
|
287
|
-
const s = this.deviceScreen ===
|
|
284
|
+
let r;
|
|
285
|
+
const s = this.config.deviceScreen === u.FRONT ? 3 : 2;
|
|
288
286
|
try {
|
|
289
|
-
const c =
|
|
290
|
-
this.deviceScreen ===
|
|
287
|
+
const c = O(i, s);
|
|
288
|
+
this.config.deviceScreen === u.BACK ? r = U(c) : r = c, this.emitData(r);
|
|
291
289
|
} catch {
|
|
292
|
-
this.emitData(
|
|
290
|
+
this.emitData(i);
|
|
293
291
|
}
|
|
294
292
|
}
|
|
295
293
|
} catch {
|
|
@@ -303,7 +301,7 @@ class F {
|
|
|
303
301
|
raw: n
|
|
304
302
|
}), this.emitStop();
|
|
305
303
|
}, this.socket.onclose = async (n) => {
|
|
306
|
-
if (this.socket = null, this.connected = !1, n.code ===
|
|
304
|
+
if (this.socket = null, this.connected = !1, n.code === P || C.has(n.code)) {
|
|
307
305
|
this.emitError({
|
|
308
306
|
code: n.code,
|
|
309
307
|
message: n.reason,
|
|
@@ -324,5 +322,6 @@ class F {
|
|
|
324
322
|
}
|
|
325
323
|
export {
|
|
326
324
|
$ as BusyBar,
|
|
325
|
+
u as DeviceScreen,
|
|
327
326
|
F as ScreenStream
|
|
328
327
|
};
|