ednl-liftstatus-web-components 1.62.8 → 1.63.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/cjs/ls-data.cjs.entry.js +39 -18
- package/dist/collection/components/ls-data/ls-data.js +8 -18
- package/dist/collection/utils/session-permissions.js +31 -0
- package/dist/components/ls-data.js +1 -1
- package/dist/ednl-liftstatus-web-components/ednl-liftstatus-web-components.esm.js +1 -1
- package/dist/ednl-liftstatus-web-components/{p-6b6f02fe.entry.js → p-d2a2bc87.entry.js} +1 -1
- package/dist/esm/ls-data.entry.js +39 -18
- package/dist/types/utils/session-permissions.d.ts +10 -0
- package/package.json +6 -4
|
@@ -4015,6 +4015,38 @@ Object.assign(lookup, {
|
|
|
4015
4015
|
connect: lookup,
|
|
4016
4016
|
});
|
|
4017
4017
|
|
|
4018
|
+
/**
|
|
4019
|
+
* No API route checks `lift_flow`, so these permissions are the only gate on
|
|
4020
|
+
* the pages. A Classic session is denied what it is not explicitly granted.
|
|
4021
|
+
* Sense passes its customer's `lift_flow` through for a JWT, but often sends
|
|
4022
|
+
* none at all; the token is already limited to its own object, so a JWT is
|
|
4023
|
+
* only denied what Sense explicitly denies.
|
|
4024
|
+
*/
|
|
4025
|
+
const getSessionPermissions = (auth) => {
|
|
4026
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
4027
|
+
const data = (_c = (_b = (_a = auth.response) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b.lift_flow) === null || _c === void 0 ? void 0 : _c.data;
|
|
4028
|
+
if (auth.type === 'sensecloud') {
|
|
4029
|
+
return {
|
|
4030
|
+
realtime: (_d = data === null || data === void 0 ? void 0 : data.realtime) !== null && _d !== void 0 ? _d : true,
|
|
4031
|
+
history: (_e = data === null || data === void 0 ? void 0 : data.history) !== null && _e !== void 0 ? _e : true,
|
|
4032
|
+
counters: (_f = data === null || data === void 0 ? void 0 : data.counters) !== null && _f !== void 0 ? _f : true,
|
|
4033
|
+
statuses: (_g = data === null || data === void 0 ? void 0 : data.statuses) !== null && _g !== void 0 ? _g : true,
|
|
4034
|
+
};
|
|
4035
|
+
}
|
|
4036
|
+
return {
|
|
4037
|
+
realtime: (data === null || data === void 0 ? void 0 : data.realtime) === true,
|
|
4038
|
+
history: (data === null || data === void 0 ? void 0 : data.history) === true,
|
|
4039
|
+
counters: (data === null || data === void 0 ? void 0 : data.counters) === true,
|
|
4040
|
+
statuses: (data === null || data === void 0 ? void 0 : data.statuses) === true,
|
|
4041
|
+
};
|
|
4042
|
+
};
|
|
4043
|
+
const NO_SESSION_PERMISSIONS = {
|
|
4044
|
+
realtime: false,
|
|
4045
|
+
history: false,
|
|
4046
|
+
counters: false,
|
|
4047
|
+
statuses: false,
|
|
4048
|
+
};
|
|
4049
|
+
|
|
4018
4050
|
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
4019
4051
|
var t = {};
|
|
4020
4052
|
for (var p in s)
|
|
@@ -4027,17 +4059,6 @@ var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
|
4027
4059
|
}
|
|
4028
4060
|
return t;
|
|
4029
4061
|
};
|
|
4030
|
-
/** Only an explicit `true` grants a permission; a missing one denies it. */
|
|
4031
|
-
const toSessionPermissions = (permissions) => {
|
|
4032
|
-
var _a;
|
|
4033
|
-
const data = (_a = permissions === null || permissions === void 0 ? void 0 : permissions.lift_flow) === null || _a === void 0 ? void 0 : _a.data;
|
|
4034
|
-
return {
|
|
4035
|
-
realtime: (data === null || data === void 0 ? void 0 : data.realtime) === true,
|
|
4036
|
-
history: (data === null || data === void 0 ? void 0 : data.history) === true,
|
|
4037
|
-
counters: (data === null || data === void 0 ? void 0 : data.counters) === true,
|
|
4038
|
-
statuses: (data === null || data === void 0 ? void 0 : data.statuses) === true,
|
|
4039
|
-
};
|
|
4040
|
-
};
|
|
4041
4062
|
const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) => {
|
|
4042
4063
|
var _a, _b;
|
|
4043
4064
|
const objectTypeByOtype = store.TOKEN_OTYPE_TO_OBJECT_TYPE;
|
|
@@ -4050,7 +4071,7 @@ const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) =>
|
|
|
4050
4071
|
objectType,
|
|
4051
4072
|
objectId: oid,
|
|
4052
4073
|
esNumber: esNumber !== null && esNumber !== void 0 ? esNumber : undefined,
|
|
4053
|
-
permissions
|
|
4074
|
+
permissions,
|
|
4054
4075
|
hasResetContactCapability: Boolean((_a = capability === null || capability === void 0 ? void 0 : capability.commands) === null || _a === void 0 ? void 0 : _a.reset_contact),
|
|
4055
4076
|
isAdmin,
|
|
4056
4077
|
liftController: (_b = capability === null || capability === void 0 ? void 0 : capability.lift_controller) === null || _b === void 0 ? void 0 : _b.type,
|
|
@@ -4069,8 +4090,8 @@ const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) =>
|
|
|
4069
4090
|
* Either way the token itself is passed on to the API unchanged.
|
|
4070
4091
|
*/
|
|
4071
4092
|
const getAuthTarget = (auth) => {
|
|
4072
|
-
var _a, _b, _c, _d;
|
|
4073
|
-
const permissions = (
|
|
4093
|
+
var _a, _b, _c, _d, _e;
|
|
4094
|
+
const permissions = getSessionPermissions(auth);
|
|
4074
4095
|
const { target } = auth;
|
|
4075
4096
|
if (target != null) {
|
|
4076
4097
|
return toAuthTarget(target.otype, target.oid, target.es_number, target.capability, permissions,
|
|
@@ -4083,20 +4104,20 @@ const getAuthTarget = (auth) => {
|
|
|
4083
4104
|
}
|
|
4084
4105
|
if (auth.type === 'liftstatus') {
|
|
4085
4106
|
const { env } = auth.response;
|
|
4086
|
-
const liftId = (
|
|
4107
|
+
const liftId = (_a = auth.response.lift) === null || _a === void 0 ? void 0 : _a.id;
|
|
4087
4108
|
if (env === undefined || env === '' || liftId === undefined || liftId === '') {
|
|
4088
4109
|
throw new Error('LiftStatus session response has no env or lift id');
|
|
4089
4110
|
}
|
|
4090
4111
|
return {
|
|
4091
4112
|
objectType: store.ObjectType.External,
|
|
4092
4113
|
objectId: `liftstatus-${env}-${liftId}`,
|
|
4093
|
-
permissions
|
|
4114
|
+
permissions,
|
|
4094
4115
|
hasResetContactCapability: false,
|
|
4095
4116
|
// `permissions.commands` lacks the API's Classic command rules
|
|
4096
4117
|
isAdmin: false,
|
|
4097
4118
|
};
|
|
4098
4119
|
}
|
|
4099
|
-
return toAuthTarget(auth.tokenData.otype, auth.tokenData.oid, (
|
|
4120
|
+
return toAuthTarget(auth.tokenData.otype, auth.tokenData.oid, (_b = auth.response) === null || _b === void 0 ? void 0 : _b.es_number, (_c = auth.response) === null || _c === void 0 ? void 0 : _c.capability, permissions, ((_e = (_d = auth.response) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.commands) === true);
|
|
4100
4121
|
};
|
|
4101
4122
|
// socket.io waits 20 s per attempt for a server that doesn't answer, which adds
|
|
4102
4123
|
// up to about 2 minutes over all retries before the first load would fail
|
|
@@ -4225,7 +4246,7 @@ const LsData = class {
|
|
|
4225
4246
|
if (!auth.isValid) {
|
|
4226
4247
|
this.lsSession.emit({
|
|
4227
4248
|
ok: false,
|
|
4228
|
-
permissions:
|
|
4249
|
+
permissions: NO_SESSION_PERMISSIONS,
|
|
4229
4250
|
isAdmin: false,
|
|
4230
4251
|
hasResetContactCapability: false,
|
|
4231
4252
|
error: {
|
|
@@ -19,18 +19,8 @@ import { authenticate, fetchSensorData, fetchSensorSummary } from "../../utils/a
|
|
|
19
19
|
import { getErrorMessageForDisplay } from "../../utils/error-message";
|
|
20
20
|
import { getLocale } from "../../utils/i18n";
|
|
21
21
|
import { DATA_REQUEST_SENSOR_IDS, getHealthStatus, HealthStatus, SENSOR } from "../../utils/sensors";
|
|
22
|
+
import { getSessionPermissions, NO_SESSION_PERMISSIONS } from "../../utils/session-permissions";
|
|
22
23
|
import { ErrorType, ObjectType, TOKEN_OTYPE_TO_OBJECT_TYPE } from "../../utils/status";
|
|
23
|
-
/** Only an explicit `true` grants a permission; a missing one denies it. */
|
|
24
|
-
const toSessionPermissions = (permissions) => {
|
|
25
|
-
var _a;
|
|
26
|
-
const data = (_a = permissions === null || permissions === void 0 ? void 0 : permissions.lift_flow) === null || _a === void 0 ? void 0 : _a.data;
|
|
27
|
-
return {
|
|
28
|
-
realtime: (data === null || data === void 0 ? void 0 : data.realtime) === true,
|
|
29
|
-
history: (data === null || data === void 0 ? void 0 : data.history) === true,
|
|
30
|
-
counters: (data === null || data === void 0 ? void 0 : data.counters) === true,
|
|
31
|
-
statuses: (data === null || data === void 0 ? void 0 : data.statuses) === true,
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
24
|
const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) => {
|
|
35
25
|
var _a, _b;
|
|
36
26
|
const objectTypeByOtype = TOKEN_OTYPE_TO_OBJECT_TYPE;
|
|
@@ -43,7 +33,7 @@ const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) =>
|
|
|
43
33
|
objectType,
|
|
44
34
|
objectId: oid,
|
|
45
35
|
esNumber: esNumber !== null && esNumber !== void 0 ? esNumber : undefined,
|
|
46
|
-
permissions
|
|
36
|
+
permissions,
|
|
47
37
|
hasResetContactCapability: Boolean((_a = capability === null || capability === void 0 ? void 0 : capability.commands) === null || _a === void 0 ? void 0 : _a.reset_contact),
|
|
48
38
|
isAdmin,
|
|
49
39
|
liftController: (_b = capability === null || capability === void 0 ? void 0 : capability.lift_controller) === null || _b === void 0 ? void 0 : _b.type,
|
|
@@ -62,8 +52,8 @@ const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) =>
|
|
|
62
52
|
* Either way the token itself is passed on to the API unchanged.
|
|
63
53
|
*/
|
|
64
54
|
const getAuthTarget = (auth) => {
|
|
65
|
-
var _a, _b, _c, _d;
|
|
66
|
-
const permissions = (
|
|
55
|
+
var _a, _b, _c, _d, _e;
|
|
56
|
+
const permissions = getSessionPermissions(auth);
|
|
67
57
|
const { target } = auth;
|
|
68
58
|
if (target != null) {
|
|
69
59
|
return toAuthTarget(target.otype, target.oid, target.es_number, target.capability, permissions,
|
|
@@ -76,20 +66,20 @@ const getAuthTarget = (auth) => {
|
|
|
76
66
|
}
|
|
77
67
|
if (auth.type === 'liftstatus') {
|
|
78
68
|
const { env } = auth.response;
|
|
79
|
-
const liftId = (
|
|
69
|
+
const liftId = (_a = auth.response.lift) === null || _a === void 0 ? void 0 : _a.id;
|
|
80
70
|
if (env === undefined || env === '' || liftId === undefined || liftId === '') {
|
|
81
71
|
throw new Error('LiftStatus session response has no env or lift id');
|
|
82
72
|
}
|
|
83
73
|
return {
|
|
84
74
|
objectType: ObjectType.External,
|
|
85
75
|
objectId: `liftstatus-${env}-${liftId}`,
|
|
86
|
-
permissions
|
|
76
|
+
permissions,
|
|
87
77
|
hasResetContactCapability: false,
|
|
88
78
|
// `permissions.commands` lacks the API's Classic command rules
|
|
89
79
|
isAdmin: false,
|
|
90
80
|
};
|
|
91
81
|
}
|
|
92
|
-
return toAuthTarget(auth.tokenData.otype, auth.tokenData.oid, (
|
|
82
|
+
return toAuthTarget(auth.tokenData.otype, auth.tokenData.oid, (_b = auth.response) === null || _b === void 0 ? void 0 : _b.es_number, (_c = auth.response) === null || _c === void 0 ? void 0 : _c.capability, permissions, ((_e = (_d = auth.response) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.commands) === true);
|
|
93
83
|
};
|
|
94
84
|
// socket.io waits 20 s per attempt for a server that doesn't answer, which adds
|
|
95
85
|
// up to about 2 minutes over all retries before the first load would fail
|
|
@@ -216,7 +206,7 @@ export class LsData {
|
|
|
216
206
|
if (!auth.isValid) {
|
|
217
207
|
this.lsSession.emit({
|
|
218
208
|
ok: false,
|
|
219
|
-
permissions:
|
|
209
|
+
permissions: NO_SESSION_PERMISSIONS,
|
|
220
210
|
isAdmin: false,
|
|
221
211
|
hasResetContactCapability: false,
|
|
222
212
|
error: {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No API route checks `lift_flow`, so these permissions are the only gate on
|
|
3
|
+
* the pages. A Classic session is denied what it is not explicitly granted.
|
|
4
|
+
* Sense passes its customer's `lift_flow` through for a JWT, but often sends
|
|
5
|
+
* none at all; the token is already limited to its own object, so a JWT is
|
|
6
|
+
* only denied what Sense explicitly denies.
|
|
7
|
+
*/
|
|
8
|
+
export const getSessionPermissions = (auth) => {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
|
+
const data = (_c = (_b = (_a = auth.response) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b.lift_flow) === null || _c === void 0 ? void 0 : _c.data;
|
|
11
|
+
if (auth.type === 'sensecloud') {
|
|
12
|
+
return {
|
|
13
|
+
realtime: (_d = data === null || data === void 0 ? void 0 : data.realtime) !== null && _d !== void 0 ? _d : true,
|
|
14
|
+
history: (_e = data === null || data === void 0 ? void 0 : data.history) !== null && _e !== void 0 ? _e : true,
|
|
15
|
+
counters: (_f = data === null || data === void 0 ? void 0 : data.counters) !== null && _f !== void 0 ? _f : true,
|
|
16
|
+
statuses: (_g = data === null || data === void 0 ? void 0 : data.statuses) !== null && _g !== void 0 ? _g : true,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
realtime: (data === null || data === void 0 ? void 0 : data.realtime) === true,
|
|
21
|
+
history: (data === null || data === void 0 ? void 0 : data.history) === true,
|
|
22
|
+
counters: (data === null || data === void 0 ? void 0 : data.counters) === true,
|
|
23
|
+
statuses: (data === null || data === void 0 ? void 0 : data.statuses) === true,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const NO_SESSION_PERMISSIONS = {
|
|
27
|
+
realtime: false,
|
|
28
|
+
history: false,
|
|
29
|
+
counters: false,
|
|
30
|
+
statuses: false,
|
|
31
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{proxyCustomElement as t,HTMLElement as s,createEvent as i,transformTag as e}from"@stencil/core/internal/client";import{g as n,d as r,m as o,b as h,E as c,u as a,n as u,O as l,T as f}from"./store.js";import{a as d}from"./status-codes.store.js";import{d as p,e as y,c as b}from"./api.js";import{g as v}from"./error-message.js";import{o as g,g as m,H as w,S as k}from"./sensors.js";import{i as E}from"./isNil.js";import{i as O}from"./isEmpty.js";import{k as A,v as C}from"./values.js";const _=Object.create(null);_.open="0",_.close="1",_.ping="2",_.pong="3",_.message="4",_.upgrade="5",_.noop="6";const j=Object.create(null);Object.keys(_).forEach((t=>{j[_[t]]=t}));const T={type:"error",data:"parser error"},N="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),I="function"==typeof ArrayBuffer,L=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,D=({type:t,data:s},i,e)=>N&&s instanceof Blob?i?e(s):S(s,e):I&&(s instanceof ArrayBuffer||L(s))?i?e(s):S(new Blob([s]),e):e(_[t]+(s||"")),S=(t,s)=>{const i=new FileReader;return i.onload=function(){const t=i.result.split(",")[1];s("b"+(t||""))},i.readAsDataURL(t)};function x(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let B;const U="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)U["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(t)]=t;const F="function"==typeof ArrayBuffer,R=(t,s)=>{if("string"!=typeof t)return{type:"message",data:M(t,s)};const i=t.charAt(0);return"b"===i?{type:"message",data:P(t.substring(1),s)}:j[i]?t.length>1?{type:j[i],data:t.substring(1)}:{type:j[i]}:T},P=(t,s)=>{if(F){const i=(t=>{let s,i,e,n,r,o=.75*t.length,h=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const a=new ArrayBuffer(o),u=new Uint8Array(a);for(s=0;s<h;s+=4)i=U[t.charCodeAt(s)],e=U[t.charCodeAt(s+1)],n=U[t.charCodeAt(s+2)],r=U[t.charCodeAt(s+3)],u[c++]=i<<2|e>>4,u[c++]=(15&e)<<4|n>>2,u[c++]=(3&n)<<6|63&r;return a})(t);return M(i,s)}return{base64:!0,data:t}},M=(t,s)=>"blob"===s?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer;let V;function $(t){return t.reduce(((t,s)=>t+s.length),0)}function K(t,s){if(t[0].length===s)return t.shift();const i=new Uint8Array(s);let e=0;for(let n=0;n<s;n++)i[n]=t[0][e++],e===t[0].length&&(t.shift(),e=0);return t.length&&e<t[0].length&&(t[0]=t[0].slice(e)),i}function H(t){if(t)return function(t){for(var s in H.prototype)t[s]=H.prototype[s];return t}(t)}H.prototype.on=H.prototype.addEventListener=function(t,s){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(s),this},H.prototype.once=function(t,s){function i(){this.off(t,i),s.apply(this,arguments)}return i.fn=s,this.on(t,i),this},H.prototype.off=H.prototype.removeListener=H.prototype.removeAllListeners=H.prototype.removeEventListener=function(t,s){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i,e=this._callbacks["$"+t];if(!e)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n=0;n<e.length;n++)if((i=e[n])===s||i.fn===s){e.splice(n,1);break}return 0===e.length&&delete this._callbacks["$"+t],this},H.prototype.emitReserved=H.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var s=Array(arguments.length-1),i=this._callbacks["$"+t],e=1;e<arguments.length;e++)s[e-1]=arguments[e];if(i){e=0;for(var n=(i=i.slice(0)).length;e<n;++e)i[e].apply(this,s)}return this},H.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},H.prototype.hasListeners=function(t){return!!this.listeners(t).length};const q="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,s)=>s(t,0),W="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function X(t,...s){return s.reduce(((s,i)=>(t.hasOwnProperty(i)&&(s[i]=t[i]),s)),{})}const z=W.setTimeout,J=W.clearTimeout;function Q(t,s){s.useNativeTimers?(t.setTimeoutFn=z.bind(W),t.clearTimeoutFn=J.bind(W)):(t.setTimeoutFn=W.setTimeout.bind(W),t.clearTimeoutFn=W.clearTimeout.bind(W))}function Y(t){return"string"==typeof t?function(t){let s=0,i=0;for(let e=0,n=t.length;e<n;e++)s=t.charCodeAt(e),s<128?i+=1:s<2048?i+=2:s<55296||s>=57344?i+=3:(e++,i+=4);return i}(t):Math.ceil(1.33*(t.byteLength||t.size))}function G(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class Z extends Error{constructor(t,s,i){super(t),this.description=s,this.context=i,this.type="TransportError"}}class tt extends H{constructor(t){super(),this.writable=!1,Q(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,i){return super.emitReserved("error",new Z(t,s,i)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=R(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const s=function(t){let s="";for(let i in t)t.hasOwnProperty(i)&&(s.length&&(s+="&"),s+=encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return s}(t);return s.length?"?"+s:""}}class st extends tt{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",(function(){--t||s()}))),this.writable||(t++,this.once("drain",(function(){--t||s()})))}else s()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,s)=>{const i=t.split(""),e=[];for(let t=0;t<i.length;t++){const n=R(i[t],s);if(e.push(n),"error"===n.type)break}return e})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,s)=>{const i=t.length,e=Array(i);let n=0;t.forEach(((t,r)=>{D(t,!1,(t=>{e[r]=t,++n===i&&s(e.join(""))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return!1!==this.opts.timestampRequests&&(s[this.opts.timestampParam]=G()),this.supportsBinary||s.sid||(s.b64=1),this.createUri(t,s)}}let it=!1;try{it="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const et=it;function nt(){}class rt extends st{constructor(t){if(super(t),"undefined"!=typeof location){const s="https:"===location.protocol;let i=location.port;i||(i=s?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||i!==t.port}}doWrite(t,s){const i=this.request({method:"POST",data:t});i.on("success",s),i.on("error",((t,s)=>{this.onError("xhr post error",t,s)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,s)=>{this.onError("xhr poll error",t,s)})),this.pollXhr=t}}class ot extends H{constructor(t,s,i){super(),this.createRequest=t,Q(this,i),this._opts=i,this._method=i.method||"GET",this._uri=s,this._data=void 0!==i.data?i.data:null,this._create()}_create(){var t;const s=X(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;const i=this._xhr=this.createRequest(s);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&i.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{i.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var t;3===i.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(i.getResponseHeader("set-cookie"))),4===i.readyState&&(200===i.status||1223===i.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof i.status?i.status:0)}),0))},i.send(this._data)}catch(t){return void this.setTimeoutFn((()=>{this._onError(t)}),0)}"undefined"!=typeof document&&(this._index=ot.requestsCount++,ot.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(null!=this._xhr){if(this._xhr.onreadystatechange=nt,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete ot.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function ht(){for(let t in ot.requests)ot.requests.hasOwnProperty(t)&&ot.requests[t].abort()}ot.requestsCount=0,ot.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",ht):"function"==typeof addEventListener&&addEventListener("onpagehide"in W?"pagehide":"unload",ht,!1));const ct=function(){const t=at({xdomain:!1});return t&&null!==t.responseType}();function at(t){const s=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!s||et))return new XMLHttpRequest}catch(t){}if(!s)try{return new(W[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const ut="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class lt extends tt{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,i=ut?{}:X(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,i)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=t[s],e=s===t.length-1;D(i,this.supportsBinary,(t=>{try{this.doWrite(i,t)}catch(t){}e&&q((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=G()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const ft=W.WebSocket||W.MozWebSocket,dt={websocket:class extends lt{createSocket(t,s,i){return ut?new ft(t,s,i):s?new ft(t,s):new ft(t)}doWrite(t,s){this.ws.send(s)}},webtransport:class extends tt{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((t=>{const s=function(t,s){V||(V=new TextDecoder);const i=[];let e=0,n=-1,r=!1;return new TransformStream({transform(o,h){for(i.push(o);;){if(0===e){if($(i)<1)break;const t=K(i,1);r=!(128&~t[0]),n=127&t[0],e=n<126?3:126===n?1:2}else if(1===e){if($(i)<2)break;const t=K(i,2);n=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),e=3}else if(2===e){if($(i)<8)break;const t=K(i,8),s=new DataView(t.buffer,t.byteOffset,t.length),r=s.getUint32(0);if(r>2097151){h.enqueue(T);break}n=4294967296*r+s.getUint32(4),e=3}else{if($(i)<n)break;const t=K(i,n);h.enqueue(R(r?t:V.decode(t),s)),e=0}if(0===n||n>t){h.enqueue(T);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=t.readable.pipeThrough(s).getReader(),e=new TransformStream({transform(t,s){!function(t,s){N&&t.data instanceof Blob?t.data.arrayBuffer().then(x).then(s):I&&(t.data instanceof ArrayBuffer||L(t.data))?s(x(t.data)):D(t,!1,(t=>{B||(B=new TextEncoder),s(B.encode(t))}))}(t,(i=>{const e=i.length;let n;if(e<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,e);else if(e<65536){n=new Uint8Array(3);const t=new DataView(n.buffer);t.setUint8(0,126),t.setUint16(1,e)}else{n=new Uint8Array(9);const t=new DataView(n.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(e))}t.data&&"string"!=typeof t.data&&(n[0]|=128),s.enqueue(n),s.enqueue(i)}))}});e.readable.pipeTo(t.writable),this._writer=e.writable.getWriter();const n=()=>{i.read().then((({done:t,value:s})=>{t||(this.onPacket(s),n())})).catch((()=>{}))};n();const r={type:"open"};this.query.sid&&(r.data=`{"sid":"${this.query.sid}"}`),this._writer.write(r).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=s===t.length-1;this._writer.write(t[s]).then((()=>{i&&q((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends rt{constructor(t){super(t),this.supportsBinary=ct&&!(t&&t.forceBase64)}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new ot(at,this.uri(),t)}}},pt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,yt=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function bt(t){if(t.length>8e3)throw"URI too long";const s=t,i=t.indexOf("["),e=t.indexOf("]");-1!=i&&-1!=e&&(t=t.substring(0,i)+t.substring(i,e).replace(/:/g,";")+t.substring(e,t.length));let n=pt.exec(t||""),r={},o=14;for(;o--;)r[yt[o]]=n[o]||"";return-1!=i&&-1!=e&&(r.source=s,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,s){const i=s.replace(/\/{2,9}/g,"/").split("/");return"/"!=s.slice(0,1)&&0!==s.length||i.splice(0,1),"/"==s.slice(-1)&&i.splice(i.length-1,1),i}(0,r.path),r.queryKey=function(t,s){const i={};return s.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,s,e){s&&(i[s]=e)})),i}(0,r.query),r}const vt="function"==typeof addEventListener&&"function"==typeof removeEventListener,gt=[];vt&&addEventListener("offline",(()=>{gt.forEach((t=>t()))}),!1);let mt=class t extends H{constructor(t,s={}){var i,e;if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._upgrades=[],this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(s=t,t=null),t){const i=bt(t);s.hostname=i.host,s.secure="https"===i.protocol||"wss"===i.protocol,s.port=i.port,i.query&&(s.query=i.query)}else s.host&&(s.hostname=bt(s.host).host);if(Q(this,s),this.secure=null!=s.secure?s.secure:"undefined"!=typeof location&&"https:"===location.protocol,s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=s.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),s.transportImplementations&&s.transports)throw Error("specifying both 'transportImplementations' and 'transports' options is not supported");s.transportImplementations||(null===(i=s.transports)||void 0===i?void 0:i.length)&&"function"==typeof s.transports[0]?(this.transports=[],this._transportsByName=Object.create(null),(null!==(e=s.transportImplementations)&&void 0!==e?e:s.transports).forEach((t=>{const s=t.prototype.name;this.transports.push(s),this._transportsByName[s]=t}))):(this.transports=s.transports?[...s.transports]:["polling","websocket","webtransport"],this._transportsByName=dt),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let s={},i=t.split("&");for(let t=0,e=i.length;t<e;t++){let e=i[t].split("=");s[decodeURIComponent(e[0])]=decodeURIComponent(e[1])}return s}(this.opts.query)),vt&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},gt.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=4,s.transport=t,this.id&&(s.sid=this.id);const i=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](i)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const s=this.opts.rememberUpgrade&&t.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const i=this.createTransport(s);i.open(),this.setTransport(i)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(t=>this._onClose("transport close",t)))}_probe(s){let i=this.createTransport(s),e=!1;t.priorWebsocketSuccess=!1;const n=()=>{e||(i.send([{type:"ping",data:"probe"}]),i.once("packet",(s=>{if(!e)if("pong"===s.type&&"probe"===s.data){if(this.upgrading=!0,this.emitReserved("upgrading",i),!i)return;t.priorWebsocketSuccess="websocket"===i.name,this.transport.pause((()=>{e||"closed"!==this.readyState&&(u(),this.setTransport(i),i.send([{type:"upgrade"}]),this.emitReserved("upgrade",i),i=null,this.upgrading=!1,this.flush())}))}else{const t=Error("probe error");t.transport=i.name,this.emitReserved("upgradeError",t)}})))};function r(){e||(e=!0,u(),i.close(),i=null)}const o=t=>{const s=Error("probe error: "+t);s.transport=i.name,r(),this.emitReserved("upgradeError",s)};function h(){o("transport closed")}function c(){o("socket closed")}function a(t){i&&t.name!==i.name&&r()}const u=()=>{i.removeListener("open",n),i.removeListener("error",o),i.removeListener("close",h),this.off("close",c),this.off("upgrading",a)};i.once("open",n),i.once("error",o),i.once("close",h),this.once("close",c),this.once("upgrading",a),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==s?this.setTimeoutFn((()=>{e||i.open()}),200):i.open()}onOpen(){if(this.readyState="open",t.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const s=Error("server error");s.code=t.data,this._onError(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._upgrades=this._filterUpgrades(t.upgrades),this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const i=this.writeBuffer[s].data;if(i&&(t+=Y(i)),s>0&&t>this._maxPayload)return this.writeBuffer.slice(0,s);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,q((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),t}write(t,s,i){return this._sendPacket("message",t,s,i),this}send(t,s,i){return this._sendPacket("message",t,s,i),this}_sendPacket(t,s,i,e){if("function"==typeof s&&(e=s,s=void 0),"function"==typeof i&&(e=i,i=null),"closing"===this.readyState||"closed"===this.readyState)return;(i=i||{}).compress=!1!==i.compress;const n={type:t,data:s,options:i};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),e&&this.once("flush",e),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},i=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?i():t()})):this.upgrading?i():t()),this}_onError(s){if(t.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",s),this._onClose("transport error",s)}_onClose(t,s){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),vt&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=gt.indexOf(this._offlineEventListener);-1!==t&>.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this._prevBufferLen=0}}_filterUpgrades(t){const s=[];for(let i=0;i<t.length;i++)~this.transports.indexOf(t[i])&&s.push(t[i]);return s}};mt.protocol=4;const wt="function"==typeof ArrayBuffer,kt=Object.prototype.toString,Et="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===kt.call(Blob),Ot="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===kt.call(File);function At(t){return wt&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||Et&&t instanceof Blob||Ot&&t instanceof File}function Ct(t,s){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let s=0,i=t.length;s<i;s++)if(Ct(t[s]))return!0;return!1}if(At(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return Ct(t.toJSON(),!0);for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&Ct(t[s]))return!0;return!1}function _t(t){const s=[],i=t;return i.data=jt(t.data,s),i.attachments=s.length,{packet:i,buffers:s}}function jt(t,s,i){if(!t)return t;if(At(t)){const i={_placeholder:!0,num:s.length};return s.push(t),i}if(Array.isArray(t)){const i=Array(t.length);for(let e=0;e<t.length;e++)i[e]=jt(t[e],s);return i}if("object"==typeof t&&!(t instanceof Date)){if(t.toJSON&&"function"==typeof t.toJSON&&!i)return jt(t.toJSON(),s,!0);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=jt(t[i],s));return e}return t}function Tt(t,s){return t.data=Nt(t.data,s),delete t.attachments,t}function Nt(t,s){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<s.length)return s[t.num];throw Error("illegal attachments")}if(Array.isArray(t))for(let i=0;i<t.length;i++)t[i]=Nt(t[i],s);else if("object"==typeof t)for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(t[i]=Nt(t[i],s));return t}const It=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Lt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Lt||(Lt={}));class Dt extends H{constructor(t){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},"function"==typeof t?{reviver:t}:t)}add(t){let s;if("string"==typeof t){if(this.reconstructor)throw Error("got plaintext data when reconstructing a packet");s=this.decodeString(t);const i=s.type===Lt.BINARY_EVENT;i||s.type===Lt.BINARY_ACK?(s.type=i?Lt.EVENT:Lt.ACK,this.reconstructor=new St(s)):super.emitReserved("decoded",s)}else{if(!At(t)&&!t.base64)throw Error("Unknown type: "+t);if(!this.reconstructor)throw Error("got binary data when not reconstructing a packet");s=this.reconstructor.takeBinaryData(t),s&&(this.reconstructor=null,super.emitReserved("decoded",s))}}decodeString(t){let s=0;const i={type:Number(t.charAt(0))};if(void 0===Lt[i.type])throw Error("unknown packet type "+i.type);if(i.type===Lt.BINARY_EVENT||i.type===Lt.BINARY_ACK){const e=s+1;for(;"-"!==t.charAt(++s)&&s!=t.length;);const n=t.substring(e,s);if(n!=Number(n)||"-"!==t.charAt(s))throw Error("Illegal attachments");const r=Number(n);if(!xt(r)||r<1)throw Error("Illegal attachments");if(r>this.opts.maxAttachments)throw Error("too many attachments");i.attachments=r}if("/"===t.charAt(s+1)){const e=s+1;for(;++s&&","!==t.charAt(s)&&s!==t.length;);i.nsp=t.substring(e,s)}else i.nsp="/";const e=t.charAt(s+1);if(""!==e&&Number(e)==e){const e=s+1;for(;++s;){const i=t.charAt(s);if(null==i||Number(i)!=i){--s;break}if(s===t.length)break}i.id=Number(t.substring(e,s+1))}if(t.charAt(++s)){const e=this.tryParse(t.substr(s));if(!Dt.isPayloadValid(i.type,e))throw Error("invalid payload");i.data=e}return i}tryParse(t){try{return JSON.parse(t,this.opts.reviver)}catch(t){return!1}}static isPayloadValid(t,s){switch(t){case Lt.CONNECT:return Bt(s);case Lt.DISCONNECT:return void 0===s;case Lt.CONNECT_ERROR:return"string"==typeof s||Bt(s);case Lt.EVENT:case Lt.BINARY_EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===It.indexOf(s[0]));case Lt.ACK:case Lt.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class St{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=Tt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const xt=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function Bt(t){return"[object Object]"===Object.prototype.toString.call(t)}var Ut=Object.freeze({__proto__:null,Decoder:Dt,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==Lt.EVENT&&t.type!==Lt.ACK||!Ct(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Lt.EVENT?Lt.BINARY_EVENT:Lt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let s=""+t.type;return t.type!==Lt.BINARY_EVENT&&t.type!==Lt.BINARY_ACK||(s+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(s+=t.nsp+","),null!=t.id&&(s+=t.id),null!=t.data&&(s+=JSON.stringify(t.data,this.replacer)),s}encodeAsBinary(t){const s=_t(t),i=this.encodeAsString(s.packet),e=s.buffers;return e.unshift(i),e}},get PacketType(){return Lt},isPacketValid:function(t){return function(t){return"string"==typeof t}(t.nsp)&&function(t){return void 0===t||xt(t)}(t.id)&&function(t,s){switch(t){case Lt.CONNECT:return void 0===s||Bt(s);case Lt.DISCONNECT:return void 0===s;case Lt.EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===It.indexOf(s[0]));case Lt.ACK:return Array.isArray(s);case Lt.CONNECT_ERROR:return"string"==typeof s||Bt(s);default:return!1}}(t.type,t.data)},protocol:5});function Ft(t,s,i){return t.on(s,i),function(){t.off(s,i)}}const Rt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Pt extends H{constructor(t,s,i){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=s,i&&i.auth&&(this.auth=i.auth),this._opts=Object.assign({},i),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Ft(t,"open",this.onopen.bind(this)),Ft(t,"packet",this.onpacket.bind(this)),Ft(t,"error",this.onerror.bind(this)),Ft(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...s){var i,e,n;if(Rt.hasOwnProperty(t))throw Error('"'+t+'" is a reserved event name');if(s.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;const r={type:Lt.EVENT,data:s,options:{}};if(r.options.compress=!1!==this.flags.compress,"function"==typeof s[s.length-1]){const t=this.ids++,i=s.pop();this._registerAckCallback(t,i),r.id=t}const o=null===(e=null===(i=this.io.engine)||void 0===i?void 0:i.transport)||void 0===e?void 0:e.writable,h=this.connected&&!(null===(n=this.io.engine)||void 0===n?void 0:n._hasPingExpired());return this.flags.volatile&&!o||(h?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,s){var i;const e=null!==(i=this.flags.timeout)&&void 0!==i?i:this._opts.ackTimeout;if(void 0===e)return void(this.acks[t]=s);const n=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let s=0;s<this.sendBuffer.length;s++)this.sendBuffer[s].id===t&&this.sendBuffer.splice(s,1);s.call(this,Error("operation has timed out"))}),e),r=(...t)=>{this.io.clearTimeoutFn(n),s.apply(this,t)};r.withError=!0,this.acks[t]=r}emitWithAck(t,...s){return new Promise(((i,e)=>{const n=(t,s)=>t?e(t):i(s);n.withError=!0,s.push(n),this.emit(t,...s)}))}_addToQueue(t){let s;"function"==typeof t[t.length-1]&&(s=t.pop());const i={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...e)=>{if(i===this._queue[0])return null!==t?i.tryCount>this._opts.retries&&(this._queue.shift(),s&&s(t)):(this._queue.shift(),s&&s(null,...e)),i.pending=!1,this._drainQueue()})),this._queue.push(i),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const s=this._queue[0];s.pending&&!t||(s.pending=!0,s.tryCount++,this.flags=s.flags,this.emit.apply(this,s.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Lt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,s){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((t=>{if(!this.sendBuffer.some((s=>s.id+""===t))){const s=this.acks[t];delete this.acks[t],s.withError&&s.call(this,Error("socket has been disconnected"))}}))}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Lt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Lt.EVENT:case Lt.BINARY_EVENT:this.onevent(t);break;case Lt.ACK:case Lt.BINARY_ACK:this.onack(t);break;case Lt.DISCONNECT:this.ondisconnect();break;case Lt.CONNECT_ERROR:this.destroy();const s=Error(t.data.message);s.data=t.data.data,this.emitReserved("connect_error",s)}}onevent(t){const s=t.data||[];null!=t.id&&s.push(this.ack(t.id)),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const s=this._anyListeners.slice();for(const i of s)i.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const s=this;let i=!1;return function(...e){i||(i=!0,s.packet({type:Lt.ACK,id:t,data:e}))}}onack(t){const s=this.acks[t.id];"function"==typeof s&&(delete this.acks[t.id],s.withError&&t.data.unshift(null),s.apply(this,t.data))}onconnect(t,s){this.id=t,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Lt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const s=this._anyListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const s=this._anyOutgoingListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const s=this._anyOutgoingListeners.slice();for(const i of s)i.apply(this,t.data)}}}function Mt(t){this.ms=(t=t||{}).min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Mt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var s=Math.random(),i=Math.floor(s*this.jitter*t);t=1&Math.floor(10*s)?t+i:t-i}return 0|Math.min(t,this.max)},Mt.prototype.reset=function(){this.attempts=0},Mt.prototype.setMin=function(t){this.ms=t},Mt.prototype.setMax=function(t){this.max=t},Mt.prototype.setJitter=function(t){this.jitter=t};class Vt extends H{constructor(t,s){var i;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(s=t,t=void 0),(s=s||{}).path=s.path||"/socket.io",this.opts=s,Q(this,s),this.reconnection(!1!==s.reconnection),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(i=s.randomizationFactor)&&void 0!==i?i:.5),this.backoff=new Mt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==s.timeout?2e4:s.timeout),this._readyState="closed",this.uri=t;const e=s.parser||Ut;this.encoder=new e.Encoder,this.decoder=new e.Decoder,this._autoConnect=!1!==s.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var s;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(s=this.backoff)||void 0===s||s.setMin(t),this)}randomizationFactor(t){var s;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(s=this.backoff)||void 0===s||s.setJitter(t),this)}reconnectionDelayMax(t){var s;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(s=this.backoff)||void 0===s||s.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new mt(this.uri,this.opts);const s=this.engine,i=this;this._readyState="opening",this.skipReconnect=!1;const e=Ft(s,"open",(function(){i.onopen(),t&&t()})),n=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},r=Ft(s,"error",n);if(!1!==this._timeout){const t=this.setTimeoutFn((()=>{e(),n(Error("timeout")),s.close()}),this._timeout);this.opts.autoUnref&&t.unref(),this.subs.push((()=>{this.clearTimeoutFn(t)}))}return this.subs.push(e),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ft(t,"ping",this.onping.bind(this)),Ft(t,"data",this.ondata.bind(this)),Ft(t,"error",this.onerror.bind(this)),Ft(t,"close",this.onclose.bind(this)),Ft(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){q((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,s){let i=this.nsps[t];return i?this._autoConnect&&!i.active&&i.connect():(i=new Pt(this,t,s),this.nsps[t]=i),i}_destroy(t){const s=Object.keys(this.nsps);for(const t of s)if(this.nsps[t].active)return;this._close()}_packet(t){const s=this.encoder.encode(t);for(let i=0;i<s.length;i++)this.engine.write(s[i],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,s){var i;this.cleanup(),null===(i=this.engine)||void 0===i||i.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const s=this.backoff.duration();this._reconnecting=!0;const i=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((s=>{s?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",s)):t.onreconnect()})))}),s);this.opts.autoUnref&&i.unref(),this.subs.push((()=>{this.clearTimeoutFn(i)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const $t={};function Kt(t,s){"object"==typeof t&&(s=t,t=void 0);const i=function(t,s="",i){let e=t;i=i||"undefined"!=typeof location&&location,null==t&&(t=i.protocol+"//"+i.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?i.protocol+t:i.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==i?i.protocol+"//"+t:"https://"+t),e=bt(t)),e.port||(/^(http|ws)$/.test(e.protocol)?e.port="80":/^(http|ws)s$/.test(e.protocol)&&(e.port="443")),e.path=e.path||"/";const n=-1!==e.host.indexOf(":")?"["+e.host+"]":e.host;return e.id=e.protocol+"://"+n+":"+e.port+s,e.href=e.protocol+"://"+n+(i&&i.port===e.port?"":":"+e.port),e}(t,(s=s||{}).path||"/socket.io"),e=i.source,n=i.id;let r;return s.forceNew||s["force new connection"]||!1===s.multiplex||$t[n]&&i.path in $t[n].nsps?r=new Vt(e,s):($t[n]||($t[n]=new Vt(e,s)),r=$t[n]),i.query&&!s.query&&(s.query=i.queryKey),r.socket(i.path,s)}Object.assign(Kt,{Manager:Vt,Socket:Pt,io:Kt,connect:Kt});const Ht=t=>{var s;const i=null===(s=null==t?void 0:t.lift_flow)||void 0===s?void 0:s.data;return{realtime:!0===(null==i?void 0:i.realtime),history:!0===(null==i?void 0:i.history),counters:!0===(null==i?void 0:i.counters),statuses:!0===(null==i?void 0:i.statuses)}},qt=(t,s,i,e,n,r)=>{var o,h;const c=f[t];if(void 0===c)throw Error(`Unknown token otype "${t}"`);return{objectType:c,objectId:s,esNumber:null!=i?i:void 0,permissions:Ht(n),hasResetContactCapability:!!(null===(o=null==e?void 0:e.commands)||void 0===o?void 0:o.reset_contact),isAdmin:r,liftController:null===(h=null==e?void 0:e.lift_controller)||void 0===h?void 0:h.type}},Wt=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.lsSession=i(this,"lsSession",7),this.apiUrl="https://api-gcp-prod.liftstatus.nl",this.store=null,this.computedIdKey=null,this.availableSensorIds=g,this.socketId=null,this.socket=null}syncStoreLocaleFromLanguage(t){null!==this.store&&this.store.set("locale",n(t))}async componentWillLoad(){var t;const s=await this.decodeAccessToken(this.accessToken);if(this.emitSession(s),!s.isValid)return;const{accessToken:i,objectId:e,objectType:a,hasResetContactCapability:u,isAdmin:l,liftController:f}=s;void 0!==f&&d(f,{apiUrl:this.apiUrl,accessToken:i});const p=this.checkHasBackdoor(a,e,i),y=[...new Set(this.availableSensorIds.concat(void 0!==this.sensorIds?this.sensorIds.split(",").filter((t=>""!==t.trim())).map((t=>parseInt(t.trim(),10))):[]))],b=this.getHistoricalData(r().subtract(1,"hour").format(),r().format(),y,a,e,i),v=this.connectToSocketServer(i),[g,O,{connected:A,socket:C}]=await Promise.all([p,b,v]);if(E(g)||E(O)||!A||void 0===C)return;const _=null!==(t=this.idKey)&&void 0!==t?t:`${a}-${e}`;this.computedIdKey=_;const j=this.getCurrentDataFromHistorical(O);o(_,{hasBackDoor:g,historicalSensorData:O,currentSensorData:j,locale:n(this.language),accessToken:i,apiUrl:this.apiUrl,externalIdentifier:e,objectType:a,hasResetContactCapability:u,isAdmin:l});try{this.store=await h(_)}catch(t){this.throwError("STORE_CREATION_FAILED",c.Token,t instanceof Error?t.message:t+"")}m(j.values[k.SensecloudConnectionHealthy])===w.Unhealthy?this.throwError("SENSECLOUD_CONNECTION_FAILED",c.Sensecloud):m(j.values[k.ControllerConnectionHealthy])===w.Unhealthy&&this.throwError("CONTROLLER_CONNECTION_FAILED",c.Controller),this.listenForSensorUpdates(C,_,y)}async decodeAccessToken(t){if(void 0===t||O(t))return this.throwError("NO_ACCESS_TOKEN",c.Token,"Add the token to the <ls-data> component like so: <ls-data access-token='yourToken'></ls-data>"),{isValid:!1,errorKey:"NO_ACCESS_TOKEN"};try{const s=await p({apiUrl:this.apiUrl,accessToken:t});return Object.assign({isValid:!0,accessToken:t},(t=>{var s,i,e,n;const r=null===(s=t.response)||void 0===s?void 0:s.permissions,{target:o}=t;if(null!=o)return qt(o.otype,o.oid,o.es_number,o.capability,r,o.commands);if("liftstatus"===t.type){const{env:s}=t.response,e=null===(i=t.response.lift)||void 0===i?void 0:i.id;if(void 0===s||""===s||void 0===e||""===e)throw Error("LiftStatus session response has no env or lift id");return{objectType:l.External,objectId:`liftstatus-${s}-${e}`,permissions:Ht(r),hasResetContactCapability:!1,isAdmin:!1}}return qt(t.tokenData.otype,t.tokenData.oid,null===(e=t.response)||void 0===e?void 0:e.es_number,null===(n=t.response)||void 0===n?void 0:n.capability,r,!0===(null==r?void 0:r.commands))})(s))}catch(t){return this.throwError("INVALID_ACCESS_TOKEN",c.Token,t instanceof Error?t.message:t+""),{isValid:!1,errorKey:"INVALID_ACCESS_TOKEN"}}}emitSession(t){if(!t.isValid)return void this.lsSession.emit({ok:!1,permissions:Ht(void 0),isAdmin:!1,hasResetContactCapability:!1,error:{hasError:!0,messageKey:t.errorKey,type:c.Token}});const s=function(t,s){var i={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&s.indexOf(e)<0&&(i[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)s.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(i[e[n]]=t[e[n]])}return i}(t,["isValid","accessToken","liftController"]);this.lsSession.emit(Object.assign({ok:!0},s))}async checkHasBackdoor(t,s,i){const e=r().subtract(7,"day").format();try{const n=await y({apiUrl:this.apiUrl,accessToken:i,objectType:t,objectId:s,sensorId:k.DoorMovementCounterRear,from:e});if(0===n.rows.length)return!1;const{start:r,end:o}=n.rows[0];return void 0===r||void 0===o||o-r!=0}catch(t){this.throwError("BACK_DOOR_CHECK_FAILED",c.API,t instanceof Error?t.message:t+"")}}async getHistoricalData(t,s,i,e,n,r){try{return await b({apiUrl:this.apiUrl,accessToken:r,objectType:e,objectId:n,from:t,to:s,sensors:i})}catch(t){this.throwError("HISTORIC_DATA_FAILED",c.API,t instanceof Error?t.message:t+"")}}connectToSocketServer(t){return O(this.socketId)||this.closeSocketConnection(),new Promise((s=>{const i=Kt(this.apiUrl,{transports:["websocket"],path:"/liftstatus/socket.io",reconnectionAttempts:5,query:{access_token:t}});this.socket=i;let e=!1;const n=t=>{e||this.socket!==i||(e=!0,clearTimeout(r),i.close(),this.throwError("SOCKET_CONNECTION_FAILED",c.Socket,t,i),s({connected:!1}))},r=setTimeout((()=>{n("No connection within 20 s")}),2e4);i.on("connect",(()=>{e=!0,clearTimeout(r),s({connected:!0,socket:i})})),i.on("error",(t=>{n(t)})),i.on("connect_error",(t=>{i.active||n(t.message)})),i.io.on("reconnect_failed",(()=>{n("No connection after the reconnection attempts")}))}))}listenForSensorUpdates(t,s,i){t.on("module",(({message:t})=>{const e=t.data,n=A(e)[0],r=parseInt(n,10),o=C(e)[0],h=t.ts,u=m(o);if(r===k.SensecloudConnectionHealthy&&u===w.Unhealthy)this.throwError("SENSECLOUD_CONNECTION_FAILED",c.Sensecloud);else if(r===k.ControllerConnectionHealthy&&u===w.Unhealthy)this.throwError("CONTROLLER_CONNECTION_FAILED",c.Controller);else if((r===k.SensecloudConnectionHealthy||r===k.ControllerConnectionHealthy)&&u===w.Healthy){if(null===this.store)return;const t=this.store.state.currentSensorData.values;(r===k.SensecloudConnectionHealthy&&m(t[k.ControllerConnectionHealthy])===w.Healthy||r===k.ControllerConnectionHealthy&&m(t[k.SensecloudConnectionHealthy])===w.Healthy)&&this.resetError()}if(!i.includes(r)&&r!==k.SensecloudConnectionHealthy&&r!==k.ControllerConnectionHealthy)return;if(null===this.store)return;const{currentSensorData:l}=this.store.state;a({lastUpdate:h,values:Object.assign(Object.assign({},l.values),{[n]:o}),updated:Object.assign(Object.assign({},l.updated),{[n]:h})},s)})),t.emit("listen",{})}getCurrentDataFromHistorical(t){let s=0;const i={},e={};return t.forEach((t=>{const n=t.sensor.id;if(0===t.rows.length)return;const o=t.rows[t.rows.length-1],h=r(o.ts).valueOf();h>s&&(s=h);const c=parseInt(o.val,10);i[n]=isFinite(c)?c:o.val,e[n]=h})),{lastUpdate:s,values:i,updated:e}}async throwError(t,s,i,e){var r,c,a;const u=n(null!==(c=null===(r=this.store)||void 0===r?void 0:r.state.locale)&&void 0!==c?c:this.language),l=v(t,u);if(console.group("%cError%c [LsData] "+l,"color: #DC2626; background-color: #FEF2F2; display: inline-block; padding: 0 4px; border-radius: 2px;",""),O(i)||console.log(i),E(e)||console.log(e),console.groupEnd(),E(this.store)){const t=null!==(a=this.idKey)&&void 0!==a?a:"error";o(t,{locale:u}),this.store=await h(t)}this.store.set("error",{hasError:!0,messageKey:t,type:s})}resetError(){if(E(this.store))return console.warn("[LsData] Cannot reset error: Store is not initialized"),!1;if(this.store.state.error.type!==c.None)try{return this.store.set("error",{hasError:!1,messageKey:void 0,type:c.None}),console.log("%c[LsData]%c "+this.store.t("ui:data.connection_restored"),"color: #059669; background-color: #ECFDF5; display: inline-block; padding: 0 4px; border-radius: 2px;",""),!0}catch(t){return console.error("[LsData] Failed to reset error:",t),!1}}closeSocketConnection(){var t;null===(t=this.socket)||void 0===t||t.close(),this.socket=null,this.socketId=null}disconnectedCallback(){this.closeSocketConnection(),null!==this.computedIdKey&&(u(this.computedIdKey),this.computedIdKey=null)}static get watchers(){return{language:[{syncStoreLocaleFromLanguage:0}]}}},[1,"ls-data",{accessToken:[1,"access-token"],idKey:[1,"id-key"],sensorIds:[1,"sensor-ids"],apiUrl:[1,"api-url"],language:[1]},void 0,{language:[{syncStoreLocaleFromLanguage:0}]}]),Xt=Wt,zt=function(){"undefined"!=typeof customElements&&["ls-data"].forEach((t=>{"ls-data"===t&&(customElements.get(e(t))||customElements.define(e(t),Wt))}))};export{Xt as LsData,zt as defineCustomElement}
|
|
1
|
+
import{proxyCustomElement as t,HTMLElement as s,createEvent as i,transformTag as e}from"@stencil/core/internal/client";import{g as n,d as r,m as o,b as h,E as c,u as a,n as u,O as l,T as f}from"./store.js";import{a as d}from"./status-codes.store.js";import{d as p,e as y,c as v}from"./api.js";import{g as b}from"./error-message.js";import{o as g,g as m,H as w,S as k}from"./sensors.js";import{i as E}from"./isNil.js";import{i as O}from"./isEmpty.js";import{k as A,v as C}from"./values.js";const _=Object.create(null);_.open="0",_.close="1",_.ping="2",_.pong="3",_.message="4",_.upgrade="5",_.noop="6";const j=Object.create(null);Object.keys(_).forEach((t=>{j[_[t]]=t}));const T={type:"error",data:"parser error"},N="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),I="function"==typeof ArrayBuffer,L=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,D=({type:t,data:s},i,e)=>N&&s instanceof Blob?i?e(s):S(s,e):I&&(s instanceof ArrayBuffer||L(s))?i?e(s):S(new Blob([s]),e):e(_[t]+(s||"")),S=(t,s)=>{const i=new FileReader;return i.onload=function(){const t=i.result.split(",")[1];s("b"+(t||""))},i.readAsDataURL(t)};function x(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let B;const U="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)U["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(t)]=t;const F="function"==typeof ArrayBuffer,R=(t,s)=>{if("string"!=typeof t)return{type:"message",data:M(t,s)};const i=t.charAt(0);return"b"===i?{type:"message",data:P(t.substring(1),s)}:j[i]?t.length>1?{type:j[i],data:t.substring(1)}:{type:j[i]}:T},P=(t,s)=>{if(F){const i=(t=>{let s,i,e,n,r,o=.75*t.length,h=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const a=new ArrayBuffer(o),u=new Uint8Array(a);for(s=0;s<h;s+=4)i=U[t.charCodeAt(s)],e=U[t.charCodeAt(s+1)],n=U[t.charCodeAt(s+2)],r=U[t.charCodeAt(s+3)],u[c++]=i<<2|e>>4,u[c++]=(15&e)<<4|n>>2,u[c++]=(3&n)<<6|63&r;return a})(t);return M(i,s)}return{base64:!0,data:t}},M=(t,s)=>"blob"===s?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer;let V;function $(t){return t.reduce(((t,s)=>t+s.length),0)}function K(t,s){if(t[0].length===s)return t.shift();const i=new Uint8Array(s);let e=0;for(let n=0;n<s;n++)i[n]=t[0][e++],e===t[0].length&&(t.shift(),e=0);return t.length&&e<t[0].length&&(t[0]=t[0].slice(e)),i}function H(t){if(t)return function(t){for(var s in H.prototype)t[s]=H.prototype[s];return t}(t)}H.prototype.on=H.prototype.addEventListener=function(t,s){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(s),this},H.prototype.once=function(t,s){function i(){this.off(t,i),s.apply(this,arguments)}return i.fn=s,this.on(t,i),this},H.prototype.off=H.prototype.removeListener=H.prototype.removeAllListeners=H.prototype.removeEventListener=function(t,s){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i,e=this._callbacks["$"+t];if(!e)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n=0;n<e.length;n++)if((i=e[n])===s||i.fn===s){e.splice(n,1);break}return 0===e.length&&delete this._callbacks["$"+t],this},H.prototype.emitReserved=H.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var s=Array(arguments.length-1),i=this._callbacks["$"+t],e=1;e<arguments.length;e++)s[e-1]=arguments[e];if(i){e=0;for(var n=(i=i.slice(0)).length;e<n;++e)i[e].apply(this,s)}return this},H.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},H.prototype.hasListeners=function(t){return!!this.listeners(t).length};const q="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,s)=>s(t,0),W="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function X(t,...s){return s.reduce(((s,i)=>(t.hasOwnProperty(i)&&(s[i]=t[i]),s)),{})}const z=W.setTimeout,J=W.clearTimeout;function Q(t,s){s.useNativeTimers?(t.setTimeoutFn=z.bind(W),t.clearTimeoutFn=J.bind(W)):(t.setTimeoutFn=W.setTimeout.bind(W),t.clearTimeoutFn=W.clearTimeout.bind(W))}function Y(t){return"string"==typeof t?function(t){let s=0,i=0;for(let e=0,n=t.length;e<n;e++)s=t.charCodeAt(e),s<128?i+=1:s<2048?i+=2:s<55296||s>=57344?i+=3:(e++,i+=4);return i}(t):Math.ceil(1.33*(t.byteLength||t.size))}function G(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class Z extends Error{constructor(t,s,i){super(t),this.description=s,this.context=i,this.type="TransportError"}}class tt extends H{constructor(t){super(),this.writable=!1,Q(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,i){return super.emitReserved("error",new Z(t,s,i)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=R(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const s=function(t){let s="";for(let i in t)t.hasOwnProperty(i)&&(s.length&&(s+="&"),s+=encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return s}(t);return s.length?"?"+s:""}}class st extends tt{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",(function(){--t||s()}))),this.writable||(t++,this.once("drain",(function(){--t||s()})))}else s()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,s)=>{const i=t.split(""),e=[];for(let t=0;t<i.length;t++){const n=R(i[t],s);if(e.push(n),"error"===n.type)break}return e})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,s)=>{const i=t.length,e=Array(i);let n=0;t.forEach(((t,r)=>{D(t,!1,(t=>{e[r]=t,++n===i&&s(e.join(""))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return!1!==this.opts.timestampRequests&&(s[this.opts.timestampParam]=G()),this.supportsBinary||s.sid||(s.b64=1),this.createUri(t,s)}}let it=!1;try{it="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const et=it;function nt(){}class rt extends st{constructor(t){if(super(t),"undefined"!=typeof location){const s="https:"===location.protocol;let i=location.port;i||(i=s?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||i!==t.port}}doWrite(t,s){const i=this.request({method:"POST",data:t});i.on("success",s),i.on("error",((t,s)=>{this.onError("xhr post error",t,s)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,s)=>{this.onError("xhr poll error",t,s)})),this.pollXhr=t}}class ot extends H{constructor(t,s,i){super(),this.createRequest=t,Q(this,i),this._opts=i,this._method=i.method||"GET",this._uri=s,this._data=void 0!==i.data?i.data:null,this._create()}_create(){var t;const s=X(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;const i=this._xhr=this.createRequest(s);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&i.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{i.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var t;3===i.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(i.getResponseHeader("set-cookie"))),4===i.readyState&&(200===i.status||1223===i.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof i.status?i.status:0)}),0))},i.send(this._data)}catch(t){return void this.setTimeoutFn((()=>{this._onError(t)}),0)}"undefined"!=typeof document&&(this._index=ot.requestsCount++,ot.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(null!=this._xhr){if(this._xhr.onreadystatechange=nt,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete ot.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function ht(){for(let t in ot.requests)ot.requests.hasOwnProperty(t)&&ot.requests[t].abort()}ot.requestsCount=0,ot.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",ht):"function"==typeof addEventListener&&addEventListener("onpagehide"in W?"pagehide":"unload",ht,!1));const ct=function(){const t=at({xdomain:!1});return t&&null!==t.responseType}();function at(t){const s=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!s||et))return new XMLHttpRequest}catch(t){}if(!s)try{return new(W[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const ut="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class lt extends tt{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,i=ut?{}:X(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,i)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=t[s],e=s===t.length-1;D(i,this.supportsBinary,(t=>{try{this.doWrite(i,t)}catch(t){}e&&q((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=G()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const ft=W.WebSocket||W.MozWebSocket,dt={websocket:class extends lt{createSocket(t,s,i){return ut?new ft(t,s,i):s?new ft(t,s):new ft(t)}doWrite(t,s){this.ws.send(s)}},webtransport:class extends tt{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((t=>{const s=function(t,s){V||(V=new TextDecoder);const i=[];let e=0,n=-1,r=!1;return new TransformStream({transform(o,h){for(i.push(o);;){if(0===e){if($(i)<1)break;const t=K(i,1);r=!(128&~t[0]),n=127&t[0],e=n<126?3:126===n?1:2}else if(1===e){if($(i)<2)break;const t=K(i,2);n=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),e=3}else if(2===e){if($(i)<8)break;const t=K(i,8),s=new DataView(t.buffer,t.byteOffset,t.length),r=s.getUint32(0);if(r>2097151){h.enqueue(T);break}n=4294967296*r+s.getUint32(4),e=3}else{if($(i)<n)break;const t=K(i,n);h.enqueue(R(r?t:V.decode(t),s)),e=0}if(0===n||n>t){h.enqueue(T);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=t.readable.pipeThrough(s).getReader(),e=new TransformStream({transform(t,s){!function(t,s){N&&t.data instanceof Blob?t.data.arrayBuffer().then(x).then(s):I&&(t.data instanceof ArrayBuffer||L(t.data))?s(x(t.data)):D(t,!1,(t=>{B||(B=new TextEncoder),s(B.encode(t))}))}(t,(i=>{const e=i.length;let n;if(e<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,e);else if(e<65536){n=new Uint8Array(3);const t=new DataView(n.buffer);t.setUint8(0,126),t.setUint16(1,e)}else{n=new Uint8Array(9);const t=new DataView(n.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(e))}t.data&&"string"!=typeof t.data&&(n[0]|=128),s.enqueue(n),s.enqueue(i)}))}});e.readable.pipeTo(t.writable),this._writer=e.writable.getWriter();const n=()=>{i.read().then((({done:t,value:s})=>{t||(this.onPacket(s),n())})).catch((()=>{}))};n();const r={type:"open"};this.query.sid&&(r.data=`{"sid":"${this.query.sid}"}`),this._writer.write(r).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=s===t.length-1;this._writer.write(t[s]).then((()=>{i&&q((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends rt{constructor(t){super(t),this.supportsBinary=ct&&!(t&&t.forceBase64)}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new ot(at,this.uri(),t)}}},pt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,yt=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function vt(t){if(t.length>8e3)throw"URI too long";const s=t,i=t.indexOf("["),e=t.indexOf("]");-1!=i&&-1!=e&&(t=t.substring(0,i)+t.substring(i,e).replace(/:/g,";")+t.substring(e,t.length));let n=pt.exec(t||""),r={},o=14;for(;o--;)r[yt[o]]=n[o]||"";return-1!=i&&-1!=e&&(r.source=s,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,s){const i=s.replace(/\/{2,9}/g,"/").split("/");return"/"!=s.slice(0,1)&&0!==s.length||i.splice(0,1),"/"==s.slice(-1)&&i.splice(i.length-1,1),i}(0,r.path),r.queryKey=function(t,s){const i={};return s.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,s,e){s&&(i[s]=e)})),i}(0,r.query),r}const bt="function"==typeof addEventListener&&"function"==typeof removeEventListener,gt=[];bt&&addEventListener("offline",(()=>{gt.forEach((t=>t()))}),!1);let mt=class t extends H{constructor(t,s={}){var i,e;if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._upgrades=[],this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(s=t,t=null),t){const i=vt(t);s.hostname=i.host,s.secure="https"===i.protocol||"wss"===i.protocol,s.port=i.port,i.query&&(s.query=i.query)}else s.host&&(s.hostname=vt(s.host).host);if(Q(this,s),this.secure=null!=s.secure?s.secure:"undefined"!=typeof location&&"https:"===location.protocol,s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=s.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),s.transportImplementations&&s.transports)throw Error("specifying both 'transportImplementations' and 'transports' options is not supported");s.transportImplementations||(null===(i=s.transports)||void 0===i?void 0:i.length)&&"function"==typeof s.transports[0]?(this.transports=[],this._transportsByName=Object.create(null),(null!==(e=s.transportImplementations)&&void 0!==e?e:s.transports).forEach((t=>{const s=t.prototype.name;this.transports.push(s),this._transportsByName[s]=t}))):(this.transports=s.transports?[...s.transports]:["polling","websocket","webtransport"],this._transportsByName=dt),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let s={},i=t.split("&");for(let t=0,e=i.length;t<e;t++){let e=i[t].split("=");s[decodeURIComponent(e[0])]=decodeURIComponent(e[1])}return s}(this.opts.query)),bt&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},gt.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=4,s.transport=t,this.id&&(s.sid=this.id);const i=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](i)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const s=this.opts.rememberUpgrade&&t.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const i=this.createTransport(s);i.open(),this.setTransport(i)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(t=>this._onClose("transport close",t)))}_probe(s){let i=this.createTransport(s),e=!1;t.priorWebsocketSuccess=!1;const n=()=>{e||(i.send([{type:"ping",data:"probe"}]),i.once("packet",(s=>{if(!e)if("pong"===s.type&&"probe"===s.data){if(this.upgrading=!0,this.emitReserved("upgrading",i),!i)return;t.priorWebsocketSuccess="websocket"===i.name,this.transport.pause((()=>{e||"closed"!==this.readyState&&(u(),this.setTransport(i),i.send([{type:"upgrade"}]),this.emitReserved("upgrade",i),i=null,this.upgrading=!1,this.flush())}))}else{const t=Error("probe error");t.transport=i.name,this.emitReserved("upgradeError",t)}})))};function r(){e||(e=!0,u(),i.close(),i=null)}const o=t=>{const s=Error("probe error: "+t);s.transport=i.name,r(),this.emitReserved("upgradeError",s)};function h(){o("transport closed")}function c(){o("socket closed")}function a(t){i&&t.name!==i.name&&r()}const u=()=>{i.removeListener("open",n),i.removeListener("error",o),i.removeListener("close",h),this.off("close",c),this.off("upgrading",a)};i.once("open",n),i.once("error",o),i.once("close",h),this.once("close",c),this.once("upgrading",a),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==s?this.setTimeoutFn((()=>{e||i.open()}),200):i.open()}onOpen(){if(this.readyState="open",t.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const s=Error("server error");s.code=t.data,this._onError(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._upgrades=this._filterUpgrades(t.upgrades),this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const i=this.writeBuffer[s].data;if(i&&(t+=Y(i)),s>0&&t>this._maxPayload)return this.writeBuffer.slice(0,s);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,q((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),t}write(t,s,i){return this._sendPacket("message",t,s,i),this}send(t,s,i){return this._sendPacket("message",t,s,i),this}_sendPacket(t,s,i,e){if("function"==typeof s&&(e=s,s=void 0),"function"==typeof i&&(e=i,i=null),"closing"===this.readyState||"closed"===this.readyState)return;(i=i||{}).compress=!1!==i.compress;const n={type:t,data:s,options:i};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),e&&this.once("flush",e),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},i=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?i():t()})):this.upgrading?i():t()),this}_onError(s){if(t.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",s),this._onClose("transport error",s)}_onClose(t,s){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),bt&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=gt.indexOf(this._offlineEventListener);-1!==t&>.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this._prevBufferLen=0}}_filterUpgrades(t){const s=[];for(let i=0;i<t.length;i++)~this.transports.indexOf(t[i])&&s.push(t[i]);return s}};mt.protocol=4;const wt="function"==typeof ArrayBuffer,kt=Object.prototype.toString,Et="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===kt.call(Blob),Ot="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===kt.call(File);function At(t){return wt&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||Et&&t instanceof Blob||Ot&&t instanceof File}function Ct(t,s){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let s=0,i=t.length;s<i;s++)if(Ct(t[s]))return!0;return!1}if(At(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return Ct(t.toJSON(),!0);for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&Ct(t[s]))return!0;return!1}function _t(t){const s=[],i=t;return i.data=jt(t.data,s),i.attachments=s.length,{packet:i,buffers:s}}function jt(t,s,i){if(!t)return t;if(At(t)){const i={_placeholder:!0,num:s.length};return s.push(t),i}if(Array.isArray(t)){const i=Array(t.length);for(let e=0;e<t.length;e++)i[e]=jt(t[e],s);return i}if("object"==typeof t&&!(t instanceof Date)){if(t.toJSON&&"function"==typeof t.toJSON&&!i)return jt(t.toJSON(),s,!0);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=jt(t[i],s));return e}return t}function Tt(t,s){return t.data=Nt(t.data,s),delete t.attachments,t}function Nt(t,s){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<s.length)return s[t.num];throw Error("illegal attachments")}if(Array.isArray(t))for(let i=0;i<t.length;i++)t[i]=Nt(t[i],s);else if("object"==typeof t)for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(t[i]=Nt(t[i],s));return t}const It=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Lt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Lt||(Lt={}));class Dt extends H{constructor(t){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},"function"==typeof t?{reviver:t}:t)}add(t){let s;if("string"==typeof t){if(this.reconstructor)throw Error("got plaintext data when reconstructing a packet");s=this.decodeString(t);const i=s.type===Lt.BINARY_EVENT;i||s.type===Lt.BINARY_ACK?(s.type=i?Lt.EVENT:Lt.ACK,this.reconstructor=new St(s)):super.emitReserved("decoded",s)}else{if(!At(t)&&!t.base64)throw Error("Unknown type: "+t);if(!this.reconstructor)throw Error("got binary data when not reconstructing a packet");s=this.reconstructor.takeBinaryData(t),s&&(this.reconstructor=null,super.emitReserved("decoded",s))}}decodeString(t){let s=0;const i={type:Number(t.charAt(0))};if(void 0===Lt[i.type])throw Error("unknown packet type "+i.type);if(i.type===Lt.BINARY_EVENT||i.type===Lt.BINARY_ACK){const e=s+1;for(;"-"!==t.charAt(++s)&&s!=t.length;);const n=t.substring(e,s);if(n!=Number(n)||"-"!==t.charAt(s))throw Error("Illegal attachments");const r=Number(n);if(!xt(r)||r<1)throw Error("Illegal attachments");if(r>this.opts.maxAttachments)throw Error("too many attachments");i.attachments=r}if("/"===t.charAt(s+1)){const e=s+1;for(;++s&&","!==t.charAt(s)&&s!==t.length;);i.nsp=t.substring(e,s)}else i.nsp="/";const e=t.charAt(s+1);if(""!==e&&Number(e)==e){const e=s+1;for(;++s;){const i=t.charAt(s);if(null==i||Number(i)!=i){--s;break}if(s===t.length)break}i.id=Number(t.substring(e,s+1))}if(t.charAt(++s)){const e=this.tryParse(t.substr(s));if(!Dt.isPayloadValid(i.type,e))throw Error("invalid payload");i.data=e}return i}tryParse(t){try{return JSON.parse(t,this.opts.reviver)}catch(t){return!1}}static isPayloadValid(t,s){switch(t){case Lt.CONNECT:return Bt(s);case Lt.DISCONNECT:return void 0===s;case Lt.CONNECT_ERROR:return"string"==typeof s||Bt(s);case Lt.EVENT:case Lt.BINARY_EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===It.indexOf(s[0]));case Lt.ACK:case Lt.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class St{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=Tt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const xt=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function Bt(t){return"[object Object]"===Object.prototype.toString.call(t)}var Ut=Object.freeze({__proto__:null,Decoder:Dt,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==Lt.EVENT&&t.type!==Lt.ACK||!Ct(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Lt.EVENT?Lt.BINARY_EVENT:Lt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let s=""+t.type;return t.type!==Lt.BINARY_EVENT&&t.type!==Lt.BINARY_ACK||(s+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(s+=t.nsp+","),null!=t.id&&(s+=t.id),null!=t.data&&(s+=JSON.stringify(t.data,this.replacer)),s}encodeAsBinary(t){const s=_t(t),i=this.encodeAsString(s.packet),e=s.buffers;return e.unshift(i),e}},get PacketType(){return Lt},isPacketValid:function(t){return function(t){return"string"==typeof t}(t.nsp)&&function(t){return void 0===t||xt(t)}(t.id)&&function(t,s){switch(t){case Lt.CONNECT:return void 0===s||Bt(s);case Lt.DISCONNECT:return void 0===s;case Lt.EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===It.indexOf(s[0]));case Lt.ACK:return Array.isArray(s);case Lt.CONNECT_ERROR:return"string"==typeof s||Bt(s);default:return!1}}(t.type,t.data)},protocol:5});function Ft(t,s,i){return t.on(s,i),function(){t.off(s,i)}}const Rt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Pt extends H{constructor(t,s,i){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=s,i&&i.auth&&(this.auth=i.auth),this._opts=Object.assign({},i),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Ft(t,"open",this.onopen.bind(this)),Ft(t,"packet",this.onpacket.bind(this)),Ft(t,"error",this.onerror.bind(this)),Ft(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...s){var i,e,n;if(Rt.hasOwnProperty(t))throw Error('"'+t+'" is a reserved event name');if(s.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;const r={type:Lt.EVENT,data:s,options:{}};if(r.options.compress=!1!==this.flags.compress,"function"==typeof s[s.length-1]){const t=this.ids++,i=s.pop();this._registerAckCallback(t,i),r.id=t}const o=null===(e=null===(i=this.io.engine)||void 0===i?void 0:i.transport)||void 0===e?void 0:e.writable,h=this.connected&&!(null===(n=this.io.engine)||void 0===n?void 0:n._hasPingExpired());return this.flags.volatile&&!o||(h?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,s){var i;const e=null!==(i=this.flags.timeout)&&void 0!==i?i:this._opts.ackTimeout;if(void 0===e)return void(this.acks[t]=s);const n=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let s=0;s<this.sendBuffer.length;s++)this.sendBuffer[s].id===t&&this.sendBuffer.splice(s,1);s.call(this,Error("operation has timed out"))}),e),r=(...t)=>{this.io.clearTimeoutFn(n),s.apply(this,t)};r.withError=!0,this.acks[t]=r}emitWithAck(t,...s){return new Promise(((i,e)=>{const n=(t,s)=>t?e(t):i(s);n.withError=!0,s.push(n),this.emit(t,...s)}))}_addToQueue(t){let s;"function"==typeof t[t.length-1]&&(s=t.pop());const i={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...e)=>{if(i===this._queue[0])return null!==t?i.tryCount>this._opts.retries&&(this._queue.shift(),s&&s(t)):(this._queue.shift(),s&&s(null,...e)),i.pending=!1,this._drainQueue()})),this._queue.push(i),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const s=this._queue[0];s.pending&&!t||(s.pending=!0,s.tryCount++,this.flags=s.flags,this.emit.apply(this,s.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Lt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,s){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((t=>{if(!this.sendBuffer.some((s=>s.id+""===t))){const s=this.acks[t];delete this.acks[t],s.withError&&s.call(this,Error("socket has been disconnected"))}}))}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Lt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Lt.EVENT:case Lt.BINARY_EVENT:this.onevent(t);break;case Lt.ACK:case Lt.BINARY_ACK:this.onack(t);break;case Lt.DISCONNECT:this.ondisconnect();break;case Lt.CONNECT_ERROR:this.destroy();const s=Error(t.data.message);s.data=t.data.data,this.emitReserved("connect_error",s)}}onevent(t){const s=t.data||[];null!=t.id&&s.push(this.ack(t.id)),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const s=this._anyListeners.slice();for(const i of s)i.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const s=this;let i=!1;return function(...e){i||(i=!0,s.packet({type:Lt.ACK,id:t,data:e}))}}onack(t){const s=this.acks[t.id];"function"==typeof s&&(delete this.acks[t.id],s.withError&&t.data.unshift(null),s.apply(this,t.data))}onconnect(t,s){this.id=t,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Lt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const s=this._anyListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const s=this._anyOutgoingListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const s=this._anyOutgoingListeners.slice();for(const i of s)i.apply(this,t.data)}}}function Mt(t){this.ms=(t=t||{}).min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Mt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var s=Math.random(),i=Math.floor(s*this.jitter*t);t=1&Math.floor(10*s)?t+i:t-i}return 0|Math.min(t,this.max)},Mt.prototype.reset=function(){this.attempts=0},Mt.prototype.setMin=function(t){this.ms=t},Mt.prototype.setMax=function(t){this.max=t},Mt.prototype.setJitter=function(t){this.jitter=t};class Vt extends H{constructor(t,s){var i;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(s=t,t=void 0),(s=s||{}).path=s.path||"/socket.io",this.opts=s,Q(this,s),this.reconnection(!1!==s.reconnection),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(i=s.randomizationFactor)&&void 0!==i?i:.5),this.backoff=new Mt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==s.timeout?2e4:s.timeout),this._readyState="closed",this.uri=t;const e=s.parser||Ut;this.encoder=new e.Encoder,this.decoder=new e.Decoder,this._autoConnect=!1!==s.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var s;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(s=this.backoff)||void 0===s||s.setMin(t),this)}randomizationFactor(t){var s;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(s=this.backoff)||void 0===s||s.setJitter(t),this)}reconnectionDelayMax(t){var s;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(s=this.backoff)||void 0===s||s.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new mt(this.uri,this.opts);const s=this.engine,i=this;this._readyState="opening",this.skipReconnect=!1;const e=Ft(s,"open",(function(){i.onopen(),t&&t()})),n=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},r=Ft(s,"error",n);if(!1!==this._timeout){const t=this.setTimeoutFn((()=>{e(),n(Error("timeout")),s.close()}),this._timeout);this.opts.autoUnref&&t.unref(),this.subs.push((()=>{this.clearTimeoutFn(t)}))}return this.subs.push(e),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ft(t,"ping",this.onping.bind(this)),Ft(t,"data",this.ondata.bind(this)),Ft(t,"error",this.onerror.bind(this)),Ft(t,"close",this.onclose.bind(this)),Ft(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){q((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,s){let i=this.nsps[t];return i?this._autoConnect&&!i.active&&i.connect():(i=new Pt(this,t,s),this.nsps[t]=i),i}_destroy(t){const s=Object.keys(this.nsps);for(const t of s)if(this.nsps[t].active)return;this._close()}_packet(t){const s=this.encoder.encode(t);for(let i=0;i<s.length;i++)this.engine.write(s[i],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,s){var i;this.cleanup(),null===(i=this.engine)||void 0===i||i.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const s=this.backoff.duration();this._reconnecting=!0;const i=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((s=>{s?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",s)):t.onreconnect()})))}),s);this.opts.autoUnref&&i.unref(),this.subs.push((()=>{this.clearTimeoutFn(i)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const $t={};function Kt(t,s){"object"==typeof t&&(s=t,t=void 0);const i=function(t,s="",i){let e=t;i=i||"undefined"!=typeof location&&location,null==t&&(t=i.protocol+"//"+i.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?i.protocol+t:i.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==i?i.protocol+"//"+t:"https://"+t),e=vt(t)),e.port||(/^(http|ws)$/.test(e.protocol)?e.port="80":/^(http|ws)s$/.test(e.protocol)&&(e.port="443")),e.path=e.path||"/";const n=-1!==e.host.indexOf(":")?"["+e.host+"]":e.host;return e.id=e.protocol+"://"+n+":"+e.port+s,e.href=e.protocol+"://"+n+(i&&i.port===e.port?"":":"+e.port),e}(t,(s=s||{}).path||"/socket.io"),e=i.source,n=i.id;let r;return s.forceNew||s["force new connection"]||!1===s.multiplex||$t[n]&&i.path in $t[n].nsps?r=new Vt(e,s):($t[n]||($t[n]=new Vt(e,s)),r=$t[n]),i.query&&!s.query&&(s.query=i.queryKey),r.socket(i.path,s)}Object.assign(Kt,{Manager:Vt,Socket:Pt,io:Kt,connect:Kt});const Ht={realtime:!1,history:!1,counters:!1,statuses:!1};const qt=(t,s,i,e,n,r)=>{var o,h;const c=f[t];if(void 0===c)throw Error(`Unknown token otype "${t}"`);return{objectType:c,objectId:s,esNumber:null!=i?i:void 0,permissions:n,hasResetContactCapability:!!(null===(o=null==e?void 0:e.commands)||void 0===o?void 0:o.reset_contact),isAdmin:r,liftController:null===(h=null==e?void 0:e.lift_controller)||void 0===h?void 0:h.type}},Wt=t(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.lsSession=i(this,"lsSession",7),this.apiUrl="https://api-gcp-prod.liftstatus.nl",this.store=null,this.computedIdKey=null,this.availableSensorIds=g,this.socketId=null,this.socket=null}syncStoreLocaleFromLanguage(t){null!==this.store&&this.store.set("locale",n(t))}async componentWillLoad(){var t;const s=await this.decodeAccessToken(this.accessToken);if(this.emitSession(s),!s.isValid)return;const{accessToken:i,objectId:e,objectType:a,hasResetContactCapability:u,isAdmin:l,liftController:f}=s;void 0!==f&&d(f,{apiUrl:this.apiUrl,accessToken:i});const p=this.checkHasBackdoor(a,e,i),y=[...new Set(this.availableSensorIds.concat(void 0!==this.sensorIds?this.sensorIds.split(",").filter((t=>""!==t.trim())).map((t=>parseInt(t.trim(),10))):[]))],v=this.getHistoricalData(r().subtract(1,"hour").format(),r().format(),y,a,e,i),b=this.connectToSocketServer(i),[g,O,{connected:A,socket:C}]=await Promise.all([p,v,b]);if(E(g)||E(O)||!A||void 0===C)return;const _=null!==(t=this.idKey)&&void 0!==t?t:`${a}-${e}`;this.computedIdKey=_;const j=this.getCurrentDataFromHistorical(O);o(_,{hasBackDoor:g,historicalSensorData:O,currentSensorData:j,locale:n(this.language),accessToken:i,apiUrl:this.apiUrl,externalIdentifier:e,objectType:a,hasResetContactCapability:u,isAdmin:l});try{this.store=await h(_)}catch(t){this.throwError("STORE_CREATION_FAILED",c.Token,t instanceof Error?t.message:t+"")}m(j.values[k.SensecloudConnectionHealthy])===w.Unhealthy?this.throwError("SENSECLOUD_CONNECTION_FAILED",c.Sensecloud):m(j.values[k.ControllerConnectionHealthy])===w.Unhealthy&&this.throwError("CONTROLLER_CONNECTION_FAILED",c.Controller),this.listenForSensorUpdates(C,_,y)}async decodeAccessToken(t){if(void 0===t||O(t))return this.throwError("NO_ACCESS_TOKEN",c.Token,"Add the token to the <ls-data> component like so: <ls-data access-token='yourToken'></ls-data>"),{isValid:!1,errorKey:"NO_ACCESS_TOKEN"};try{const s=await p({apiUrl:this.apiUrl,accessToken:t});return Object.assign({isValid:!0,accessToken:t},(t=>{var s,i,e,n,r;const o=(t=>{var s,i,e,n,r,o,h;const c=null===(e=null===(i=null===(s=t.response)||void 0===s?void 0:s.permissions)||void 0===i?void 0:i.lift_flow)||void 0===e?void 0:e.data;return"sensecloud"===t.type?{realtime:null===(n=null==c?void 0:c.realtime)||void 0===n||n,history:null===(r=null==c?void 0:c.history)||void 0===r||r,counters:null===(o=null==c?void 0:c.counters)||void 0===o||o,statuses:null===(h=null==c?void 0:c.statuses)||void 0===h||h}:{realtime:!0===(null==c?void 0:c.realtime),history:!0===(null==c?void 0:c.history),counters:!0===(null==c?void 0:c.counters),statuses:!0===(null==c?void 0:c.statuses)}})(t),{target:h}=t;if(null!=h)return qt(h.otype,h.oid,h.es_number,h.capability,o,h.commands);if("liftstatus"===t.type){const{env:i}=t.response,e=null===(s=t.response.lift)||void 0===s?void 0:s.id;if(void 0===i||""===i||void 0===e||""===e)throw Error("LiftStatus session response has no env or lift id");return{objectType:l.External,objectId:`liftstatus-${i}-${e}`,permissions:o,hasResetContactCapability:!1,isAdmin:!1}}return qt(t.tokenData.otype,t.tokenData.oid,null===(i=t.response)||void 0===i?void 0:i.es_number,null===(e=t.response)||void 0===e?void 0:e.capability,o,!0===(null===(r=null===(n=t.response)||void 0===n?void 0:n.permissions)||void 0===r?void 0:r.commands))})(s))}catch(t){return this.throwError("INVALID_ACCESS_TOKEN",c.Token,t instanceof Error?t.message:t+""),{isValid:!1,errorKey:"INVALID_ACCESS_TOKEN"}}}emitSession(t){if(!t.isValid)return void this.lsSession.emit({ok:!1,permissions:Ht,isAdmin:!1,hasResetContactCapability:!1,error:{hasError:!0,messageKey:t.errorKey,type:c.Token}});const s=function(t,s){var i={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&s.indexOf(e)<0&&(i[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)s.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(i[e[n]]=t[e[n]])}return i}(t,["isValid","accessToken","liftController"]);this.lsSession.emit(Object.assign({ok:!0},s))}async checkHasBackdoor(t,s,i){const e=r().subtract(7,"day").format();try{const n=await y({apiUrl:this.apiUrl,accessToken:i,objectType:t,objectId:s,sensorId:k.DoorMovementCounterRear,from:e});if(0===n.rows.length)return!1;const{start:r,end:o}=n.rows[0];return void 0===r||void 0===o||o-r!=0}catch(t){this.throwError("BACK_DOOR_CHECK_FAILED",c.API,t instanceof Error?t.message:t+"")}}async getHistoricalData(t,s,i,e,n,r){try{return await v({apiUrl:this.apiUrl,accessToken:r,objectType:e,objectId:n,from:t,to:s,sensors:i})}catch(t){this.throwError("HISTORIC_DATA_FAILED",c.API,t instanceof Error?t.message:t+"")}}connectToSocketServer(t){return O(this.socketId)||this.closeSocketConnection(),new Promise((s=>{const i=Kt(this.apiUrl,{transports:["websocket"],path:"/liftstatus/socket.io",reconnectionAttempts:5,query:{access_token:t}});this.socket=i;let e=!1;const n=t=>{e||this.socket!==i||(e=!0,clearTimeout(r),i.close(),this.throwError("SOCKET_CONNECTION_FAILED",c.Socket,t,i),s({connected:!1}))},r=setTimeout((()=>{n("No connection within 20 s")}),2e4);i.on("connect",(()=>{e=!0,clearTimeout(r),s({connected:!0,socket:i})})),i.on("error",(t=>{n(t)})),i.on("connect_error",(t=>{i.active||n(t.message)})),i.io.on("reconnect_failed",(()=>{n("No connection after the reconnection attempts")}))}))}listenForSensorUpdates(t,s,i){t.on("module",(({message:t})=>{const e=t.data,n=A(e)[0],r=parseInt(n,10),o=C(e)[0],h=t.ts,u=m(o);if(r===k.SensecloudConnectionHealthy&&u===w.Unhealthy)this.throwError("SENSECLOUD_CONNECTION_FAILED",c.Sensecloud);else if(r===k.ControllerConnectionHealthy&&u===w.Unhealthy)this.throwError("CONTROLLER_CONNECTION_FAILED",c.Controller);else if((r===k.SensecloudConnectionHealthy||r===k.ControllerConnectionHealthy)&&u===w.Healthy){if(null===this.store)return;const t=this.store.state.currentSensorData.values;(r===k.SensecloudConnectionHealthy&&m(t[k.ControllerConnectionHealthy])===w.Healthy||r===k.ControllerConnectionHealthy&&m(t[k.SensecloudConnectionHealthy])===w.Healthy)&&this.resetError()}if(!i.includes(r)&&r!==k.SensecloudConnectionHealthy&&r!==k.ControllerConnectionHealthy)return;if(null===this.store)return;const{currentSensorData:l}=this.store.state;a({lastUpdate:h,values:Object.assign(Object.assign({},l.values),{[n]:o}),updated:Object.assign(Object.assign({},l.updated),{[n]:h})},s)})),t.emit("listen",{})}getCurrentDataFromHistorical(t){let s=0;const i={},e={};return t.forEach((t=>{const n=t.sensor.id;if(0===t.rows.length)return;const o=t.rows[t.rows.length-1],h=r(o.ts).valueOf();h>s&&(s=h);const c=parseInt(o.val,10);i[n]=isFinite(c)?c:o.val,e[n]=h})),{lastUpdate:s,values:i,updated:e}}async throwError(t,s,i,e){var r,c,a;const u=n(null!==(c=null===(r=this.store)||void 0===r?void 0:r.state.locale)&&void 0!==c?c:this.language),l=b(t,u);if(console.group("%cError%c [LsData] "+l,"color: #DC2626; background-color: #FEF2F2; display: inline-block; padding: 0 4px; border-radius: 2px;",""),O(i)||console.log(i),E(e)||console.log(e),console.groupEnd(),E(this.store)){const t=null!==(a=this.idKey)&&void 0!==a?a:"error";o(t,{locale:u}),this.store=await h(t)}this.store.set("error",{hasError:!0,messageKey:t,type:s})}resetError(){if(E(this.store))return console.warn("[LsData] Cannot reset error: Store is not initialized"),!1;if(this.store.state.error.type!==c.None)try{return this.store.set("error",{hasError:!1,messageKey:void 0,type:c.None}),console.log("%c[LsData]%c "+this.store.t("ui:data.connection_restored"),"color: #059669; background-color: #ECFDF5; display: inline-block; padding: 0 4px; border-radius: 2px;",""),!0}catch(t){return console.error("[LsData] Failed to reset error:",t),!1}}closeSocketConnection(){var t;null===(t=this.socket)||void 0===t||t.close(),this.socket=null,this.socketId=null}disconnectedCallback(){this.closeSocketConnection(),null!==this.computedIdKey&&(u(this.computedIdKey),this.computedIdKey=null)}static get watchers(){return{language:[{syncStoreLocaleFromLanguage:0}]}}},[1,"ls-data",{accessToken:[1,"access-token"],idKey:[1,"id-key"],sensorIds:[1,"sensor-ids"],apiUrl:[1,"api-url"],language:[1]},void 0,{language:[{syncStoreLocaleFromLanguage:0}]}]),Xt=Wt,zt=function(){"undefined"!=typeof customElements&&["ls-data"].forEach((t=>{"ls-data"===t&&(customElements.get(e(t))||customElements.define(e(t),Wt))}))};export{Xt as LsData,zt as defineCustomElement}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as e,g as i,b as t}from"./p-CqIIZZwb.js";export{s as setNonce}from"./p-CqIIZZwb.js";(()=>{const s=import.meta.url,i={};return""!==s&&(i.resourcesUrl=new URL(".",s).href),e(i)})().then((async e=>(await i(),t([["p-04595102",[[257,"ls-3d-scene",{idKey:[1,"id-key"],movementState:[32],currentStop:[32],lastPassedStop:[32],lastUpdate:[32],errorState:[32]},[[9,"resize","scheduleSceneResizeOnWindowResize"]]]]],["p-e86e455e",[[257,"ls-status",{sensorIds:[1,"sensor-ids"],idKey:[1,"id-key"],labelType:[1,"label-type"],sensorIdsArray:[32],errorState:[32],useTwoColumns:[32]}]]],["p-30589dd5",[[257,"ls-counters",{idKey:[1,"id-key"],hideTitle:[4,"hide-title"],hidePeriod:[4,"hide-period"],hideStops:[4,"hide-stops"],hideTotals:[4,"hide-totals"],from:[1],to:[1],dateFormat:[1,"date-format"],dateTimeFormat:[1,"date-time-format"],sensorRows:[32],hasBackDoor:[32],isLoading:[32],isRefreshing:[32],errorState:[32]},null,{from:[{handlePeriodPropChange:0}],to:[{handlePeriodPropChange:0}]}]]],["p-
|
|
1
|
+
import{p as e,g as i,b as t}from"./p-CqIIZZwb.js";export{s as setNonce}from"./p-CqIIZZwb.js";(()=>{const s=import.meta.url,i={};return""!==s&&(i.resourcesUrl=new URL(".",s).href),e(i)})().then((async e=>(await i(),t([["p-04595102",[[257,"ls-3d-scene",{idKey:[1,"id-key"],movementState:[32],currentStop:[32],lastPassedStop:[32],lastUpdate:[32],errorState:[32]},[[9,"resize","scheduleSceneResizeOnWindowResize"]]]]],["p-e86e455e",[[257,"ls-status",{sensorIds:[1,"sensor-ids"],idKey:[1,"id-key"],labelType:[1,"label-type"],sensorIdsArray:[32],errorState:[32],useTwoColumns:[32]}]]],["p-30589dd5",[[257,"ls-counters",{idKey:[1,"id-key"],hideTitle:[4,"hide-title"],hidePeriod:[4,"hide-period"],hideStops:[4,"hide-stops"],hideTotals:[4,"hide-totals"],from:[1],to:[1],dateFormat:[1,"date-format"],dateTimeFormat:[1,"date-time-format"],sensorRows:[32],hasBackDoor:[32],isLoading:[32],isRefreshing:[32],errorState:[32]},null,{from:[{handlePeriodPropChange:0}],to:[{handlePeriodPropChange:0}]}]]],["p-d2a2bc87",[[1,"ls-data",{accessToken:[1,"access-token"],idKey:[1,"id-key"],sensorIds:[1,"sensor-ids"],apiUrl:[1,"api-url"],language:[1]},null,{language:[{syncStoreLocaleFromLanguage:0}]}]]],["p-62c2b6c3",[[257,"ls-date-picker",{idKey:[1,"id-key"],wholeDays:[4,"whole-days"]}]]],["p-2615134f",[[257,"ls-energy-usage",{idKey:[1,"id-key"],hideTitle:[4,"hide-title"],from:[1],to:[1],height:[2],barColor:[1,"bar-color"],rows:[32],isLoading:[32],isRefreshing:[32],errorState:[32]},null,{from:[{handlePeriodPropChange:0}],to:[{handlePeriodPropChange:0}]}]]],["p-6b87d7ce",[[257,"ls-history-swimlane",{idKey:[1,"id-key"],from:[1],to:[1],focusDate:[1,"focus-date"],errorState:[32],isLoading:[32],range:[32]},null,{from:[{onRangeProps:0}],to:[{onRangeProps:0}],focusDate:[{onFocusDate:0}]}]]],["p-f3e9060c",[[257,"ls-recent-stops",{idKey:[1,"id-key"],initialVisibleMinutes:[2,"initial-visible-minutes"],minVisibleMinutes:[2,"min-visible-minutes"],errorState:[32],isLoading:[32]}]]],["p-733e88db",[[1,"ls-reset-steering",{idKey:[1,"id-key"],isResetAvailable:[32],pendingCommand:[32],confirmingCommand:[32],feedback:[32],errorState:[32]}]]],["p-f8701d09",[[257,"ls-status-count",{idKey:[1,"id-key"],impactLevel:[1,"impact-level"],messageCount:[32],isLoading:[32],errorState:[32]}]]],["p-b41161e0",[[257,"ls-status-history",{idKey:[1,"id-key"],hideTitle:[4,"hide-title"],from:[1],to:[1],dateFormat:[1,"date-format"],showSeverityIcons:[4,"show-severity-icons"],pageSize:[2,"page-size"],severityOptions:[1,"severity-options"],entries:[32],isLoading:[32],errorKey:[32],storeErrorKey:[32],severityFilter:[32],nowMs:[32],showClosed:[32],page:[32],selectedDay:[32],selectedEndDay:[32],selectedTimeRange:[32]},null,{severityOptions:[{onSeverityOptionsChange:0}],from:[{onPeriodPropChange:0}],to:[{onPeriodPropChange:0}]}]]],["p-fba515aa",[[257,"ls-status-messages",{hideTitle:[4,"hide-title"],showSeverityIcons:[4,"show-severity-icons"],severityOptions:[1,"severity-options"],dateFormat:[1,"date-format"],idKey:[1,"id-key"],statusMessages:[32],lastChange:[32],statusCodesLoadState:[32],time:[32],errorState:[32]}]]],["p-2b75a7d2",[[257,"ls-swimlane",{sensorIds:[1,"sensor-ids"],idKey:[1,"id-key"],sensorIdsArray:[32],errorState:[32],isLoading:[32]},[[9,"resize","resizeWindow"]]]]],["p-ef76bad7",[[1,"ls-indicator",{sensorId:[2,"sensor-id"],idKey:[1,"id-key"],sensorData:[32]}]]],["p-89b2d1b9",[[257,"ls-status-item",{sensorId:[2,"sensor-id"],idKey:[1,"id-key"],labelType:[1,"label-type"],sensorData:[32],timestamp:[32],errorState:[32]},null,{sensorId:[{watchPropHandler:0}]}]]]],e))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t,e as s}from"./p-CqIIZZwb.js";import{g as i,d as e,m as n,b as r,E as o,u as h,n as c,O as a,T as u}from"./p-Ca9AC73B.js";import{a as l}from"./p-CgCghaxm.js";import{d as f,e as d,c as p}from"./p-CdeZiu7c.js";import{g as y}from"./p-BzZBVh5g.js";import{o as b,g as v,H as g,S as m}from"./p-DFTN3X9p.js";import{i as w}from"./p-DjSNdVAB.js";import{i as k}from"./p-BuFJl4bx.js";import{k as E,v as O}from"./p-GHMPnNk2.js";import"./p-CPEl--Uc.js";const A=Object.create(null);A.open="0",A.close="1",A.ping="2",A.pong="3",A.message="4",A.upgrade="5",A.noop="6";const C=Object.create(null);Object.keys(A).forEach((t=>{C[A[t]]=t}));const j={type:"error",data:"parser error"},_="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),T="function"==typeof ArrayBuffer,N=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,S=({type:t,data:s},i,e)=>_&&s instanceof Blob?i?e(s):D(s,e):T&&(s instanceof ArrayBuffer||N(s))?i?e(s):D(new Blob([s]),e):e(A[t]+(s||"")),D=(t,s)=>{const i=new FileReader;return i.onload=function(){const t=i.result.split(",")[1];s("b"+(t||""))},i.readAsDataURL(t)};function I(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let B;const L="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)L["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(t)]=t;const x="function"==typeof ArrayBuffer,U=(t,s)=>{if("string"!=typeof t)return{type:"message",data:R(t,s)};const i=t.charAt(0);return"b"===i?{type:"message",data:F(t.substring(1),s)}:C[i]?t.length>1?{type:C[i],data:t.substring(1)}:{type:C[i]}:j},F=(t,s)=>{if(x){const i=(t=>{let s,i,e,n,r,o=.75*t.length,h=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const a=new ArrayBuffer(o),u=new Uint8Array(a);for(s=0;s<h;s+=4)i=L[t.charCodeAt(s)],e=L[t.charCodeAt(s+1)],n=L[t.charCodeAt(s+2)],r=L[t.charCodeAt(s+3)],u[c++]=i<<2|e>>4,u[c++]=(15&e)<<4|n>>2,u[c++]=(3&n)<<6|63&r;return a})(t);return R(i,s)}return{base64:!0,data:t}},R=(t,s)=>"blob"===s?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,P=String.fromCharCode(30);let M;function V(t){return t.reduce(((t,s)=>t+s.length),0)}function $(t,s){if(t[0].length===s)return t.shift();const i=new Uint8Array(s);let e=0;for(let n=0;n<s;n++)i[n]=t[0][e++],e===t[0].length&&(t.shift(),e=0);return t.length&&e<t[0].length&&(t[0]=t[0].slice(e)),i}function K(t){if(t)return function(t){for(var s in K.prototype)t[s]=K.prototype[s];return t}(t)}K.prototype.on=K.prototype.addEventListener=function(t,s){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(s),this},K.prototype.once=function(t,s){function i(){this.off(t,i),s.apply(this,arguments)}return i.fn=s,this.on(t,i),this},K.prototype.off=K.prototype.removeListener=K.prototype.removeAllListeners=K.prototype.removeEventListener=function(t,s){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i,e=this._callbacks["$"+t];if(!e)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n=0;n<e.length;n++)if((i=e[n])===s||i.fn===s){e.splice(n,1);break}return 0===e.length&&delete this._callbacks["$"+t],this},K.prototype.emitReserved=K.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var s=new Array(arguments.length-1),i=this._callbacks["$"+t],e=1;e<arguments.length;e++)s[e-1]=arguments[e];if(i){e=0;for(var n=(i=i.slice(0)).length;e<n;++e)i[e].apply(this,s)}return this},K.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},K.prototype.hasListeners=function(t){return!!this.listeners(t).length};const H="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,s)=>s(t,0),q="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function X(t,...s){return s.reduce(((s,i)=>(t.hasOwnProperty(i)&&(s[i]=t[i]),s)),{})}const z=q.setTimeout,W=q.clearTimeout;function J(t,s){s.useNativeTimers?(t.setTimeoutFn=z.bind(q),t.clearTimeoutFn=W.bind(q)):(t.setTimeoutFn=q.setTimeout.bind(q),t.clearTimeoutFn=q.clearTimeout.bind(q))}function Z(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class Q extends Error{constructor(t,s,i){super(t),this.description=s,this.context=i,this.type="TransportError"}}class G extends K{constructor(t){super(),this.writable=!1,J(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,i){return super.emitReserved("error",new Q(t,s,i)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=U(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const s=function(t){let s="";for(let i in t)t.hasOwnProperty(i)&&(s.length&&(s+="&"),s+=encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return s}(t);return s.length?"?"+s:""}}class Y extends G{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",(function(){--t||s()}))),this.writable||(t++,this.once("drain",(function(){--t||s()})))}else s()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,s)=>{const i=t.split(P),e=[];for(let t=0;t<i.length;t++){const n=U(i[t],s);if(e.push(n),"error"===n.type)break}return e})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,s)=>{const i=t.length,e=new Array(i);let n=0;t.forEach(((t,r)=>{S(t,!1,(t=>{e[r]=t,++n===i&&s(e.join(P))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return!1!==this.opts.timestampRequests&&(s[this.opts.timestampParam]=Z()),this.supportsBinary||s.sid||(s.b64=1),this.createUri(t,s)}}let tt=!1;try{tt="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const st=tt;function it(){}class et extends Y{constructor(t){if(super(t),"undefined"!=typeof location){const s="https:"===location.protocol;let i=location.port;i||(i=s?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||i!==t.port}}doWrite(t,s){const i=this.request({method:"POST",data:t});i.on("success",s),i.on("error",((t,s)=>{this.onError("xhr post error",t,s)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,s)=>{this.onError("xhr poll error",t,s)})),this.pollXhr=t}}class nt extends K{constructor(t,s,i){super(),this.createRequest=t,J(this,i),this._opts=i,this._method=i.method||"GET",this._uri=s,this._data=void 0!==i.data?i.data:null,this._create()}_create(){var t;const s=X(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;const i=this._xhr=this.createRequest(s);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&i.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{i.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var t;3===i.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(i.getResponseHeader("set-cookie"))),4===i.readyState&&(200===i.status||1223===i.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof i.status?i.status:0)}),0))},i.send(this._data)}catch(t){return void this.setTimeoutFn((()=>{this._onError(t)}),0)}"undefined"!=typeof document&&(this._index=nt.requestsCount++,nt.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(null!=this._xhr){if(this._xhr.onreadystatechange=it,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete nt.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function rt(){for(let t in nt.requests)nt.requests.hasOwnProperty(t)&&nt.requests[t].abort()}nt.requestsCount=0,nt.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",rt):"function"==typeof addEventListener&&addEventListener("onpagehide"in q?"pagehide":"unload",rt,!1));const ot=function(){const t=ht({xdomain:!1});return t&&null!==t.responseType}();function ht(t){const s=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!s||st))return new XMLHttpRequest}catch(t){}if(!s)try{return new(q[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const ct="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class at extends G{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,i=ct?{}:X(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,i)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=t[s],e=s===t.length-1;S(i,this.supportsBinary,(t=>{try{this.doWrite(i,t)}catch(t){}e&&H((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=Z()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const ut=q.WebSocket||q.MozWebSocket,lt={websocket:class extends at{createSocket(t,s,i){return ct?new ut(t,s,i):s?new ut(t,s):new ut(t)}doWrite(t,s){this.ws.send(s)}},webtransport:class extends G{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((t=>{const s=function(t,s){M||(M=new TextDecoder);const i=[];let e=0,n=-1,r=!1;return new TransformStream({transform(o,h){for(i.push(o);;){if(0===e){if(V(i)<1)break;const t=$(i,1);r=!(128&~t[0]),n=127&t[0],e=n<126?3:126===n?1:2}else if(1===e){if(V(i)<2)break;const t=$(i,2);n=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),e=3}else if(2===e){if(V(i)<8)break;const t=$(i,8),s=new DataView(t.buffer,t.byteOffset,t.length),r=s.getUint32(0);if(r>Math.pow(2,21)-1){h.enqueue(j);break}n=r*Math.pow(2,32)+s.getUint32(4),e=3}else{if(V(i)<n)break;const t=$(i,n);h.enqueue(U(r?t:M.decode(t),s)),e=0}if(0===n||n>t){h.enqueue(j);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=t.readable.pipeThrough(s).getReader(),e=new TransformStream({transform(t,s){!function(t,s){_&&t.data instanceof Blob?t.data.arrayBuffer().then(I).then(s):T&&(t.data instanceof ArrayBuffer||N(t.data))?s(I(t.data)):S(t,!1,(t=>{B||(B=new TextEncoder),s(B.encode(t))}))}(t,(i=>{const e=i.length;let n;if(e<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,e);else if(e<65536){n=new Uint8Array(3);const t=new DataView(n.buffer);t.setUint8(0,126),t.setUint16(1,e)}else{n=new Uint8Array(9);const t=new DataView(n.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(e))}t.data&&"string"!=typeof t.data&&(n[0]|=128),s.enqueue(n),s.enqueue(i)}))}});e.readable.pipeTo(t.writable),this._writer=e.writable.getWriter();const n=()=>{i.read().then((({done:t,value:s})=>{t||(this.onPacket(s),n())})).catch((()=>{}))};n();const r={type:"open"};this.query.sid&&(r.data=`{"sid":"${this.query.sid}"}`),this._writer.write(r).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=s===t.length-1;this._writer.write(t[s]).then((()=>{i&&H((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends et{constructor(t){super(t),this.supportsBinary=ot&&!(t&&t.forceBase64)}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new nt(ht,this.uri(),t)}}},ft=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,dt=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function pt(t){if(t.length>8e3)throw"URI too long";const s=t,i=t.indexOf("["),e=t.indexOf("]");-1!=i&&-1!=e&&(t=t.substring(0,i)+t.substring(i,e).replace(/:/g,";")+t.substring(e,t.length));let n=ft.exec(t||""),r={},o=14;for(;o--;)r[dt[o]]=n[o]||"";return-1!=i&&-1!=e&&(r.source=s,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,s){const i=s.replace(/\/{2,9}/g,"/").split("/");return"/"!=s.slice(0,1)&&0!==s.length||i.splice(0,1),"/"==s.slice(-1)&&i.splice(i.length-1,1),i}(0,r.path),r.queryKey=function(t,s){const i={};return s.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,s,e){s&&(i[s]=e)})),i}(0,r.query),r}const yt="function"==typeof addEventListener&&"function"==typeof removeEventListener,bt=[];yt&&addEventListener("offline",(()=>{bt.forEach((t=>t()))}),!1);let vt=class t extends K{constructor(t,s={}){var i,e;if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._upgrades=[],this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(s=t,t=null),t){const i=pt(t);s.hostname=i.host,s.secure="https"===i.protocol||"wss"===i.protocol,s.port=i.port,i.query&&(s.query=i.query)}else s.host&&(s.hostname=pt(s.host).host);if(J(this,s),this.secure=null!=s.secure?s.secure:"undefined"!=typeof location&&"https:"===location.protocol,s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=s.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),s.transportImplementations&&s.transports)throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");s.transportImplementations||(null===(i=s.transports)||void 0===i?void 0:i.length)&&"function"==typeof s.transports[0]?(this.transports=[],this._transportsByName=Object.create(null),(null!==(e=s.transportImplementations)&&void 0!==e?e:s.transports).forEach((t=>{const s=t.prototype.name;this.transports.push(s),this._transportsByName[s]=t}))):(this.transports=s.transports?[...s.transports]:["polling","websocket","webtransport"],this._transportsByName=lt),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let s={},i=t.split("&");for(let t=0,e=i.length;t<e;t++){let e=i[t].split("=");s[decodeURIComponent(e[0])]=decodeURIComponent(e[1])}return s}(this.opts.query)),yt&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},bt.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=4,s.transport=t,this.id&&(s.sid=this.id);const i=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](i)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const s=this.opts.rememberUpgrade&&t.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const i=this.createTransport(s);i.open(),this.setTransport(i)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(t=>this._onClose("transport close",t)))}_probe(s){let i=this.createTransport(s),e=!1;t.priorWebsocketSuccess=!1;const n=()=>{e||(i.send([{type:"ping",data:"probe"}]),i.once("packet",(s=>{if(!e)if("pong"===s.type&&"probe"===s.data){if(this.upgrading=!0,this.emitReserved("upgrading",i),!i)return;t.priorWebsocketSuccess="websocket"===i.name,this.transport.pause((()=>{e||"closed"!==this.readyState&&(u(),this.setTransport(i),i.send([{type:"upgrade"}]),this.emitReserved("upgrade",i),i=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=i.name,this.emitReserved("upgradeError",t)}})))};function r(){e||(e=!0,u(),i.close(),i=null)}const o=t=>{const s=new Error("probe error: "+t);s.transport=i.name,r(),this.emitReserved("upgradeError",s)};function h(){o("transport closed")}function c(){o("socket closed")}function a(t){i&&t.name!==i.name&&r()}const u=()=>{i.removeListener("open",n),i.removeListener("error",o),i.removeListener("close",h),this.off("close",c),this.off("upgrading",a)};i.once("open",n),i.once("error",o),i.once("close",h),this.once("close",c),this.once("upgrading",a),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==s?this.setTimeoutFn((()=>{e||i.open()}),200):i.open()}onOpen(){if(this.readyState="open",t.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const s=new Error("server error");s.code=t.data,this._onError(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._upgrades=this._filterUpgrades(t.upgrades),this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let i=0;i<this.writeBuffer.length;i++){const e=this.writeBuffer[i].data;if(e&&(t+="string"==typeof(s=e)?function(t){let s=0,i=0;for(let e=0,n=t.length;e<n;e++)s=t.charCodeAt(e),s<128?i+=1:s<2048?i+=2:s<55296||s>=57344?i+=3:(e++,i+=4);return i}(s):Math.ceil(1.33*(s.byteLength||s.size))),i>0&&t>this._maxPayload)return this.writeBuffer.slice(0,i);t+=2}var s;return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,H((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),t}write(t,s,i){return this._sendPacket("message",t,s,i),this}send(t,s,i){return this._sendPacket("message",t,s,i),this}_sendPacket(t,s,i,e){if("function"==typeof s&&(e=s,s=void 0),"function"==typeof i&&(e=i,i=null),"closing"===this.readyState||"closed"===this.readyState)return;(i=i||{}).compress=!1!==i.compress;const n={type:t,data:s,options:i};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),e&&this.once("flush",e),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},i=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?i():t()})):this.upgrading?i():t()),this}_onError(s){if(t.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",s),this._onClose("transport error",s)}_onClose(t,s){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),yt&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=bt.indexOf(this._offlineEventListener);-1!==t&&bt.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this._prevBufferLen=0}}_filterUpgrades(t){const s=[];for(let i=0;i<t.length;i++)~this.transports.indexOf(t[i])&&s.push(t[i]);return s}};vt.protocol=4;const gt="function"==typeof ArrayBuffer,mt=Object.prototype.toString,wt="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===mt.call(Blob),kt="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===mt.call(File);function Et(t){return gt&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||wt&&t instanceof Blob||kt&&t instanceof File}function Ot(t,s){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let s=0,i=t.length;s<i;s++)if(Ot(t[s]))return!0;return!1}if(Et(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return Ot(t.toJSON(),!0);for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&Ot(t[s]))return!0;return!1}function At(t){const s=[],i=t;return i.data=Ct(t.data,s),i.attachments=s.length,{packet:i,buffers:s}}function Ct(t,s,i){if(!t)return t;if(Et(t)){const i={_placeholder:!0,num:s.length};return s.push(t),i}if(Array.isArray(t)){const i=new Array(t.length);for(let e=0;e<t.length;e++)i[e]=Ct(t[e],s);return i}if("object"==typeof t&&!(t instanceof Date)){if(t.toJSON&&"function"==typeof t.toJSON&&!i)return Ct(t.toJSON(),s,!0);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=Ct(t[i],s));return e}return t}function jt(t,s){return t.data=_t(t.data,s),delete t.attachments,t}function _t(t,s){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<s.length)return s[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let i=0;i<t.length;i++)t[i]=_t(t[i],s);else if("object"==typeof t)for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(t[i]=_t(t[i],s));return t}const Tt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Nt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Nt||(Nt={}));class St extends K{constructor(t){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},"function"==typeof t?{reviver:t}:t)}add(t){let s;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(t);const i=s.type===Nt.BINARY_EVENT;i||s.type===Nt.BINARY_ACK?(s.type=i?Nt.EVENT:Nt.ACK,this.reconstructor=new Dt(s)):super.emitReserved("decoded",s)}else{if(!Et(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");s=this.reconstructor.takeBinaryData(t),s&&(this.reconstructor=null,super.emitReserved("decoded",s))}}decodeString(t){let s=0;const i={type:Number(t.charAt(0))};if(void 0===Nt[i.type])throw new Error("unknown packet type "+i.type);if(i.type===Nt.BINARY_EVENT||i.type===Nt.BINARY_ACK){const e=s+1;for(;"-"!==t.charAt(++s)&&s!=t.length;);const n=t.substring(e,s);if(n!=Number(n)||"-"!==t.charAt(s))throw new Error("Illegal attachments");const r=Number(n);if(!It(r)||r<1)throw new Error("Illegal attachments");if(r>this.opts.maxAttachments)throw new Error("too many attachments");i.attachments=r}if("/"===t.charAt(s+1)){const e=s+1;for(;++s&&","!==t.charAt(s)&&s!==t.length;);i.nsp=t.substring(e,s)}else i.nsp="/";const e=t.charAt(s+1);if(""!==e&&Number(e)==e){const e=s+1;for(;++s;){const i=t.charAt(s);if(null==i||Number(i)!=i){--s;break}if(s===t.length)break}i.id=Number(t.substring(e,s+1))}if(t.charAt(++s)){const e=this.tryParse(t.substr(s));if(!St.isPayloadValid(i.type,e))throw new Error("invalid payload");i.data=e}return i}tryParse(t){try{return JSON.parse(t,this.opts.reviver)}catch(t){return!1}}static isPayloadValid(t,s){switch(t){case Nt.CONNECT:return Bt(s);case Nt.DISCONNECT:return void 0===s;case Nt.CONNECT_ERROR:return"string"==typeof s||Bt(s);case Nt.EVENT:case Nt.BINARY_EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===Tt.indexOf(s[0]));case Nt.ACK:case Nt.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Dt{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=jt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const It=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function Bt(t){return"[object Object]"===Object.prototype.toString.call(t)}var Lt=Object.freeze({__proto__:null,Decoder:St,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==Nt.EVENT&&t.type!==Nt.ACK||!Ot(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Nt.EVENT?Nt.BINARY_EVENT:Nt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let s=""+t.type;return t.type!==Nt.BINARY_EVENT&&t.type!==Nt.BINARY_ACK||(s+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(s+=t.nsp+","),null!=t.id&&(s+=t.id),null!=t.data&&(s+=JSON.stringify(t.data,this.replacer)),s}encodeAsBinary(t){const s=At(t),i=this.encodeAsString(s.packet),e=s.buffers;return e.unshift(i),e}},get PacketType(){return Nt},isPacketValid:function(t){return"string"==typeof t.nsp&&(void 0===(s=t.id)||It(s))&&function(t,s){switch(t){case Nt.CONNECT:return void 0===s||Bt(s);case Nt.DISCONNECT:return void 0===s;case Nt.EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===Tt.indexOf(s[0]));case Nt.ACK:return Array.isArray(s);case Nt.CONNECT_ERROR:return"string"==typeof s||Bt(s);default:return!1}}(t.type,t.data);var s},protocol:5});function xt(t,s,i){return t.on(s,i),function(){t.off(s,i)}}const Ut=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ft extends K{constructor(t,s,i){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=s,i&&i.auth&&(this.auth=i.auth),this._opts=Object.assign({},i),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[xt(t,"open",this.onopen.bind(this)),xt(t,"packet",this.onpacket.bind(this)),xt(t,"error",this.onerror.bind(this)),xt(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...s){var i,e,n;if(Ut.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(s.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;const r={type:Nt.EVENT,data:s,options:{}};if(r.options.compress=!1!==this.flags.compress,"function"==typeof s[s.length-1]){const t=this.ids++,i=s.pop();this._registerAckCallback(t,i),r.id=t}const o=null===(e=null===(i=this.io.engine)||void 0===i?void 0:i.transport)||void 0===e?void 0:e.writable,h=this.connected&&!(null===(n=this.io.engine)||void 0===n?void 0:n._hasPingExpired());return this.flags.volatile&&!o||(h?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,s){var i;const e=null!==(i=this.flags.timeout)&&void 0!==i?i:this._opts.ackTimeout;if(void 0===e)return void(this.acks[t]=s);const n=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let s=0;s<this.sendBuffer.length;s++)this.sendBuffer[s].id===t&&this.sendBuffer.splice(s,1);s.call(this,new Error("operation has timed out"))}),e),r=(...t)=>{this.io.clearTimeoutFn(n),s.apply(this,t)};r.withError=!0,this.acks[t]=r}emitWithAck(t,...s){return new Promise(((i,e)=>{const n=(t,s)=>t?e(t):i(s);n.withError=!0,s.push(n),this.emit(t,...s)}))}_addToQueue(t){let s;"function"==typeof t[t.length-1]&&(s=t.pop());const i={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...e)=>{if(i===this._queue[0])return null!==t?i.tryCount>this._opts.retries&&(this._queue.shift(),s&&s(t)):(this._queue.shift(),s&&s(null,...e)),i.pending=!1,this._drainQueue()})),this._queue.push(i),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const s=this._queue[0];s.pending&&!t||(s.pending=!0,s.tryCount++,this.flags=s.flags,this.emit.apply(this,s.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Nt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,s){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((t=>{if(!this.sendBuffer.some((s=>String(s.id)===t))){const s=this.acks[t];delete this.acks[t],s.withError&&s.call(this,new Error("socket has been disconnected"))}}))}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Nt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Nt.EVENT:case Nt.BINARY_EVENT:this.onevent(t);break;case Nt.ACK:case Nt.BINARY_ACK:this.onack(t);break;case Nt.DISCONNECT:this.ondisconnect();break;case Nt.CONNECT_ERROR:this.destroy();const s=new Error(t.data.message);s.data=t.data.data,this.emitReserved("connect_error",s)}}onevent(t){const s=t.data||[];null!=t.id&&s.push(this.ack(t.id)),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const s=this._anyListeners.slice();for(const i of s)i.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const s=this;let i=!1;return function(...e){i||(i=!0,s.packet({type:Nt.ACK,id:t,data:e}))}}onack(t){const s=this.acks[t.id];"function"==typeof s&&(delete this.acks[t.id],s.withError&&t.data.unshift(null),s.apply(this,t.data))}onconnect(t,s){this.id=t,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Nt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const s=this._anyListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const s=this._anyOutgoingListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const s=this._anyOutgoingListeners.slice();for(const i of s)i.apply(this,t.data)}}}function Rt(t){this.ms=(t=t||{}).min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Rt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var s=Math.random(),i=Math.floor(s*this.jitter*t);t=1&Math.floor(10*s)?t+i:t-i}return 0|Math.min(t,this.max)},Rt.prototype.reset=function(){this.attempts=0},Rt.prototype.setMin=function(t){this.ms=t},Rt.prototype.setMax=function(t){this.max=t},Rt.prototype.setJitter=function(t){this.jitter=t};class Pt extends K{constructor(t,s){var i;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(s=t,t=void 0),(s=s||{}).path=s.path||"/socket.io",this.opts=s,J(this,s),this.reconnection(!1!==s.reconnection),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(i=s.randomizationFactor)&&void 0!==i?i:.5),this.backoff=new Rt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==s.timeout?2e4:s.timeout),this._readyState="closed",this.uri=t;const e=s.parser||Lt;this.encoder=new e.Encoder,this.decoder=new e.Decoder,this._autoConnect=!1!==s.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var s;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(s=this.backoff)||void 0===s||s.setMin(t),this)}randomizationFactor(t){var s;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(s=this.backoff)||void 0===s||s.setJitter(t),this)}reconnectionDelayMax(t){var s;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(s=this.backoff)||void 0===s||s.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new vt(this.uri,this.opts);const s=this.engine,i=this;this._readyState="opening",this.skipReconnect=!1;const e=xt(s,"open",(function(){i.onopen(),t&&t()})),n=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},r=xt(s,"error",n);if(!1!==this._timeout){const t=this.setTimeoutFn((()=>{e(),n(new Error("timeout")),s.close()}),this._timeout);this.opts.autoUnref&&t.unref(),this.subs.push((()=>{this.clearTimeoutFn(t)}))}return this.subs.push(e),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(xt(t,"ping",this.onping.bind(this)),xt(t,"data",this.ondata.bind(this)),xt(t,"error",this.onerror.bind(this)),xt(t,"close",this.onclose.bind(this)),xt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){H((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,s){let i=this.nsps[t];return i?this._autoConnect&&!i.active&&i.connect():(i=new Ft(this,t,s),this.nsps[t]=i),i}_destroy(t){const s=Object.keys(this.nsps);for(const t of s)if(this.nsps[t].active)return;this._close()}_packet(t){const s=this.encoder.encode(t);for(let i=0;i<s.length;i++)this.engine.write(s[i],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,s){var i;this.cleanup(),null===(i=this.engine)||void 0===i||i.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const s=this.backoff.duration();this._reconnecting=!0;const i=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((s=>{s?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",s)):t.onreconnect()})))}),s);this.opts.autoUnref&&i.unref(),this.subs.push((()=>{this.clearTimeoutFn(i)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const Mt={};function Vt(t,s){"object"==typeof t&&(s=t,t=void 0);const i=function(t,s="",i){let e=t;i=i||"undefined"!=typeof location&&location,null==t&&(t=i.protocol+"//"+i.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?i.protocol+t:i.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==i?i.protocol+"//"+t:"https://"+t),e=pt(t)),e.port||(/^(http|ws)$/.test(e.protocol)?e.port="80":/^(http|ws)s$/.test(e.protocol)&&(e.port="443")),e.path=e.path||"/";const n=-1!==e.host.indexOf(":")?"["+e.host+"]":e.host;return e.id=e.protocol+"://"+n+":"+e.port+s,e.href=e.protocol+"://"+n+(i&&i.port===e.port?"":":"+e.port),e}(t,(s=s||{}).path||"/socket.io"),e=i.source,n=i.id;let r;return s.forceNew||s["force new connection"]||!1===s.multiplex||Mt[n]&&i.path in Mt[n].nsps?r=new Pt(e,s):(Mt[n]||(Mt[n]=new Pt(e,s)),r=Mt[n]),i.query&&!s.query&&(s.query=i.queryKey),r.socket(i.path,s)}Object.assign(Vt,{Manager:Pt,Socket:Ft,io:Vt,connect:Vt});const $t=t=>{var s;const i=null===(s=null==t?void 0:t.lift_flow)||void 0===s?void 0:s.data;return{realtime:!0===(null==i?void 0:i.realtime),history:!0===(null==i?void 0:i.history),counters:!0===(null==i?void 0:i.counters),statuses:!0===(null==i?void 0:i.statuses)}},Kt=(t,s,i,e,n,r)=>{var o,h;const c=u[t];if(void 0===c)throw new Error(`Unknown token otype "${t}"`);return{objectType:c,objectId:s,esNumber:null!=i?i:void 0,permissions:$t(n),hasResetContactCapability:Boolean(null===(o=null==e?void 0:e.commands)||void 0===o?void 0:o.reset_contact),isAdmin:r,liftController:null===(h=null==e?void 0:e.lift_controller)||void 0===h?void 0:h.type}},Ht=class{constructor(i){t(this,i),this.lsSession=s(this,"lsSession"),this.apiUrl="https://api-gcp-prod.liftstatus.nl",this.store=null,this.computedIdKey=null,this.availableSensorIds=b,this.socketId=null,this.socket=null}syncStoreLocaleFromLanguage(t){null!==this.store&&this.store.set("locale",i(t))}async componentWillLoad(){var t;const s=await this.decodeAccessToken(this.accessToken);if(this.emitSession(s),!s.isValid)return;const{accessToken:h,objectId:c,objectType:a,hasResetContactCapability:u,isAdmin:f,liftController:d}=s;void 0!==d&&l(d,{apiUrl:this.apiUrl,accessToken:h});const p=this.checkHasBackdoor(a,c,h),y=[...new Set(this.availableSensorIds.concat(void 0!==this.sensorIds?this.sensorIds.split(",").filter((t=>""!==t.trim())).map((t=>parseInt(t.trim(),10))):[]))],b=this.getHistoricalData(e().subtract(1,"hour").format(),e().format(),y,a,c,h),k=this.connectToSocketServer(h),[E,O,{connected:A,socket:C}]=await Promise.all([p,b,k]);if(w(E)||w(O)||!A||void 0===C)return;const j=null!==(t=this.idKey)&&void 0!==t?t:`${a}-${c}`;this.computedIdKey=j;const _=this.getCurrentDataFromHistorical(O);n(j,{hasBackDoor:E,historicalSensorData:O,currentSensorData:_,locale:i(this.language),accessToken:h,apiUrl:this.apiUrl,externalIdentifier:c,objectType:a,hasResetContactCapability:u,isAdmin:f});try{this.store=await r(j)}catch(t){this.throwError("STORE_CREATION_FAILED",o.Token,t instanceof Error?t.message:String(t))}v(_.values[m.SensecloudConnectionHealthy])===g.Unhealthy?this.throwError("SENSECLOUD_CONNECTION_FAILED",o.Sensecloud):v(_.values[m.ControllerConnectionHealthy])===g.Unhealthy&&this.throwError("CONTROLLER_CONNECTION_FAILED",o.Controller),this.listenForSensorUpdates(C,j,y)}async decodeAccessToken(t){if(void 0===t||k(t))return this.throwError("NO_ACCESS_TOKEN",o.Token,"Add the token to the <ls-data> component like so: <ls-data access-token='yourToken'></ls-data>"),{isValid:!1,errorKey:"NO_ACCESS_TOKEN"};try{const s=await f({apiUrl:this.apiUrl,accessToken:t});return Object.assign({isValid:!0,accessToken:t},(t=>{var s,i,e,n;const r=null===(s=t.response)||void 0===s?void 0:s.permissions,{target:o}=t;if(null!=o)return Kt(o.otype,o.oid,o.es_number,o.capability,r,o.commands);if("liftstatus"===t.type){const{env:s}=t.response,e=null===(i=t.response.lift)||void 0===i?void 0:i.id;if(void 0===s||""===s||void 0===e||""===e)throw new Error("LiftStatus session response has no env or lift id");return{objectType:a.External,objectId:`liftstatus-${s}-${e}`,permissions:$t(r),hasResetContactCapability:!1,isAdmin:!1}}return Kt(t.tokenData.otype,t.tokenData.oid,null===(e=t.response)||void 0===e?void 0:e.es_number,null===(n=t.response)||void 0===n?void 0:n.capability,r,!0===(null==r?void 0:r.commands))})(s))}catch(t){return this.throwError("INVALID_ACCESS_TOKEN",o.Token,t instanceof Error?t.message:String(t)),{isValid:!1,errorKey:"INVALID_ACCESS_TOKEN"}}}emitSession(t){if(!t.isValid)return void this.lsSession.emit({ok:!1,permissions:$t(void 0),isAdmin:!1,hasResetContactCapability:!1,error:{hasError:!0,messageKey:t.errorKey,type:o.Token}});const s=function(t,s){var i={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&s.indexOf(e)<0&&(i[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)s.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(i[e[n]]=t[e[n]])}return i}(t,["isValid","accessToken","liftController"]);this.lsSession.emit(Object.assign({ok:!0},s))}async checkHasBackdoor(t,s,i){const n=e().subtract(7,"day").format();try{const e=await d({apiUrl:this.apiUrl,accessToken:i,objectType:t,objectId:s,sensorId:m.DoorMovementCounterRear,from:n});if(0===e.rows.length)return!1;const{start:r,end:o}=e.rows[0];return void 0===r||void 0===o||o-r!=0}catch(t){this.throwError("BACK_DOOR_CHECK_FAILED",o.API,t instanceof Error?t.message:String(t))}}async getHistoricalData(t,s,i,e,n,r){try{return await p({apiUrl:this.apiUrl,accessToken:r,objectType:e,objectId:n,from:t,to:s,sensors:i})}catch(t){this.throwError("HISTORIC_DATA_FAILED",o.API,t instanceof Error?t.message:String(t))}}connectToSocketServer(t){return k(this.socketId)||this.closeSocketConnection(),new Promise((s=>{const i=Vt(this.apiUrl,{transports:["websocket"],path:"/liftstatus/socket.io",reconnectionAttempts:5,query:{access_token:t}});this.socket=i;let e=!1;const n=t=>{e||this.socket!==i||(e=!0,clearTimeout(r),i.close(),this.throwError("SOCKET_CONNECTION_FAILED",o.Socket,t,i),s({connected:!1}))},r=setTimeout((()=>{n("No connection within 20 s")}),2e4);i.on("connect",(()=>{e=!0,clearTimeout(r),s({connected:!0,socket:i})})),i.on("error",(t=>{n(t)})),i.on("connect_error",(t=>{i.active||n(t.message)})),i.io.on("reconnect_failed",(()=>{n("No connection after the reconnection attempts")}))}))}listenForSensorUpdates(t,s,i){t.on("module",(({message:t})=>{const e=t.data,n=E(e)[0],r=parseInt(n,10),c=O(e)[0],a=t.ts,u=v(c);if(r===m.SensecloudConnectionHealthy&&u===g.Unhealthy)this.throwError("SENSECLOUD_CONNECTION_FAILED",o.Sensecloud);else if(r===m.ControllerConnectionHealthy&&u===g.Unhealthy)this.throwError("CONTROLLER_CONNECTION_FAILED",o.Controller);else if((r===m.SensecloudConnectionHealthy||r===m.ControllerConnectionHealthy)&&u===g.Healthy){if(null===this.store)return;const t=this.store.state.currentSensorData.values;(r===m.SensecloudConnectionHealthy&&v(t[m.ControllerConnectionHealthy])===g.Healthy||r===m.ControllerConnectionHealthy&&v(t[m.SensecloudConnectionHealthy])===g.Healthy)&&this.resetError()}if(!i.includes(r)&&r!==m.SensecloudConnectionHealthy&&r!==m.ControllerConnectionHealthy)return;if(null===this.store)return;const{currentSensorData:l}=this.store.state;h({lastUpdate:a,values:Object.assign(Object.assign({},l.values),{[n]:c}),updated:Object.assign(Object.assign({},l.updated),{[n]:a})},s)})),t.emit("listen",{})}getCurrentDataFromHistorical(t){let s=0;const i={},n={};return t.forEach((t=>{const r=t.sensor.id;if(0===t.rows.length)return;const o=t.rows[t.rows.length-1],h=e(o.ts).valueOf();h>s&&(s=h);const c=parseInt(o.val,10);i[r]=isFinite(c)?c:o.val,n[r]=h})),{lastUpdate:s,values:i,updated:n}}async throwError(t,s,e,o){var h,c,a;const u=i(null!==(c=null===(h=this.store)||void 0===h?void 0:h.state.locale)&&void 0!==c?c:this.language),l=y(t,u);if(console.group(`%cError%c [LsData] ${l}`,"color: #DC2626; background-color: #FEF2F2; display: inline-block; padding: 0 4px; border-radius: 2px;",""),k(e)||console.log(e),w(o)||console.log(o),console.groupEnd(),w(this.store)){const t=null!==(a=this.idKey)&&void 0!==a?a:"error";n(t,{locale:u}),this.store=await r(t)}this.store.set("error",{hasError:!0,messageKey:t,type:s})}resetError(){if(w(this.store))return console.warn("[LsData] Cannot reset error: Store is not initialized"),!1;if(this.store.state.error.type!==o.None)try{return this.store.set("error",{hasError:!1,messageKey:void 0,type:o.None}),console.log(`%c[LsData]%c ${this.store.t("ui:data.connection_restored")}`,"color: #059669; background-color: #ECFDF5; display: inline-block; padding: 0 4px; border-radius: 2px;",""),!0}catch(t){return console.error("[LsData] Failed to reset error:",t),!1}}closeSocketConnection(){var t;null===(t=this.socket)||void 0===t||t.close(),this.socket=null,this.socketId=null}disconnectedCallback(){this.closeSocketConnection(),null!==this.computedIdKey&&(c(this.computedIdKey),this.computedIdKey=null)}static get watchers(){return{language:[{syncStoreLocaleFromLanguage:0}]}}};export{Ht as ls_data}
|
|
1
|
+
import{r as t,e as s}from"./p-CqIIZZwb.js";import{g as i,d as e,m as n,b as r,E as o,u as h,n as c,O as a,T as u}from"./p-Ca9AC73B.js";import{a as l}from"./p-CgCghaxm.js";import{d as f,e as d,c as p}from"./p-CdeZiu7c.js";import{g as y}from"./p-BzZBVh5g.js";import{o as v,g as b,H as g,S as m}from"./p-DFTN3X9p.js";import{i as w}from"./p-DjSNdVAB.js";import{i as k}from"./p-BuFJl4bx.js";import{k as E,v as O}from"./p-GHMPnNk2.js";import"./p-CPEl--Uc.js";const A=Object.create(null);A.open="0",A.close="1",A.ping="2",A.pong="3",A.message="4",A.upgrade="5",A.noop="6";const C=Object.create(null);Object.keys(A).forEach((t=>{C[A[t]]=t}));const j={type:"error",data:"parser error"},_="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),T="function"==typeof ArrayBuffer,N=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,S=({type:t,data:s},i,e)=>_&&s instanceof Blob?i?e(s):D(s,e):T&&(s instanceof ArrayBuffer||N(s))?i?e(s):D(new Blob([s]),e):e(A[t]+(s||"")),D=(t,s)=>{const i=new FileReader;return i.onload=function(){const t=i.result.split(",")[1];s("b"+(t||""))},i.readAsDataURL(t)};function I(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let B;const L="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)L["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(t)]=t;const x="function"==typeof ArrayBuffer,U=(t,s)=>{if("string"!=typeof t)return{type:"message",data:R(t,s)};const i=t.charAt(0);return"b"===i?{type:"message",data:F(t.substring(1),s)}:C[i]?t.length>1?{type:C[i],data:t.substring(1)}:{type:C[i]}:j},F=(t,s)=>{if(x){const i=(t=>{let s,i,e,n,r,o=.75*t.length,h=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const a=new ArrayBuffer(o),u=new Uint8Array(a);for(s=0;s<h;s+=4)i=L[t.charCodeAt(s)],e=L[t.charCodeAt(s+1)],n=L[t.charCodeAt(s+2)],r=L[t.charCodeAt(s+3)],u[c++]=i<<2|e>>4,u[c++]=(15&e)<<4|n>>2,u[c++]=(3&n)<<6|63&r;return a})(t);return R(i,s)}return{base64:!0,data:t}},R=(t,s)=>"blob"===s?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,P=String.fromCharCode(30);let M;function V(t){return t.reduce(((t,s)=>t+s.length),0)}function $(t,s){if(t[0].length===s)return t.shift();const i=new Uint8Array(s);let e=0;for(let n=0;n<s;n++)i[n]=t[0][e++],e===t[0].length&&(t.shift(),e=0);return t.length&&e<t[0].length&&(t[0]=t[0].slice(e)),i}function K(t){if(t)return function(t){for(var s in K.prototype)t[s]=K.prototype[s];return t}(t)}K.prototype.on=K.prototype.addEventListener=function(t,s){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(s),this},K.prototype.once=function(t,s){function i(){this.off(t,i),s.apply(this,arguments)}return i.fn=s,this.on(t,i),this},K.prototype.off=K.prototype.removeListener=K.prototype.removeAllListeners=K.prototype.removeEventListener=function(t,s){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i,e=this._callbacks["$"+t];if(!e)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n=0;n<e.length;n++)if((i=e[n])===s||i.fn===s){e.splice(n,1);break}return 0===e.length&&delete this._callbacks["$"+t],this},K.prototype.emitReserved=K.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var s=new Array(arguments.length-1),i=this._callbacks["$"+t],e=1;e<arguments.length;e++)s[e-1]=arguments[e];if(i){e=0;for(var n=(i=i.slice(0)).length;e<n;++e)i[e].apply(this,s)}return this},K.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},K.prototype.hasListeners=function(t){return!!this.listeners(t).length};const H="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,s)=>s(t,0),q="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function X(t,...s){return s.reduce(((s,i)=>(t.hasOwnProperty(i)&&(s[i]=t[i]),s)),{})}const z=q.setTimeout,W=q.clearTimeout;function J(t,s){s.useNativeTimers?(t.setTimeoutFn=z.bind(q),t.clearTimeoutFn=W.bind(q)):(t.setTimeoutFn=q.setTimeout.bind(q),t.clearTimeoutFn=q.clearTimeout.bind(q))}function Z(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class Q extends Error{constructor(t,s,i){super(t),this.description=s,this.context=i,this.type="TransportError"}}class G extends K{constructor(t){super(),this.writable=!1,J(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,s,i){return super.emitReserved("error",new Q(t,s,i)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const s=U(t,this.socket.binaryType);this.onPacket(s)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,s={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const s=function(t){let s="";for(let i in t)t.hasOwnProperty(i)&&(s.length&&(s+="&"),s+=encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return s}(t);return s.length?"?"+s:""}}class Y extends G{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const s=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",(function(){--t||s()}))),this.writable||(t++,this.once("drain",(function(){--t||s()})))}else s()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,s)=>{const i=t.split(P),e=[];for(let t=0;t<i.length;t++){const n=U(i[t],s);if(e.push(n),"error"===n.type)break}return e})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,s)=>{const i=t.length,e=new Array(i);let n=0;t.forEach(((t,r)=>{S(t,!1,(t=>{e[r]=t,++n===i&&s(e.join(P))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",s=this.query||{};return!1!==this.opts.timestampRequests&&(s[this.opts.timestampParam]=Z()),this.supportsBinary||s.sid||(s.b64=1),this.createUri(t,s)}}let tt=!1;try{tt="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const st=tt;function it(){}class et extends Y{constructor(t){if(super(t),"undefined"!=typeof location){const s="https:"===location.protocol;let i=location.port;i||(i=s?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||i!==t.port}}doWrite(t,s){const i=this.request({method:"POST",data:t});i.on("success",s),i.on("error",((t,s)=>{this.onError("xhr post error",t,s)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,s)=>{this.onError("xhr poll error",t,s)})),this.pollXhr=t}}class nt extends K{constructor(t,s,i){super(),this.createRequest=t,J(this,i),this._opts=i,this._method=i.method||"GET",this._uri=s,this._data=void 0!==i.data?i.data:null,this._create()}_create(){var t;const s=X(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;const i=this._xhr=this.createRequest(s);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&i.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{i.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var t;3===i.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(i.getResponseHeader("set-cookie"))),4===i.readyState&&(200===i.status||1223===i.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof i.status?i.status:0)}),0))},i.send(this._data)}catch(t){return void this.setTimeoutFn((()=>{this._onError(t)}),0)}"undefined"!=typeof document&&(this._index=nt.requestsCount++,nt.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(null!=this._xhr){if(this._xhr.onreadystatechange=it,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete nt.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}function rt(){for(let t in nt.requests)nt.requests.hasOwnProperty(t)&&nt.requests[t].abort()}nt.requestsCount=0,nt.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",rt):"function"==typeof addEventListener&&addEventListener("onpagehide"in q?"pagehide":"unload",rt,!1));const ot=function(){const t=ht({xdomain:!1});return t&&null!==t.responseType}();function ht(t){const s=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!s||st))return new XMLHttpRequest}catch(t){}if(!s)try{return new(q[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const ct="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class at extends G{get name(){return"websocket"}doOpen(){const t=this.uri(),s=this.opts.protocols,i=ct?{}:X(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,s,i)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=t[s],e=s===t.length-1;S(i,this.supportsBinary,(t=>{try{this.doWrite(i,t)}catch(t){}e&&H((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=Z()),this.supportsBinary||(s.b64=1),this.createUri(t,s)}}const ut=q.WebSocket||q.MozWebSocket,lt={websocket:class extends at{createSocket(t,s,i){return ct?new ut(t,s,i):s?new ut(t,s):new ut(t)}doWrite(t,s){this.ws.send(s)}},webtransport:class extends G{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this._transport.ready.then((()=>{this._transport.createBidirectionalStream().then((t=>{const s=function(t,s){M||(M=new TextDecoder);const i=[];let e=0,n=-1,r=!1;return new TransformStream({transform(o,h){for(i.push(o);;){if(0===e){if(V(i)<1)break;const t=$(i,1);r=!(128&~t[0]),n=127&t[0],e=n<126?3:126===n?1:2}else if(1===e){if(V(i)<2)break;const t=$(i,2);n=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),e=3}else if(2===e){if(V(i)<8)break;const t=$(i,8),s=new DataView(t.buffer,t.byteOffset,t.length),r=s.getUint32(0);if(r>Math.pow(2,21)-1){h.enqueue(j);break}n=r*Math.pow(2,32)+s.getUint32(4),e=3}else{if(V(i)<n)break;const t=$(i,n);h.enqueue(U(r?t:M.decode(t),s)),e=0}if(0===n||n>t){h.enqueue(j);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=t.readable.pipeThrough(s).getReader(),e=new TransformStream({transform(t,s){!function(t,s){_&&t.data instanceof Blob?t.data.arrayBuffer().then(I).then(s):T&&(t.data instanceof ArrayBuffer||N(t.data))?s(I(t.data)):S(t,!1,(t=>{B||(B=new TextEncoder),s(B.encode(t))}))}(t,(i=>{const e=i.length;let n;if(e<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,e);else if(e<65536){n=new Uint8Array(3);const t=new DataView(n.buffer);t.setUint8(0,126),t.setUint16(1,e)}else{n=new Uint8Array(9);const t=new DataView(n.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(e))}t.data&&"string"!=typeof t.data&&(n[0]|=128),s.enqueue(n),s.enqueue(i)}))}});e.readable.pipeTo(t.writable),this._writer=e.writable.getWriter();const n=()=>{i.read().then((({done:t,value:s})=>{t||(this.onPacket(s),n())})).catch((()=>{}))};n();const r={type:"open"};this.query.sid&&(r.data=`{"sid":"${this.query.sid}"}`),this._writer.write(r).then((()=>this.onOpen()))}))}))}write(t){this.writable=!1;for(let s=0;s<t.length;s++){const i=s===t.length-1;this._writer.write(t[s]).then((()=>{i&&H((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends et{constructor(t){super(t),this.supportsBinary=ot&&!(t&&t.forceBase64)}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new nt(ht,this.uri(),t)}}},ft=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,dt=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function pt(t){if(t.length>8e3)throw"URI too long";const s=t,i=t.indexOf("["),e=t.indexOf("]");-1!=i&&-1!=e&&(t=t.substring(0,i)+t.substring(i,e).replace(/:/g,";")+t.substring(e,t.length));let n=ft.exec(t||""),r={},o=14;for(;o--;)r[dt[o]]=n[o]||"";return-1!=i&&-1!=e&&(r.source=s,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,s){const i=s.replace(/\/{2,9}/g,"/").split("/");return"/"!=s.slice(0,1)&&0!==s.length||i.splice(0,1),"/"==s.slice(-1)&&i.splice(i.length-1,1),i}(0,r.path),r.queryKey=function(t,s){const i={};return s.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,s,e){s&&(i[s]=e)})),i}(0,r.query),r}const yt="function"==typeof addEventListener&&"function"==typeof removeEventListener,vt=[];yt&&addEventListener("offline",(()=>{vt.forEach((t=>t()))}),!1);let bt=class t extends K{constructor(t,s={}){var i,e;if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._upgrades=[],this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(s=t,t=null),t){const i=pt(t);s.hostname=i.host,s.secure="https"===i.protocol||"wss"===i.protocol,s.port=i.port,i.query&&(s.query=i.query)}else s.host&&(s.hostname=pt(s.host).host);if(J(this,s),this.secure=null!=s.secure?s.secure:"undefined"!=typeof location&&"https:"===location.protocol,s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=s.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),s.transportImplementations&&s.transports)throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");s.transportImplementations||(null===(i=s.transports)||void 0===i?void 0:i.length)&&"function"==typeof s.transports[0]?(this.transports=[],this._transportsByName=Object.create(null),(null!==(e=s.transportImplementations)&&void 0!==e?e:s.transports).forEach((t=>{const s=t.prototype.name;this.transports.push(s),this._transportsByName[s]=t}))):(this.transports=s.transports?[...s.transports]:["polling","websocket","webtransport"],this._transportsByName=lt),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let s={},i=t.split("&");for(let t=0,e=i.length;t<e;t++){let e=i[t].split("=");s[decodeURIComponent(e[0])]=decodeURIComponent(e[1])}return s}(this.opts.query)),yt&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},vt.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const s=Object.assign({},this.opts.query);s.EIO=4,s.transport=t,this.id&&(s.sid=this.id);const i=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](i)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const s=this.opts.rememberUpgrade&&t.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const i=this.createTransport(s);i.open(),this.setTransport(i)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",(t=>this._onClose("transport close",t)))}_probe(s){let i=this.createTransport(s),e=!1;t.priorWebsocketSuccess=!1;const n=()=>{e||(i.send([{type:"ping",data:"probe"}]),i.once("packet",(s=>{if(!e)if("pong"===s.type&&"probe"===s.data){if(this.upgrading=!0,this.emitReserved("upgrading",i),!i)return;t.priorWebsocketSuccess="websocket"===i.name,this.transport.pause((()=>{e||"closed"!==this.readyState&&(u(),this.setTransport(i),i.send([{type:"upgrade"}]),this.emitReserved("upgrade",i),i=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=i.name,this.emitReserved("upgradeError",t)}})))};function r(){e||(e=!0,u(),i.close(),i=null)}const o=t=>{const s=new Error("probe error: "+t);s.transport=i.name,r(),this.emitReserved("upgradeError",s)};function h(){o("transport closed")}function c(){o("socket closed")}function a(t){i&&t.name!==i.name&&r()}const u=()=>{i.removeListener("open",n),i.removeListener("error",o),i.removeListener("close",h),this.off("close",c),this.off("upgrading",a)};i.once("open",n),i.once("error",o),i.once("close",h),this.once("close",c),this.once("upgrading",a),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==s?this.setTimeoutFn((()=>{e||i.open()}),200):i.open()}onOpen(){if(this.readyState="open",t.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const s=new Error("server error");s.code=t.data,this._onError(s);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._upgrades=this._filterUpgrades(t.upgrades),this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let i=0;i<this.writeBuffer.length;i++){const e=this.writeBuffer[i].data;if(e&&(t+="string"==typeof(s=e)?function(t){let s=0,i=0;for(let e=0,n=t.length;e<n;e++)s=t.charCodeAt(e),s<128?i+=1:s<2048?i+=2:s<55296||s>=57344?i+=3:(e++,i+=4);return i}(s):Math.ceil(1.33*(s.byteLength||s.size))),i>0&&t>this._maxPayload)return this.writeBuffer.slice(0,i);t+=2}var s;return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,H((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),t}write(t,s,i){return this._sendPacket("message",t,s,i),this}send(t,s,i){return this._sendPacket("message",t,s,i),this}_sendPacket(t,s,i,e){if("function"==typeof s&&(e=s,s=void 0),"function"==typeof i&&(e=i,i=null),"closing"===this.readyState||"closed"===this.readyState)return;(i=i||{}).compress=!1!==i.compress;const n={type:t,data:s,options:i};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),e&&this.once("flush",e),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},s=()=>{this.off("upgrade",s),this.off("upgradeError",s),t()},i=()=>{this.once("upgrade",s),this.once("upgradeError",s)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?i():t()})):this.upgrading?i():t()),this}_onError(s){if(t.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",s),this._onClose("transport error",s)}_onClose(t,s){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),yt&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=vt.indexOf(this._offlineEventListener);-1!==t&&vt.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,s),this.writeBuffer=[],this._prevBufferLen=0}}_filterUpgrades(t){const s=[];for(let i=0;i<t.length;i++)~this.transports.indexOf(t[i])&&s.push(t[i]);return s}};bt.protocol=4;const gt="function"==typeof ArrayBuffer,mt=Object.prototype.toString,wt="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===mt.call(Blob),kt="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===mt.call(File);function Et(t){return gt&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||wt&&t instanceof Blob||kt&&t instanceof File}function Ot(t,s){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let s=0,i=t.length;s<i;s++)if(Ot(t[s]))return!0;return!1}if(Et(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return Ot(t.toJSON(),!0);for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&Ot(t[s]))return!0;return!1}function At(t){const s=[],i=t;return i.data=Ct(t.data,s),i.attachments=s.length,{packet:i,buffers:s}}function Ct(t,s,i){if(!t)return t;if(Et(t)){const i={_placeholder:!0,num:s.length};return s.push(t),i}if(Array.isArray(t)){const i=new Array(t.length);for(let e=0;e<t.length;e++)i[e]=Ct(t[e],s);return i}if("object"==typeof t&&!(t instanceof Date)){if(t.toJSON&&"function"==typeof t.toJSON&&!i)return Ct(t.toJSON(),s,!0);const e={};for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=Ct(t[i],s));return e}return t}function jt(t,s){return t.data=_t(t.data,s),delete t.attachments,t}function _t(t,s){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<s.length)return s[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let i=0;i<t.length;i++)t[i]=_t(t[i],s);else if("object"==typeof t)for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(t[i]=_t(t[i],s));return t}const Tt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Nt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Nt||(Nt={}));class St extends K{constructor(t){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},"function"==typeof t?{reviver:t}:t)}add(t){let s;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(t);const i=s.type===Nt.BINARY_EVENT;i||s.type===Nt.BINARY_ACK?(s.type=i?Nt.EVENT:Nt.ACK,this.reconstructor=new Dt(s)):super.emitReserved("decoded",s)}else{if(!Et(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");s=this.reconstructor.takeBinaryData(t),s&&(this.reconstructor=null,super.emitReserved("decoded",s))}}decodeString(t){let s=0;const i={type:Number(t.charAt(0))};if(void 0===Nt[i.type])throw new Error("unknown packet type "+i.type);if(i.type===Nt.BINARY_EVENT||i.type===Nt.BINARY_ACK){const e=s+1;for(;"-"!==t.charAt(++s)&&s!=t.length;);const n=t.substring(e,s);if(n!=Number(n)||"-"!==t.charAt(s))throw new Error("Illegal attachments");const r=Number(n);if(!It(r)||r<1)throw new Error("Illegal attachments");if(r>this.opts.maxAttachments)throw new Error("too many attachments");i.attachments=r}if("/"===t.charAt(s+1)){const e=s+1;for(;++s&&","!==t.charAt(s)&&s!==t.length;);i.nsp=t.substring(e,s)}else i.nsp="/";const e=t.charAt(s+1);if(""!==e&&Number(e)==e){const e=s+1;for(;++s;){const i=t.charAt(s);if(null==i||Number(i)!=i){--s;break}if(s===t.length)break}i.id=Number(t.substring(e,s+1))}if(t.charAt(++s)){const e=this.tryParse(t.substr(s));if(!St.isPayloadValid(i.type,e))throw new Error("invalid payload");i.data=e}return i}tryParse(t){try{return JSON.parse(t,this.opts.reviver)}catch(t){return!1}}static isPayloadValid(t,s){switch(t){case Nt.CONNECT:return Bt(s);case Nt.DISCONNECT:return void 0===s;case Nt.CONNECT_ERROR:return"string"==typeof s||Bt(s);case Nt.EVENT:case Nt.BINARY_EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===Tt.indexOf(s[0]));case Nt.ACK:case Nt.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Dt{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=jt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const It=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function Bt(t){return"[object Object]"===Object.prototype.toString.call(t)}var Lt=Object.freeze({__proto__:null,Decoder:St,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==Nt.EVENT&&t.type!==Nt.ACK||!Ot(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===Nt.EVENT?Nt.BINARY_EVENT:Nt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let s=""+t.type;return t.type!==Nt.BINARY_EVENT&&t.type!==Nt.BINARY_ACK||(s+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(s+=t.nsp+","),null!=t.id&&(s+=t.id),null!=t.data&&(s+=JSON.stringify(t.data,this.replacer)),s}encodeAsBinary(t){const s=At(t),i=this.encodeAsString(s.packet),e=s.buffers;return e.unshift(i),e}},get PacketType(){return Nt},isPacketValid:function(t){return"string"==typeof t.nsp&&(void 0===(s=t.id)||It(s))&&function(t,s){switch(t){case Nt.CONNECT:return void 0===s||Bt(s);case Nt.DISCONNECT:return void 0===s;case Nt.EVENT:return Array.isArray(s)&&("number"==typeof s[0]||"string"==typeof s[0]&&-1===Tt.indexOf(s[0]));case Nt.ACK:return Array.isArray(s);case Nt.CONNECT_ERROR:return"string"==typeof s||Bt(s);default:return!1}}(t.type,t.data);var s},protocol:5});function xt(t,s,i){return t.on(s,i),function(){t.off(s,i)}}const Ut=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ft extends K{constructor(t,s,i){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=s,i&&i.auth&&(this.auth=i.auth),this._opts=Object.assign({},i),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[xt(t,"open",this.onopen.bind(this)),xt(t,"packet",this.onpacket.bind(this)),xt(t,"error",this.onerror.bind(this)),xt(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...s){var i,e,n;if(Ut.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(s.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;const r={type:Nt.EVENT,data:s,options:{}};if(r.options.compress=!1!==this.flags.compress,"function"==typeof s[s.length-1]){const t=this.ids++,i=s.pop();this._registerAckCallback(t,i),r.id=t}const o=null===(e=null===(i=this.io.engine)||void 0===i?void 0:i.transport)||void 0===e?void 0:e.writable,h=this.connected&&!(null===(n=this.io.engine)||void 0===n?void 0:n._hasPingExpired());return this.flags.volatile&&!o||(h?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(t,s){var i;const e=null!==(i=this.flags.timeout)&&void 0!==i?i:this._opts.ackTimeout;if(void 0===e)return void(this.acks[t]=s);const n=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let s=0;s<this.sendBuffer.length;s++)this.sendBuffer[s].id===t&&this.sendBuffer.splice(s,1);s.call(this,new Error("operation has timed out"))}),e),r=(...t)=>{this.io.clearTimeoutFn(n),s.apply(this,t)};r.withError=!0,this.acks[t]=r}emitWithAck(t,...s){return new Promise(((i,e)=>{const n=(t,s)=>t?e(t):i(s);n.withError=!0,s.push(n),this.emit(t,...s)}))}_addToQueue(t){let s;"function"==typeof t[t.length-1]&&(s=t.pop());const i={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...e)=>{if(i===this._queue[0])return null!==t?i.tryCount>this._opts.retries&&(this._queue.shift(),s&&s(t)):(this._queue.shift(),s&&s(null,...e)),i.pending=!1,this._drainQueue()})),this._queue.push(i),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const s=this._queue[0];s.pending&&!t||(s.pending=!0,s.tryCount++,this.flags=s.flags,this.emit.apply(this,s.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:Nt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,s){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach((t=>{if(!this.sendBuffer.some((s=>String(s.id)===t))){const s=this.acks[t];delete this.acks[t],s.withError&&s.call(this,new Error("socket has been disconnected"))}}))}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Nt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Nt.EVENT:case Nt.BINARY_EVENT:this.onevent(t);break;case Nt.ACK:case Nt.BINARY_ACK:this.onack(t);break;case Nt.DISCONNECT:this.ondisconnect();break;case Nt.CONNECT_ERROR:this.destroy();const s=new Error(t.data.message);s.data=t.data.data,this.emitReserved("connect_error",s)}}onevent(t){const s=t.data||[];null!=t.id&&s.push(this.ack(t.id)),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const s=this._anyListeners.slice();for(const i of s)i.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const s=this;let i=!1;return function(...e){i||(i=!0,s.packet({type:Nt.ACK,id:t,data:e}))}}onack(t){const s=this.acks[t.id];"function"==typeof s&&(delete this.acks[t.id],s.withError&&t.data.unshift(null),s.apply(this,t.data))}onconnect(t,s){this.id=t,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Nt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const s=this._anyListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const s=this._anyOutgoingListeners;for(let i=0;i<s.length;i++)if(t===s[i])return s.splice(i,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const s=this._anyOutgoingListeners.slice();for(const i of s)i.apply(this,t.data)}}}function Rt(t){this.ms=(t=t||{}).min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Rt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var s=Math.random(),i=Math.floor(s*this.jitter*t);t=1&Math.floor(10*s)?t+i:t-i}return 0|Math.min(t,this.max)},Rt.prototype.reset=function(){this.attempts=0},Rt.prototype.setMin=function(t){this.ms=t},Rt.prototype.setMax=function(t){this.max=t},Rt.prototype.setJitter=function(t){this.jitter=t};class Pt extends K{constructor(t,s){var i;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(s=t,t=void 0),(s=s||{}).path=s.path||"/socket.io",this.opts=s,J(this,s),this.reconnection(!1!==s.reconnection),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(i=s.randomizationFactor)&&void 0!==i?i:.5),this.backoff=new Rt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==s.timeout?2e4:s.timeout),this._readyState="closed",this.uri=t;const e=s.parser||Lt;this.encoder=new e.Encoder,this.decoder=new e.Decoder,this._autoConnect=!1!==s.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var s;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(s=this.backoff)||void 0===s||s.setMin(t),this)}randomizationFactor(t){var s;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(s=this.backoff)||void 0===s||s.setJitter(t),this)}reconnectionDelayMax(t){var s;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(s=this.backoff)||void 0===s||s.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new bt(this.uri,this.opts);const s=this.engine,i=this;this._readyState="opening",this.skipReconnect=!1;const e=xt(s,"open",(function(){i.onopen(),t&&t()})),n=s=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",s),t?t(s):this.maybeReconnectOnOpen()},r=xt(s,"error",n);if(!1!==this._timeout){const t=this.setTimeoutFn((()=>{e(),n(new Error("timeout")),s.close()}),this._timeout);this.opts.autoUnref&&t.unref(),this.subs.push((()=>{this.clearTimeoutFn(t)}))}return this.subs.push(e),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(xt(t,"ping",this.onping.bind(this)),xt(t,"data",this.ondata.bind(this)),xt(t,"error",this.onerror.bind(this)),xt(t,"close",this.onclose.bind(this)),xt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){H((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,s){let i=this.nsps[t];return i?this._autoConnect&&!i.active&&i.connect():(i=new Ft(this,t,s),this.nsps[t]=i),i}_destroy(t){const s=Object.keys(this.nsps);for(const t of s)if(this.nsps[t].active)return;this._close()}_packet(t){const s=this.encoder.encode(t);for(let i=0;i<s.length;i++)this.engine.write(s[i],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,s){var i;this.cleanup(),null===(i=this.engine)||void 0===i||i.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const s=this.backoff.duration();this._reconnecting=!0;const i=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((s=>{s?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",s)):t.onreconnect()})))}),s);this.opts.autoUnref&&i.unref(),this.subs.push((()=>{this.clearTimeoutFn(i)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const Mt={};function Vt(t,s){"object"==typeof t&&(s=t,t=void 0);const i=function(t,s="",i){let e=t;i=i||"undefined"!=typeof location&&location,null==t&&(t=i.protocol+"//"+i.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?i.protocol+t:i.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==i?i.protocol+"//"+t:"https://"+t),e=pt(t)),e.port||(/^(http|ws)$/.test(e.protocol)?e.port="80":/^(http|ws)s$/.test(e.protocol)&&(e.port="443")),e.path=e.path||"/";const n=-1!==e.host.indexOf(":")?"["+e.host+"]":e.host;return e.id=e.protocol+"://"+n+":"+e.port+s,e.href=e.protocol+"://"+n+(i&&i.port===e.port?"":":"+e.port),e}(t,(s=s||{}).path||"/socket.io"),e=i.source,n=i.id;let r;return s.forceNew||s["force new connection"]||!1===s.multiplex||Mt[n]&&i.path in Mt[n].nsps?r=new Pt(e,s):(Mt[n]||(Mt[n]=new Pt(e,s)),r=Mt[n]),i.query&&!s.query&&(s.query=i.queryKey),r.socket(i.path,s)}Object.assign(Vt,{Manager:Pt,Socket:Ft,io:Vt,connect:Vt});const $t={realtime:!1,history:!1,counters:!1,statuses:!1};const Kt=(t,s,i,e,n,r)=>{var o,h;const c=u[t];if(void 0===c)throw new Error(`Unknown token otype "${t}"`);return{objectType:c,objectId:s,esNumber:null!=i?i:void 0,permissions:n,hasResetContactCapability:Boolean(null===(o=null==e?void 0:e.commands)||void 0===o?void 0:o.reset_contact),isAdmin:r,liftController:null===(h=null==e?void 0:e.lift_controller)||void 0===h?void 0:h.type}},Ht=class{constructor(i){t(this,i),this.lsSession=s(this,"lsSession"),this.apiUrl="https://api-gcp-prod.liftstatus.nl",this.store=null,this.computedIdKey=null,this.availableSensorIds=v,this.socketId=null,this.socket=null}syncStoreLocaleFromLanguage(t){null!==this.store&&this.store.set("locale",i(t))}async componentWillLoad(){var t;const s=await this.decodeAccessToken(this.accessToken);if(this.emitSession(s),!s.isValid)return;const{accessToken:h,objectId:c,objectType:a,hasResetContactCapability:u,isAdmin:f,liftController:d}=s;void 0!==d&&l(d,{apiUrl:this.apiUrl,accessToken:h});const p=this.checkHasBackdoor(a,c,h),y=[...new Set(this.availableSensorIds.concat(void 0!==this.sensorIds?this.sensorIds.split(",").filter((t=>""!==t.trim())).map((t=>parseInt(t.trim(),10))):[]))],v=this.getHistoricalData(e().subtract(1,"hour").format(),e().format(),y,a,c,h),k=this.connectToSocketServer(h),[E,O,{connected:A,socket:C}]=await Promise.all([p,v,k]);if(w(E)||w(O)||!A||void 0===C)return;const j=null!==(t=this.idKey)&&void 0!==t?t:`${a}-${c}`;this.computedIdKey=j;const _=this.getCurrentDataFromHistorical(O);n(j,{hasBackDoor:E,historicalSensorData:O,currentSensorData:_,locale:i(this.language),accessToken:h,apiUrl:this.apiUrl,externalIdentifier:c,objectType:a,hasResetContactCapability:u,isAdmin:f});try{this.store=await r(j)}catch(t){this.throwError("STORE_CREATION_FAILED",o.Token,t instanceof Error?t.message:String(t))}b(_.values[m.SensecloudConnectionHealthy])===g.Unhealthy?this.throwError("SENSECLOUD_CONNECTION_FAILED",o.Sensecloud):b(_.values[m.ControllerConnectionHealthy])===g.Unhealthy&&this.throwError("CONTROLLER_CONNECTION_FAILED",o.Controller),this.listenForSensorUpdates(C,j,y)}async decodeAccessToken(t){if(void 0===t||k(t))return this.throwError("NO_ACCESS_TOKEN",o.Token,"Add the token to the <ls-data> component like so: <ls-data access-token='yourToken'></ls-data>"),{isValid:!1,errorKey:"NO_ACCESS_TOKEN"};try{const s=await f({apiUrl:this.apiUrl,accessToken:t});return Object.assign({isValid:!0,accessToken:t},(t=>{var s,i,e,n,r;const o=(t=>{var s,i,e,n,r,o,h;const c=null===(e=null===(i=null===(s=t.response)||void 0===s?void 0:s.permissions)||void 0===i?void 0:i.lift_flow)||void 0===e?void 0:e.data;return"sensecloud"===t.type?{realtime:null===(n=null==c?void 0:c.realtime)||void 0===n||n,history:null===(r=null==c?void 0:c.history)||void 0===r||r,counters:null===(o=null==c?void 0:c.counters)||void 0===o||o,statuses:null===(h=null==c?void 0:c.statuses)||void 0===h||h}:{realtime:!0===(null==c?void 0:c.realtime),history:!0===(null==c?void 0:c.history),counters:!0===(null==c?void 0:c.counters),statuses:!0===(null==c?void 0:c.statuses)}})(t),{target:h}=t;if(null!=h)return Kt(h.otype,h.oid,h.es_number,h.capability,o,h.commands);if("liftstatus"===t.type){const{env:i}=t.response,e=null===(s=t.response.lift)||void 0===s?void 0:s.id;if(void 0===i||""===i||void 0===e||""===e)throw new Error("LiftStatus session response has no env or lift id");return{objectType:a.External,objectId:`liftstatus-${i}-${e}`,permissions:o,hasResetContactCapability:!1,isAdmin:!1}}return Kt(t.tokenData.otype,t.tokenData.oid,null===(i=t.response)||void 0===i?void 0:i.es_number,null===(e=t.response)||void 0===e?void 0:e.capability,o,!0===(null===(r=null===(n=t.response)||void 0===n?void 0:n.permissions)||void 0===r?void 0:r.commands))})(s))}catch(t){return this.throwError("INVALID_ACCESS_TOKEN",o.Token,t instanceof Error?t.message:String(t)),{isValid:!1,errorKey:"INVALID_ACCESS_TOKEN"}}}emitSession(t){if(!t.isValid)return void this.lsSession.emit({ok:!1,permissions:$t,isAdmin:!1,hasResetContactCapability:!1,error:{hasError:!0,messageKey:t.errorKey,type:o.Token}});const s=function(t,s){var i={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&s.indexOf(e)<0&&(i[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)s.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(i[e[n]]=t[e[n]])}return i}(t,["isValid","accessToken","liftController"]);this.lsSession.emit(Object.assign({ok:!0},s))}async checkHasBackdoor(t,s,i){const n=e().subtract(7,"day").format();try{const e=await d({apiUrl:this.apiUrl,accessToken:i,objectType:t,objectId:s,sensorId:m.DoorMovementCounterRear,from:n});if(0===e.rows.length)return!1;const{start:r,end:o}=e.rows[0];return void 0===r||void 0===o||o-r!=0}catch(t){this.throwError("BACK_DOOR_CHECK_FAILED",o.API,t instanceof Error?t.message:String(t))}}async getHistoricalData(t,s,i,e,n,r){try{return await p({apiUrl:this.apiUrl,accessToken:r,objectType:e,objectId:n,from:t,to:s,sensors:i})}catch(t){this.throwError("HISTORIC_DATA_FAILED",o.API,t instanceof Error?t.message:String(t))}}connectToSocketServer(t){return k(this.socketId)||this.closeSocketConnection(),new Promise((s=>{const i=Vt(this.apiUrl,{transports:["websocket"],path:"/liftstatus/socket.io",reconnectionAttempts:5,query:{access_token:t}});this.socket=i;let e=!1;const n=t=>{e||this.socket!==i||(e=!0,clearTimeout(r),i.close(),this.throwError("SOCKET_CONNECTION_FAILED",o.Socket,t,i),s({connected:!1}))},r=setTimeout((()=>{n("No connection within 20 s")}),2e4);i.on("connect",(()=>{e=!0,clearTimeout(r),s({connected:!0,socket:i})})),i.on("error",(t=>{n(t)})),i.on("connect_error",(t=>{i.active||n(t.message)})),i.io.on("reconnect_failed",(()=>{n("No connection after the reconnection attempts")}))}))}listenForSensorUpdates(t,s,i){t.on("module",(({message:t})=>{const e=t.data,n=E(e)[0],r=parseInt(n,10),c=O(e)[0],a=t.ts,u=b(c);if(r===m.SensecloudConnectionHealthy&&u===g.Unhealthy)this.throwError("SENSECLOUD_CONNECTION_FAILED",o.Sensecloud);else if(r===m.ControllerConnectionHealthy&&u===g.Unhealthy)this.throwError("CONTROLLER_CONNECTION_FAILED",o.Controller);else if((r===m.SensecloudConnectionHealthy||r===m.ControllerConnectionHealthy)&&u===g.Healthy){if(null===this.store)return;const t=this.store.state.currentSensorData.values;(r===m.SensecloudConnectionHealthy&&b(t[m.ControllerConnectionHealthy])===g.Healthy||r===m.ControllerConnectionHealthy&&b(t[m.SensecloudConnectionHealthy])===g.Healthy)&&this.resetError()}if(!i.includes(r)&&r!==m.SensecloudConnectionHealthy&&r!==m.ControllerConnectionHealthy)return;if(null===this.store)return;const{currentSensorData:l}=this.store.state;h({lastUpdate:a,values:Object.assign(Object.assign({},l.values),{[n]:c}),updated:Object.assign(Object.assign({},l.updated),{[n]:a})},s)})),t.emit("listen",{})}getCurrentDataFromHistorical(t){let s=0;const i={},n={};return t.forEach((t=>{const r=t.sensor.id;if(0===t.rows.length)return;const o=t.rows[t.rows.length-1],h=e(o.ts).valueOf();h>s&&(s=h);const c=parseInt(o.val,10);i[r]=isFinite(c)?c:o.val,n[r]=h})),{lastUpdate:s,values:i,updated:n}}async throwError(t,s,e,o){var h,c,a;const u=i(null!==(c=null===(h=this.store)||void 0===h?void 0:h.state.locale)&&void 0!==c?c:this.language),l=y(t,u);if(console.group(`%cError%c [LsData] ${l}`,"color: #DC2626; background-color: #FEF2F2; display: inline-block; padding: 0 4px; border-radius: 2px;",""),k(e)||console.log(e),w(o)||console.log(o),console.groupEnd(),w(this.store)){const t=null!==(a=this.idKey)&&void 0!==a?a:"error";n(t,{locale:u}),this.store=await r(t)}this.store.set("error",{hasError:!0,messageKey:t,type:s})}resetError(){if(w(this.store))return console.warn("[LsData] Cannot reset error: Store is not initialized"),!1;if(this.store.state.error.type!==o.None)try{return this.store.set("error",{hasError:!1,messageKey:void 0,type:o.None}),console.log(`%c[LsData]%c ${this.store.t("ui:data.connection_restored")}`,"color: #059669; background-color: #ECFDF5; display: inline-block; padding: 0 4px; border-radius: 2px;",""),!0}catch(t){return console.error("[LsData] Failed to reset error:",t),!1}}closeSocketConnection(){var t;null===(t=this.socket)||void 0===t||t.close(),this.socket=null,this.socketId=null}disconnectedCallback(){this.closeSocketConnection(),null!==this.computedIdKey&&(c(this.computedIdKey),this.computedIdKey=null)}static get watchers(){return{language:[{syncStoreLocaleFromLanguage:0}]}}};export{Ht as ls_data}
|
|
@@ -4013,6 +4013,38 @@ Object.assign(lookup, {
|
|
|
4013
4013
|
connect: lookup,
|
|
4014
4014
|
});
|
|
4015
4015
|
|
|
4016
|
+
/**
|
|
4017
|
+
* No API route checks `lift_flow`, so these permissions are the only gate on
|
|
4018
|
+
* the pages. A Classic session is denied what it is not explicitly granted.
|
|
4019
|
+
* Sense passes its customer's `lift_flow` through for a JWT, but often sends
|
|
4020
|
+
* none at all; the token is already limited to its own object, so a JWT is
|
|
4021
|
+
* only denied what Sense explicitly denies.
|
|
4022
|
+
*/
|
|
4023
|
+
const getSessionPermissions = (auth) => {
|
|
4024
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
4025
|
+
const data = (_c = (_b = (_a = auth.response) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b.lift_flow) === null || _c === void 0 ? void 0 : _c.data;
|
|
4026
|
+
if (auth.type === 'sensecloud') {
|
|
4027
|
+
return {
|
|
4028
|
+
realtime: (_d = data === null || data === void 0 ? void 0 : data.realtime) !== null && _d !== void 0 ? _d : true,
|
|
4029
|
+
history: (_e = data === null || data === void 0 ? void 0 : data.history) !== null && _e !== void 0 ? _e : true,
|
|
4030
|
+
counters: (_f = data === null || data === void 0 ? void 0 : data.counters) !== null && _f !== void 0 ? _f : true,
|
|
4031
|
+
statuses: (_g = data === null || data === void 0 ? void 0 : data.statuses) !== null && _g !== void 0 ? _g : true,
|
|
4032
|
+
};
|
|
4033
|
+
}
|
|
4034
|
+
return {
|
|
4035
|
+
realtime: (data === null || data === void 0 ? void 0 : data.realtime) === true,
|
|
4036
|
+
history: (data === null || data === void 0 ? void 0 : data.history) === true,
|
|
4037
|
+
counters: (data === null || data === void 0 ? void 0 : data.counters) === true,
|
|
4038
|
+
statuses: (data === null || data === void 0 ? void 0 : data.statuses) === true,
|
|
4039
|
+
};
|
|
4040
|
+
};
|
|
4041
|
+
const NO_SESSION_PERMISSIONS = {
|
|
4042
|
+
realtime: false,
|
|
4043
|
+
history: false,
|
|
4044
|
+
counters: false,
|
|
4045
|
+
statuses: false,
|
|
4046
|
+
};
|
|
4047
|
+
|
|
4016
4048
|
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
4017
4049
|
var t = {};
|
|
4018
4050
|
for (var p in s)
|
|
@@ -4025,17 +4057,6 @@ var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
|
4025
4057
|
}
|
|
4026
4058
|
return t;
|
|
4027
4059
|
};
|
|
4028
|
-
/** Only an explicit `true` grants a permission; a missing one denies it. */
|
|
4029
|
-
const toSessionPermissions = (permissions) => {
|
|
4030
|
-
var _a;
|
|
4031
|
-
const data = (_a = permissions === null || permissions === void 0 ? void 0 : permissions.lift_flow) === null || _a === void 0 ? void 0 : _a.data;
|
|
4032
|
-
return {
|
|
4033
|
-
realtime: (data === null || data === void 0 ? void 0 : data.realtime) === true,
|
|
4034
|
-
history: (data === null || data === void 0 ? void 0 : data.history) === true,
|
|
4035
|
-
counters: (data === null || data === void 0 ? void 0 : data.counters) === true,
|
|
4036
|
-
statuses: (data === null || data === void 0 ? void 0 : data.statuses) === true,
|
|
4037
|
-
};
|
|
4038
|
-
};
|
|
4039
4060
|
const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) => {
|
|
4040
4061
|
var _a, _b;
|
|
4041
4062
|
const objectTypeByOtype = TOKEN_OTYPE_TO_OBJECT_TYPE;
|
|
@@ -4048,7 +4069,7 @@ const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) =>
|
|
|
4048
4069
|
objectType,
|
|
4049
4070
|
objectId: oid,
|
|
4050
4071
|
esNumber: esNumber !== null && esNumber !== void 0 ? esNumber : undefined,
|
|
4051
|
-
permissions
|
|
4072
|
+
permissions,
|
|
4052
4073
|
hasResetContactCapability: Boolean((_a = capability === null || capability === void 0 ? void 0 : capability.commands) === null || _a === void 0 ? void 0 : _a.reset_contact),
|
|
4053
4074
|
isAdmin,
|
|
4054
4075
|
liftController: (_b = capability === null || capability === void 0 ? void 0 : capability.lift_controller) === null || _b === void 0 ? void 0 : _b.type,
|
|
@@ -4067,8 +4088,8 @@ const toAuthTarget = (otype, oid, esNumber, capability, permissions, isAdmin) =>
|
|
|
4067
4088
|
* Either way the token itself is passed on to the API unchanged.
|
|
4068
4089
|
*/
|
|
4069
4090
|
const getAuthTarget = (auth) => {
|
|
4070
|
-
var _a, _b, _c, _d;
|
|
4071
|
-
const permissions = (
|
|
4091
|
+
var _a, _b, _c, _d, _e;
|
|
4092
|
+
const permissions = getSessionPermissions(auth);
|
|
4072
4093
|
const { target } = auth;
|
|
4073
4094
|
if (target != null) {
|
|
4074
4095
|
return toAuthTarget(target.otype, target.oid, target.es_number, target.capability, permissions,
|
|
@@ -4081,20 +4102,20 @@ const getAuthTarget = (auth) => {
|
|
|
4081
4102
|
}
|
|
4082
4103
|
if (auth.type === 'liftstatus') {
|
|
4083
4104
|
const { env } = auth.response;
|
|
4084
|
-
const liftId = (
|
|
4105
|
+
const liftId = (_a = auth.response.lift) === null || _a === void 0 ? void 0 : _a.id;
|
|
4085
4106
|
if (env === undefined || env === '' || liftId === undefined || liftId === '') {
|
|
4086
4107
|
throw new Error('LiftStatus session response has no env or lift id');
|
|
4087
4108
|
}
|
|
4088
4109
|
return {
|
|
4089
4110
|
objectType: ObjectType.External,
|
|
4090
4111
|
objectId: `liftstatus-${env}-${liftId}`,
|
|
4091
|
-
permissions
|
|
4112
|
+
permissions,
|
|
4092
4113
|
hasResetContactCapability: false,
|
|
4093
4114
|
// `permissions.commands` lacks the API's Classic command rules
|
|
4094
4115
|
isAdmin: false,
|
|
4095
4116
|
};
|
|
4096
4117
|
}
|
|
4097
|
-
return toAuthTarget(auth.tokenData.otype, auth.tokenData.oid, (
|
|
4118
|
+
return toAuthTarget(auth.tokenData.otype, auth.tokenData.oid, (_b = auth.response) === null || _b === void 0 ? void 0 : _b.es_number, (_c = auth.response) === null || _c === void 0 ? void 0 : _c.capability, permissions, ((_e = (_d = auth.response) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.commands) === true);
|
|
4098
4119
|
};
|
|
4099
4120
|
// socket.io waits 20 s per attempt for a server that doesn't answer, which adds
|
|
4100
4121
|
// up to about 2 minutes over all retries before the first load would fail
|
|
@@ -4223,7 +4244,7 @@ const LsData = class {
|
|
|
4223
4244
|
if (!auth.isValid) {
|
|
4224
4245
|
this.lsSession.emit({
|
|
4225
4246
|
ok: false,
|
|
4226
|
-
permissions:
|
|
4247
|
+
permissions: NO_SESSION_PERMISSIONS,
|
|
4227
4248
|
isAdmin: false,
|
|
4228
4249
|
hasResetContactCapability: false,
|
|
4229
4250
|
error: {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ILiftStatusAuth, ILiftStatusSessionPermissions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* No API route checks `lift_flow`, so these permissions are the only gate on
|
|
4
|
+
* the pages. A Classic session is denied what it is not explicitly granted.
|
|
5
|
+
* Sense passes its customer's `lift_flow` through for a JWT, but often sends
|
|
6
|
+
* none at all; the token is already limited to its own object, so a JWT is
|
|
7
|
+
* only denied what Sense explicitly denies.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getSessionPermissions: (auth: ILiftStatusAuth) => ILiftStatusSessionPermissions;
|
|
10
|
+
export declare const NO_SESSION_PERMISSIONS: ILiftStatusSessionPermissions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ednl-liftstatus-web-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.63.0",
|
|
4
4
|
"description": "The EDNL LiftStatus web components",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "stencil build --docs",
|
|
27
27
|
"start": "stencil build --dev --watch --serve",
|
|
28
|
-
"test": "
|
|
29
|
-
"test.watch": "
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test.watch": "vitest",
|
|
30
30
|
"generate": "stencil generate",
|
|
31
31
|
"lint": "eslint .",
|
|
32
32
|
"lint:fix": "eslint . --fix",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
63
63
|
"@stencil/eslint-plugin": "^1.4.0",
|
|
64
64
|
"@stencil/store": "^2.2.0",
|
|
65
|
+
"@stencil/vitest": "^1.16.1",
|
|
65
66
|
"@types/d3": "^7.4.3",
|
|
66
67
|
"@types/jest": "^30.0.0",
|
|
67
68
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -83,7 +84,8 @@
|
|
|
83
84
|
"socket.io-client": "^4.8.1",
|
|
84
85
|
"typescript": "5.8.3",
|
|
85
86
|
"typescript-eslint": "^8.71.2",
|
|
86
|
-
"vanillajs-datepicker": "^1.3.4"
|
|
87
|
+
"vanillajs-datepicker": "^1.3.4",
|
|
88
|
+
"vitest": "^5.1.0"
|
|
87
89
|
},
|
|
88
90
|
"optionalDependencies": {
|
|
89
91
|
"@rollup/rollup-linux-x64-gnu": "4.50.1"
|