phirepass-widgets 0.0.82 → 0.0.84

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.
Files changed (25) hide show
  1. package/dist/cjs/phirepass-rdp.cjs.entry.js +86 -13
  2. package/dist/cjs/phirepass-sftp-client.cjs.entry.js +1 -1
  3. package/dist/cjs/phirepass-terminal.cjs.entry.js +1 -1
  4. package/dist/cjs/{protocol-DS0qXomZ.js → protocol-CLPcBss-.js} +3 -3
  5. package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +52 -13
  6. package/dist/collection/components/phirepass-rdp/phirepass-rdp.viewport.js +34 -0
  7. package/dist/collection/phirepass-channel_bg.wasm +0 -0
  8. package/dist/{phirepass-widgets/p-CWIhN33k.js → components/p-B29jN5hK.js} +1 -1
  9. package/dist/components/phirepass-rdp.js +1 -1
  10. package/dist/components/phirepass-sftp-client.js +1 -1
  11. package/dist/components/phirepass-terminal.js +1 -1
  12. package/dist/esm/phirepass-rdp.entry.js +86 -13
  13. package/dist/esm/phirepass-sftp-client.entry.js +1 -1
  14. package/dist/esm/phirepass-terminal.entry.js +1 -1
  15. package/dist/esm/{protocol-CWIhN33k.js → protocol-B29jN5hK.js} +2 -2
  16. package/dist/phirepass-widgets/{p-8dca9e3a.entry.js → p-72791b1f.entry.js} +1 -1
  17. package/dist/{components/p-CWIhN33k.js → phirepass-widgets/p-B29jN5hK.js} +1 -1
  18. package/dist/phirepass-widgets/p-b23756c5.entry.js +1 -0
  19. package/dist/phirepass-widgets/{p-b74a5300.entry.js → p-ddd48131.entry.js} +1 -1
  20. package/dist/phirepass-widgets/phirepass-channel_bg.wasm +0 -0
  21. package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
  22. package/dist/types/components/phirepass-rdp/phirepass-rdp.d.ts +15 -0
  23. package/dist/types/components/phirepass-rdp/phirepass-rdp.viewport.d.ts +14 -0
  24. package/package.json +2 -2
  25. package/dist/phirepass-widgets/p-306c47c5.entry.js +0 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-Dtiw2goq.js');
4
- var protocol = require('./protocol-DS0qXomZ.js');
4
+ var protocol = require('./protocol-CLPcBss-.js');
5
5
 
6
6
  /**
7
7
  * RDP's display-control PDU describes a monitor in whole, even pixels within
@@ -11,6 +11,14 @@ var protocol = require('./protocol-DS0qXomZ.js');
11
11
  */
12
12
  const MIN_DIMENSION = 200;
13
13
  const MAX_DIMENSION = 8192;
14
+ /**
15
+ * The size requested at *connect* time travels in the Client Core Data, whose
16
+ * desktop dimensions the protocol caps at 4096 — half what the display-control
17
+ * PDU above allows. A host does not negotiate an out-of-range value down; it
18
+ * drops the connection partway through the sequence, which the client can only
19
+ * report as a truncated stream.
20
+ */
21
+ const MAX_CONNECT_DIMENSION = 4096;
14
22
  /** How long a drag has to settle before the host is asked for a new size. */
15
23
  const RESIZE_DEBOUNCE_MS = 250;
16
24
  function clamp(value) {
@@ -30,6 +38,32 @@ function measure_desktop_size(element) {
30
38
  const rect = element.getBoundingClientRect();
31
39
  return clamp_desktop_size(rect.width, rect.height);
32
40
  }
41
+ /**
42
+ * The size to open a session at, or `undefined` when the widget has no usable
43
+ * layout yet — in which case the host should choose and [`ViewportSync`] will
44
+ * correct it as soon as the client is visible.
45
+ *
46
+ * This is deliberately not [`measure_desktop_size`]. That function clamps, which
47
+ * is right for a resize — a host asked for something silly should get the
48
+ * nearest legal size — but wrong here, because the widget legitimately measures
49
+ * 0×0 before connecting: it sits in a `display: none` tab, or in a container
50
+ * that has not been laid out, or is simply still hidden. Clamping turns that
51
+ * into a request to open the desktop at 200×200, and "the smallest legal
52
+ * desktop" is not what a zero-sized box meant. Asking for nothing is.
53
+ */
54
+ function measure_initial_desktop_size(element) {
55
+ const rect = element.getBoundingClientRect();
56
+ if (!Number.isFinite(rect.width) || !Number.isFinite(rect.height)) {
57
+ return undefined;
58
+ }
59
+ if (rect.width < MIN_DIMENSION || rect.height < MIN_DIMENSION) {
60
+ return undefined;
61
+ }
62
+ return {
63
+ width: even(Math.min(Math.floor(rect.width), MAX_CONNECT_DIMENSION)),
64
+ height: even(Math.min(Math.floor(rect.height), MAX_CONNECT_DIMENSION)),
65
+ };
66
+ }
33
67
  function same_desktop_size(a, b) {
34
68
  return !!a && !!b && a.width === b.width && a.height === b.height;
35
69
  }
@@ -193,6 +227,7 @@ const PhirepassRdp = class {
193
227
  domReady = false;
194
228
  runtimeReady = false;
195
229
  connected = false;
230
+ disposed = false;
196
231
  session_id;
197
232
  onFullscreenChange = () => this.sync_keyboard_lock();
198
233
  /** Credentials in force for this session, from props or from the prompt. */
@@ -276,6 +311,9 @@ const PhirepassRdp = class {
276
311
  }
277
312
  async connectedCallback() {
278
313
  document.addEventListener('fullscreenchange', this.onFullscreenChange);
314
+ // A widget can be moved in the DOM rather than destroyed, which
315
+ // disconnects and reconnects it; the second life is a real one.
316
+ this.disposed = false;
279
317
  await protocol.__wbg_init();
280
318
  this.open_comms();
281
319
  this.runtimeReady = true;
@@ -289,8 +327,18 @@ const PhirepassRdp = class {
289
327
  this.domReady = true;
290
328
  this.try_connect();
291
329
  }
330
+ /**
331
+ * Closing an RDP tab unmounts the widget, and this is the only notice we
332
+ * get. Everything the session is made of has to go with it — including the
333
+ * parts that are still being built: the tunnel can be authorised, or the RDP
334
+ * client's own WebSocket already open, while the modules it needs are still
335
+ * loading. `disposed` is what those in-flight steps check before carrying
336
+ * on, and clearing `session_id` invalidates any answer still on its way.
337
+ */
292
338
  async disconnectedCallback() {
293
339
  document.removeEventListener('fullscreenchange', this.onFullscreenChange);
340
+ this.disposed = true;
341
+ this.session_id = undefined;
294
342
  this.connected = false;
295
343
  this.domReady = false;
296
344
  this.runtimeReady = false;
@@ -422,11 +470,11 @@ const PhirepassRdp = class {
422
470
  import('@devolutions/iron-remote-desktop'),
423
471
  ]);
424
472
  // The element may have gone away while the modules were loading.
425
- if (!this.containerEl || this.session_id !== web.sid) {
473
+ if (this.disposed || !this.containerEl || this.session_id !== web.sid) {
426
474
  return;
427
475
  }
428
476
  await backend.init('info');
429
- if (!this.containerEl || this.session_id !== web.sid) {
477
+ if (this.disposed || !this.containerEl || this.session_id !== web.sid) {
430
478
  return;
431
479
  }
432
480
  // Built imperatively rather than in `render()` so `module` is set
@@ -469,13 +517,30 @@ const PhirepassRdp = class {
469
517
  .withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`)
470
518
  .withAuthToken(ticket)
471
519
  .withExtension(credssp);
472
- // Asking for the widget's size up front costs nothing and saves the
473
- // remote host a resolution change immediately after logon.
520
+ // Asking for the widget's size up front saves the remote host a
521
+ // resolution change immediately after logon — but only when the widget
522
+ // has been laid out. An unmeasurable widget asks for nothing and lets
523
+ // `start_viewport_sync` correct the size once the client is visible;
524
+ // sending a size derived from a zero-sized box is how a host ends up
525
+ // refusing the connection outright.
474
526
  if (this.dynamicResize) {
475
- builder.withDesktopSize(measure_desktop_size(this.el));
527
+ const size = measure_initial_desktop_size(this.el);
528
+ if (size) {
529
+ builder.withDesktopSize(size);
530
+ }
476
531
  }
477
532
  try {
478
533
  const session = await userInteraction.connect(builder.build());
534
+ // The tab can be closed while this handshake is in flight. The
535
+ // session owns the RDP WebSocket and nothing else can close it, so
536
+ // the socket is only released by letting the session loop start and
537
+ // see the shutdown it was already handed — terminate first, then
538
+ // run, and never make the widget visible.
539
+ if (this.disposed) {
540
+ this.shutdown_session(userInteraction);
541
+ await session.run();
542
+ return;
543
+ }
479
544
  userInteraction.setVisibility(true);
480
545
  this.statusMessage = undefined;
481
546
  this.focus_desktop();
@@ -553,16 +618,24 @@ const PhirepassRdp = class {
553
618
  this.statusMessage = error.message;
554
619
  this.connectionStateChanged.emit([protocol.ConnectionState.Error, error]);
555
620
  }
621
+ /**
622
+ * Asks the RDP client to end its session, which is also what closes the
623
+ * socket it opened. Failing here is not worth propagating: the caller is
624
+ * already tearing the widget down and has nothing else to try.
625
+ */
626
+ shutdown_session(userInteraction) {
627
+ try {
628
+ userInteraction.shutdown();
629
+ }
630
+ catch (err) {
631
+ console.warn('Failed to shut the RDP session down cleanly:', err);
632
+ }
633
+ }
556
634
  teardown_client() {
557
635
  this.stop_viewport_sync();
558
636
  unlock_keyboard();
559
637
  if (this.userInteraction) {
560
- try {
561
- this.userInteraction.shutdown();
562
- }
563
- catch (err) {
564
- console.warn('Failed to shut the RDP session down cleanly:', err);
565
- }
638
+ this.shutdown_session(this.userInteraction);
566
639
  this.userInteraction = undefined;
567
640
  }
568
641
  this.ironEl?.remove();
@@ -580,7 +653,7 @@ const PhirepassRdp = class {
580
653
  this.request_tunnel();
581
654
  }
582
655
  render() {
583
- return (index.h(index.Host, { key: '140e8f813403dad27cbbe3b0d3e3099e90c9e08d' }, index.h("div", { key: '0f695b83c808a678b9bff3434ac1ff65a6765e1e', class: "screen", ref: (el) => (this.containerEl = el) }, index.h("slot", { key: 'b382a47294606909074c8b64983419645cda438b' })), this.credentialsPrompt && (index.h("form", { key: '18606a269f254c5bffc81c6c45a4e85473fff557', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, index.h("label", { key: 'f4c2bf9aaa483e323b38d12774728e3a687962a4', htmlFor: "rdp-username" }, "Windows username"), index.h("input", { key: 'ba766990c9fc089b1aa9d894ac5d7032f0c87edf', id: "rdp-username", type: "text", autocomplete: "username", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), index.h("label", { key: '885ee563e3537712d3ad85e47485f44f2de576c5', htmlFor: "rdp-password" }, "Password"), index.h("input", { key: '19cfa162b515e6b230b19a3f2f8fd267ff5388ec', id: "rdp-password", type: "password", autocomplete: "current-password", onInput: (event) => (this.passwordBuffer = event.target.value) }), index.h("button", { key: '04b428b4947f1d0f957399961c5196d5bbc6b5a7', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (index.h("div", { key: 'eb66cd3974a3aa8a563bd54599912bc735007214', class: "status" }, this.statusMessage))));
656
+ return (index.h(index.Host, { key: '892fd55fb84abf180866dd7af4e44adc9c23f338' }, index.h("div", { key: 'fd6ac08295b6ce9e3bd3932abea271c9c6fc8a00', class: "screen", ref: (el) => (this.containerEl = el) }, index.h("slot", { key: 'b9240f804177898f29598b0c7ec7b4f4d2e8d6c6' })), this.credentialsPrompt && (index.h("form", { key: '49ce099f575a30c0bb326a64de74d30cf599418f', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, index.h("label", { key: '1a12eb01993f858bbbc2498cc8d896b1dd1dbf88', htmlFor: "rdp-username" }, "Windows username"), index.h("input", { key: '79c8482390211b3ba3d253e8485e7895fc52b393', id: "rdp-username", type: "text", autocomplete: "username", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), index.h("label", { key: '3c07473b2d85ddb4e13a45f3d771b23749570c2e', htmlFor: "rdp-password" }, "Password"), index.h("input", { key: '8740ab5c45186bac0f452931d9e6ccec6c4fdeab', id: "rdp-password", type: "password", autocomplete: "current-password", onInput: (event) => (this.passwordBuffer = event.target.value) }), index.h("button", { key: 'df366feb5122cd0bcf0d0a07a034f18302e0f9e3', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (index.h("div", { key: '1823a89de1c881121fa8dee61af053ff1ac3e5e3', class: "status" }, this.statusMessage))));
584
657
  }
585
658
  static get watchers() { return {
586
659
  "nodeId": [{
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-Dtiw2goq.js');
4
- var protocol = require('./protocol-DS0qXomZ.js');
4
+ var protocol = require('./protocol-CLPcBss-.js');
5
5
 
6
6
  const phirepassSftpClientLogoSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIgogICAgc3Ryb2tlPSJyZ2IoNDYsIDE4NCwgMTM4KSIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiCiAgICBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10ZXJtaW5hbCB3LTMuNSBoLTMuNSB0ZXh0LXByaW1hcnkiPgogICAgPHBvbHlsaW5lIHBvaW50cz0iNCAxNyAxMCAxMSA0IDUiPjwvcG9seWxpbmU+CiAgICA8bGluZSB4MT0iMTIiIHgyPSIyMCIgeTE9IjE5IiB5Mj0iMTkiPjwvbGluZT4KPC9zdmc+Cg==';
7
7
 
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-Dtiw2goq.js');
4
- var protocol = require('./protocol-DS0qXomZ.js');
4
+ var protocol = require('./protocol-CLPcBss-.js');
5
5
 
6
6
  /**
7
7
  * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
@@ -463,7 +463,7 @@ function __wbg_get_imports() {
463
463
  const ret = Reflect.get(getObject(arg0), getObject(arg1));
464
464
  return addHeapObject(ret);
465
465
  }, arguments); },
466
- __wbg_info_e70a4ed57b90fedf: function(arg0, arg1) {
466
+ __wbg_info_50b082b6c686951d: function(arg0, arg1) {
467
467
  console.info(getStringFromWasm0(arg0, arg1));
468
468
  },
469
469
  __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
@@ -535,7 +535,7 @@ function __wbg_get_imports() {
535
535
  __wbg_set_onopen_4f65470ae522a61a: function(arg0, arg1) {
536
536
  getObject(arg0).onopen = getObject(arg1);
537
537
  },
538
- __wbg_warn_5c89b14defca8e2c: function(arg0, arg1) {
538
+ __wbg_warn_0a2d995b00b43107: function(arg0, arg1) {
539
539
  console.warn(getStringFromWasm0(arg0, arg1));
540
540
  },
541
541
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
@@ -905,7 +905,7 @@ async function __wbg_init(module_or_path) {
905
905
  }
906
906
 
907
907
  if (module_or_path === undefined) {
908
- module_or_path = new URL('phirepass-channel_bg.wasm', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('protocol-DS0qXomZ.js', document.baseURI).href)));
908
+ module_or_path = new URL('phirepass-channel_bg.wasm', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('protocol-CLPcBss-.js', document.baseURI).href)));
909
909
  }
910
910
  const imports = __wbg_get_imports();
911
911
 
@@ -1,7 +1,7 @@
1
1
  import { Host, h } from "@stencil/core";
2
2
  import init, { Channel as PhirepassChannel } from "phirepass-channel";
3
3
  import { ConnectionState, ProtocolMessageType, } from "../../common/protocol";
4
- import { measure_desktop_size, ViewportSync } from "./phirepass-rdp.viewport";
4
+ import { measure_initial_desktop_size, ViewportSync } from "./phirepass-rdp.viewport";
5
5
  import { focus_client, keyboard_lock_supported, lock_keyboard, shown_fullscreen, toggle_fullscreen, unlock_keyboard, } from "./phirepass-rdp.keyboard";
6
6
  /**
7
7
  * Remote desktop over RDP.
@@ -22,6 +22,7 @@ export class PhirepassRdp {
22
22
  domReady = false;
23
23
  runtimeReady = false;
24
24
  connected = false;
25
+ disposed = false;
25
26
  session_id;
26
27
  onFullscreenChange = () => this.sync_keyboard_lock();
27
28
  /** Credentials in force for this session, from props or from the prompt. */
@@ -105,6 +106,9 @@ export class PhirepassRdp {
105
106
  }
106
107
  async connectedCallback() {
107
108
  document.addEventListener('fullscreenchange', this.onFullscreenChange);
109
+ // A widget can be moved in the DOM rather than destroyed, which
110
+ // disconnects and reconnects it; the second life is a real one.
111
+ this.disposed = false;
108
112
  await init();
109
113
  this.open_comms();
110
114
  this.runtimeReady = true;
@@ -118,8 +122,18 @@ export class PhirepassRdp {
118
122
  this.domReady = true;
119
123
  this.try_connect();
120
124
  }
125
+ /**
126
+ * Closing an RDP tab unmounts the widget, and this is the only notice we
127
+ * get. Everything the session is made of has to go with it — including the
128
+ * parts that are still being built: the tunnel can be authorised, or the RDP
129
+ * client's own WebSocket already open, while the modules it needs are still
130
+ * loading. `disposed` is what those in-flight steps check before carrying
131
+ * on, and clearing `session_id` invalidates any answer still on its way.
132
+ */
121
133
  async disconnectedCallback() {
122
134
  document.removeEventListener('fullscreenchange', this.onFullscreenChange);
135
+ this.disposed = true;
136
+ this.session_id = undefined;
123
137
  this.connected = false;
124
138
  this.domReady = false;
125
139
  this.runtimeReady = false;
@@ -251,11 +265,11 @@ export class PhirepassRdp {
251
265
  import('@devolutions/iron-remote-desktop'),
252
266
  ]);
253
267
  // The element may have gone away while the modules were loading.
254
- if (!this.containerEl || this.session_id !== web.sid) {
268
+ if (this.disposed || !this.containerEl || this.session_id !== web.sid) {
255
269
  return;
256
270
  }
257
271
  await backend.init('info');
258
- if (!this.containerEl || this.session_id !== web.sid) {
272
+ if (this.disposed || !this.containerEl || this.session_id !== web.sid) {
259
273
  return;
260
274
  }
261
275
  // Built imperatively rather than in `render()` so `module` is set
@@ -298,13 +312,30 @@ export class PhirepassRdp {
298
312
  .withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`)
299
313
  .withAuthToken(ticket)
300
314
  .withExtension(credssp);
301
- // Asking for the widget's size up front costs nothing and saves the
302
- // remote host a resolution change immediately after logon.
315
+ // Asking for the widget's size up front saves the remote host a
316
+ // resolution change immediately after logon — but only when the widget
317
+ // has been laid out. An unmeasurable widget asks for nothing and lets
318
+ // `start_viewport_sync` correct the size once the client is visible;
319
+ // sending a size derived from a zero-sized box is how a host ends up
320
+ // refusing the connection outright.
303
321
  if (this.dynamicResize) {
304
- builder.withDesktopSize(measure_desktop_size(this.el));
322
+ const size = measure_initial_desktop_size(this.el);
323
+ if (size) {
324
+ builder.withDesktopSize(size);
325
+ }
305
326
  }
306
327
  try {
307
328
  const session = await userInteraction.connect(builder.build());
329
+ // The tab can be closed while this handshake is in flight. The
330
+ // session owns the RDP WebSocket and nothing else can close it, so
331
+ // the socket is only released by letting the session loop start and
332
+ // see the shutdown it was already handed — terminate first, then
333
+ // run, and never make the widget visible.
334
+ if (this.disposed) {
335
+ this.shutdown_session(userInteraction);
336
+ await session.run();
337
+ return;
338
+ }
308
339
  userInteraction.setVisibility(true);
309
340
  this.statusMessage = undefined;
310
341
  this.focus_desktop();
@@ -382,16 +413,24 @@ export class PhirepassRdp {
382
413
  this.statusMessage = error.message;
383
414
  this.connectionStateChanged.emit([ConnectionState.Error, error]);
384
415
  }
416
+ /**
417
+ * Asks the RDP client to end its session, which is also what closes the
418
+ * socket it opened. Failing here is not worth propagating: the caller is
419
+ * already tearing the widget down and has nothing else to try.
420
+ */
421
+ shutdown_session(userInteraction) {
422
+ try {
423
+ userInteraction.shutdown();
424
+ }
425
+ catch (err) {
426
+ console.warn('Failed to shut the RDP session down cleanly:', err);
427
+ }
428
+ }
385
429
  teardown_client() {
386
430
  this.stop_viewport_sync();
387
431
  unlock_keyboard();
388
432
  if (this.userInteraction) {
389
- try {
390
- this.userInteraction.shutdown();
391
- }
392
- catch (err) {
393
- console.warn('Failed to shut the RDP session down cleanly:', err);
394
- }
433
+ this.shutdown_session(this.userInteraction);
395
434
  this.userInteraction = undefined;
396
435
  }
397
436
  this.ironEl?.remove();
@@ -409,7 +448,7 @@ export class PhirepassRdp {
409
448
  this.request_tunnel();
410
449
  }
411
450
  render() {
412
- return (h(Host, { key: '140e8f813403dad27cbbe3b0d3e3099e90c9e08d' }, h("div", { key: '0f695b83c808a678b9bff3434ac1ff65a6765e1e', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: 'b382a47294606909074c8b64983419645cda438b' })), this.credentialsPrompt && (h("form", { key: '18606a269f254c5bffc81c6c45a4e85473fff557', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: 'f4c2bf9aaa483e323b38d12774728e3a687962a4', htmlFor: "rdp-username" }, "Windows username"), h("input", { key: 'ba766990c9fc089b1aa9d894ac5d7032f0c87edf', id: "rdp-username", type: "text", autocomplete: "username", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: '885ee563e3537712d3ad85e47485f44f2de576c5', htmlFor: "rdp-password" }, "Password"), h("input", { key: '19cfa162b515e6b230b19a3f2f8fd267ff5388ec', id: "rdp-password", type: "password", autocomplete: "current-password", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: '04b428b4947f1d0f957399961c5196d5bbc6b5a7', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: 'eb66cd3974a3aa8a563bd54599912bc735007214', class: "status" }, this.statusMessage))));
451
+ return (h(Host, { key: '892fd55fb84abf180866dd7af4e44adc9c23f338' }, h("div", { key: 'fd6ac08295b6ce9e3bd3932abea271c9c6fc8a00', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: 'b9240f804177898f29598b0c7ec7b4f4d2e8d6c6' })), this.credentialsPrompt && (h("form", { key: '49ce099f575a30c0bb326a64de74d30cf599418f', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: '1a12eb01993f858bbbc2498cc8d896b1dd1dbf88', htmlFor: "rdp-username" }, "Windows username"), h("input", { key: '79c8482390211b3ba3d253e8485e7895fc52b393', id: "rdp-username", type: "text", autocomplete: "username", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: '3c07473b2d85ddb4e13a45f3d771b23749570c2e', htmlFor: "rdp-password" }, "Password"), h("input", { key: '8740ab5c45186bac0f452931d9e6ccec6c4fdeab', id: "rdp-password", type: "password", autocomplete: "current-password", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: 'df366feb5122cd0bcf0d0a07a034f18302e0f9e3', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: '1823a89de1c881121fa8dee61af053ff1ac3e5e3', class: "status" }, this.statusMessage))));
413
452
  }
414
453
  static get is() { return "phirepass-rdp"; }
415
454
  static get encapsulation() { return "shadow"; }
@@ -6,6 +6,14 @@
6
6
  */
7
7
  const MIN_DIMENSION = 200;
8
8
  const MAX_DIMENSION = 8192;
9
+ /**
10
+ * The size requested at *connect* time travels in the Client Core Data, whose
11
+ * desktop dimensions the protocol caps at 4096 — half what the display-control
12
+ * PDU above allows. A host does not negotiate an out-of-range value down; it
13
+ * drops the connection partway through the sequence, which the client can only
14
+ * report as a truncated stream.
15
+ */
16
+ const MAX_CONNECT_DIMENSION = 4096;
9
17
  /** How long a drag has to settle before the host is asked for a new size. */
10
18
  export const RESIZE_DEBOUNCE_MS = 250;
11
19
  function clamp(value) {
@@ -25,6 +33,32 @@ export function measure_desktop_size(element) {
25
33
  const rect = element.getBoundingClientRect();
26
34
  return clamp_desktop_size(rect.width, rect.height);
27
35
  }
36
+ /**
37
+ * The size to open a session at, or `undefined` when the widget has no usable
38
+ * layout yet — in which case the host should choose and [`ViewportSync`] will
39
+ * correct it as soon as the client is visible.
40
+ *
41
+ * This is deliberately not [`measure_desktop_size`]. That function clamps, which
42
+ * is right for a resize — a host asked for something silly should get the
43
+ * nearest legal size — but wrong here, because the widget legitimately measures
44
+ * 0×0 before connecting: it sits in a `display: none` tab, or in a container
45
+ * that has not been laid out, or is simply still hidden. Clamping turns that
46
+ * into a request to open the desktop at 200×200, and "the smallest legal
47
+ * desktop" is not what a zero-sized box meant. Asking for nothing is.
48
+ */
49
+ export function measure_initial_desktop_size(element) {
50
+ const rect = element.getBoundingClientRect();
51
+ if (!Number.isFinite(rect.width) || !Number.isFinite(rect.height)) {
52
+ return undefined;
53
+ }
54
+ if (rect.width < MIN_DIMENSION || rect.height < MIN_DIMENSION) {
55
+ return undefined;
56
+ }
57
+ return {
58
+ width: even(Math.min(Math.floor(rect.width), MAX_CONNECT_DIMENSION)),
59
+ height: even(Math.min(Math.floor(rect.height), MAX_CONNECT_DIMENSION)),
60
+ };
61
+ }
28
62
  export function same_desktop_size(a, b) {
29
63
  return !!a && !!b && a.width === b.width && a.height === b.height;
30
64
  }
@@ -1 +1 @@
1
- class n{__destroy_into_raw(){const n=this.__wbg_ptr;return this.__wbg_ptr=0,_.unregister(this),n}free(){const n=this.__destroy_into_raw();O.__wbg_channel_free(n,0)}authenticate(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(t,O.__wbindgen_export,O.__wbindgen_export2);O.channel_authenticate(this.__wbg_ptr,r,o,c,P,R(e)?Number.MAX_SAFE_INTEGER:e>>>0)}connect(){O.channel_connect(this.__wbg_ptr)}create_service(n,t,e,r,o,c,i,s,_,u){const a=S(n,O.__wbindgen_export,O.__wbindgen_export2),f=P,b=S(t,O.__wbindgen_export,O.__wbindgen_export2),l=P;var d=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),w=P;const g=S(r,O.__wbindgen_export,O.__wbindgen_export2),h=P;var p=R(c)?0:S(c,O.__wbindgen_export,O.__wbindgen_export2),y=P,m=R(i)?0:S(i,O.__wbindgen_export,O.__wbindgen_export2),v=P,A=R(s)?0:S(s,O.__wbindgen_export,O.__wbindgen_export2),N=P,T=R(_)?0:S(_,O.__wbindgen_export,O.__wbindgen_export2);O.channel_create_service(this.__wbg_ptr,a,f,b,l,d,w,g,h,o,p,y,m,v,A,N,T,P,R(u)?Number.MAX_SAFE_INTEGER:u>>>0)}delete_service(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(t,O.__wbindgen_export,O.__wbindgen_export2);O.channel_delete_service(this.__wbg_ptr,r,o,c,P,R(e)?Number.MAX_SAFE_INTEGER:e>>>0)}disconnect(){O.channel_disconnect(this.__wbg_ptr)}is_connected(){return 0!==O.channel_is_connected(this.__wbg_ptr)}is_disconnected(){return 0!==O.channel_is_disconnected(this.__wbg_ptr)}constructor(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(t,O.__wbindgen_export,O.__wbindgen_export2),i=P;var s=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2);const u=O.channel_new(r,o,c,i,s,P);return this.__wbg_ptr=u,_.register(this,this.__wbg_ptr,this),this}on_connection_close(n){O.channel_on_connection_close(this.__wbg_ptr,R(n)?0:u(n))}on_connection_error(n){O.channel_on_connection_error(this.__wbg_ptr,R(n)?0:u(n))}on_connection_message(n){O.channel_on_connection_message(this.__wbg_ptr,R(n)?0:u(n))}on_connection_open(n){O.channel_on_connection_open(this.__wbg_ptr,R(n)?0:u(n))}on_protocol_message(n){O.channel_on_protocol_message(this.__wbg_ptr,R(n)?0:u(n))}on_protocol_message_type(n,t){const e=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_on_protocol_message_type(this.__wbg_ptr,e,P,R(t)?0:u(t))}open_rdp_tunnel(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(t,O.__wbindgen_export,O.__wbindgen_export2),_=P;var u=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_open_rdp_tunnel(this.__wbg_ptr,c,i,s,_,u,a,f,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}open_sftp_tunnel(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(t,O.__wbindgen_export,O.__wbindgen_export2),_=P;var u=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_open_sftp_tunnel(this.__wbg_ptr,c,i,s,_,u,a,f,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}open_ssh_tunnel(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(t,O.__wbindgen_export,O.__wbindgen_export2),_=P;var u=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_open_ssh_tunnel(this.__wbg_ptr,c,i,s,_,u,a,f,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_delete(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(e,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_delete(this.__wbg_ptr,c,i,t,s,_,u,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_download_ack(n,t,e,r){const o=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_download_ack(this.__wbg_ptr,o,P,t,e,r)}send_sftp_download_chunk(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_download_chunk(this.__wbg_ptr,c,P,t,e,r,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_download_start(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(e,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_download_start(this.__wbg_ptr,c,i,t,s,_,u,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_list_data(n,t,e,r){const o=S(n,O.__wbindgen_export,O.__wbindgen_export2),c=P,i=S(e,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_list_data(this.__wbg_ptr,o,c,t,i,P,R(r)?Number.MAX_SAFE_INTEGER:r>>>0)}send_sftp_upload_chunk(n,t,e,r,o,c,i){const s=S(n,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=function(n){const t=(0,O.__wbindgen_export)(1*n.length,1)>>>0;return h().set(n,t/1),P=n.length,t}(c);O.channel_send_sftp_upload_chunk(this.__wbg_ptr,s,_,t,e,r,o,u,P,R(i)?Number.MAX_SAFE_INTEGER:i>>>0)}send_sftp_upload_start(n,t,e,r,o,c,i){const s=S(n,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_upload_start(this.__wbg_ptr,s,_,t,u,a,f,P,o,c,R(i)?Number.MAX_SAFE_INTEGER:i>>>0)}send_ssh_terminal_resize(n,t,e,r,o,c){const i=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_ssh_terminal_resize(this.__wbg_ptr,i,P,t,e,r,o,c)}send_ssh_tunnel_data(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(e,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_ssh_tunnel_data(this.__wbg_ptr,r,o,t,c,P)}start_heartbeat(n){O.channel_start_heartbeat(this.__wbg_ptr,n)}stop_heartbeat(){O.channel_stop_heartbeat(this.__wbg_ptr)}update_service(n,t,e,r,o,c,i,s,_,u,a){const f=S(n,O.__wbindgen_export,O.__wbindgen_export2),b=P,l=S(t,O.__wbindgen_export,O.__wbindgen_export2),d=P,w=S(e,O.__wbindgen_export,O.__wbindgen_export2),g=P;var h=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2),p=P;const y=S(o,O.__wbindgen_export,O.__wbindgen_export2),m=P;var v=R(i)?0:S(i,O.__wbindgen_export,O.__wbindgen_export2),A=P,N=R(s)?0:S(s,O.__wbindgen_export,O.__wbindgen_export2),T=P,U=R(_)?0:S(_,O.__wbindgen_export,O.__wbindgen_export2),j=P,F=R(u)?0:S(u,O.__wbindgen_export,O.__wbindgen_export2);O.channel_update_service(this.__wbg_ptr,f,b,l,d,w,g,h,p,y,m,c,v,A,N,T,U,j,F,P,R(a)?Number.MAX_SAFE_INTEGER:a>>>0)}}Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);const t=Object.freeze({Generic:0,0:"Generic",Authentication:10,10:"Authentication",RequiresUsername:100,100:"RequiresUsername",RequiresPassword:110,110:"RequiresPassword",RequiresUsernamePassword:120,120:"RequiresUsernamePassword"});function e(){const n={__proto__:null,__wbg_Error_92b29b0548f8b746:function(n,t){return u(Error(w(n,t)))},__wbg_String_8564e559799eccda:function(n,t){const e=S(String(p(t)),O.__wbindgen_export,O.__wbindgen_export2),r=P;d().setInt32(n+4,r,!0),d().setInt32(n+0,e,!0)},__wbg___wbindgen_debug_string_c25d447a39f5578f:function(n,t){const e=S(f(p(t)),O.__wbindgen_export,O.__wbindgen_export2),r=P;d().setInt32(n+4,r,!0),d().setInt32(n+0,e,!0)},__wbg___wbindgen_string_get_b0ca35b86a603356:function(n,t){const e=p(t),r="string"==typeof e?e:void 0;var o=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2),c=P;d().setInt32(n+4,c,!0),d().setInt32(n+0,o,!0)},__wbg___wbindgen_throw_344f42d3211c4765:function(n,t){throw new Error(w(n,t))},__wbg__wbg_cb_unref_fffb441def202758:function(n){p(n)._wbg_cb_unref()},__wbg_call_8a2dd23819f8a60a:function(){return y((function(n,t){return u(p(n).call(p(t)))}),arguments)},__wbg_call_a6e5c5dce5018821:function(){return y((function(n,t,e){return u(p(n).call(p(t),p(e)))}),arguments)},__wbg_call_e3b662382210db98:function(){return y((function(n,t,e,r){return u(p(n).call(p(t),p(e),p(r)))}),arguments)},__wbg_clearInterval_26ba580547547579:function(n){return u(clearInterval(N(n)))},__wbg_close_c65ca0257e895318:function(){return y((function(n){p(n).close()}),arguments)},__wbg_data_328de4280640da92:function(n){return u(p(n).data)},__wbg_from_13e323c65fc8f464:function(n){return u(Array.from(p(n)))},__wbg_getRandomValues_3f44b700395062e5:function(){return y((function(n,t){globalThis.crypto.getRandomValues(b(n,t))}),arguments)},__wbg_get_78f252d074a84d0b:function(){return y((function(n,t){return u(Reflect.get(p(n),p(t)))}),arguments)},__wbg_info_e70a4ed57b90fedf:function(n,t){console.info(w(n,t))},__wbg_instanceof_ArrayBuffer_4480b9e0068a8adb:function(n){let t;try{t=p(n)instanceof ArrayBuffer}catch(n){t=!1}return t},__wbg_length_1f0964f4a5e2c6d8:function(n){return p(n).length},__wbg_new_32b398fb48b6d94a:function(){return u(new Array)},__wbg_new_cd45aabdf6073e84:function(n){return u(new Uint8Array(p(n)))},__wbg_new_da52cf8fe3429cb2:function(){return u(new Object)},__wbg_new_with_str_sequence_2de2f569c29910ad:function(){return y((function(n,t,e){return u(new WebSocket(w(n,t),p(e)))}),arguments)},__wbg_prototypesetcall_4770620bbe4688a0:function(n,t,e){Uint8Array.prototype.set.call(b(n,t),p(e))},__wbg_push_d2ae3af0c1217ae6:function(n,t){return p(n).push(p(t))},__wbg_readyState_50bc38c2a9e83db6:function(n){return p(n).readyState},__wbg_send_a321b376d40ec867:function(){return y((function(n,t,e){p(n).send(b(t,e))}),arguments)},__wbg_setInterval_cbf1c35c6a692d37:function(){return y((function(n,t){return u(setInterval(p(n),t))}),arguments)},__wbg_set_6be42768c690e380:function(n,t,e){p(n)[N(t)]=N(e)},__wbg_set_8a16b38e4805b298:function(n,t,e){p(n)[t>>>0]=N(e)},__wbg_set_binaryType_a37b086c78ca7c29:function(n,t){p(n).binaryType=s[t]},__wbg_set_onclose_f706475385ecce07:function(n,t){p(n).onclose=p(t)},__wbg_set_onerror_9f5773fd31512333:function(n,t){p(n).onerror=p(t)},__wbg_set_onmessage_836d2f72130b4706:function(n,t){p(n).onmessage=p(t)},__wbg_set_onopen_4f65470ae522a61a:function(n,t){p(n).onopen=p(t)},__wbg_warn_5c89b14defca8e2c:function(n,t){console.warn(w(n,t))},__wbindgen_cast_0000000000000001:function(n,t){return u(A(n,t,o))},__wbindgen_cast_0000000000000002:function(n,t){return u(A(n,t,c))},__wbindgen_cast_0000000000000003:function(n,t){return u(A(n,t,i))},__wbindgen_cast_0000000000000004:function(n,t){return u(A(n,t,r))},__wbindgen_cast_0000000000000005:function(n){return u(n)},__wbindgen_cast_0000000000000006:function(n,t){return u(b(n,t))},__wbindgen_cast_0000000000000007:function(n,t){return u(w(n,t))},__wbindgen_cast_0000000000000008:function(n){return u(BigInt.asUintN(64,n))},__wbindgen_object_clone_ref:function(n){return u(p(n))},__wbindgen_object_drop_ref:function(n){N(n)}};return{__proto__:null,"./phirepass-channel_bg.js":n}}function r(n,t){O.__wasm_bindgen_func_elem_63(n,t)}function o(n,t,e){O.__wasm_bindgen_func_elem_59(n,t,u(e))}function c(n,t,e){O.__wasm_bindgen_func_elem_59_1(n,t,u(e))}function i(n,t,e){O.__wasm_bindgen_func_elem_59_2(n,t,u(e))}const s=["blob","arraybuffer"],_="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>O.__wbg_channel_free(n,1)));function u(n){v===m.length&&m.push(m.length+1);const t=v;return v=m[t],m[t]=n,t}const a="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>O.__wbindgen_export4(n.a,n.b)));function f(n){const t=typeof n;if("number"==t||"boolean"==t||null==n)return`${n}`;if("string"==t)return`"${n}"`;if("symbol"==t){const t=n.description;return null==t?"Symbol":`Symbol(${t})`}if("function"==t){const t=n.name;return"string"==typeof t&&t.length>0?`Function(${t})`:"Function"}if(Array.isArray(n)){const t=n.length;let e="[";t>0&&(e+=f(n[0]));for(let r=1;r<t;r++)e+=", "+f(n[r]);return e+="]",e}const e=/\[object ([^\]]+)\]/.exec(toString.call(n));let r;if(!(e&&e.length>1))return toString.call(n);if(r=e[1],"Object"==r)try{return"Object("+JSON.stringify(n)+")"}catch(n){return"Object"}return n instanceof Error?`${n.name}: ${n.message}\n${n.stack}`:r}function b(n,t){return n>>>=0,h().subarray(n/1,n/1+t)}let l=null;function d(){return(null===l||!0===l.buffer.detached||void 0===l.buffer.detached&&l.buffer!==O.memory.buffer)&&(l=new DataView(O.memory.buffer)),l}function w(n,t){return function(n,t){return j+=t,j>=U&&(T=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),T.decode(),j=t),T.decode(h().subarray(n,n+t))}(n>>>0,t)}let g=null;function h(){return null!==g&&0!==g.byteLength||(g=new Uint8Array(O.memory.buffer)),g}function p(n){return m[n]}function y(n,t){try{return n.apply(this,t)}catch(n){O.__wbindgen_export3(u(n))}}let m=new Array(1024).fill(void 0);m.push(void 0,null,!0,!1);let v=m.length;function R(n){return null==n}function A(n,t,e){const r={a:n,b:t,cnt:1},o=(...n)=>{r.cnt++;const t=r.a;r.a=0;try{return e(t,r.b,...n)}finally{r.a=t,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{0==--r.cnt&&(O.__wbindgen_export4(r.a,r.b),r.a=0,a.unregister(r))},a.register(o,r,r),o}function S(n,t,e){if(void 0===e){const e=F.encode(n),r=t(e.length,1)>>>0;return h().subarray(r,r+e.length).set(e),P=e.length,r}let r=n.length,o=t(r,1)>>>0;const c=h();let i=0;for(;i<r;i++){const t=n.charCodeAt(i);if(t>127)break;c[o+i]=t}if(i!==r){0!==i&&(n=n.slice(i)),o=e(o,r,r=i+3*n.length,1)>>>0;const t=h().subarray(o+i,o+r);i+=F.encodeInto(n,t).written,o=e(o,r,i,1)>>>0}return P=i,o}function N(n){const t=p(n);return function(n){n<1028||(m[n]=v,v=n)}(n),t}let T=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});T.decode();const U=2146435072;let j=0;const F=new TextEncoder;"encodeInto"in F||(F.encodeInto=function(n,t){const e=F.encode(n);return t.set(e),{read:n.length,written:e.length}});let O,P=0;async function k(n){if(void 0!==O)return O;void 0!==n&&(Object.getPrototypeOf(n)===Object.prototype?({module_or_path:n}=n):console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===n&&(n=new URL("phirepass-channel_bg.wasm",import.meta.url));const t=e();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:r}=await async function(n,t){if("function"==typeof Response&&n instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(n,t)}catch(t){if(!n.ok||!function(n){switch(n){case"basic":case"cors":case"default":return!0}return!1}(n.type)||"application/wasm"===n.headers.get("Content-Type"))throw t;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t)}const e=await n.arrayBuffer();return await WebAssembly.instantiate(e,t)}{const e=await WebAssembly.instantiate(n,t);return e instanceof WebAssembly.Instance?{instance:e,module:n}:e}}(await n,t);return function(n){return O=n.exports,l=null,g=null,O}(r)}var q,I,W;!function(n){n.Error="Error",n.AuthSuccess="AuthSuccess",n.TunnelOpened="TunnelOpened",n.TunnelClosed="TunnelClosed",n.TunnelData="TunnelData",n.RDPAuthorized="RDPAuthorized",n.SFTPListItems="SFTPListItems",n.SFTPDownloadStartResponse="SFTPDownloadStartResponse",n.SFTPDownloadChunk="SFTPDownloadChunk",n.SFTPUploadStartResponse="SFTPUploadStartResponse",n.SFTPUploadChunkAck="SFTPUploadChunkAck"}(q||(q={})),function(n){n[n.Username=0]="Username",n[n.Password=1]="Password",n[n.Default=2]="Default"}(I||(I={})),function(n){n.Disconnected="disconnected",n.Connected="connected",n.Error="error"}(W||(W={}));export{n as C,t as E,I,q as P,k as _,W as a}
1
+ class n{__destroy_into_raw(){const n=this.__wbg_ptr;return this.__wbg_ptr=0,_.unregister(this),n}free(){const n=this.__destroy_into_raw();O.__wbg_channel_free(n,0)}authenticate(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(t,O.__wbindgen_export,O.__wbindgen_export2);O.channel_authenticate(this.__wbg_ptr,r,o,c,P,R(e)?Number.MAX_SAFE_INTEGER:e>>>0)}connect(){O.channel_connect(this.__wbg_ptr)}create_service(n,t,e,r,o,c,i,s,_,u){const a=S(n,O.__wbindgen_export,O.__wbindgen_export2),f=P,b=S(t,O.__wbindgen_export,O.__wbindgen_export2),l=P;var d=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),w=P;const g=S(r,O.__wbindgen_export,O.__wbindgen_export2),h=P;var p=R(c)?0:S(c,O.__wbindgen_export,O.__wbindgen_export2),y=P,m=R(i)?0:S(i,O.__wbindgen_export,O.__wbindgen_export2),v=P,A=R(s)?0:S(s,O.__wbindgen_export,O.__wbindgen_export2),N=P,T=R(_)?0:S(_,O.__wbindgen_export,O.__wbindgen_export2);O.channel_create_service(this.__wbg_ptr,a,f,b,l,d,w,g,h,o,p,y,m,v,A,N,T,P,R(u)?Number.MAX_SAFE_INTEGER:u>>>0)}delete_service(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(t,O.__wbindgen_export,O.__wbindgen_export2);O.channel_delete_service(this.__wbg_ptr,r,o,c,P,R(e)?Number.MAX_SAFE_INTEGER:e>>>0)}disconnect(){O.channel_disconnect(this.__wbg_ptr)}is_connected(){return 0!==O.channel_is_connected(this.__wbg_ptr)}is_disconnected(){return 0!==O.channel_is_disconnected(this.__wbg_ptr)}constructor(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(t,O.__wbindgen_export,O.__wbindgen_export2),i=P;var s=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2);const u=O.channel_new(r,o,c,i,s,P);return this.__wbg_ptr=u,_.register(this,this.__wbg_ptr,this),this}on_connection_close(n){O.channel_on_connection_close(this.__wbg_ptr,R(n)?0:u(n))}on_connection_error(n){O.channel_on_connection_error(this.__wbg_ptr,R(n)?0:u(n))}on_connection_message(n){O.channel_on_connection_message(this.__wbg_ptr,R(n)?0:u(n))}on_connection_open(n){O.channel_on_connection_open(this.__wbg_ptr,R(n)?0:u(n))}on_protocol_message(n){O.channel_on_protocol_message(this.__wbg_ptr,R(n)?0:u(n))}on_protocol_message_type(n,t){const e=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_on_protocol_message_type(this.__wbg_ptr,e,P,R(t)?0:u(t))}open_rdp_tunnel(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(t,O.__wbindgen_export,O.__wbindgen_export2),_=P;var u=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_open_rdp_tunnel(this.__wbg_ptr,c,i,s,_,u,a,f,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}open_sftp_tunnel(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(t,O.__wbindgen_export,O.__wbindgen_export2),_=P;var u=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_open_sftp_tunnel(this.__wbg_ptr,c,i,s,_,u,a,f,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}open_ssh_tunnel(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(t,O.__wbindgen_export,O.__wbindgen_export2),_=P;var u=R(e)?0:S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_open_ssh_tunnel(this.__wbg_ptr,c,i,s,_,u,a,f,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_delete(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(e,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_delete(this.__wbg_ptr,c,i,t,s,_,u,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_download_ack(n,t,e,r){const o=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_download_ack(this.__wbg_ptr,o,P,t,e,r)}send_sftp_download_chunk(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_download_chunk(this.__wbg_ptr,c,P,t,e,r,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_download_start(n,t,e,r,o){const c=S(n,O.__wbindgen_export,O.__wbindgen_export2),i=P,s=S(e,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_download_start(this.__wbg_ptr,c,i,t,s,_,u,P,R(o)?Number.MAX_SAFE_INTEGER:o>>>0)}send_sftp_list_data(n,t,e,r){const o=S(n,O.__wbindgen_export,O.__wbindgen_export2),c=P,i=S(e,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_list_data(this.__wbg_ptr,o,c,t,i,P,R(r)?Number.MAX_SAFE_INTEGER:r>>>0)}send_sftp_upload_chunk(n,t,e,r,o,c,i){const s=S(n,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=function(n){const t=(0,O.__wbindgen_export)(1*n.length,1)>>>0;return h().set(n,t/1),P=n.length,t}(c);O.channel_send_sftp_upload_chunk(this.__wbg_ptr,s,_,t,e,r,o,u,P,R(i)?Number.MAX_SAFE_INTEGER:i>>>0)}send_sftp_upload_start(n,t,e,r,o,c,i){const s=S(n,O.__wbindgen_export,O.__wbindgen_export2),_=P,u=S(e,O.__wbindgen_export,O.__wbindgen_export2),a=P,f=S(r,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_sftp_upload_start(this.__wbg_ptr,s,_,t,u,a,f,P,o,c,R(i)?Number.MAX_SAFE_INTEGER:i>>>0)}send_ssh_terminal_resize(n,t,e,r,o,c){const i=S(n,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_ssh_terminal_resize(this.__wbg_ptr,i,P,t,e,r,o,c)}send_ssh_tunnel_data(n,t,e){const r=S(n,O.__wbindgen_export,O.__wbindgen_export2),o=P,c=S(e,O.__wbindgen_export,O.__wbindgen_export2);O.channel_send_ssh_tunnel_data(this.__wbg_ptr,r,o,t,c,P)}start_heartbeat(n){O.channel_start_heartbeat(this.__wbg_ptr,n)}stop_heartbeat(){O.channel_stop_heartbeat(this.__wbg_ptr)}update_service(n,t,e,r,o,c,i,s,_,u,a){const f=S(n,O.__wbindgen_export,O.__wbindgen_export2),b=P,l=S(t,O.__wbindgen_export,O.__wbindgen_export2),d=P,w=S(e,O.__wbindgen_export,O.__wbindgen_export2),g=P;var h=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2),p=P;const y=S(o,O.__wbindgen_export,O.__wbindgen_export2),m=P;var v=R(i)?0:S(i,O.__wbindgen_export,O.__wbindgen_export2),A=P,N=R(s)?0:S(s,O.__wbindgen_export,O.__wbindgen_export2),T=P,U=R(_)?0:S(_,O.__wbindgen_export,O.__wbindgen_export2),j=P,F=R(u)?0:S(u,O.__wbindgen_export,O.__wbindgen_export2);O.channel_update_service(this.__wbg_ptr,f,b,l,d,w,g,h,p,y,m,c,v,A,N,T,U,j,F,P,R(a)?Number.MAX_SAFE_INTEGER:a>>>0)}}Symbol.dispose&&(n.prototype[Symbol.dispose]=n.prototype.free);const t=Object.freeze({Generic:0,0:"Generic",Authentication:10,10:"Authentication",RequiresUsername:100,100:"RequiresUsername",RequiresPassword:110,110:"RequiresPassword",RequiresUsernamePassword:120,120:"RequiresUsernamePassword"});function e(){const n={__proto__:null,__wbg_Error_92b29b0548f8b746:function(n,t){return u(Error(w(n,t)))},__wbg_String_8564e559799eccda:function(n,t){const e=S(String(p(t)),O.__wbindgen_export,O.__wbindgen_export2),r=P;d().setInt32(n+4,r,!0),d().setInt32(n+0,e,!0)},__wbg___wbindgen_debug_string_c25d447a39f5578f:function(n,t){const e=S(f(p(t)),O.__wbindgen_export,O.__wbindgen_export2),r=P;d().setInt32(n+4,r,!0),d().setInt32(n+0,e,!0)},__wbg___wbindgen_string_get_b0ca35b86a603356:function(n,t){const e=p(t),r="string"==typeof e?e:void 0;var o=R(r)?0:S(r,O.__wbindgen_export,O.__wbindgen_export2),c=P;d().setInt32(n+4,c,!0),d().setInt32(n+0,o,!0)},__wbg___wbindgen_throw_344f42d3211c4765:function(n,t){throw new Error(w(n,t))},__wbg__wbg_cb_unref_fffb441def202758:function(n){p(n)._wbg_cb_unref()},__wbg_call_8a2dd23819f8a60a:function(){return y((function(n,t){return u(p(n).call(p(t)))}),arguments)},__wbg_call_a6e5c5dce5018821:function(){return y((function(n,t,e){return u(p(n).call(p(t),p(e)))}),arguments)},__wbg_call_e3b662382210db98:function(){return y((function(n,t,e,r){return u(p(n).call(p(t),p(e),p(r)))}),arguments)},__wbg_clearInterval_26ba580547547579:function(n){return u(clearInterval(N(n)))},__wbg_close_c65ca0257e895318:function(){return y((function(n){p(n).close()}),arguments)},__wbg_data_328de4280640da92:function(n){return u(p(n).data)},__wbg_from_13e323c65fc8f464:function(n){return u(Array.from(p(n)))},__wbg_getRandomValues_3f44b700395062e5:function(){return y((function(n,t){globalThis.crypto.getRandomValues(b(n,t))}),arguments)},__wbg_get_78f252d074a84d0b:function(){return y((function(n,t){return u(Reflect.get(p(n),p(t)))}),arguments)},__wbg_info_50b082b6c686951d:function(n,t){console.info(w(n,t))},__wbg_instanceof_ArrayBuffer_4480b9e0068a8adb:function(n){let t;try{t=p(n)instanceof ArrayBuffer}catch(n){t=!1}return t},__wbg_length_1f0964f4a5e2c6d8:function(n){return p(n).length},__wbg_new_32b398fb48b6d94a:function(){return u(new Array)},__wbg_new_cd45aabdf6073e84:function(n){return u(new Uint8Array(p(n)))},__wbg_new_da52cf8fe3429cb2:function(){return u(new Object)},__wbg_new_with_str_sequence_2de2f569c29910ad:function(){return y((function(n,t,e){return u(new WebSocket(w(n,t),p(e)))}),arguments)},__wbg_prototypesetcall_4770620bbe4688a0:function(n,t,e){Uint8Array.prototype.set.call(b(n,t),p(e))},__wbg_push_d2ae3af0c1217ae6:function(n,t){return p(n).push(p(t))},__wbg_readyState_50bc38c2a9e83db6:function(n){return p(n).readyState},__wbg_send_a321b376d40ec867:function(){return y((function(n,t,e){p(n).send(b(t,e))}),arguments)},__wbg_setInterval_cbf1c35c6a692d37:function(){return y((function(n,t){return u(setInterval(p(n),t))}),arguments)},__wbg_set_6be42768c690e380:function(n,t,e){p(n)[N(t)]=N(e)},__wbg_set_8a16b38e4805b298:function(n,t,e){p(n)[t>>>0]=N(e)},__wbg_set_binaryType_a37b086c78ca7c29:function(n,t){p(n).binaryType=s[t]},__wbg_set_onclose_f706475385ecce07:function(n,t){p(n).onclose=p(t)},__wbg_set_onerror_9f5773fd31512333:function(n,t){p(n).onerror=p(t)},__wbg_set_onmessage_836d2f72130b4706:function(n,t){p(n).onmessage=p(t)},__wbg_set_onopen_4f65470ae522a61a:function(n,t){p(n).onopen=p(t)},__wbg_warn_0a2d995b00b43107:function(n,t){console.warn(w(n,t))},__wbindgen_cast_0000000000000001:function(n,t){return u(A(n,t,o))},__wbindgen_cast_0000000000000002:function(n,t){return u(A(n,t,c))},__wbindgen_cast_0000000000000003:function(n,t){return u(A(n,t,i))},__wbindgen_cast_0000000000000004:function(n,t){return u(A(n,t,r))},__wbindgen_cast_0000000000000005:function(n){return u(n)},__wbindgen_cast_0000000000000006:function(n,t){return u(b(n,t))},__wbindgen_cast_0000000000000007:function(n,t){return u(w(n,t))},__wbindgen_cast_0000000000000008:function(n){return u(BigInt.asUintN(64,n))},__wbindgen_object_clone_ref:function(n){return u(p(n))},__wbindgen_object_drop_ref:function(n){N(n)}};return{__proto__:null,"./phirepass-channel_bg.js":n}}function r(n,t){O.__wasm_bindgen_func_elem_63(n,t)}function o(n,t,e){O.__wasm_bindgen_func_elem_59(n,t,u(e))}function c(n,t,e){O.__wasm_bindgen_func_elem_59_1(n,t,u(e))}function i(n,t,e){O.__wasm_bindgen_func_elem_59_2(n,t,u(e))}const s=["blob","arraybuffer"],_="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>O.__wbg_channel_free(n,1)));function u(n){v===m.length&&m.push(m.length+1);const t=v;return v=m[t],m[t]=n,t}const a="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((n=>O.__wbindgen_export4(n.a,n.b)));function f(n){const t=typeof n;if("number"==t||"boolean"==t||null==n)return`${n}`;if("string"==t)return`"${n}"`;if("symbol"==t){const t=n.description;return null==t?"Symbol":`Symbol(${t})`}if("function"==t){const t=n.name;return"string"==typeof t&&t.length>0?`Function(${t})`:"Function"}if(Array.isArray(n)){const t=n.length;let e="[";t>0&&(e+=f(n[0]));for(let r=1;r<t;r++)e+=", "+f(n[r]);return e+="]",e}const e=/\[object ([^\]]+)\]/.exec(toString.call(n));let r;if(!(e&&e.length>1))return toString.call(n);if(r=e[1],"Object"==r)try{return"Object("+JSON.stringify(n)+")"}catch(n){return"Object"}return n instanceof Error?`${n.name}: ${n.message}\n${n.stack}`:r}function b(n,t){return n>>>=0,h().subarray(n/1,n/1+t)}let l=null;function d(){return(null===l||!0===l.buffer.detached||void 0===l.buffer.detached&&l.buffer!==O.memory.buffer)&&(l=new DataView(O.memory.buffer)),l}function w(n,t){return function(n,t){return j+=t,j>=U&&(T=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),T.decode(),j=t),T.decode(h().subarray(n,n+t))}(n>>>0,t)}let g=null;function h(){return null!==g&&0!==g.byteLength||(g=new Uint8Array(O.memory.buffer)),g}function p(n){return m[n]}function y(n,t){try{return n.apply(this,t)}catch(n){O.__wbindgen_export3(u(n))}}let m=new Array(1024).fill(void 0);m.push(void 0,null,!0,!1);let v=m.length;function R(n){return null==n}function A(n,t,e){const r={a:n,b:t,cnt:1},o=(...n)=>{r.cnt++;const t=r.a;r.a=0;try{return e(t,r.b,...n)}finally{r.a=t,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{0==--r.cnt&&(O.__wbindgen_export4(r.a,r.b),r.a=0,a.unregister(r))},a.register(o,r,r),o}function S(n,t,e){if(void 0===e){const e=F.encode(n),r=t(e.length,1)>>>0;return h().subarray(r,r+e.length).set(e),P=e.length,r}let r=n.length,o=t(r,1)>>>0;const c=h();let i=0;for(;i<r;i++){const t=n.charCodeAt(i);if(t>127)break;c[o+i]=t}if(i!==r){0!==i&&(n=n.slice(i)),o=e(o,r,r=i+3*n.length,1)>>>0;const t=h().subarray(o+i,o+r);i+=F.encodeInto(n,t).written,o=e(o,r,i,1)>>>0}return P=i,o}function N(n){const t=p(n);return function(n){n<1028||(m[n]=v,v=n)}(n),t}let T=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});T.decode();const U=2146435072;let j=0;const F=new TextEncoder;"encodeInto"in F||(F.encodeInto=function(n,t){const e=F.encode(n);return t.set(e),{read:n.length,written:e.length}});let O,P=0;async function k(n){if(void 0!==O)return O;void 0!==n&&(Object.getPrototypeOf(n)===Object.prototype?({module_or_path:n}=n):console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===n&&(n=new URL("phirepass-channel_bg.wasm",import.meta.url));const t=e();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:r}=await async function(n,t){if("function"==typeof Response&&n instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(n,t)}catch(t){if(!n.ok||!function(n){switch(n){case"basic":case"cors":case"default":return!0}return!1}(n.type)||"application/wasm"===n.headers.get("Content-Type"))throw t;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t)}const e=await n.arrayBuffer();return await WebAssembly.instantiate(e,t)}{const e=await WebAssembly.instantiate(n,t);return e instanceof WebAssembly.Instance?{instance:e,module:n}:e}}(await n,t);return function(n){return O=n.exports,l=null,g=null,O}(r)}var q,I,W;!function(n){n.Error="Error",n.AuthSuccess="AuthSuccess",n.TunnelOpened="TunnelOpened",n.TunnelClosed="TunnelClosed",n.TunnelData="TunnelData",n.RDPAuthorized="RDPAuthorized",n.SFTPListItems="SFTPListItems",n.SFTPDownloadStartResponse="SFTPDownloadStartResponse",n.SFTPDownloadChunk="SFTPDownloadChunk",n.SFTPUploadStartResponse="SFTPUploadStartResponse",n.SFTPUploadChunkAck="SFTPUploadChunkAck"}(q||(q={})),function(n){n[n.Username=0]="Username",n[n.Password=1]="Password",n[n.Default=2]="Default"}(I||(I={})),function(n){n.Disconnected="disconnected",n.Connected="connected",n.Error="error"}(W||(W={}));export{n as C,t as E,I,q as P,k as _,W as a}
@@ -1 +1 @@
1
- import{t,p as e,H as s,c as i,h as o,a as n}from"./index.js";import{_ as r,C as h,a,P as c}from"./p-CWIhN33k.js";function d(t){return!Number.isFinite(t)||t<=0?200:Math.min(8192,Math.max(200,Math.floor(t)))}function u(t){return t-t%2}function l(t){const e=t.getBoundingClientRect();return function(t,e){return{width:u(d(t)),height:u(d(e))}}(e.width,e.height)}class p{onResize;debounceMs;observer;handle;reported;constructor(t,e=250){this.onResize=t,this.debounceMs=e}observe(t){this.disconnect(),this.report(l(t)),"undefined"!=typeof ResizeObserver&&(this.observer=new ResizeObserver((()=>{clearTimeout(this.handle),this.handle=setTimeout((()=>this.report(l(t))),this.debounceMs)})),this.observer.observe(t))}disconnect(){clearTimeout(this.handle),this.handle=void 0,this.observer?.disconnect(),this.observer=void 0,this.reported=void 0}report(t){(function(t,e){return!!t&&!!e&&t.width===e.width&&t.height===e.height})(t,this.reported)||(this.reported=t,this.onResize(t))}}function f(){return navigator.keyboard}function m(){return"function"==typeof f()?.lock}function b(t){return document.fullscreenElement===t}function y(t){return document.fullscreenElement?.contains(t)??!1}function w(){if(m())try{f().unlock()}catch(t){console.warn("Failed to release the keyboard lock:",t)}}const v=e(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.connectionStateChanged=i(this,"connectionStateChanged")}channel;containerEl;ironEl;userInteraction;viewport;domReady=!1;runtimeReady=!1;connected=!1;session_id;onFullscreenChange=()=>this.sync_keyboard_lock();credentials;credentialsPrompt=!1;statusMessage;usernameBuffer="";passwordBuffer="";get el(){return this}serverHost="phirepass.com";serverPort=443;allowInsecure=!1;heartbeatInterval=3e4;nodeId;serviceId;token;username;password;destination;scale="fit";dynamicResize=!0;captureKeyboard=!0;onNodeIdChange(t,e){this.reset_session_state(),this.channel&&this.channel.is_connected()&&this.close_comms(),t&&(this.open_comms(),this.channel.connect())}serverId;onServerIdChange(t,e){this.onNodeIdChange(this.nodeId,this.nodeId)}connectionStateChanged;create_web_socket_endpoint(){const t=this.allowInsecure?"ws":"wss";return this.allowInsecure||443!==this.serverPort?this.allowInsecure&&80===this.serverPort?`${t}://${this.serverHost}`:`${t}://${this.serverHost}:${this.serverPort}`:`${t}://${this.serverHost}`}async connectedCallback(){document.addEventListener("fullscreenchange",this.onFullscreenChange),await r(),this.open_comms(),this.runtimeReady=!0,this.nodeId?this.try_connect():console.warn("Prop node_id is not set. Cannot connect to RDP.")}componentDidLoad(){this.domReady=!0,this.try_connect()}async disconnectedCallback(){document.removeEventListener("fullscreenchange",this.onFullscreenChange),this.connected=!1,this.domReady=!1,this.runtimeReady=!1,this.close_comms()}async toggleFullscreen(){const t=await async function(t){try{return b(t)?(await document.exitFullscreen(),!1):(await t.requestFullscreen({navigationUI:"hide"}),!0)}catch(e){return console.warn("Failed to change the fullscreen state of the RDP session:",e),b(t)}}(this.el);return this.focus_desktop(),t}async keyboardLockSupported(){return m()}async focusDesktop(){this.focus_desktop()}try_connect(){!this.connected&&this.domReady&&this.runtimeReady&&this.containerEl&&this.channel&&this.connect()}connect(){this.connected=!0,this.channel.connect()}open_comms(){this.channel=this.serverId?new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId,this.serverId):new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId),this.channel.on_connection_open((()=>{this.connectionStateChanged.emit([a.Connected]),this.channel.authenticate(this.token,this.nodeId)})),this.channel.on_connection_close((()=>{this.connectionStateChanged.emit([a.Disconnected]),this.teardown_client()})),this.channel.on_connection_error((t=>{this.connectionStateChanged.emit([a.Error,t])})),this.channel.on_connection_message((()=>{})),this.channel.on_protocol_message((t=>{const{web:e}=t.data;switch(e.type){case c.Error:this.handle_error(e);break;case c.AuthSuccess:this.handle_auth_success(e);break;case c.RDPAuthorized:this.handle_rdp_authorized(e);break;case c.TunnelClosed:this.handle_tunnel_closed(e);break;default:console.warn("Unknown protocol message type:",e)}}))}close_comms(){this.teardown_client(),this.channel&&(this.channel.stop_heartbeat(),this.channel.disconnect())}reset_session_state(){this.session_id=void 0,this.credentials=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer="",this.statusMessage=void 0}handle_auth_success(t){if(this.channel.start_heartbeat(this.heartbeatInterval<=15e3?3e4:this.heartbeatInterval),this.username&&this.password)return this.credentials={username:this.username,password:this.password},void this.request_tunnel();this.credentialsPrompt=!0}request_tunnel(){this.credentials&&(this.statusMessage=void 0,this.channel.open_rdp_tunnel(this.nodeId,this.serviceId,this.credentials.username,this.credentials.password))}async handle_rdp_authorized(t){this.session_id=t.sid,this.statusMessage="Connecting…";const[e]=await Promise.all([import("@devolutions/iron-remote-desktop-rdp"),import("@devolutions/iron-remote-desktop")]);if(!this.containerEl||this.session_id!==t.sid)return;if(await e.init("info"),!this.containerEl||this.session_id!==t.sid)return;const s=document.createElement("iron-remote-desktop");s.module=e.Backend,s.scale=this.scale,s.flexcenter=!0,s.verbose=!1,s.addEventListener("ready",(s=>{this.start_session(s.detail.irgUserInteraction,t.ticket,e.enableCredssp(!0))})),this.ironEl=s,this.mount_client(s)}mount_client(t){this.el.appendChild(t)}async start_session(t,e,s){this.userInteraction=t;const i=t.configBuilder().withUsername(this.credentials?.username??"").withPassword(this.credentials?.password??"").withDestination(this.destination??this.nodeId).withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`).withAuthToken(e).withExtension(s);this.dynamicResize&&i.withDesktopSize(l(this.el));try{const e=await t.connect(i.build());t.setVisibility(!0),this.statusMessage=void 0,this.focus_desktop(),this.start_viewport_sync(),this.sync_keyboard_lock();const s=await e.run();this.statusMessage=s.reason()}catch(t){const e=this.describe_error(t);this.statusMessage=e,this.connectionStateChanged.emit([a.Error,t])}}start_viewport_sync(){this.dynamicResize&&(this.viewport=new p((t=>this.resize_desktop(t))),this.viewport.observe(this.el))}stop_viewport_sync(){this.viewport?.disconnect(),this.viewport=void 0}resize_desktop(t){try{this.userInteraction?.resize(t.width,t.height)}catch(t){console.warn("The remote host would not resize its desktop:",t)}}focus_desktop(){!function(t){t?.focus({preventScroll:!0})}(this.ironEl)}async sync_keyboard_lock(){this.captureKeyboard&&y(this.el)?(await async function(t){if(m()&&y(t))try{await f().lock()}catch(t){console.warn("Failed to lock the keyboard for the RDP session:",t)}}(this.el),this.focus_desktop()):w()}describe_error(t){return t&&"function"==typeof t.backtrace?t.backtrace():t instanceof Error?t.message:"Connection failed."}handle_tunnel_closed(t){this.session_id=void 0,this.statusMessage=this.statusMessage??"Connection closed.",this.teardown_client(),this.close_comms()}handle_error(t){this.statusMessage=t.message,this.connectionStateChanged.emit([a.Error,t])}teardown_client(){if(this.stop_viewport_sync(),w(),this.userInteraction){try{this.userInteraction.shutdown()}catch(t){console.warn("Failed to shut the RDP session down cleanly:",t)}this.userInteraction=void 0}this.ironEl?.remove(),this.ironEl=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer=""}submit_credentials(t){t.preventDefault(),this.credentialsPrompt=!1,this.credentials={username:this.usernameBuffer,password:this.passwordBuffer},this.usernameBuffer="",this.passwordBuffer="",this.request_tunnel()}render(){return o(n,{key:"140e8f813403dad27cbbe3b0d3e3099e90c9e08d"},o("div",{key:"0f695b83c808a678b9bff3434ac1ff65a6765e1e",class:"screen",ref:t=>this.containerEl=t},o("slot",{key:"b382a47294606909074c8b64983419645cda438b"})),this.credentialsPrompt&&o("form",{key:"18606a269f254c5bffc81c6c45a4e85473fff557",class:"prompt",onSubmit:t=>this.submit_credentials(t)},o("label",{key:"f4c2bf9aaa483e323b38d12774728e3a687962a4",htmlFor:"rdp-username"},"Windows username"),o("input",{key:"ba766990c9fc089b1aa9d894ac5d7032f0c87edf",id:"rdp-username",type:"text",autocomplete:"username",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),o("label",{key:"885ee563e3537712d3ad85e47485f44f2de576c5",htmlFor:"rdp-password"},"Password"),o("input",{key:"19cfa162b515e6b230b19a3f2f8fd267ff5388ec",id:"rdp-password",type:"password",autocomplete:"current-password",onInput:t=>this.passwordBuffer=t.target.value}),o("button",{key:"04b428b4947f1d0f957399961c5196d5bbc6b5a7",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&o("div",{key:"eb66cd3974a3aa8a563bd54599912bc735007214",class:"status"},this.statusMessage))}static get watchers(){return{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}}static get style(){return':host{display:block;width:100%;height:100%;min-width:0;min-height:0;overflow:hidden;position:relative;background:#0b1021}.screen{width:100%;height:100%;display:flex}::slotted(iron-remote-desktop){display:block;flex:1 1 auto;min-width:0;min-height:0;width:100%;height:100%}:host(:fullscreen){width:100vw;height:100vh;background:#000}.prompt{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.5rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.875rem}.prompt input{padding:0.5rem 0.75rem;border:1px solid #334155;border-radius:0.375rem;background:#0f172a;color:inherit;font:inherit;min-width:16rem}.prompt input:focus{outline:2px solid #67e8f9;outline-offset:1px}.prompt button{margin-top:0.5rem;padding:0.5rem 1.25rem;border:0;border-radius:0.375rem;background:#67e8f9;color:#0b1021;font:inherit;font-weight:600;cursor:pointer}.status{position:absolute;inset-inline:0;bottom:0;padding:0.5rem 0.75rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.8125rem;text-align:center}'}},[769,"phirepass-rdp",{serverHost:[1,"server-host"],serverPort:[2,"server-port"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],nodeId:[1,"node-id"],serviceId:[1,"service-id"],token:[1],username:[1],password:[1],destination:[1],scale:[1],dynamicResize:[4,"dynamic-resize"],captureKeyboard:[4,"capture-keyboard"],serverId:[1,"server-id"],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64]},void 0,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]);function k(){"undefined"!=typeof customElements&&["phirepass-rdp"].forEach((e=>{"phirepass-rdp"===e&&(customElements.get(t(e))||customElements.define(t(e),v))}))}k();const g=v,_=k;export{g as PhirepassRdp,_ as defineCustomElement}
1
+ import{t,p as e,H as s,c as i,h as o,a as n}from"./index.js";import{_ as r,C as h,a,P as c}from"./p-B29jN5hK.js";const d=200;function u(t){return!Number.isFinite(t)||t<=0?d:Math.min(8192,Math.max(d,Math.floor(t)))}function l(t){return t-t%2}function p(t){const e=t.getBoundingClientRect();return function(t,e){return{width:l(u(t)),height:l(u(e))}}(e.width,e.height)}class f{onResize;debounceMs;observer;handle;reported;constructor(t,e=250){this.onResize=t,this.debounceMs=e}observe(t){this.disconnect(),this.report(p(t)),"undefined"!=typeof ResizeObserver&&(this.observer=new ResizeObserver((()=>{clearTimeout(this.handle),this.handle=setTimeout((()=>this.report(p(t))),this.debounceMs)})),this.observer.observe(t))}disconnect(){clearTimeout(this.handle),this.handle=void 0,this.observer?.disconnect(),this.observer=void 0,this.reported=void 0}report(t){(function(t,e){return!!t&&!!e&&t.width===e.width&&t.height===e.height})(t,this.reported)||(this.reported=t,this.onResize(t))}}function m(){return navigator.keyboard}function b(){return"function"==typeof m()?.lock}function y(t){return document.fullscreenElement===t}function w(t){return document.fullscreenElement?.contains(t)??!1}function v(){if(b())try{m().unlock()}catch(t){console.warn("Failed to release the keyboard lock:",t)}}const g=e(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.connectionStateChanged=i(this,"connectionStateChanged")}channel;containerEl;ironEl;userInteraction;viewport;domReady=!1;runtimeReady=!1;connected=!1;disposed=!1;session_id;onFullscreenChange=()=>this.sync_keyboard_lock();credentials;credentialsPrompt=!1;statusMessage;usernameBuffer="";passwordBuffer="";get el(){return this}serverHost="phirepass.com";serverPort=443;allowInsecure=!1;heartbeatInterval=3e4;nodeId;serviceId;token;username;password;destination;scale="fit";dynamicResize=!0;captureKeyboard=!0;onNodeIdChange(t,e){this.reset_session_state(),this.channel&&this.channel.is_connected()&&this.close_comms(),t&&(this.open_comms(),this.channel.connect())}serverId;onServerIdChange(t,e){this.onNodeIdChange(this.nodeId,this.nodeId)}connectionStateChanged;create_web_socket_endpoint(){const t=this.allowInsecure?"ws":"wss";return this.allowInsecure||443!==this.serverPort?this.allowInsecure&&80===this.serverPort?`${t}://${this.serverHost}`:`${t}://${this.serverHost}:${this.serverPort}`:`${t}://${this.serverHost}`}async connectedCallback(){document.addEventListener("fullscreenchange",this.onFullscreenChange),this.disposed=!1,await r(),this.open_comms(),this.runtimeReady=!0,this.nodeId?this.try_connect():console.warn("Prop node_id is not set. Cannot connect to RDP.")}componentDidLoad(){this.domReady=!0,this.try_connect()}async disconnectedCallback(){document.removeEventListener("fullscreenchange",this.onFullscreenChange),this.disposed=!0,this.session_id=void 0,this.connected=!1,this.domReady=!1,this.runtimeReady=!1,this.close_comms()}async toggleFullscreen(){const t=await async function(t){try{return y(t)?(await document.exitFullscreen(),!1):(await t.requestFullscreen({navigationUI:"hide"}),!0)}catch(e){return console.warn("Failed to change the fullscreen state of the RDP session:",e),y(t)}}(this.el);return this.focus_desktop(),t}async keyboardLockSupported(){return b()}async focusDesktop(){this.focus_desktop()}try_connect(){!this.connected&&this.domReady&&this.runtimeReady&&this.containerEl&&this.channel&&this.connect()}connect(){this.connected=!0,this.channel.connect()}open_comms(){this.channel=this.serverId?new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId,this.serverId):new h(this.create_web_socket_endpoint()+"/api/web/ws",this.nodeId),this.channel.on_connection_open((()=>{this.connectionStateChanged.emit([a.Connected]),this.channel.authenticate(this.token,this.nodeId)})),this.channel.on_connection_close((()=>{this.connectionStateChanged.emit([a.Disconnected]),this.teardown_client()})),this.channel.on_connection_error((t=>{this.connectionStateChanged.emit([a.Error,t])})),this.channel.on_connection_message((()=>{})),this.channel.on_protocol_message((t=>{const{web:e}=t.data;switch(e.type){case c.Error:this.handle_error(e);break;case c.AuthSuccess:this.handle_auth_success(e);break;case c.RDPAuthorized:this.handle_rdp_authorized(e);break;case c.TunnelClosed:this.handle_tunnel_closed(e);break;default:console.warn("Unknown protocol message type:",e)}}))}close_comms(){this.teardown_client(),this.channel&&(this.channel.stop_heartbeat(),this.channel.disconnect())}reset_session_state(){this.session_id=void 0,this.credentials=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer="",this.statusMessage=void 0}handle_auth_success(t){if(this.channel.start_heartbeat(this.heartbeatInterval<=15e3?3e4:this.heartbeatInterval),this.username&&this.password)return this.credentials={username:this.username,password:this.password},void this.request_tunnel();this.credentialsPrompt=!0}request_tunnel(){this.credentials&&(this.statusMessage=void 0,this.channel.open_rdp_tunnel(this.nodeId,this.serviceId,this.credentials.username,this.credentials.password))}async handle_rdp_authorized(t){this.session_id=t.sid,this.statusMessage="Connecting…";const[e]=await Promise.all([import("@devolutions/iron-remote-desktop-rdp"),import("@devolutions/iron-remote-desktop")]);if(this.disposed||!this.containerEl||this.session_id!==t.sid)return;if(await e.init("info"),this.disposed||!this.containerEl||this.session_id!==t.sid)return;const s=document.createElement("iron-remote-desktop");s.module=e.Backend,s.scale=this.scale,s.flexcenter=!0,s.verbose=!1,s.addEventListener("ready",(s=>{this.start_session(s.detail.irgUserInteraction,t.ticket,e.enableCredssp(!0))})),this.ironEl=s,this.mount_client(s)}mount_client(t){this.el.appendChild(t)}async start_session(t,e,s){this.userInteraction=t;const i=t.configBuilder().withUsername(this.credentials?.username??"").withPassword(this.credentials?.password??"").withDestination(this.destination??this.nodeId).withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`).withAuthToken(e).withExtension(s);if(this.dynamicResize){const t=function(t){const e=t.getBoundingClientRect();if(Number.isFinite(e.width)&&Number.isFinite(e.height)&&!(e.width<d||e.height<d))return{width:l(Math.min(Math.floor(e.width),4096)),height:l(Math.min(Math.floor(e.height),4096))}}(this.el);t&&i.withDesktopSize(t)}try{const e=await t.connect(i.build());if(this.disposed)return this.shutdown_session(t),void await e.run();t.setVisibility(!0),this.statusMessage=void 0,this.focus_desktop(),this.start_viewport_sync(),this.sync_keyboard_lock();const s=await e.run();this.statusMessage=s.reason()}catch(t){const e=this.describe_error(t);this.statusMessage=e,this.connectionStateChanged.emit([a.Error,t])}}start_viewport_sync(){this.dynamicResize&&(this.viewport=new f((t=>this.resize_desktop(t))),this.viewport.observe(this.el))}stop_viewport_sync(){this.viewport?.disconnect(),this.viewport=void 0}resize_desktop(t){try{this.userInteraction?.resize(t.width,t.height)}catch(t){console.warn("The remote host would not resize its desktop:",t)}}focus_desktop(){!function(t){t?.focus({preventScroll:!0})}(this.ironEl)}async sync_keyboard_lock(){this.captureKeyboard&&w(this.el)?(await async function(t){if(b()&&w(t))try{await m().lock()}catch(t){console.warn("Failed to lock the keyboard for the RDP session:",t)}}(this.el),this.focus_desktop()):v()}describe_error(t){return t&&"function"==typeof t.backtrace?t.backtrace():t instanceof Error?t.message:"Connection failed."}handle_tunnel_closed(t){this.session_id=void 0,this.statusMessage=this.statusMessage??"Connection closed.",this.teardown_client(),this.close_comms()}handle_error(t){this.statusMessage=t.message,this.connectionStateChanged.emit([a.Error,t])}shutdown_session(t){try{t.shutdown()}catch(t){console.warn("Failed to shut the RDP session down cleanly:",t)}}teardown_client(){this.stop_viewport_sync(),v(),this.userInteraction&&(this.shutdown_session(this.userInteraction),this.userInteraction=void 0),this.ironEl?.remove(),this.ironEl=void 0,this.credentialsPrompt=!1,this.usernameBuffer="",this.passwordBuffer=""}submit_credentials(t){t.preventDefault(),this.credentialsPrompt=!1,this.credentials={username:this.usernameBuffer,password:this.passwordBuffer},this.usernameBuffer="",this.passwordBuffer="",this.request_tunnel()}render(){return o(n,{key:"892fd55fb84abf180866dd7af4e44adc9c23f338"},o("div",{key:"fd6ac08295b6ce9e3bd3932abea271c9c6fc8a00",class:"screen",ref:t=>this.containerEl=t},o("slot",{key:"b9240f804177898f29598b0c7ec7b4f4d2e8d6c6"})),this.credentialsPrompt&&o("form",{key:"49ce099f575a30c0bb326a64de74d30cf599418f",class:"prompt",onSubmit:t=>this.submit_credentials(t)},o("label",{key:"1a12eb01993f858bbbc2498cc8d896b1dd1dbf88",htmlFor:"rdp-username"},"Windows username"),o("input",{key:"79c8482390211b3ba3d253e8485e7895fc52b393",id:"rdp-username",type:"text",autocomplete:"username",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),o("label",{key:"3c07473b2d85ddb4e13a45f3d771b23749570c2e",htmlFor:"rdp-password"},"Password"),o("input",{key:"8740ab5c45186bac0f452931d9e6ccec6c4fdeab",id:"rdp-password",type:"password",autocomplete:"current-password",onInput:t=>this.passwordBuffer=t.target.value}),o("button",{key:"df366feb5122cd0bcf0d0a07a034f18302e0f9e3",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&o("div",{key:"1823a89de1c881121fa8dee61af053ff1ac3e5e3",class:"status"},this.statusMessage))}static get watchers(){return{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}}static get style(){return':host{display:block;width:100%;height:100%;min-width:0;min-height:0;overflow:hidden;position:relative;background:#0b1021}.screen{width:100%;height:100%;display:flex}::slotted(iron-remote-desktop){display:block;flex:1 1 auto;min-width:0;min-height:0;width:100%;height:100%}:host(:fullscreen){width:100vw;height:100vh;background:#000}.prompt{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.5rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.875rem}.prompt input{padding:0.5rem 0.75rem;border:1px solid #334155;border-radius:0.375rem;background:#0f172a;color:inherit;font:inherit;min-width:16rem}.prompt input:focus{outline:2px solid #67e8f9;outline-offset:1px}.prompt button{margin-top:0.5rem;padding:0.5rem 1.25rem;border:0;border-radius:0.375rem;background:#67e8f9;color:#0b1021;font:inherit;font-weight:600;cursor:pointer}.status{position:absolute;inset-inline:0;bottom:0;padding:0.5rem 0.75rem;background:rgba(11, 16, 33, 0.92);color:#e2e8f0;font-family:"Berkeley Mono", "Fira Code", "SFMono-Regular", Menlo, monospace;font-size:0.8125rem;text-align:center}'}},[769,"phirepass-rdp",{serverHost:[1,"server-host"],serverPort:[2,"server-port"],allowInsecure:[4,"allow-insecure"],heartbeatInterval:[2,"heartbeat-interval"],nodeId:[1,"node-id"],serviceId:[1,"service-id"],token:[1],username:[1],password:[1],destination:[1],scale:[1],dynamicResize:[4,"dynamic-resize"],captureKeyboard:[4,"capture-keyboard"],serverId:[1,"server-id"],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64]},void 0,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]);function k(){"undefined"!=typeof customElements&&["phirepass-rdp"].forEach((e=>{"phirepass-rdp"===e&&(customElements.get(t(e))||customElements.define(t(e),g))}))}k();const _=g,I=k;export{_ as PhirepassRdp,I as defineCustomElement}