livedesk 0.1.696 → 0.1.697

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.
@@ -55,14 +55,14 @@
55
55
  .vuvodesk-static-boot [hidden] { display: none; }
56
56
  @keyframes vuvodesk-static-boot-spin { to { transform: rotate(360deg); } }
57
57
  </style>
58
- <script type="module" crossorigin src="/assets/main-CSJAuJm1.js" data-vuvodesk-entry></script>
58
+ <script type="module" crossorigin src="/assets/main-BXBJt96-.js" data-vuvodesk-entry></script>
59
59
  <link rel="modulepreload" crossorigin href="/assets/public-site-routing-pddZbLCj.js">
60
60
  <link rel="modulepreload" crossorigin href="/assets/icons-ChMazCZR.js">
61
61
  <link rel="modulepreload" crossorigin href="/assets/pwa-bootstrap-ljOQTt2e.js">
62
62
  <link rel="modulepreload" crossorigin href="/assets/pwa-startup-BiuYh5eN.js">
63
63
  <link rel="modulepreload" crossorigin href="/assets/react-CnkEM7Rb.js">
64
64
  <link rel="modulepreload" crossorigin href="/assets/client-D-D35ghV.js">
65
- <link rel="modulepreload" crossorigin href="/assets/MonitorStackIcon-CiDB9DkB.js">
65
+ <link rel="modulepreload" crossorigin href="/assets/MonitorStackIcon-led0pnag.js">
66
66
  <link rel="stylesheet" crossorigin href="/assets/main-CVbEVGge.css">
67
67
  <link rel="stylesheet" crossorigin href="/assets/styles-CQz52HHV.css">
68
68
  </head>
package/web/dist/sw.js CHANGED
@@ -1,8 +1,8 @@
1
- const PWA_RELEASE = '0.1.696';
1
+ const PWA_RELEASE = '0.1.697';
2
2
  const PWA_CACHE = `livedesk-pwa-shell-${PWA_RELEASE}`;
3
3
  const OFFLINE_URL = '/offline.html';
4
4
  const PWA_APP_URL = `/app?pwa=${PWA_RELEASE}&shell=${PWA_RELEASE}`;
5
- const PWA_SHELL_ASSETS = ["/assets/app-B234Zxw4.js","/assets/public-site-routing-pddZbLCj.js","/assets/pwa-bootstrap-ljOQTt2e.js","/assets/client-D-D35ghV.js","/assets/icons-ChMazCZR.js","/assets/react-CnkEM7Rb.js","/assets/HubApp-CXzY-toF.js","/assets/pwa-startup-BiuYh5eN.js","/assets/MonitorStackIcon-CiDB9DkB.js","/assets/supabase-C7qjtLN3.js","/assets/frame-lifecycle-D91nchvm.js","/assets/HubApp-DdHHVOM0.css","/assets/styles-CQz52HHV.css"];
5
+ const PWA_SHELL_ASSETS = ["/assets/app-DcrmhmnT.js","/assets/public-site-routing-pddZbLCj.js","/assets/pwa-bootstrap-ljOQTt2e.js","/assets/client-D-D35ghV.js","/assets/icons-ChMazCZR.js","/assets/react-CnkEM7Rb.js","/assets/HubApp-CqNxUVJD.js","/assets/pwa-startup-BiuYh5eN.js","/assets/MonitorStackIcon-led0pnag.js","/assets/supabase-C7qjtLN3.js","/assets/frame-lifecycle-D91nchvm.js","/assets/HubApp-DdHHVOM0.css","/assets/styles-CQz52HHV.css"];
6
6
  const PWA_SHELL_ASSET_PATHS = new Set(PWA_SHELL_ASSETS);
7
7
 
8
8
  self.addEventListener('install', event => {
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "kind": "livedesk-production-web-source-evidence",
4
- "generatedAt": "2026-09-07T07:30:43.132Z",
5
- "pwaRelease": "0.1.696",
6
- "sourceHash": "949b5d2527b4b88e90c4cadcb729372e3703d17b211e4a797c53f029ea93e360",
4
+ "generatedAt": "2026-09-07T09:47:32.269Z",
5
+ "pwaRelease": "0.1.697",
6
+ "sourceHash": "16536727242625cdf7a72d3b87979452576e15c130802ad82e71d21504de7fd2",
7
7
  "sourceFileCount": 234,
8
- "sourceBytes": 4330605,
8
+ "sourceBytes": 4338074,
9
9
  "viteEnvironmentHash": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945",
10
- "outputHash": "dc013c9bee55d356239c4fe7dd31e4c8b4504e2818be65ce9bd48e233590940d",
10
+ "outputHash": "779349b4050ef9ef94019262c263a5b7631aace03d88f09fa0b4402bad07c4bf",
11
11
  "outputFileCount": 49,
12
- "outputBytes": 3183154,
12
+ "outputBytes": 3187422,
13
13
  "outputManifest": [
14
14
  {
15
15
  "path": "_headers",
@@ -19,12 +19,12 @@
19
19
  {
20
20
  "path": "app.html",
21
21
  "bytes": 5915,
22
- "sha256": "1f594516aded0dadce42e300e6dee589c037ac7e26e347f7b425364f94093f39"
22
+ "sha256": "650465182c26f4ec3c9c52aea5e7845fafdc0697762f84920df0bbf81274fc2e"
23
23
  },
24
24
  {
25
25
  "path": "app.webmanifest",
26
26
  "bytes": 841,
27
- "sha256": "feb7913e3a502db256777e8eb18c8184b3f1505e8da1a5f75a2b46c4aaa4102b"
27
+ "sha256": "ffa2bff96cb8b1d0d9ec261583fd42443e1a2a08d0e6904f730e77b9c7679292"
28
28
  },
29
29
  {
30
30
  "path": "apple-touch-icon.png",
@@ -32,14 +32,14 @@
32
32
  "sha256": "0c8f7e411c993a1acaa1c41046b952cf412dbc5ff53b9d5a8fc17158ee1f0520"
33
33
  },
34
34
  {
35
- "path": "assets/AgentSettingsTab-DE87RukW.js",
35
+ "path": "assets/AgentSettingsTab-DRWDCG0o.js",
36
36
  "bytes": 4547,
37
- "sha256": "24ea126db4a5372904e875eea12dfff580e5159305cdaee8655a61b1aa8b38b0"
37
+ "sha256": "781db59dbb313f79dbcd14edaa93734747b9c21e2046e66e15c11390ba65c088"
38
38
  },
39
39
  {
40
- "path": "assets/AgentsPage-CegBXGiy.js",
40
+ "path": "assets/AgentsPage-BnF3p9G1.js",
41
41
  "bytes": 65762,
42
- "sha256": "483112f8f45adbee34ee953431e2ac7126e746d3a77f748875e9b384ddaf311e"
42
+ "sha256": "aaefbdd21d4e34b8ba78c33f5a7047d304765c024e61d7e821b811c81bbc17c4"
43
43
  },
44
44
  {
45
45
  "path": "assets/AgentsPage-D29gvPcH.css",
@@ -47,14 +47,14 @@
47
47
  "sha256": "fe349e23f92e35f98583c791185a73d99b3e9e263d2151b404e3937b0212a4aa"
48
48
  },
49
49
  {
50
- "path": "assets/app-B234Zxw4.js",
50
+ "path": "assets/app-DcrmhmnT.js",
51
51
  "bytes": 2568,
52
- "sha256": "54da45ebe30b5fcee082e2816c7472d3d473474e3e85b7ffd2139330a911e112"
52
+ "sha256": "f11994006308a78afbaadc8d0e20d384cd28841d72591c9e6e3fa030f6a3e292"
53
53
  },
54
54
  {
55
- "path": "assets/CaptureGallery-C9vKLkR_.js",
55
+ "path": "assets/CaptureGallery-8lr9Ct1i.js",
56
56
  "bytes": 2585,
57
- "sha256": "6e9c84d8579c361be50e265a77e036d956430ac8380cd4d91b113cafce52f38a"
57
+ "sha256": "951130a9f4c30e9fe74d6d7cd21ba1f7de066d68aa750e3e8a1f5395d5b3d524"
58
58
  },
59
59
  {
60
60
  "path": "assets/client-D-D35ghV.js",
@@ -77,9 +77,9 @@
77
77
  "sha256": "660bc0e5f758efb204a39602d1c0a7c0701248de64fb95465e8445b7a93d5ce7"
78
78
  },
79
79
  {
80
- "path": "assets/HubApp-CXzY-toF.js",
81
- "bytes": 521273,
82
- "sha256": "1d18e9a9aecd108fded8df0984e11307a814f385aa97405530764e53be013990"
80
+ "path": "assets/HubApp-CqNxUVJD.js",
81
+ "bytes": 521402,
82
+ "sha256": "229fb8723e179601dab7bd27bad3e6631aaabec1cc885c387a33e89b6dc44a07"
83
83
  },
84
84
  {
85
85
  "path": "assets/HubApp-DdHHVOM0.css",
@@ -92,9 +92,9 @@
92
92
  "sha256": "a63091c35460ea8365c50f30a47beadaa9cfa08c6d156d1e53805266c42c01d3"
93
93
  },
94
94
  {
95
- "path": "assets/main-CSJAuJm1.js",
95
+ "path": "assets/main-BXBJt96-.js",
96
96
  "bytes": 34715,
97
- "sha256": "b64ca684e0f088840042d507ab1dbc6e3135c28977952c329392c608c0c54a79"
97
+ "sha256": "860f6ab4798a1004562cca6c39ee9c05f01486fb7da3c963b04f638495b1f6bf"
98
98
  },
99
99
  {
100
100
  "path": "assets/main-CVbEVGge.css",
@@ -102,9 +102,9 @@
102
102
  "sha256": "47e2b17b7a52c1a0c6bfc885706a2107e8af06cc2a484f7cf8ddfb87d202bea0"
103
103
  },
104
104
  {
105
- "path": "assets/MonitorStackIcon-CiDB9DkB.js",
106
- "bytes": 59037,
107
- "sha256": "d86fb6d759ed6c0e9bbefd280e13d5e6e0612714bcd05b8658a7251da6965287"
105
+ "path": "assets/MonitorStackIcon-led0pnag.js",
106
+ "bytes": 63176,
107
+ "sha256": "6fc80d7ba024cab2c6637594770134d865718796ea119ef37c936cd937039c80"
108
108
  },
109
109
  {
110
110
  "path": "assets/public-site-routing-pddZbLCj.js",
@@ -137,9 +137,9 @@
137
137
  "sha256": "9ffcc619bc1785028bd28eaabd19c577d22228f06c0182500dec58a378fe17bc"
138
138
  },
139
139
  {
140
- "path": "assets/SettingsPage-Beec8L9Q.js",
140
+ "path": "assets/SettingsPage-k202bRU1.js",
141
141
  "bytes": 10189,
142
- "sha256": "eb7a7bad471554b171860e28bb0fb57d5b03eb31150864ac714db51a9fd25f96"
142
+ "sha256": "eb29eaab0a06c8baed443ed311fad0e79592f1eaba37ec2e789abe2691b75444"
143
143
  },
144
144
  {
145
145
  "path": "assets/SettingsTabs-v57M-CCZ.js",
@@ -152,9 +152,9 @@
152
152
  "sha256": "8eed16509e17695b37a28790e25e12f8a00a50b8f5fcc11c5c68fae0687c9c98"
153
153
  },
154
154
  {
155
- "path": "assets/ShareFilesPage-DCbC6-YF.js",
155
+ "path": "assets/ShareFilesPage-DRW1qS1Z.js",
156
156
  "bytes": 188712,
157
- "sha256": "cf6203a7dc197c86057c870258c7fb87852ba5348025c4b3c6e7311f581272b7"
157
+ "sha256": "51788a7354fd3b45f26982573f1ed4c7b350fd8d2b5c6b3f369b39b0cb382cd3"
158
158
  },
159
159
  {
160
160
  "path": "assets/styles-CQz52HHV.css",
@@ -172,9 +172,9 @@
172
172
  "sha256": "59a383e6d7382973d103d21b4817bd53b124b9fa908c459bf5c418c9e4c88e82"
173
173
  },
174
174
  {
175
- "path": "assets/SupportPage-DruQIvyG.js",
175
+ "path": "assets/SupportPage-DXkBQh_W.js",
176
176
  "bytes": 30733,
177
- "sha256": "741419f3d9c18578084b96fbf588f21d1b6045b5a0108322d86901b80052b1cd"
177
+ "sha256": "372b09672949e1e207e39f28a01a8934dd3ba6042c71b58c482ecb807cddb981"
178
178
  },
179
179
  {
180
180
  "path": "assets/vuvodesk-mobile-wall.jpg",
@@ -192,9 +192,9 @@
192
192
  "sha256": "46b020c1806e59e07b454da8ab61ae111f5835f09b12f6df6364e94d146dbd56"
193
193
  },
194
194
  {
195
- "path": "assets/VuvoDeskApp-D9YNArJ0.js",
195
+ "path": "assets/VuvoDeskApp-BHcF72r3.js",
196
196
  "bytes": 32610,
197
- "sha256": "63f4f914dad6bf85df882f4c4e0b6c99169cfcc5d16f295193354269c779f7ea"
197
+ "sha256": "60f702af5350273ab0670f69fcef43cbe212c3068447c307005d34a5ae9cef82"
198
198
  },
199
199
  {
200
200
  "path": "desktop-auth-callback.html",
@@ -219,7 +219,7 @@
219
219
  {
220
220
  "path": "index.html",
221
221
  "bytes": 7825,
222
- "sha256": "c96afbf8d99c1dead206d3c18d93271d652d21aef9e1a1cf58c396cd4b89a7a9"
222
+ "sha256": "759efba046168ceda9155005bc80ea7541d29c60dee4c6200f0f23bada67a4c8"
223
223
  },
224
224
  {
225
225
  "path": "offline.html",
@@ -254,7 +254,7 @@
254
254
  {
255
255
  "path": "sw.js",
256
256
  "bytes": 3981,
257
- "sha256": "1e466a34ee956dc03e6a25be302671066db1dc4880784ea09ec9f7cc4642d6b3"
257
+ "sha256": "6e5e03ab7f6e381c8f6eef67984c8bc7eea40de88e6bca68f51944945be83505"
258
258
  }
259
259
  ]
260
260
  }
@@ -1,8 +0,0 @@
1
- import{j as M}from"./pwa-startup-BiuYh5eN.js";const W=15e3;function Ne(n,e=W){const t=Number(n),i=Number.isFinite(Number(e))?Number(e):W;return Math.max(250,Math.min(12e4,Math.trunc(Number.isFinite(t)?t:i)))}class fe extends Error{constructor(e){super(`VuvoDesk Hub request timed out after ${e} ms.`),this.name="HubRequestTimeoutError",this.code="livedesk-hub-request-timeout",this.timeoutMs=e}}async function xe(n,e,t){const i=Ne(e),s=new AbortController;let r=!1;const o=()=>{s.signal.aborted||s.abort(n?.reason)};n?.aborted?o():n?.addEventListener("abort",o,{once:!0});const a=setTimeout(()=>{r=!0,s.signal.aborted||s.abort(new fe(i))},i);try{return await t(s.signal)}catch(c){throw r?new fe(i):c}finally{clearTimeout(a),n?.removeEventListener("abort",o)}}function dn(n,e){if(n.current)return n.current;const t=Promise.resolve().then(e);return n.current=t,t.finally(()=>{n.current===t&&(n.current=null)}).catch(()=>{}),t}const oe=16*1024,k=6*1024*1024,We=12*1024*1024,A=24,D=oe-A,Le=1,Be=2,pe=32,Z=4294967295,ee=Symbol("direct-console-wire-budget-reserve"),te=Object.freeze([76,68,67,87]),ve=Object.freeze({control:1,text:2,binary:3}),Ue=Object.freeze({1:"control",2:"text",3:"binary"});class B extends Error{constructor(e,t=void 0){super(String(e||"direct-console-wire-error")),this.name="DirectConsoleWireError",this.code=String(e||"direct-console-wire-error"),t!==void 0&&(this.details=t)}}function f(n,e=void 0){throw new B(n,e)}function ae(n,e){return n===void 0?{}:((!n||typeof n!="object"||Array.isArray(n))&&f(`${e}-options-invalid`),n)}function F(n,e,t,i){const s=Number(n);return(!Number.isInteger(s)||s<t||s>i)&&f(e),s}function ye(n){return n===void 0?k:F(n,"max-message-bytes-invalid",1,Z)}function He(n,e){const t=n===void 0?e?"text":"binary":String(n);return Object.hasOwn(ve,t)||f("message-kind-invalid"),e&&t==="binary"&&f("binary-message-requires-bytes"),!e&&t!=="binary"&&f(`${t}-message-requires-text`),t}function Fe(n){if(typeof n=="string")return{bytes:new TextEncoder().encode(n),isText:!0};if(n instanceof Uint8Array)return{bytes:n,isText:!1};if(n instanceof ArrayBuffer)return{bytes:new Uint8Array(n),isText:!1};f("message-payload-invalid")}function qe(n){if(n instanceof Uint8Array)return n;if(n instanceof ArrayBuffer)return new Uint8Array(n);f("wire-chunk-type-invalid")}function Ge(n,{kind:e,messageId:t,chunkIndex:i,chunkCount:s,totalLength:r}){n.set(te,0);const o=new DataView(n.buffer,n.byteOffset,A);o.setUint8(4,Le),o.setUint8(5,ve[e]),o.setUint16(6,0,!1),o.setUint32(8,t,!1),o.setUint32(12,i,!1),o.setUint32(16,s,!1),o.setUint32(20,r,!1)}function je(n,e){const t=qe(n);(t.byteLength<A||t.byteLength>oe)&&f("wire-chunk-length-invalid");for(let w=0;w<te.length;w+=1)t[w]!==te[w]&&f("wire-magic-invalid");const i=new DataView(t.buffer,t.byteOffset,A);i.getUint8(4)!==Le&&f("wire-version-invalid");const s=Ue[i.getUint8(5)];s||f("wire-kind-invalid"),i.getUint16(6,!1)!==0&&f("wire-reserved-invalid");const r=i.getUint32(8,!1),o=i.getUint32(12,!1),a=i.getUint32(16,!1),c=i.getUint32(20,!1);c>e&&f("message-too-large");const u=Math.max(1,Math.ceil(c/D));(a!==u||o>=a)&&f("wire-chunk-layout-invalid");const d=t.byteLength-A,h=o<a-1?D:c-o*D;return d!==h&&f("wire-chunk-layout-invalid"),{bytes:t,kind:s,messageId:r,chunkIndex:o,chunkCount:a,totalLength:c,payloadLength:d}}function ke(n=void 0){const e=ae(n,"budget"),t=e.maxBytes===void 0?We:F(e.maxBytes,"budget-max-bytes-invalid",1,Number.MAX_SAFE_INTEGER);let i=0,s=0;const r=()=>Object.freeze({maxBytes:t,retainedBytes:i,reservationCount:s}),o=a=>{const c=F(a,"budget-reservation-invalid",0,Number.MAX_SAFE_INTEGER);c>t-i&&f("shared-budget-overflow"),i+=c,s+=1;let u=!0;return Object.freeze({byteLength:c,release(){return u?(u=!1,i-=c,s-=1,(i<0||s<0)&&(i=0,s=0,f("shared-budget-underflow")),!0):!1}})};return Object.freeze({inspect:r,[ee]:o})}function $e(n,e=void 0){const t=ae(e,"encode"),i=F(t.messageId,"message-id-invalid",0,Z),s=ye(t.maxMessageBytes),r=Fe(n),o=He(t.kind,r.isText),a=r.bytes.byteLength;(a>s||a>Z)&&f("message-too-large");const c=Math.max(1,Math.ceil(a/D)),u=new Array(c);for(let d=0;d<c;d+=1){const h=d*D,w=Math.min(D,a-h),m=new Uint8Array(A+w);Ge(m,{kind:o,messageId:i,chunkIndex:d,chunkCount:c,totalLength:a}),w>0&&m.set(r.bytes.subarray(h,h+w),A),u[d]=m}return u}function ge(n=void 0){const e=ae(n,"assembler"),t=ye(e.maxMessageBytes),i=e.maxPendingMessages===void 0?Be:Number(e.maxPendingMessages);(!Number.isSafeInteger(i)||i<1||i>pe)&&f("max-pending-messages-invalid");const s=e.budget===void 0?ke():e.budget;(!s||typeof s[ee]!="function"||typeof s.inspect!="function")&&f("shared-budget-invalid");const r=new Map,o=new Map;let a=!1;const c=()=>{for(const b of r.values())b.reservation.release();r.clear()},u=()=>{o.clear()},d=()=>{let b=0;for(const E of r.values())b+=E.totalLength;let l=0;for(const E of o.values())l+=E.remainingChunks;return Object.freeze({disposed:a,maxMessageBytes:t,maxPendingMessages:i,pendingMessages:r.size,pendingBytes:b,abandonedMessages:o.size,abandonedChunksRemaining:l,budget:s.inspect()})},h=()=>(a||(a=!0,c(),u()),d()),w=b=>{throw a=!0,c(),u(),b instanceof B?b:new B("wire-chunk-malformed")};return Object.freeze({abandonPending:()=>{a&&f("assembler-disposed");for(const[b,l]of r.entries()){if(o.size>=pe){const E=o.keys().next().value;o.delete(E)}o.set(b,{kind:l.kind,chunkCount:l.chunkCount,totalLength:l.totalLength,receivedChunks:new Uint8Array(l.receivedChunks),remainingChunks:Math.max(0,l.chunkCount-l.receivedChunkCount)}),l.reservation.release()}return r.clear(),d()},dispose:h,inspect:d,push:b=>{a&&f("assembler-disposed");try{const l=je(b,t),E=o.get(l.messageId);if(E)return(E.kind!==l.kind||E.chunkCount!==l.chunkCount||E.totalLength!==l.totalLength)&&f("wire-message-metadata-mismatch"),E.receivedChunks[l.chunkIndex]===0&&(E.receivedChunks[l.chunkIndex]=1,E.remainingChunks-=1),E.remainingChunks<=0&&o.delete(l.messageId),null;let g=r.get(l.messageId);if(g)(g.kind!==l.kind||g.chunkCount!==l.chunkCount||g.totalLength!==l.totalLength)&&f("wire-message-metadata-mismatch");else{r.size>=i&&f("pending-message-limit");const de=s[ee](l.totalLength);let he;try{he=new Uint8Array(l.totalLength)}catch{de.release(),f("message-allocation-failed")}g={kind:l.kind,chunkCount:l.chunkCount,totalLength:l.totalLength,receivedChunks:new Uint8Array(l.chunkCount),receivedChunkCount:0,receivedBytes:0,buffer:he,reservation:de},r.set(l.messageId,g)}g.receivedChunks[l.chunkIndex]!==0&&f("duplicate-wire-chunk");const L=l.chunkIndex*D,Pe=L+l.payloadLength;if((L<0||Pe>g.totalLength)&&f("wire-chunk-overlap"),l.payloadLength>0&&g.buffer.set(l.bytes.subarray(A),L),g.receivedChunks[l.chunkIndex]=1,g.receivedChunkCount+=1,g.receivedBytes+=l.payloadLength,g.receivedChunkCount<g.chunkCount)return null;g.receivedBytes!==g.totalLength&&f("wire-message-length-mismatch");let ue;try{ue=g.kind==="binary"?g.buffer:new TextDecoder("utf-8",{fatal:!0}).decode(g.buffer)}catch{f("wire-text-invalid")}finally{r.delete(l.messageId),g.reservation.release()}return Object.freeze({messageId:l.messageId,kind:g.kind,byteLength:g.totalLength,data:ue})}catch(l){return w(l)}}})}const ze="Direct connection signaling is unavailable. Try again.",Ve="Desktop Hub is offline.",Xe="A direct connection could not be established on this network.",Ae=750,Ye=2e3,Ke=1500,Je=3e3,Qe=512*1024,Ze=64*1024;function et(n){return n.replace(/^a=sctp-init:[^\r\n]*(?:\r?\n|$)/gm,"")}function we(n){const e=Math.max(0,Number(n)||0),t=Math.ceil(e/Qe*1e3);return Math.min(Ye,Ae+t)}function tt(n){const e=Math.max(0,Number(n)||0),t=Math.ceil(e/Ze*1e3);return Math.max(Ke,Math.min(Je,Ae+t))}const ne=Object.freeze({"signal-service-unavailable":ze,"hub-unavailable":Ve,"p2p-unavailable":Xe});function ce(n){const e=new Error(ne[n]);return e.name="ConsoleDirectError",e.code=n,e.directFailureKind=n,e}function S(){return ce("signal-service-unavailable")}function V(){return ce("hub-unavailable")}function p(){return ce("p2p-unavailable")}function X(n){const e=String(n?.directFailureKind||n?.code||""),t=`${e}
2
- ${String(n?.message||n||"")}`.toLowerCase(),i=Object.hasOwn(ne,e)?e:/hub[- ]?(offline|unavailable)|desktop hub is offline/.test(t)?"hub-unavailable":/signal|websocket|wake-service/.test(t)?"signal-service-unavailable":"p2p-unavailable";return Object.freeze({kind:i,message:ne[i],retryAt:0})}function nt({userId:n,connectionId:e,hubEpoch:t,generation:i}){const s={userId:String(n||""),connectionId:String(e||""),hubEpoch:String(t||""),generation:Number(i)};if(!s.userId||!s.connectionId||!s.hubEpoch||!Number.isSafeInteger(s.generation)||s.generation<1)throw new Error("console-direct-owner-invalid");return Object.freeze(s)}function it(n,e){return!!n&&!!e&&n.userId===e.userId&&n.connectionId===e.connectionId&&n.hubEpoch===e.hubEpoch&&n.generation===e.generation}const Te="https://livedesk-wake.lovecrdm.workers.dev",st="stun:stun.cloudflare.com:3478",rt="livedesk-console-signal-v2",ot="livedesk-auth.",at="livedesk-control-v1",ct="livedesk-ws-v1:",lt=1e4,Y=12e3,me=1e4,ut=5e3,dt=5e3,ht=15e3,ft=15e3,be=24,pt=16,Ee=32,gt=64,wt=64,mt=4*1024,bt=1024*1024,Et=new Set(["/api/remote/status","/api/remote/devices"]),Ce=4*1024*1024,Ct=12*1024*1024,Se=8*1024*1024+oe,St=8,It=1,Lt=2,vt=2,yt=new Set(["rtc-offer","rtc-ice","rtc-close"]),kt=new Set(["frame","atlas","input","audio"]),N=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function At(n){const e=String(Te).trim(),t=new URL(e);return t.protocol=t.protocol==="http:"?"ws:":t.protocol==="https:"?"wss:":t.protocol,t.pathname="/v2/rtc/console",t.search="",t.searchParams.set("workspaceId",n),t.hash="",t.toString()}function Tt(n){const e=String(Te).trim(),t=new URL(e);if(t.protocol!=="http:"&&t.protocol!=="https:")throw new Error("console-direct-signal-http-url-invalid");return t.pathname=n,t.search="",t.hash="",t.toString()}function Mt(n){const e=String(n?.accessToken||"").trim(),t=String(n?.user?.id||"").trim(),i=String(n?.workspaceId||"").trim(),s=String(n?.workspaceKind||"").trim().toLowerCase(),r=String(n?.workspaceRole||"").trim().toLowerCase(),o=Number(n?.membershipRevision||0);return e&&t&&N.test(i)&&["personal","team"].includes(s)&&["owner","operator"].includes(r)&&Number.isSafeInteger(o)&&o>=1&&(s!=="personal"||i===t)?{accessToken:e,user:{id:t},workspaceId:i,workspaceKind:s,workspaceRole:r,membershipRevision:o}:null}function Dt(){const n="".split(/[\s,]+/).map(t=>t.trim()).filter(t=>/^stun:[^\s@]+$/i.test(t)&&t.length<=512),e=[...new Set(n)].slice(0,4);return e.length>0?e:[st]}function Ot(n){let e="";for(let i=0;i<n.byteLength;i+=32768)e+=String.fromCharCode(...n.subarray(i,Math.min(n.byteLength,i+32768)));return btoa(e)}function Rt(n){const e=atob(n),t=new Uint8Array(e.length);for(let i=0;i<e.length;i+=1)t[i]=e.charCodeAt(i);return t}async function _t(n){if(n==null)return new Uint8Array;if(typeof n=="string")return new TextEncoder().encode(n);if(n instanceof URLSearchParams)return new TextEncoder().encode(n.toString());if(n instanceof Blob)return new Uint8Array(await n.arrayBuffer());if(n instanceof ArrayBuffer)return new Uint8Array(n);if(ArrayBuffer.isView(n))return new Uint8Array(n.buffer,n.byteOffset,n.byteLength);throw new Error("This request body cannot be sent through the direct mobile Console connection.")}function Pt(n){const e=new Headers(n?.headers||{}),t={};for(const i of["accept","content-type","if-match","range","x-livedesk-csrf"]){const s=e.get(i);s&&(t[i]=s)}return t}function P(n){return/(?:^|\r?\n)(?:a=)?candidate:[^\r\n]*\btyp\s+relay(?:\s|$)/i.test(String(n||""))}function ie(n,e=1e3){const t=Number(n);return Number.isInteger(t)&&t>=0&&t<=65535?t:e}function K(n,e="console-direct-failed"){return n instanceof Error?n:new Error(String(n||e))}function se(n){if(n instanceof ArrayBuffer||n instanceof Uint8Array)return n;throw new B("wire-chunk-type-invalid")}function Nt(n){const e=se(n),t=e instanceof Uint8Array?e:new Uint8Array(e),i={chunkBytes:t.byteLength,headerReadable:!1,messageId:0,chunkIndex:0,chunkCount:0,totalLength:0};if(t.byteLength<be)return i;const s=new DataView(t.buffer,t.byteOffset,be);return{...i,headerReadable:t[0]===76&&t[1]===68&&t[2]===67&&t[3]===87,messageId:s.getUint32(8,!1),chunkIndex:s.getUint32(12,!1),chunkCount:s.getUint32(16,!1),totalLength:s.getUint32(20,!1)}}function xt(n,e){return e?e.aborted?Promise.reject(e.reason||new Error("Mobile Console request cancelled.")):new Promise((t,i)=>{let s=!1;const r=a=>{s||(s=!0,e.removeEventListener("abort",o),a())},o=()=>r(()=>i(e.reason||new Error("Mobile Console request cancelled.")));e.addEventListener("abort",o,{once:!0}),n.then(a=>r(()=>t(a)),a=>r(()=>i(a)))}):n}class Wt extends EventTarget{constructor(e,t,i,s){super(),this.manager=e,this.channelId=t,this.purpose=i,this.url=s}manager;channelId;purpose;url;protocol="livedesk-ws-v1";extensions="";binaryType="blob";readyState=WebSocket.CONNECTING;onopen=null;onmessage=null;onerror=null;onclose=null;get bufferedAmount(){return this.manager.logicalBufferedAmount(this.channelId)}send(e){if(this.readyState!==WebSocket.OPEN)throw new DOMException("WebSocket is not open.","InvalidStateError");this.manager.sendLogicalMessage(this.channelId,e)}close(e=1e3,t=""){this.readyState===WebSocket.CLOSED||this.readyState===WebSocket.CLOSING||(this.readyState=WebSocket.CLOSING,this.manager.closeLogicalChannel(this.channelId,ie(e),String(t||"").slice(0,120),!0))}managerOpened(){if(this.readyState!==WebSocket.CONNECTING)return;this.readyState=WebSocket.OPEN;const e=new Event("open");this.onopen?.call(this,e),this.dispatchEvent(e)}managerMessage(e){if(this.readyState!==WebSocket.OPEN)return;const t=new MessageEvent("message",{data:e});this.onmessage?.call(this,t),this.dispatchEvent(t)}managerError(){if(this.readyState===WebSocket.CLOSED)return;const e=new Event("error");this.onerror?.call(this,e),this.dispatchEvent(e)}managerClosed(e,t,i=!1){if(this.readyState===WebSocket.CLOSED)return;i&&this.managerError(),this.readyState=WebSocket.CLOSED;const s=new CloseEvent("close",{code:ie(e,1006),reason:String(t||"").slice(0,120),wasClean:e===1e3});this.onclose?.call(this,s),this.dispatchEvent(s)}}class Bt{session=null;preferred=!1;generation=0;stage="idle";signalSocket=null;signalReady=!1;consoleId="";hubEpoch="";peerOwner=null;peer=null;controlChannel=null;controlAssembler=null;controlWireDeadline=null;wireBudget=null;remoteDescriptionApplied=!1;localOfferSent=!1;pendingLocalCandidates=[];pendingRemoteCandidates=[];directReady=!1;connectPromise=null;resolveConnect=null;rejectConnect=null;connectTimer=null;peerDisconnectTimer=null;wireMessageId=0;pendingHttp=new Map;channels=new Map;livenessEvidenceEpoch=0;consecutiveLivenessRequestTimeouts=0;livenessRequestTimeoutCount=0;consecutiveMediaLogicalOpenFailures=0;logicalChannelFailureCount=0;lastLogicalChannelFailure=null;partialMediaWireTimeoutCount=0;lastPartialMediaWireTimeout=null;preOpenMediaCoalesceCount=0;lastPreOpenMediaCoalesce=null;logicalWireFailureCount=0;lastLogicalWireFailure=null;controlMediaRecoveryCount=0;lastControlMediaRecovery=null;livenessMediaRecoveryGeneration=0;mediaAttachmentHoldGeneration=0;lastFailure=null;lastTerminalWireBytes=0;lastTerminalWireReservations=0;workspaceReauthAttempt=null;configure(e){const t=Mt(e),i=this.session?`${this.session.user.id}
3
- ${this.session.workspaceId}
4
- ${this.session.workspaceRole}`:"",s=t?`${t.user.id}
5
- ${t.workspaceId}
6
- ${t.workspaceRole}`:"";this.session=t,i!==s&&(this.teardown("console-session-replaced",null,!0),this.lastFailure=null)}preferDirect(){this.preferred=!0}markLocalHubReachable(){this.preferred=!1,this.teardown("local-hub-reachable",null,!0),this.lastFailure=null}resume(){if(this.invalidateLivenessEvidence(),this.hasReadyPayloadPeer()){this.lastFailure=null;return}this.teardown("console-resume",null,!0),this.lastFailure=null}suspendLivenessEvidence(){this.invalidateLivenessEvidence()}retry(){this.preferred=!0,this.teardown("console-manual-retry",null,!0),this.lastFailure=null}shouldUseDirect(){return this.preferred&&!!this.session?.accessToken}inspect(){const e=this.wireBudget?.inspect()||{retainedBytes:0,reservationCount:0},t=[...this.channels.values()].filter(c=>c.wireDeadline!==null).length,i=[...this.channels.values()].filter(c=>c.openDeadline!==null).length,s=this.connectTimer===null?0:1,r=this.peerDisconnectTimer===null?0:1,o=this.controlWireDeadline===null?0:1,a=this.workspaceReauthAttempt?.deadline==null?0:1;return Object.freeze({preferred:this.preferred,stage:this.stage,directReady:this.directReady,generation:this.generation,consoleId:this.consoleId||null,connectionId:this.peerOwner?.connectionId||null,signalSockets:this.signalSocket?1:0,peerCount:this.peer?1:0,controlChannels:this.controlChannel?1:0,logicalChannels:this.channels.size,openLogicalChannels:[...this.channels.values()].filter(c=>c.opened).length,pendingHttpRequests:this.pendingHttp.size,livenessEvidenceEpoch:this.livenessEvidenceEpoch,workspaceReauthRequests:this.workspaceReauthAttempt?1:0,consecutiveLivenessRequestTimeouts:this.consecutiveLivenessRequestTimeouts,livenessRequestTimeoutCount:this.livenessRequestTimeoutCount,consecutiveMediaLogicalOpenFailures:this.consecutiveMediaLogicalOpenFailures,logicalChannelFailureCount:this.logicalChannelFailureCount,lastLogicalChannelFailure:this.lastLogicalChannelFailure,partialMediaWireTimeoutCount:this.partialMediaWireTimeoutCount,lastPartialMediaWireTimeout:this.lastPartialMediaWireTimeout,preOpenMediaCoalesceCount:this.preOpenMediaCoalesceCount,lastPreOpenMediaCoalesce:this.lastPreOpenMediaCoalesce,logicalWireFailureCount:this.logicalWireFailureCount,lastLogicalWireFailure:this.lastLogicalWireFailure,controlMediaRecoveryCount:this.controlMediaRecoveryCount,lastControlMediaRecovery:this.lastControlMediaRecovery,mediaAttachmentHoldGeneration:this.mediaAttachmentHoldGeneration,heldMediaLogicalChannels:[...this.channels.values()].filter(c=>(c.purpose==="frame"||c.purpose==="atlas")&&c.owner===null&&c.dataChannel===null).length,pendingRemoteCandidates:this.pendingRemoteCandidates.length,pendingLocalCandidates:this.pendingLocalCandidates.length,connectTimers:s,peerDisconnectTimers:r,controlWireTimers:o,workspaceReauthTimers:a,logicalOpenTimers:i,logicalWireTimers:t,resourceTimers:s+r+o+a+i+t+this.pendingHttp.size,wireRetainedBytes:e.retainedBytes,wireReservations:e.reservationCount,sendBufferedBytes:this.peerBufferedAmount(),lastTerminalWireBytes:this.lastTerminalWireBytes,lastTerminalWireReservations:this.lastTerminalWireReservations,failure:this.lastFailure})}nextMessageId(){return this.wireMessageId=this.wireMessageId>=4294967295?1:this.wireMessageId+1,this.wireMessageId}isSignalOwner(e,t){return e===this.generation&&this.signalSocket===t}isPeerOwner(e){return it(this.peerOwner,e)}hasReadyPayloadPeer(){return this.directReady&&!!this.peerOwner&&!!this.peer&&this.peer?.connectionState!=="failed"&&this.peer?.connectionState!=="closed"&&this.controlChannel?.readyState==="open"}detachSignalFromReadyPeer(e,t,i){if(!this.isSignalOwner(e,t)||!this.hasReadyPayloadPeer())return!1;this.cancelWorkspaceReauthAttempt(e,t),this.signalSocket=null,this.signalReady=!1,this.consoleId="";try{t.close(1e3,i)}catch{}return!0}clearConnectTimer(){this.connectTimer!==null&&(window.clearTimeout(this.connectTimer),this.connectTimer=null)}clearPeerDisconnectTimer(){this.peerDisconnectTimer!==null&&(window.clearTimeout(this.peerDisconnectTimer),this.peerDisconnectTimer=null)}cancelWorkspaceReauthAttempt(e,t){const i=this.workspaceReauthAttempt;if(!i||e!==void 0&&i.generation!==e||t!==void 0&&i.socket!==t)return!1;this.workspaceReauthAttempt=null,i.deadline!==null&&(window.clearTimeout(i.deadline),i.deadline=null);try{i.controller.abort()}catch{}return!0}refreshPeerDisconnectDeadline(e,t){if(!this.isPeerOwner(e)||this.peer!==t)return;if(!(t.connectionState==="disconnected"||t.iceConnectionState==="disconnected")){this.clearPeerDisconnectTimer();return}if(this.peerDisconnectTimer!==null)return;const s=window.setTimeout(()=>{this.peerDisconnectTimer===s&&(this.peerDisconnectTimer=null,!(!this.isPeerOwner(e)||this.peer!==t)&&(t.connectionState==="disconnected"||t.iceConnectionState==="disconnected")&&this.fail(p(),"peer-disconnected-timeout",!0))},ut);this.peerDisconnectTimer=s}clearControlWireDeadline(){this.controlWireDeadline!==null&&(window.clearTimeout(this.controlWireDeadline),this.controlWireDeadline=null)}refreshControlWireDeadline(e,t){if((t.inspect().pendingMessages||0)===0){this.clearControlWireDeadline();return}if(this.controlWireDeadline!==null)return;const s=window.setTimeout(()=>{this.controlWireDeadline===s&&(this.controlWireDeadline=null,!(!this.isPeerOwner(e)||this.controlAssembler!==t)&&(t.inspect().pendingMessages||0)>0&&this.fail(p(),"control-wire-assembly-timeout",!0))},ht);this.controlWireDeadline=s}resolveCurrentConnect(){const e=this.resolveConnect;this.resolveConnect=null,this.rejectConnect=null,this.connectPromise=null,this.clearConnectTimer(),e?.()}rejectCurrentConnect(e){const t=this.rejectConnect;this.resolveConnect=null,this.rejectConnect=null,this.connectPromise=null,this.clearConnectTimer(),t?.(e)}signal(e){if(!yt.has(String(e.type||"")))throw new Error("console-direct-signal-type-forbidden");const t=this.signalSocket;if(!t||t.readyState!==WebSocket.OPEN||!this.signalReady)throw S();t.send(JSON.stringify(e))}peerBufferedAmount(){let e=Number(this.controlChannel?.bufferedAmount||0);for(const t of this.channels.values())e+=Number(t.dataChannel?.bufferedAmount||0);return e}sendWire(e,t,i,s){if(e.readyState!=="open")throw new Error("console-direct-data-channel-not-open");const r=$e(t,{messageId:this.nextMessageId(),kind:i,maxMessageBytes:s}),o=r.reduce((a,c)=>a+c.byteLength,0);if(o>Ce||this.peerBufferedAmount()>Ce-o)throw new Error("console-direct-send-buffer-full");for(const a of r)e.send(a)}sendControl(e){const t=this.controlChannel;if(!t||!this.directReady||!this.peerOwner)throw p();this.sendWire(t,JSON.stringify(e),"control",k)}fail(e,t,i=!0){this.lastFailure=X(e),this.teardown(t,e,i)}teardown(e,t,i,s=!1){const r=this.signalSocket,o=this.peerOwner;if(i&&r?.readyState===WebSocket.OPEN&&this.signalReady&&o)try{this.signal({type:"rtc-close",connectionId:o.connectionId,hubEpoch:o.hubEpoch,reason:String(e||"console-direct-closed").slice(0,120)})}catch{}s?this.stage="hub-offline":(this.generation+=1,this.stage="idle",this.signalSocket=null,this.signalReady=!1,this.consoleId="",this.cancelWorkspaceReauthAttempt()),this.hubEpoch="",this.peerOwner=null,this.directReady=!1,this.remoteDescriptionApplied=!1,this.localOfferSent=!1,this.pendingLocalCandidates=[],this.pendingRemoteCandidates=[],this.invalidateLivenessEvidence(),this.clearConnectTimer(),this.clearPeerDisconnectTimer();const a=t||new Error(e||"console-direct-closed");this.rejectCurrentConnect(a);for(const[h,w]of this.pendingHttp)window.clearTimeout(w.timeout),w.detachAbort(),w.reject(a),this.pendingHttp.delete(h);for(const h of[...this.channels.values()])this.retireLogicalEntry(h,t?1011:1001,e,!!t,!1);this.clearControlWireDeadline(),this.controlAssembler?.dispose(),this.controlAssembler=null;const c=this.controlChannel;if(this.controlChannel=null,c){c.onopen=null,c.onmessage=null,c.onerror=null,c.onclose=null;try{c.close()}catch{}}const u=this.peer;if(this.peer=null,u){u.onicecandidate=null,u.onconnectionstatechange=null,u.oniceconnectionstatechange=null;try{u.close()}catch{}}if(!s)try{r?.close(1e3,String(e||"console-direct-closed").slice(0,120))}catch{}const d=this.wireBudget?.inspect();this.lastTerminalWireBytes=Number(d?.retainedBytes||0),this.lastTerminalWireReservations=Number(d?.reservationCount||0),this.wireBudget=null}async connect(){if(this.directReady&&this.peerOwner&&this.controlChannel?.readyState==="open")return;if(this.connectPromise)return this.connectPromise;const e=this.session;if(!e)throw S();const t=this.signalSocket?.readyState===WebSocket.OPEN&&this.signalReady;if(t&&this.stage==="hub-offline"){const r=V();throw this.lastFailure=X(r),r}if(t&&this.stage==="p2p"&&this.peerOwner&&this.peer){const r=this.generation,o=new Promise((a,c)=>{this.resolveConnect=a,this.rejectConnect=c});return this.connectPromise=o,this.connectTimer===null&&(this.connectTimer=window.setTimeout(()=>{r===this.generation&&!this.directReady&&this.fail(p(),"direct-ready-timeout",!0)},Y)),o}const i=this.generation+1;this.generation=i,this.stage="signal",this.lastFailure=null;const s=new Promise((r,o)=>{this.resolveConnect=r,this.rejectConnect=o});this.connectPromise=s,this.connectTimer=window.setTimeout(()=>{if(i!==this.generation)return;const r=this.stage==="signal"?S():p();this.fail(r,this.stage==="signal"?"signal-timeout":"direct-ready-timeout",!1)},this.stage==="signal"?lt:Y);try{const r=new WebSocket(At(e.workspaceId),[rt,`${ot}${e.accessToken}`]);this.signalSocket=r,r.addEventListener("message",o=>{if(!this.isSignalOwner(i,r)||typeof o.data!="string")return;let a;try{a=JSON.parse(o.data)}catch{this.fail(S(),"invalid-signal-json",!1);return}this.handleSignal(a,i,r)}),r.addEventListener("error",()=>{this.isSignalOwner(i,r)&&(this.detachSignalFromReadyPeer(i,r,"signal-detached-after-ready")||this.fail(S(),"signal-service-unavailable",!1))}),r.addEventListener("close",()=>{this.isSignalOwner(i,r)&&(this.detachSignalFromReadyPeer(i,r,"signal-closed-after-ready")||this.fail(S(),"signal-service-closed",!1))})}catch{this.fail(S(),"signal-constructor-failed",!1)}return s}handleSignal(e,t,i){if(!this.isSignalOwner(t,i))return;if(e.type==="workspace-reauth-required"){const r=this.session,o=String(e.workspaceId||r?.workspaceId||"").trim(),a=String(e.challengeNonce||"").trim();if(!r||o!==r.workspaceId||!N.test(a)){this.fail(S(),"workspace-reauth-owner-mismatch",!1);return}if(this.workspaceReauthAttempt?.challengeNonce===a&&this.workspaceReauthAttempt.generation===t&&this.workspaceReauthAttempt.socket===i)return;this.cancelWorkspaceReauthAttempt();const c=new AbortController,u={challengeNonce:a,generation:t,socket:i,controller:c,deadline:null},d=Number(e.deadlineAt||0),h=Number.isFinite(d)&&d>0?Math.max(1,d-Date.now()):me;u.deadline=window.setTimeout(()=>{this.workspaceReauthAttempt===u&&this.cancelWorkspaceReauthAttempt(t,i)},Math.max(1,Math.min(me,h))),this.workspaceReauthAttempt=u,(async()=>{try{await fetch(Tt("/v2/rtc/reauth"),{method:"POST",headers:{Authorization:`Bearer ${r.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({workspaceId:r.workspaceId,challengeNonce:a}),signal:c.signal,cache:"no-store"})}catch{}})().finally(()=>{this.workspaceReauthAttempt===u&&(this.workspaceReauthAttempt=null,u.deadline!==null&&(window.clearTimeout(u.deadline),u.deadline=null))});return}if(e.type==="workspace-access-refreshed"||e.type==="workspace-reauth-ok"){e.type==="workspace-reauth-ok"&&this.cancelWorkspaceReauthAttempt(t,i);return}if(e.type==="workspace-access-expired"){this.fail(S(),"workspace-access-expired",!1);return}if(e.type==="signal-ready"){const r=String(e.consoleId||""),o=String(e.hubEpoch||"");if(e.role!=="console"||!N.test(r)){this.fail(S(),"invalid-signal-ready",!1);return}if(this.signalReady=!0,this.consoleId=r,e.hubOnline!==!0){const a=V();this.lastFailure=X(a),this.teardown("hub-offline",a,!1,!0);return}if(!N.test(o)){this.fail(S(),"invalid-hub-epoch",!1);return}if(this.peerOwner){this.peerOwner.hubEpoch!==o&&this.fail(p(),"hub-epoch-replaced",!1);return}this.hubEpoch=o,this.stage="p2p",this.lastFailure=null,this.clearConnectTimer(),this.connectTimer=window.setTimeout(()=>{t===this.generation&&!this.directReady&&this.fail(p(),"direct-ready-timeout",!0)},Y),this.beginPeer(t,o);return}const s=this.peerOwner;if(!(!s||String(e.connectionId||"")!==s.connectionId||String(e.hubEpoch||"")!==s.hubEpoch)){if(e.type==="rtc-answer")this.acceptAnswer(s,e.description);else if(e.type==="rtc-ice")this.acceptRemoteCandidate(s,e.candidate,e.sdpMid);else if(e.type==="rtc-close"){const r=String(e.reason||"rtc-closed"),o=/hub-offline/i.test(r)?V():p();this.fail(o,r,!1)}}}beginPeer(e,t){if(e!==this.generation||this.peer)return;const i=this.session;if(!i){this.fail(S(),"session-missing",!1);return}const s=nt({userId:i.user.id,connectionId:crypto.randomUUID(),hubEpoch:t,generation:e});this.consecutiveMediaLogicalOpenFailures=0,this.peerOwner=s,this.wireBudget=ke({maxBytes:Ct}),this.controlAssembler=ge({budget:this.wireBudget,maxMessageBytes:k});let r;try{r=new RTCPeerConnection({iceServers:[{urls:Dt()}],iceTransportPolicy:"all",bundlePolicy:"max-bundle",rtcpMuxPolicy:"require"})}catch{this.fail(p(),"peer-constructor-failed",!0);return}this.peer=r;const o=r.createDataChannel(at,{ordered:!0});o.binaryType="arraybuffer",this.controlChannel=o,r.onicecandidate=a=>{if(!this.isPeerOwner(s)||this.peer!==r||!a.candidate)return;const c=String(a.candidate.candidate||"");if(P(c)){this.fail(p(),"relay-ice-candidate-forbidden",!0);return}if(new TextEncoder().encode(c).byteLength>mt){this.fail(p(),"local-ice-candidate-invalid",!0);return}if(!this.localOfferSent){if(this.pendingLocalCandidates.length>=wt){this.fail(p(),"local-ice-capacity-reached",!0);return}this.pendingLocalCandidates.push({candidate:c,sdpMid:a.candidate.sdpMid});return}try{this.signal({type:"rtc-ice",connectionId:s.connectionId,hubEpoch:s.hubEpoch,candidate:c,sdpMid:a.candidate.sdpMid})}catch{this.fail(S(),"signal-ice-failed",!1)}},r.onconnectionstatechange=()=>{if(!(!this.isPeerOwner(s)||this.peer!==r)){if(r.connectionState==="failed"||r.connectionState==="closed"){this.fail(p(),`peer-${r.connectionState}`,!0);return}this.refreshPeerDisconnectDeadline(s,r)}},r.oniceconnectionstatechange=()=>{if(!(!this.isPeerOwner(s)||this.peer!==r)){if(r.iceConnectionState==="failed"||r.iceConnectionState==="closed"){this.fail(p(),`ice-${r.iceConnectionState}`,!0);return}this.refreshPeerDisconnectDeadline(s,r)}},o.onmessage=a=>{!this.isPeerOwner(s)||this.controlChannel!==o||this.handleControlWire(s,a.data)},o.onerror=()=>{!this.isPeerOwner(s)||this.controlChannel!==o||this.fail(p(),"control-channel-error",!0)},o.onclose=()=>{!this.isPeerOwner(s)||this.controlChannel!==o||this.fail(p(),"control-channel-closed",!0)},(async()=>{try{const a=await r.createOffer();if(!this.isPeerOwner(s)||this.peer!==r)return;if(a.type!=="offer"||P(a.sdp))throw new Error("relay-sdp-forbidden");if(await r.setLocalDescription(a),!this.isPeerOwner(s)||this.peer!==r)return;const c=r.localDescription||a;if(c.type!=="offer"||P(c.sdp))throw new Error("relay-sdp-forbidden");this.signal({type:"rtc-offer",connectionId:s.connectionId,hubEpoch:s.hubEpoch,description:{type:"offer",sdp:et(c.sdp||"")}}),this.localOfferSent=!0;const u=this.pendingLocalCandidates;this.pendingLocalCandidates=[];for(const d of u){if(!this.isPeerOwner(s)||this.peer!==r)return;this.signal({type:"rtc-ice",connectionId:s.connectionId,hubEpoch:s.hubEpoch,...d})}}catch(a){if(!this.isPeerOwner(s))return;const c=/signal/i.test(String(a?.message||""))?S():p();this.fail(c,"rtc-offer-failed",!0)}})()}async acceptAnswer(e,t){const i=this.peer;if(!(!this.isPeerOwner(e)||!i||this.remoteDescriptionApplied)){if(t?.type!=="answer"||typeof t.sdp!="string"||P(t.sdp)){this.fail(p(),"rtc-answer-invalid",!0);return}try{if(await i.setRemoteDescription({type:"answer",sdp:t.sdp}),!this.isPeerOwner(e)||this.peer!==i)return;this.remoteDescriptionApplied=!0;const s=this.pendingRemoteCandidates;this.pendingRemoteCandidates=[];for(const r of s){if(!this.isPeerOwner(e)||this.peer!==i)return;await i.addIceCandidate(r.candidate?r:null)}}catch{this.isPeerOwner(e)&&this.fail(p(),"rtc-answer-apply-failed",!0)}}}async acceptRemoteCandidate(e,t,i){if(!this.isPeerOwner(e))return;const s=String(t??""),r=i==null?null:String(i);if(s.length>4*1024||r!==null&&r.length>256||P(s)){this.fail(p(),"rtc-candidate-invalid",!0);return}const o=this.peer;if(o){if(!this.remoteDescriptionApplied){if(this.pendingRemoteCandidates.length>=gt){this.fail(p(),"rtc-candidate-capacity",!0);return}this.pendingRemoteCandidates.push({candidate:s,sdpMid:r});return}try{await o.addIceCandidate(s?{candidate:s,sdpMid:r}:null)}catch{this.isPeerOwner(e)&&this.fail(p(),"rtc-candidate-apply-failed",!0)}}}handleControlWire(e,t){const i=this.controlAssembler;if(!(!this.isPeerOwner(e)||!i))try{const s=i.push(se(t));if(this.refreshControlWireDeadline(e,i),!s)return;if(s.kind!=="control"||typeof s.data!="string")throw new Error("control-wire-kind-invalid");const r=JSON.parse(s.data);if(r.type==="direct-ready"){if(r.connectionId!==e.connectionId||r.hubEpoch!==e.hubEpoch||this.controlChannel?.readyState!=="open")throw new Error("direct-ready-owner-invalid");this.directReady||(this.consecutiveLivenessRequestTimeouts=0,this.directReady=!0,this.stage="ready",this.resolveCurrentConnect());return}if(r.type==="http-response"){this.handleHttpResponse(e,r);return}if(r.type==="ws-opened"||r.type==="ws-closed"||r.type==="ws-error"){this.handleLogicalLifecycle(e,r);return}throw new Error("control-message-type-invalid")}catch{this.isPeerOwner(e)&&this.fail(p(),"control-wire-invalid",!0)}}handleLogicalLifecycle(e,t){if(t.connectionId!==e.connectionId||t.hubEpoch!==e.hubEpoch)throw new Error("logical-lifecycle-owner-invalid");const i=String(t.channelId||"");if(!N.test(i))throw new Error("logical-lifecycle-channel-invalid");const s=this.channels.get(i);if(!s)return;const r=s.dataChannel;if(!r||!s.openRequested||!this.logicalEntryIsCurrent(s,e,r))throw new Error("logical-lifecycle-owner-invalid");if(t.type==="ws-opened"){if(s.opened)return;s.opened=!0,(s.purpose==="frame"||s.purpose==="atlas")&&(this.consecutiveMediaLogicalOpenFailures=0),this.clearLogicalOpenDeadline(s);const o=s.pendingInbound.splice(0);if(s.pendingInboundBytes=0,s.socket.managerOpened(),!this.logicalEntryIsCurrent(s,e,r)||!s.opened)return;for(const a of o)this.deliverLogicalMessage(s,a);return}if(t.type==="ws-closed"){this.retireLogicalEntry(s,ie(t.code,1e3),String(t.reason||""),!1,!1);return}this.retireLogicalEntry(s,1011,String(t.error||"console-direct-websocket-error"),!0,!1)}handleHttpResponse(e,t){const i=String(t.requestId||""),s=this.pendingHttp.get(i);if(!s||s.generation!==e.generation||!this.isPeerOwner(e))return;this.consecutiveLivenessRequestTimeouts=0,this.livenessMediaRecoveryGeneration=0;const r=this.mediaAttachmentHoldGeneration===e.generation;this.pendingHttp.delete(i),window.clearTimeout(s.timeout),s.detachAbort();try{const o=Number(t.status||502),a=t.bodyBase64?Rt(t.bodyBase64):new TextEncoder().encode(JSON.stringify({ok:!1,error:t.error||"console-direct-request-failed"})),c=new Response(a,{status:Number.isInteger(o)&&o>=200&&o<=599?o:502,statusText:String(t.statusText||""),headers:t.headers||{"content-type":"application/json"}});s.resolve(c),r&&(this.mediaAttachmentHoldGeneration=0,this.attachHeldMediaChannels(e))}catch(o){s.reject(K(o))}}async fetch(e,t,i){await xt(this.connect(),t?.signal);const s=this.peerOwner;if(!s||!this.directReady||this.controlChannel?.readyState!=="open")throw p();if(this.pendingHttp.size>=Ee)throw new Error("console-direct-http-capacity-reached");const r=await _t(t?.body);if(r.byteLength>bt)throw new Error("console-direct-http-body-too-large");if(!this.isPeerOwner(s)||!this.directReady)throw p();if(this.pendingHttp.size>=Ee)throw new Error("console-direct-http-capacity-reached");if(t?.signal?.aborted)throw t.signal.reason||new Error("Mobile Console request cancelled.");const o=crypto.randomUUID(),a=Number.isFinite(i)&&i>0?Math.floor(i):4e3,c=String(t?.method||"GET").toUpperCase(),u=c==="GET"&&Et.has(e),d=u?this.livenessEvidenceEpoch:null,h=new Promise((w,m)=>{const C=(E,g=!1)=>{const L=this.pendingHttp.get(o);if(L){this.pendingHttp.delete(o),window.clearTimeout(L.timeout),L.detachAbort();try{this.sendControl({type:"http-cancel",requestId:o})}catch{}m(E),g&&u&&this.recordLivenessRequestTimeout(s,L.livenessEvidenceEpoch)}},b=()=>C(t?.signal?.reason instanceof Error?t.signal.reason:new Error("Mobile Console request cancelled."));t?.signal?.addEventListener("abort",b,{once:!0});const l=window.setTimeout(()=>{C(new Error("Mobile Console direct request timed out."),!0)},a);this.pendingHttp.set(o,{generation:s.generation,livenessEvidenceEpoch:d,resolve:w,reject:m,timeout:l,detachAbort:()=>t?.signal?.removeEventListener("abort",b)})});try{this.sendControl({type:"http-request",requestId:o,method:c,path:e,headers:Pt(t),bodyBase64:r.byteLength>0?Ot(r):""})}catch(w){const m=this.pendingHttp.get(o);m&&(this.pendingHttp.delete(o),window.clearTimeout(m.timeout),m.detachAbort(),m.reject(K(w))),this.fail(p(),"control-send-failed",!0)}return h}openWebSocket(e,t){if(!kt.has(t))throw new Error("console-direct-purpose-invalid");if(this.channels.size>=pt)throw new Error("console-direct-channel-capacity-reached");const i=crypto.randomUUID(),s=new Wt(this,i,t,e),r={channelId:i,path:e,purpose:t,socket:s,owner:null,dataChannel:null,assembler:null,openDeadline:null,wireDeadline:null,wireScheduledAtEpochMs:0,wireStartedAtEpochMs:0,wireLastProgressAtEpochMs:0,wireAbsoluteDeadlineAtEpochMs:0,openRequested:!1,opened:!1,pendingInbound:[],pendingInboundBytes:0};return this.channels.set(i,r),this.connect().then(()=>{this.channels.get(i)===r&&this.attachLogicalChannel(r)}).catch(o=>{this.channels.get(i)===r&&this.retireLogicalEntry(r,1011,K(o).message,!0,!1)}),s}attachLogicalChannel(e){const t=this.peerOwner,i=this.peer,s=this.wireBudget;if(!t||!i||!s||!this.directReady||this.channels.get(e.channelId)!==e){this.retireLogicalEntry(e,1011,"console-direct-not-ready",!0,!1);return}const r=e.purpose==="frame"||e.purpose==="atlas";if(r&&this.mediaAttachmentHoldGeneration===t.generation)return;e.owner=t;let o;try{o=i.createDataChannel(`${ct}${e.channelId}:${e.purpose}`,{ordered:!0})}catch{this.retireLogicalOpenFailure(e,t,1011,"console-direct-channel-create-failed",!0,!0);return}o.binaryType="arraybuffer",e.dataChannel=o,e.assembler=ge({budget:s,maxMessageBytes:r?Se:k,maxPendingMessages:r?St:2}),this.refreshLogicalOpenDeadline(e,t,o),o.onopen=()=>{if(this.logicalEntryIsCurrent(e,t,o))try{this.sendControl({type:"ws-open",connectionId:t.connectionId,hubEpoch:t.hubEpoch,channelId:e.channelId,purpose:e.purpose,path:e.path}),e.openRequested=!0}catch{this.retireLogicalEntry(e,1011,"console-direct-ws-open-failed",!0,!1)}},o.onmessage=a=>{this.logicalEntryIsCurrent(e,t,o)&&this.handleLogicalWire(e,t,a.data)},o.onerror=()=>{this.logicalEntryIsCurrent(e,t,o)&&this.retireLogicalOpenFailure(e,t,1011,"console-direct-channel-error",!0,!1)},o.onclose=()=>{this.logicalEntryIsCurrent(e,t,o)&&this.retireLogicalOpenFailure(e,t,1006,"console-direct-channel-closed",!1,!1)}}retireLogicalOpenFailure(e,t,i,s,r,o){if(this.channels.get(e.channelId)!==e||!this.isPeerOwner(t))return;const a=!e.openRequested&&(e.purpose==="frame"||e.purpose==="atlas");this.logicalChannelFailureCount+=1,this.lastLogicalChannelFailure=Object.freeze({reason:String(s||"console-direct-logical-channel-failed").slice(0,120),purpose:e.purpose,generation:t.generation,occurredAt:Date.now()}),a&&(this.consecutiveMediaLogicalOpenFailures+=1);const c=[...this.channels.values()].some(d=>d!==e&&d.opened&&(d.purpose==="frame"||d.purpose==="atlas")&&d.dataChannel?.readyState==="open"),u=a&&!c&&(o||this.consecutiveMediaLogicalOpenFailures>=vt);this.retireLogicalEntry(e,i,s,r,!1),u&&this.isPeerOwner(t)&&this.fail(p(),"console-direct-media-channel-unusable",!0)}logicalEntryIsCurrent(e,t,i){return this.channels.get(e.channelId)===e&&e.owner===t&&e.dataChannel===i&&this.isPeerOwner(t)}clearLogicalOpenDeadline(e){e.openDeadline!==null&&(window.clearTimeout(e.openDeadline),e.openDeadline=null)}refreshLogicalOpenDeadline(e,t,i){this.clearLogicalOpenDeadline(e);const s=window.setTimeout(()=>{e.openDeadline===s&&(e.openDeadline=null,!(!this.logicalEntryIsCurrent(e,t,i)||e.opened)&&this.retireLogicalOpenFailure(e,t,1011,"console-direct-logical-open-timeout",!0,!1))},dt);e.openDeadline=s}invalidateLivenessEvidence(){this.livenessEvidenceEpoch+=1,this.consecutiveLivenessRequestTimeouts=0,this.livenessMediaRecoveryGeneration=0,this.peerOwner||(this.mediaAttachmentHoldGeneration=0)}attachHeldMediaChannels(e){if(!this.isPeerOwner(e)||!this.directReady)return 0;let t=0;for(const i of[...this.channels.values()])i.owner!==null||i.dataChannel!==null||i.purpose!=="frame"&&i.purpose!=="atlas"||(this.attachLogicalChannel(i),t+=1);return t}recoverControlFromMediaPressure(e){if(!this.isPeerOwner(e)||this.livenessMediaRecoveryGeneration===e.generation)return!1;const t=[...this.channels.values()].filter(i=>(i.purpose==="frame"||i.purpose==="atlas")&&i.owner===e&&i.dataChannel?.readyState==="open");if(t.length===0)return!1;this.livenessMediaRecoveryGeneration=e.generation,this.mediaAttachmentHoldGeneration=e.generation,this.livenessEvidenceEpoch+=1,this.consecutiveLivenessRequestTimeouts=0,this.controlMediaRecoveryCount+=1,this.lastControlMediaRecovery=Object.freeze({generation:e.generation,retiredMediaLanes:t.length,occurredAt:Date.now()});for(const i of t)this.retireLogicalEntry(i,1013,"console-direct-control-media-recovery",!1,!0);return!0}recordLivenessRequestTimeout(e,t){t===null||t!==this.livenessEvidenceEpoch||!this.isPeerOwner(e)||!this.directReady||(this.livenessRequestTimeoutCount+=1,this.consecutiveLivenessRequestTimeouts+=1,!(this.consecutiveLivenessRequestTimeouts<2)&&(this.recoverControlFromMediaPressure(e)||this.fail(p(),"control-http-timeout",!0)))}handleLogicalWire(e,t,i){const s=e.assembler;if(!s||!this.logicalEntryIsCurrent(e,t,e.dataChannel))return;const r=s.inspect();let o={chunkBytes:0,headerReadable:!1,messageId:0,chunkIndex:0,chunkCount:0,totalLength:0};try{o=Nt(i);const a=s.push(se(i));if(this.refreshLogicalWireDeadline(e,t),!a)return;if(a.kind==="control")throw new Error("logical-control-forbidden");let c;if(a.kind==="text"&&typeof a.data=="string")c={kind:"text",data:a.data,byteLength:a.byteLength};else if(a.kind==="binary"&&a.data instanceof Uint8Array)c={kind:"binary",data:a.data,byteLength:a.byteLength};else throw new Error("logical-wire-kind-invalid");if(!e.opened){this.queuePreOpenLogicalMessage(e,c);return}this.deliverLogicalMessage(e,c)}catch(a){this.logicalWireFailureCount+=1,this.lastLogicalWireFailure=Object.freeze({errorCode:a instanceof B?a.code:a instanceof Error?a.message.slice(0,120):"logical-wire-invalid",purpose:e.purpose,generation:t.generation,pendingMessagesBefore:Math.max(0,Number(r.pendingMessages||0)),pendingBytesBefore:Math.max(0,Number(r.pendingBytes||0)),...o,occurredAt:Date.now()}),this.retireLogicalEntry(e,1011,"console-direct-wire-invalid",!0,!1)}}queuePreOpenLogicalMessage(e,t){const i=e.purpose==="frame"||e.purpose==="atlas",s=i?Se:k;if(i){if(e.pendingInbound.length===0){e.pendingInbound.push(t),e.pendingInboundBytes=t.byteLength;return}if(e.pendingInbound.length<Lt&&e.pendingInboundBytes+t.byteLength<=s){e.pendingInbound.push(t),e.pendingInboundBytes+=t.byteLength;return}const r=e.pendingInbound[0],o=r.byteLength+t.byteLength,a=o<=s?"replace-latest":"drop-over-budget";a==="replace-latest"&&(e.pendingInbound=[r,t],e.pendingInboundBytes=o),this.preOpenMediaCoalesceCount+=1,this.lastPreOpenMediaCoalesce=Object.freeze({action:a,purpose:e.purpose==="atlas"?"atlas":"frame",generation:e.owner?.generation||0,retainedMessages:e.pendingInbound.length,retainedBytes:e.pendingInboundBytes,incomingBytes:t.byteLength,occurredAt:Date.now()});return}if(e.pendingInbound.length>=It||e.pendingInboundBytes+t.byteLength>s)throw new Error("logical-preopen-buffer-full");e.pendingInbound.push(t),e.pendingInboundBytes+=t.byteLength}deliverLogicalMessage(e,t){if(t.kind==="text"){e.socket.managerMessage(t.data);return}const i=t.data;if(e.socket.binaryType==="arraybuffer"){const s=i.buffer instanceof ArrayBuffer&&i.byteOffset===0&&i.byteLength===i.buffer.byteLength?i.buffer:i.slice().buffer;e.socket.managerMessage(s)}else e.socket.managerMessage(new Blob([i]))}logicalBufferedAmount(e){return Number(this.channels.get(e)?.dataChannel?.bufferedAmount||0)}clearLogicalWireDeadline(e){e.wireDeadline!==null&&(window.clearTimeout(e.wireDeadline),e.wireDeadline=null),e.wireScheduledAtEpochMs=0,e.wireStartedAtEpochMs=0,e.wireLastProgressAtEpochMs=0,e.wireAbsoluteDeadlineAtEpochMs=0}scheduleLogicalWireDeadline(e,t){const i=e.purpose==="frame"||e.purpose==="atlas",s=Date.now(),r=e.assembler?.inspect(),o=i?we(Number(r?.pendingBytes||0)):Number.POSITIVE_INFINITY,a=i?Math.max(1,o-(s-e.wireLastProgressAtEpochMs)):Number.POSITIVE_INFINITY,c=Math.max(1,e.wireAbsoluteDeadlineAtEpochMs-s),u=Math.min(a,c),d=s+u;if(e.wireDeadline!==null&&e.wireScheduledAtEpochMs<=d)return;e.wireDeadline!==null&&window.clearTimeout(e.wireDeadline);const h=window.setTimeout(()=>{if(e.wireDeadline!==h)return;e.wireDeadline=null,e.wireScheduledAtEpochMs=0;const w=e.dataChannel;if(!w||!this.logicalEntryIsCurrent(e,t,w))return;const m=e.assembler?.inspect(),C=Number(m?.pendingMessages||0);if(C===0){this.clearLogicalWireDeadline(e);return}const b=Date.now(),l=Math.max(0,b-e.wireLastProgressAtEpochMs),E=Math.max(0,b-e.wireStartedAtEpochMs),g=i?we(Number(m?.pendingBytes||0)):Number.POSITIVE_INFINITY;if(!(!i||l>=g||b>=e.wireAbsoluteDeadlineAtEpochMs)){this.scheduleLogicalWireDeadline(e,t);return}if(i){this.partialMediaWireTimeoutCount+=1,this.lastPartialMediaWireTimeout=Object.freeze({recovery:"abandon-message",purpose:e.purpose,generation:t.generation,pendingMessages:C,pendingBytes:Math.max(0,Number(m?.pendingBytes||0)),stalledForMs:l,lifetimeMs:E,idleDeadlineMs:g,absoluteDeadlineMs:Math.max(0,e.wireAbsoluteDeadlineAtEpochMs-e.wireStartedAtEpochMs),occurredAt:b}),e.assembler?.abandonPending(),this.clearLogicalWireDeadline(e);return}this.retireLogicalEntry(e,1011,"console-direct-partial-message-timeout",!0,!1)},u);e.wireDeadline=h,e.wireScheduledAtEpochMs=d}refreshLogicalWireDeadline(e,t){const i=e.assembler?.inspect();if(Number(i?.pendingMessages||0)===0){this.clearLogicalWireDeadline(e);return}const r=Date.now(),o=e.purpose==="frame"||e.purpose==="atlas";e.wireStartedAtEpochMs<=0&&(e.wireStartedAtEpochMs=r,e.wireAbsoluteDeadlineAtEpochMs=r+(o?tt(Number(i?.pendingBytes||0)):ft)),e.wireLastProgressAtEpochMs=r,this.scheduleLogicalWireDeadline(e,t)}sendLogicalMessage(e,t){const i=this.channels.get(e),s=i?.dataChannel;if(!i||!s||!i.opened||s.readyState!=="open")throw new DOMException("WebSocket is not open.","InvalidStateError");try{if(typeof t=="string")this.sendWire(s,t,"text",k);else if(t instanceof ArrayBuffer)this.sendWire(s,t,"binary",k);else if(ArrayBuffer.isView(t)){const r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.sendWire(s,r,"binary",k)}else throw new DOMException("Blob sends are not supported by the direct Console channel.","NotSupportedError")}catch(r){throw this.retireLogicalEntry(i,1011,"console-direct-send-failed",!0,!1),r}}closeLogicalChannel(e,t,i,s){const r=this.channels.get(e);r&&this.retireLogicalEntry(r,t,i,!1,s)}retireLogicalEntry(e,t,i,s,r){if(this.channels.get(e.channelId)!==e)return;this.channels.delete(e.channelId);const o=e.dataChannel,a=e.owner;if(r&&a&&e.openRequested&&this.isPeerOwner(a)&&this.controlChannel?.readyState==="open")try{this.sendControl({type:"ws-close",connectionId:a.connectionId,hubEpoch:a.hubEpoch,channelId:e.channelId,code:t,reason:i})}catch{s=!0}if(this.clearLogicalWireDeadline(e),this.clearLogicalOpenDeadline(e),e.assembler?.dispose(),e.assembler=null,e.pendingInbound=[],e.pendingInboundBytes=0,e.dataChannel=null,e.owner=null,e.openRequested=!1,e.opened=!1,o){o.onopen=null,o.onmessage=null,o.onerror=null,o.onclose=null;try{o.close()}catch{}}e.socket.managerClosed(t,i,s)}}const I=new Bt;function Me(n){I.configure(n)}function Ut(){I.preferDirect()}function Ht(){I.markLocalHubReachable()}function hn(){I.resume()}function fn(){I.suspendLivenessEvidence()}function pn(){I.retry()}function J(n,e,t){return I.preferDirect(),I.fetch(n,e,t)}function gn(n,e,t){return I.shouldUseDirect()?I.openWebSocket(e,t):new WebSocket(n)}function wn(){return I.inspect()}function Ft(n){let e=null;return{run(){if(e)return e;const t=Promise.resolve().then(n);e=t.finally(()=>{(e===t||e===i)&&(e=null)});const i=e;return i}}}async function qt(n,e){return n&&await n.catch(()=>{}),e()}function Gt(n,e={}){if(e.publicConsole===!0)throw new Error("Public Console does not create a Hub cookie session.");return n?.workspaceKind==="team"&&n?.workspaceRole==="operator"?{accessToken:n.accessToken,workspaceId:n.workspaceId}:{accessToken:n.accessToken,refreshToken:n.refreshToken,expiresAt:n.expiresAt,user:n.user,workspaceId:n.workspaceId}}function le(n){return!n?.user?.id||!n?.workspaceId?"":[n.user.id,n.workspaceId,n.workspaceKind,n.workspaceRole,Number(n.membershipRevision||0)].join(`
7
- `)}function jt(n){const e=le(n);return!e||!n?.accessToken||!n?.refreshToken?"":[e,n.accessToken,n.refreshToken,Number(n.expiresAt||0)].join(`
8
- `)}function $t({publicConsole:n,path:e,requiresUiSession:t}){return n?String(e||"").split("?")[0]==="/api/auth/session"?"reject-auth-session":t?"direct":"local":"local"}const x=5179,_=H(`http://127.0.0.1:${x}`);function zt(n){const e=n.split(".").map(t=>Number(t));return e.length===4&&e.every(t=>Number.isInteger(t)&&t>=0&&t<=255)?e:[]}function De(n){const e=n.trim().toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}function Vt(n){const e=n.trim().toLowerCase();return!e||e==="0.0.0.0"||e==="::"||e==="[::]"}function Oe(n){const e=zt(n);return e.length===0?!1:e[0]===10||e[0]===172&&e[1]>=16&&e[1]<=31||e[0]===192&&e[1]===168}function Xt(n){return n.includes(":")&&!n.startsWith("[")?`[${n}]`:n}function Yt(n){const e=String(n||"").trim();if(!e)return null;const t=/^[a-z][a-z\d+.-]*:\/\//i.test(e)?e:`tcp://${e}`;try{const i=new URL(t),s=i.hostname.replace(/^\[|\]$/g,""),r=Number(i.port);return!s||!Number.isInteger(r)||r<1||r>65535||Vt(s)?null:{host:s,port:r}}catch{return null}}function H(n){const e=String(n||"").trim()||`http://127.0.0.1:${x}`,t=/^[a-z][a-z\d+.-]*:\/\//i.test(e)?e:`http://${e}`;try{const i=new URL(t);return i.port||(i.port=String(x)),i.hash="",i.search="",i.toString().replace(/\/+$/,"")}catch{return`http://127.0.0.1:${x}`}}function Kt(n){const e=Yt(n);return e?H(`http://${Xt(e.host)}:${x}`):""}function mn(n){const t=[n?.endpoint,...Array.isArray(n?.endpoint_candidates)?n.endpoint_candidates:[]].map(i=>Kt(String(i||""))).filter(Boolean);return[...new Set(t)]}function Jt(n=_){if(!(typeof window>"u"||window.location.protocol!=="https:"))try{const e=new URL(n);if(e.protocol!=="http:")return;if(De(e.hostname))return"loopback";if(Oe(e.hostname))return"local"}catch{return}}function bn(n,e=_){const t=new URL(n,H(e));return t.protocol=t.protocol==="https:"?"wss:":"ws:",t.toString()}let v=null,R="",T="";const y=new Map,O=new Map,U=new Map,q=new Set;function $(n){const e=U.get(n);e!==void 0&&typeof window<"u"&&window.clearTimeout(e),U.delete(n)}function Re(){for(const n of U.keys())$(n)}function re(n){const e=Number(n||0);if(Number.isFinite(e)&&e>0)return e<1e10?e*1e3:e;const t=Date.parse(String(n||""));return Number.isFinite(t)?t:0}function _e(n,e,t){if($(n),typeof window>"u"||e<=Date.now())return;const i=Math.max(1e3,Math.min(45e3,e-Date.now()-15e3)),s=window.setTimeout(()=>{U.delete(n),!(t!==R||v?.workspaceKind!=="team")&&j(n,!0).catch(()=>{})},i);U.set(n,s)}function Qt(n,e,t){const i=v?.workspaceKind==="team",s=i?re(e.accessExpiresAt)||Date.now()+6e4:0;y.set(n,{csrfToken:e.csrfToken,expiresAt:e.expiresAt,accessExpiresAt:s,ownerSignature:T}),q.add(n),i?_e(n,s,t):$(n)}function En(n){const e=n?.accessToken&&n?.refreshToken&&n?.user?.id?n:null,t=le(e),i=jt(e);if(t!==T&&(e&&y.clear(),T=t),i!==R&&(Re(),R=i,e?.workspaceKind==="team"))for(const[s,r]of y)r.ownerSignature===t&&_e(s,r.accessExpiresAt,i);v=e,Me(e?{accessToken:e.accessToken,user:{id:e.user.id},workspaceId:e.workspaceId,workspaceKind:e.workspaceKind,workspaceRole:e.workspaceRole,membershipRevision:e.membershipRevision}:null),e&&z()&&Ut()}function z(){if(typeof window>"u"||window.location.protocol!=="https:")return!1;const n=window.location.hostname.replace(/^\[|\]$/g,"");return!De(n)&&!Oe(n)}function Q(n){const e=n.split("?")[0];return e==="/api/health"||e==="/api/runtime/status"||e==="/api/auth/status"||e==="/api/auth/session"}async function G(n,e,t,i,s){const r=Jt(t);return r&&(e.targetAddressSpace=r),xe(s,i,async o=>{e.signal=o;try{return await fetch(`${t}${n}`,e)}catch(a){throw!o.aborted&&r?new Error("VuvoDesk Hub is not reachable at this local network address. If Chrome shows a local network prompt, allow it; otherwise restart the Hub so port 5179 is open on the network."):a}})}async function j(n,e=!1){if(z())throw new Error("Public Console uses verified P2P authorization instead of a Hub cookie session.");const t=y.get(n);if(!e&&t&&t.ownerSignature===T&&t.expiresAt>Date.now()+3e4&&(t.accessExpiresAt===0||t.accessExpiresAt>Date.now()+15e3))return;e&&y.delete(n);const i=v,s=R;if(!i)return;const r=O.get(n);if(r)return r.authSignature===s?r.promise:r.promise.catch(()=>{}).then(()=>j(n,e));let o;const a=(async()=>{const c=await G("/api/auth/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Gt(i,{publicConsole:!1})),credentials:"include",cache:"no-store"},n,W),u=await c.json().catch(()=>null);if(!c.ok)throw new Error(`${c.status} ${u?.error||c.statusText}`);const d=String(u?.uiSession?.csrfToken||"").trim(),h=Number(u?.uiSession?.expiresAt||0);if(!d||!Number.isFinite(h)||h<=Date.now())throw new Error("VuvoDesk Hub did not issue a valid UI session.");if(s!==R)throw y.set(n,{csrfToken:d,expiresAt:h,accessExpiresAt:re(u?.uiSession?.accessExpiresAt),ownerSignature:le(i)}),q.add(n),new Error("VuvoDesk workspace changed while the Hub session was opening.");Qt(n,{csrfToken:d,expiresAt:h,accessExpiresAt:re(u?.uiSession?.accessExpiresAt)},s)})().finally(()=>{O.get(n)===o&&O.delete(n)});return o={authSignature:s,promise:a},O.set(n,o),a}async function Zt(){const n=new Set(q);for(const t of O.keys())n.add(t);z()||n.add(H(_));const e=[...n].map(t=>qt(O.get(t)?.promise,async()=>{const i=y.get(t),s=await G("/api/auth/session",{method:"DELETE",headers:i?.csrfToken?{"X-LiveDesk-CSRF":i.csrfToken}:{},credentials:"include",cache:"no-store"},t,W);if(!s.ok&&s.status!==401){const r=await s.json().catch(()=>null);throw new Error(`${s.status} ${r?.error||s.statusText}`)}q.delete(t),y.delete(t),$(t)}));await Promise.all(e)}const en=Ft(Zt);function Cn(){return v=null,R="",T="",Re(),Me(null),en.run()}async function tn(n,e,t=_){const i=H(t),{timeoutMs:s=W,signal:r,transport:o="auto",...a}=e||{},c=!Q(n),u=c?T:"",d=()=>!c||!!u&&u===T,h=()=>{if(!d())throw new Error("VuvoDesk workspace changed while the Hub request was running.")},w=$t({publicConsole:z(),path:n,requiresUiSession:c});if(c&&!v)throw new Error("VuvoDesk account authority is not available for this Hub request.");const m=()=>{const C=String(a.method||"GET").toUpperCase(),b=y.get(i),l=b?.ownerSignature===T?b.csrfToken:"";return{...a,...r?{signal:r}:{},headers:{...a.headers||{},...!["GET","HEAD","OPTIONS"].includes(C)&&l?{"X-LiveDesk-CSRF":l}:{}},credentials:"include",cache:"no-store"}};if(w==="reject-auth-session")throw new Error("Public Console does not create a Hub cookie session.");if(w==="direct"){if(h(),r?.aborted)throw r.reason||new Error("VuvoDesk Hub request cancelled.");return J(n,m(),s)}if(o==="p2p"){if(h(),r?.aborted)throw r.reason||new Error("VuvoDesk Hub request cancelled.");if(!v||Q(n))throw new Error("Mobile Console direct connection requires an authenticated management request.");return J(n,m(),s)}try{c&&await j(i),h();let C=await G(n,m(),i,s,r);if(h(),Ht(),c&&C.status===401&&v){const b=await C.clone().json().catch(()=>null);/^hub-ui-session-(required|expired)$/.test(String(b?.error||""))&&(await j(i,!0),h(),C=await G(n,m(),i,s,r),h())}return C}catch(C){if(!d()||r?.aborted||!v||Q(n))throw C;return J(n,m(),s)}}async function nn(n,e,t=_){const i=await tn(n,{...e||{},headers:{"Content-Type":"application/json",...e?.headers||{}}},t);let s=null;try{s=await i.json()}catch(r){if(e?.signal?.aborted)throw r;s=null}if(!i.ok){const r=s&&typeof s=="object"&&"error"in s?String(s.error||""):"";throw new Error(`${i.status} ${r||i.statusText}`)}return s}async function Sn({baseUrl:n=_,targetRole:e,previousRuntimePid:t=0,allowedStates:i=["running","waiting-auth"],timeoutMs:s=3e4}){const r=Date.now()+s;let o=null;for(;Date.now()<r;){try{const c=await nn("/api/runtime/status",void 0,n),u=String(c.role||"").toLowerCase(),d=String(c.state||"").toLowerCase(),h=Number(c.runtimePid||0),w=t>1?h>1&&h!==t:h>1;if(u===e&&i.map(m=>m.toLowerCase()).includes(d)&&w)return c}catch(c){o=c}await new Promise(c=>setTimeout(c,300))}const a=o instanceof Error?` ${o.message}`:"";throw new Error(`VuvoDesk runtime did not become ${e} with a new process.${a}`)}function In(n,e=120){if(typeof window>"u")return;const t=new URL(window.location.href);t.port=String(n),t.pathname="/",t.search="",t.hash="";const i=t.toString();let s=0;const r=()=>{fetch(i,{cache:"no-store",mode:"no-cors"}).then(()=>window.location.replace(i)).catch(()=>{if(s+=1,s>=e){window.location.replace(i);return}window.setTimeout(r,250)})};r()}function Ln(n){if(!n)return"-";const e=Date.now()-Date.parse(n);return Number.isFinite(e)?e<1e3?"now":e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`:"-"}async function vn(n){await navigator.clipboard.writeText(n)}const sn=5,Ie=20,rn=50,on=Number.POSITIVE_INFINITY,an=5,yn={free:{name:"Free",price:"$0",limit:sn,people:1,audience:"Personal, ad-supported",note:"Up to 5 personal devices supported by a standard banner."},ltd:{name:"Plus",price:"$5",ltd:"$79 LTD",limit:Ie,people:1,audience:"Creators and homelabs",note:`${Ie} devices, no ads, personal use.`},pro:{name:"Pro / Business",price:"$15",ltd:"$199 LTD",limit:rn,people:1,audience:"Schools, academies, studios, and businesses",note:"Up to 50 devices for school, academy, and commercial use."},team:{name:"Team",price:"$49",limit:on,people:an,audience:"Shared business operations",note:"Commercial use, a shared Team Space, and up to 5 people using their own accounts."}},cn="0.1.696",ln={version:cn},kn=String(ln.version).trim();function An({size:n=22}){return M.jsxs("svg",{width:n,height:n,viewBox:"0 0 28 28",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[M.jsx("rect",{x:"2.5",y:"4",width:"14",height:"9",rx:"1.5",stroke:"currentColor",strokeWidth:"1.7",opacity:"0.42"}),M.jsx("path",{d:"M7 16v1.5h5",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",opacity:"0.42"}),M.jsx("rect",{x:"10.5",y:"2.5",width:"14",height:"9",rx:"1.5",stroke:"currentColor",strokeWidth:"1.7",opacity:"0.62"}),M.jsx("path",{d:"M15 14.5V16h5",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",opacity:"0.62"}),M.jsx("rect",{x:"6.5",y:"8.5",width:"15",height:"10",rx:"1.7",fill:"currentColor",fillOpacity:"0.12",stroke:"currentColor",strokeWidth:"1.9"}),M.jsx("path",{d:"M12 21v1.5H9.5M16 21v1.5h2.5M9.5 22.5h9",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round"})]})}export{_ as D,sn as F,kn as L,An as M,Ie as P,an as T,rn as a,Cn as b,vn as c,X as d,pn as e,Ln as f,Jt as g,nn as h,z as i,gn as j,bn as k,H as l,hn as m,In as n,tn as o,yn as p,En as q,dn as r,fn as s,mn as t,wn as u,Sn as w};