phirepass-widgets 0.0.100 → 0.0.101

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.
@@ -91,9 +91,20 @@ class ViewportSync {
91
91
  /**
92
92
  * Starts watching `element`. The current size is reported immediately, so a
93
93
  * widget that was resized while disconnected catches up on reconnect.
94
+ *
95
+ * `openedAt` is the size the session was actually opened at, and passing it
96
+ * is what stops that immediate report from being a resize to the resolution
97
+ * the host is already showing. That redundant request is not free: a
98
+ * display-control PDU makes the host renegotiate capabilities and resend the
99
+ * screen, and arriving moments after the connection sequence it is the worst
100
+ * possible time to ask — the client can end up parsing a bitmap whose
101
+ * declared length no longer matches the stream. Seeded here rather than
102
+ * suppressed at the call site because "what has the host been told" is this
103
+ * class's state; the caller only knows what it asked for at connect.
94
104
  */
95
- observe(element) {
105
+ observe(element, openedAt) {
96
106
  this.disconnect();
107
+ this.reported = openedAt;
97
108
  this.report(measure_desktop_size(element));
98
109
  // Absent under the spec test environment, and on nothing else worth
99
110
  // supporting — a missing observer costs the dynamic resize, not the
@@ -602,10 +613,11 @@ const PhirepassRdp = class {
602
613
  // `start_viewport_sync` correct the size once the client is visible;
603
614
  // sending a size derived from a zero-sized box is how a host ends up
604
615
  // refusing the connection outright.
616
+ let openedAt;
605
617
  if (this.dynamicResize) {
606
- const size = measure_initial_desktop_size(this.el);
607
- if (size) {
608
- builder.withDesktopSize(size);
618
+ openedAt = measure_initial_desktop_size(this.el);
619
+ if (openedAt) {
620
+ builder.withDesktopSize(openedAt);
609
621
  }
610
622
  }
611
623
  try {
@@ -623,9 +635,17 @@ const PhirepassRdp = class {
623
635
  userInteraction.setVisibility(true);
624
636
  this.statusMessage = undefined;
625
637
  this.focus_desktop();
626
- this.start_viewport_sync();
627
638
  void this.sync_keyboard_lock();
628
- const termination = await session.run();
639
+ // Started before the viewport sync, and kept unawaited until after
640
+ // it: `run` drives the stream, and the sync can emit a
641
+ // display-control PDU the moment it is attached. Asking the host to
642
+ // change resolution while the connection sequence is still being
643
+ // parsed is how a fast-path bitmap ends up truncated against its own
644
+ // declared length. Entering `run` first means anything the sync
645
+ // sends lands on a session that is already reading.
646
+ const running = session.run();
647
+ this.start_viewport_sync(openedAt);
648
+ const termination = await running;
629
649
  this.statusMessage = termination.reason();
630
650
  }
631
651
  catch (err) {
@@ -641,12 +661,12 @@ const PhirepassRdp = class {
641
661
  * measurement has to happen after it — measuring earlier reads a hidden,
642
662
  * zero-sized box.
643
663
  */
644
- start_viewport_sync() {
664
+ start_viewport_sync(openedAt) {
645
665
  if (!this.dynamicResize) {
646
666
  return;
647
667
  }
648
668
  this.viewport = new ViewportSync((size) => this.resize_desktop(size));
649
- this.viewport.observe(this.el);
669
+ this.viewport.observe(this.el, openedAt);
650
670
  }
651
671
  stop_viewport_sync() {
652
672
  this.viewport?.disconnect();
@@ -732,7 +752,7 @@ const PhirepassRdp = class {
732
752
  this.request_tunnel();
733
753
  }
734
754
  render() {
735
- return (index.h(index.Host, { key: '9eb8ba7d53d4c9489df71a9da5bae59f348b3d8a' }, index.h("div", { key: '2172cf49625768c585cb5a976f5164d0348e8426', class: "screen", ref: (el) => (this.containerEl = el) }, index.h("slot", { key: '46f7cffae68155552bb5262c94d8fa308dbcb5df' })), this.credentialsPrompt && (index.h("form", { key: '02da607149cf5d444389888bc4dc1422f7ed44bd', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, index.h("label", { key: '5e560dd128da72280e0711c545335ec3624a7934', htmlFor: "rdp-username" }, "Username"), index.h("input", { key: '3969f84697c0112cb3a7eeab0a2f8238cff7cff5', id: "rdp-username", type: "text", autocomplete: "off", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), index.h("label", { key: 'fec51856a4523c8713938cee20b0e0025ff32795', htmlFor: "rdp-password" }, "Password"), index.h("input", { key: 'e4dff2271b1eb7576bff701540f2566d0bbb897d', id: "rdp-password", type: "password", autocomplete: "off", onInput: (event) => (this.passwordBuffer = event.target.value) }), index.h("button", { key: 'b59d8a69c27e065831d815c9f5a7c8a3432594f6', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (index.h("div", { key: '7439841369456b3d057a3c389cabeca6affa6f98', class: "status" }, this.statusMessage))));
755
+ return (index.h(index.Host, { key: '56354df7bd0d3f01fcd5ff65ca5618ceb6af1b91' }, index.h("div", { key: '446dc83e41a29c3bc2c341a26092ed3581565967', class: "screen", ref: (el) => (this.containerEl = el) }, index.h("slot", { key: '2beafc92d81662dfac5c7b41356f6c6c802643b9' })), this.credentialsPrompt && (index.h("form", { key: 'dcc29b21fba03bb97526ec3d1cf5a1fb51b483e9', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, index.h("label", { key: 'b5a3e302089b2282aedbdbefd4fb5eaca7c34455', htmlFor: "rdp-username" }, "Username"), index.h("input", { key: '3bd1c902a6bc41bc7e69c16258cac78035a949bd', id: "rdp-username", type: "text", autocomplete: "off", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), index.h("label", { key: '2defe12d73b609cbad27c06447c3c3221ff3e5aa', htmlFor: "rdp-password" }, "Password"), index.h("input", { key: '55935891f24f0c1db71a14c42b2fc7a96c0c0ba6', id: "rdp-password", type: "password", autocomplete: "off", onInput: (event) => (this.passwordBuffer = event.target.value) }), index.h("button", { key: '83439c0e8756001c7042fc3b6754889d62a8eada', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (index.h("div", { key: '294262625f44a3f45d54bcd492875a9b6fd03219', class: "status" }, this.statusMessage))));
736
756
  }
737
757
  static get watchers() { return {
738
758
  "nodeId": [{
@@ -397,10 +397,11 @@ export class PhirepassRdp {
397
397
  // `start_viewport_sync` correct the size once the client is visible;
398
398
  // sending a size derived from a zero-sized box is how a host ends up
399
399
  // refusing the connection outright.
400
+ let openedAt;
400
401
  if (this.dynamicResize) {
401
- const size = measure_initial_desktop_size(this.el);
402
- if (size) {
403
- builder.withDesktopSize(size);
402
+ openedAt = measure_initial_desktop_size(this.el);
403
+ if (openedAt) {
404
+ builder.withDesktopSize(openedAt);
404
405
  }
405
406
  }
406
407
  try {
@@ -418,9 +419,17 @@ export class PhirepassRdp {
418
419
  userInteraction.setVisibility(true);
419
420
  this.statusMessage = undefined;
420
421
  this.focus_desktop();
421
- this.start_viewport_sync();
422
422
  void this.sync_keyboard_lock();
423
- const termination = await session.run();
423
+ // Started before the viewport sync, and kept unawaited until after
424
+ // it: `run` drives the stream, and the sync can emit a
425
+ // display-control PDU the moment it is attached. Asking the host to
426
+ // change resolution while the connection sequence is still being
427
+ // parsed is how a fast-path bitmap ends up truncated against its own
428
+ // declared length. Entering `run` first means anything the sync
429
+ // sends lands on a session that is already reading.
430
+ const running = session.run();
431
+ this.start_viewport_sync(openedAt);
432
+ const termination = await running;
424
433
  this.statusMessage = termination.reason();
425
434
  }
426
435
  catch (err) {
@@ -436,12 +445,12 @@ export class PhirepassRdp {
436
445
  * measurement has to happen after it — measuring earlier reads a hidden,
437
446
  * zero-sized box.
438
447
  */
439
- start_viewport_sync() {
448
+ start_viewport_sync(openedAt) {
440
449
  if (!this.dynamicResize) {
441
450
  return;
442
451
  }
443
452
  this.viewport = new ViewportSync((size) => this.resize_desktop(size));
444
- this.viewport.observe(this.el);
453
+ this.viewport.observe(this.el, openedAt);
445
454
  }
446
455
  stop_viewport_sync() {
447
456
  this.viewport?.disconnect();
@@ -527,7 +536,7 @@ export class PhirepassRdp {
527
536
  this.request_tunnel();
528
537
  }
529
538
  render() {
530
- return (h(Host, { key: '9eb8ba7d53d4c9489df71a9da5bae59f348b3d8a' }, h("div", { key: '2172cf49625768c585cb5a976f5164d0348e8426', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: '46f7cffae68155552bb5262c94d8fa308dbcb5df' })), this.credentialsPrompt && (h("form", { key: '02da607149cf5d444389888bc4dc1422f7ed44bd', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: '5e560dd128da72280e0711c545335ec3624a7934', htmlFor: "rdp-username" }, "Username"), h("input", { key: '3969f84697c0112cb3a7eeab0a2f8238cff7cff5', id: "rdp-username", type: "text", autocomplete: "off", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: 'fec51856a4523c8713938cee20b0e0025ff32795', htmlFor: "rdp-password" }, "Password"), h("input", { key: 'e4dff2271b1eb7576bff701540f2566d0bbb897d', id: "rdp-password", type: "password", autocomplete: "off", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: 'b59d8a69c27e065831d815c9f5a7c8a3432594f6', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: '7439841369456b3d057a3c389cabeca6affa6f98', class: "status" }, this.statusMessage))));
539
+ return (h(Host, { key: '56354df7bd0d3f01fcd5ff65ca5618ceb6af1b91' }, h("div", { key: '446dc83e41a29c3bc2c341a26092ed3581565967', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: '2beafc92d81662dfac5c7b41356f6c6c802643b9' })), this.credentialsPrompt && (h("form", { key: 'dcc29b21fba03bb97526ec3d1cf5a1fb51b483e9', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: 'b5a3e302089b2282aedbdbefd4fb5eaca7c34455', htmlFor: "rdp-username" }, "Username"), h("input", { key: '3bd1c902a6bc41bc7e69c16258cac78035a949bd', id: "rdp-username", type: "text", autocomplete: "off", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: '2defe12d73b609cbad27c06447c3c3221ff3e5aa', htmlFor: "rdp-password" }, "Password"), h("input", { key: '55935891f24f0c1db71a14c42b2fc7a96c0c0ba6', id: "rdp-password", type: "password", autocomplete: "off", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: '83439c0e8756001c7042fc3b6754889d62a8eada', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: '294262625f44a3f45d54bcd492875a9b6fd03219', class: "status" }, this.statusMessage))));
531
540
  }
532
541
  static get is() { return "phirepass-rdp"; }
533
542
  static get encapsulation() { return "shadow"; }
@@ -86,9 +86,20 @@ export class ViewportSync {
86
86
  /**
87
87
  * Starts watching `element`. The current size is reported immediately, so a
88
88
  * widget that was resized while disconnected catches up on reconnect.
89
+ *
90
+ * `openedAt` is the size the session was actually opened at, and passing it
91
+ * is what stops that immediate report from being a resize to the resolution
92
+ * the host is already showing. That redundant request is not free: a
93
+ * display-control PDU makes the host renegotiate capabilities and resend the
94
+ * screen, and arriving moments after the connection sequence it is the worst
95
+ * possible time to ask — the client can end up parsing a bitmap whose
96
+ * declared length no longer matches the stream. Seeded here rather than
97
+ * suppressed at the call site because "what has the host been told" is this
98
+ * class's state; the caller only knows what it asked for at connect.
89
99
  */
90
- observe(element) {
100
+ observe(element, openedAt) {
91
101
  this.disconnect();
102
+ this.reported = openedAt;
92
103
  this.report(measure_desktop_size(element));
93
104
  // Absent under the spec test environment, and on nothing else worth
94
105
  // supporting — a missing observer costs the dynamic resize, not the
@@ -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-DFhjP92A.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;clipboard=!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()}async sendCtrlAltDel(){return!!this.userInteraction&&(this.userInteraction.ctrlAltDel(),this.focus_desktop(),!0)}async sendMetaKey(){return!!this.userInteraction&&(this.userInteraction.metaKey(),this.focus_desktop(),!0)}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;const i=[e.enableCredssp(!0)];this.dynamicResize&&i.push(e.displayControl(!0)),s.addEventListener("ready",(e=>{this.start_session(e.detail.irgUserInteraction,t.ticket,i)})),this.ironEl=s,this.mount_client(s)}mount_client(t){this.el.appendChild(t)}async start_session(t,e,s){this.userInteraction=t,this.clipboard||t.setEnableClipboard(!1),t.onWarningCallback((t=>{console.warn("The remote desktop client reported a problem:",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);for(const t of s)i.withExtension(t);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:"9eb8ba7d53d4c9489df71a9da5bae59f348b3d8a"},o("div",{key:"2172cf49625768c585cb5a976f5164d0348e8426",class:"screen",ref:t=>this.containerEl=t},o("slot",{key:"46f7cffae68155552bb5262c94d8fa308dbcb5df"})),this.credentialsPrompt&&o("form",{key:"02da607149cf5d444389888bc4dc1422f7ed44bd",class:"prompt",onSubmit:t=>this.submit_credentials(t)},o("label",{key:"5e560dd128da72280e0711c545335ec3624a7934",htmlFor:"rdp-username"},"Username"),o("input",{key:"3969f84697c0112cb3a7eeab0a2f8238cff7cff5",id:"rdp-username",type:"text",autocomplete:"off",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),o("label",{key:"fec51856a4523c8713938cee20b0e0025ff32795",htmlFor:"rdp-password"},"Password"),o("input",{key:"e4dff2271b1eb7576bff701540f2566d0bbb897d",id:"rdp-password",type:"password",autocomplete:"off",onInput:t=>this.passwordBuffer=t.target.value}),o("button",{key:"b59d8a69c27e065831d815c9f5a7c8a3432594f6",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&o("div",{key:"7439841369456b3d057a3c389cabeca6affa6f98",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"],clipboard:[4],serverId:[1,"server-id"],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64],sendCtrlAltDel:[64],sendMetaKey:[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}
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-DFhjP92A.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,e){this.disconnect(),this.reported=e,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;clipboard=!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()}async sendCtrlAltDel(){return!!this.userInteraction&&(this.userInteraction.ctrlAltDel(),this.focus_desktop(),!0)}async sendMetaKey(){return!!this.userInteraction&&(this.userInteraction.metaKey(),this.focus_desktop(),!0)}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;const i=[e.enableCredssp(!0)];this.dynamicResize&&i.push(e.displayControl(!0)),s.addEventListener("ready",(e=>{this.start_session(e.detail.irgUserInteraction,t.ticket,i)})),this.ironEl=s,this.mount_client(s)}mount_client(t){this.el.appendChild(t)}async start_session(t,e,s){this.userInteraction=t,this.clipboard||t.setEnableClipboard(!1),t.onWarningCallback((t=>{console.warn("The remote desktop client reported a problem:",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);for(const t of s)i.withExtension(t);let o;this.dynamicResize&&(o=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),o&&i.withDesktopSize(o));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.sync_keyboard_lock();const s=e.run();this.start_viewport_sync(o);const n=await s;this.statusMessage=n.reason()}catch(t){const e=this.describe_error(t);this.statusMessage=e,this.connectionStateChanged.emit([a.Error,t])}}start_viewport_sync(t){this.dynamicResize&&(this.viewport=new f((t=>this.resize_desktop(t))),this.viewport.observe(this.el,t))}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:"56354df7bd0d3f01fcd5ff65ca5618ceb6af1b91"},o("div",{key:"446dc83e41a29c3bc2c341a26092ed3581565967",class:"screen",ref:t=>this.containerEl=t},o("slot",{key:"2beafc92d81662dfac5c7b41356f6c6c802643b9"})),this.credentialsPrompt&&o("form",{key:"dcc29b21fba03bb97526ec3d1cf5a1fb51b483e9",class:"prompt",onSubmit:t=>this.submit_credentials(t)},o("label",{key:"b5a3e302089b2282aedbdbefd4fb5eaca7c34455",htmlFor:"rdp-username"},"Username"),o("input",{key:"3bd1c902a6bc41bc7e69c16258cac78035a949bd",id:"rdp-username",type:"text",autocomplete:"off",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),o("label",{key:"2defe12d73b609cbad27c06447c3c3221ff3e5aa",htmlFor:"rdp-password"},"Password"),o("input",{key:"55935891f24f0c1db71a14c42b2fc7a96c0c0ba6",id:"rdp-password",type:"password",autocomplete:"off",onInput:t=>this.passwordBuffer=t.target.value}),o("button",{key:"83439c0e8756001c7042fc3b6754889d62a8eada",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&o("div",{key:"294262625f44a3f45d54bcd492875a9b6fd03219",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"],clipboard:[4],serverId:[1,"server-id"],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64],sendCtrlAltDel:[64],sendMetaKey:[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}
@@ -89,9 +89,20 @@ class ViewportSync {
89
89
  /**
90
90
  * Starts watching `element`. The current size is reported immediately, so a
91
91
  * widget that was resized while disconnected catches up on reconnect.
92
+ *
93
+ * `openedAt` is the size the session was actually opened at, and passing it
94
+ * is what stops that immediate report from being a resize to the resolution
95
+ * the host is already showing. That redundant request is not free: a
96
+ * display-control PDU makes the host renegotiate capabilities and resend the
97
+ * screen, and arriving moments after the connection sequence it is the worst
98
+ * possible time to ask — the client can end up parsing a bitmap whose
99
+ * declared length no longer matches the stream. Seeded here rather than
100
+ * suppressed at the call site because "what has the host been told" is this
101
+ * class's state; the caller only knows what it asked for at connect.
92
102
  */
93
- observe(element) {
103
+ observe(element, openedAt) {
94
104
  this.disconnect();
105
+ this.reported = openedAt;
95
106
  this.report(measure_desktop_size(element));
96
107
  // Absent under the spec test environment, and on nothing else worth
97
108
  // supporting — a missing observer costs the dynamic resize, not the
@@ -600,10 +611,11 @@ const PhirepassRdp = class {
600
611
  // `start_viewport_sync` correct the size once the client is visible;
601
612
  // sending a size derived from a zero-sized box is how a host ends up
602
613
  // refusing the connection outright.
614
+ let openedAt;
603
615
  if (this.dynamicResize) {
604
- const size = measure_initial_desktop_size(this.el);
605
- if (size) {
606
- builder.withDesktopSize(size);
616
+ openedAt = measure_initial_desktop_size(this.el);
617
+ if (openedAt) {
618
+ builder.withDesktopSize(openedAt);
607
619
  }
608
620
  }
609
621
  try {
@@ -621,9 +633,17 @@ const PhirepassRdp = class {
621
633
  userInteraction.setVisibility(true);
622
634
  this.statusMessage = undefined;
623
635
  this.focus_desktop();
624
- this.start_viewport_sync();
625
636
  void this.sync_keyboard_lock();
626
- const termination = await session.run();
637
+ // Started before the viewport sync, and kept unawaited until after
638
+ // it: `run` drives the stream, and the sync can emit a
639
+ // display-control PDU the moment it is attached. Asking the host to
640
+ // change resolution while the connection sequence is still being
641
+ // parsed is how a fast-path bitmap ends up truncated against its own
642
+ // declared length. Entering `run` first means anything the sync
643
+ // sends lands on a session that is already reading.
644
+ const running = session.run();
645
+ this.start_viewport_sync(openedAt);
646
+ const termination = await running;
627
647
  this.statusMessage = termination.reason();
628
648
  }
629
649
  catch (err) {
@@ -639,12 +659,12 @@ const PhirepassRdp = class {
639
659
  * measurement has to happen after it — measuring earlier reads a hidden,
640
660
  * zero-sized box.
641
661
  */
642
- start_viewport_sync() {
662
+ start_viewport_sync(openedAt) {
643
663
  if (!this.dynamicResize) {
644
664
  return;
645
665
  }
646
666
  this.viewport = new ViewportSync((size) => this.resize_desktop(size));
647
- this.viewport.observe(this.el);
667
+ this.viewport.observe(this.el, openedAt);
648
668
  }
649
669
  stop_viewport_sync() {
650
670
  this.viewport?.disconnect();
@@ -730,7 +750,7 @@ const PhirepassRdp = class {
730
750
  this.request_tunnel();
731
751
  }
732
752
  render() {
733
- return (h(Host, { key: '9eb8ba7d53d4c9489df71a9da5bae59f348b3d8a' }, h("div", { key: '2172cf49625768c585cb5a976f5164d0348e8426', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: '46f7cffae68155552bb5262c94d8fa308dbcb5df' })), this.credentialsPrompt && (h("form", { key: '02da607149cf5d444389888bc4dc1422f7ed44bd', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: '5e560dd128da72280e0711c545335ec3624a7934', htmlFor: "rdp-username" }, "Username"), h("input", { key: '3969f84697c0112cb3a7eeab0a2f8238cff7cff5', id: "rdp-username", type: "text", autocomplete: "off", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: 'fec51856a4523c8713938cee20b0e0025ff32795', htmlFor: "rdp-password" }, "Password"), h("input", { key: 'e4dff2271b1eb7576bff701540f2566d0bbb897d', id: "rdp-password", type: "password", autocomplete: "off", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: 'b59d8a69c27e065831d815c9f5a7c8a3432594f6', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: '7439841369456b3d057a3c389cabeca6affa6f98', class: "status" }, this.statusMessage))));
753
+ return (h(Host, { key: '56354df7bd0d3f01fcd5ff65ca5618ceb6af1b91' }, h("div", { key: '446dc83e41a29c3bc2c341a26092ed3581565967', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: '2beafc92d81662dfac5c7b41356f6c6c802643b9' })), this.credentialsPrompt && (h("form", { key: 'dcc29b21fba03bb97526ec3d1cf5a1fb51b483e9', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: 'b5a3e302089b2282aedbdbefd4fb5eaca7c34455', htmlFor: "rdp-username" }, "Username"), h("input", { key: '3bd1c902a6bc41bc7e69c16258cac78035a949bd', id: "rdp-username", type: "text", autocomplete: "off", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: '2defe12d73b609cbad27c06447c3c3221ff3e5aa', htmlFor: "rdp-password" }, "Password"), h("input", { key: '55935891f24f0c1db71a14c42b2fc7a96c0c0ba6', id: "rdp-password", type: "password", autocomplete: "off", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: '83439c0e8756001c7042fc3b6754889d62a8eada', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: '294262625f44a3f45d54bcd492875a9b6fd03219', class: "status" }, this.statusMessage))));
734
754
  }
735
755
  static get watchers() { return {
736
756
  "nodeId": [{
@@ -0,0 +1 @@
1
+ import{r as t,c as s,g as e,h as i,H as o}from"./p-AP5XjS35.js";import{_ as n,C as h,a as r,P as a}from"./p-DFhjP92A.js";const c=200;function d(t){return!Number.isFinite(t)||t<=0?c:Math.min(8192,Math.max(c,Math.floor(t)))}function l(t){return t-t%2}function u(t){const s=t.getBoundingClientRect();return e=s.height,{width:l(d(s.width)),height:l(d(e))};var e}class p{onResize;debounceMs;observer;handle;reported;constructor(t,s=250){this.onResize=t,this.debounceMs=s}observe(t,s){this.disconnect(),this.reported=s,this.report(u(t)),"undefined"!=typeof ResizeObserver&&(this.observer=new ResizeObserver((()=>{clearTimeout(this.handle),this.handle=setTimeout((()=>this.report(u(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){var s,e;e=this.reported,(s=t)&&e&&s.width===e.width&&s.height===e.height||(this.reported=t,this.onResize(t))}}function f(){return navigator.keyboard}function b(){return"function"==typeof f()?.lock}function m(t){return document.fullscreenElement===t}function y(t){return document.fullscreenElement?.contains(t)??!1}function w(){if(b())try{f().unlock()}catch(t){console.warn("Failed to release the keyboard lock:",t)}}const g=class{constructor(e){t(this,e),this.connectionStateChanged=s(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 e(this)}serverHost="phirepass.com";serverPort=443;allowInsecure=!1;heartbeatInterval=3e4;nodeId;serviceId;token;username;password;destination;scale="fit";dynamicResize=!0;captureKeyboard=!0;clipboard=!0;onNodeIdChange(t,s){this.reset_session_state(),this.channel&&this.channel.is_connected()&&this.close_comms(),t&&(this.open_comms(),this.channel.connect())}serverId;onServerIdChange(t,s){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 n(),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 m(t)?(await document.exitFullscreen(),!1):(await t.requestFullscreen({navigationUI:"hide"}),!0)}catch(s){return console.warn("Failed to change the fullscreen state of the RDP session:",s),m(t)}}(this.el);return this.focus_desktop(),t}async keyboardLockSupported(){return b()}async focusDesktop(){this.focus_desktop()}async sendCtrlAltDel(){return!!this.userInteraction&&(this.userInteraction.ctrlAltDel(),this.focus_desktop(),!0)}async sendMetaKey(){return!!this.userInteraction&&(this.userInteraction.metaKey(),this.focus_desktop(),!0)}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([r.Connected]),this.channel.authenticate(this.token,this.nodeId)})),this.channel.on_connection_close((()=>{this.connectionStateChanged.emit([r.Disconnected]),this.teardown_client()})),this.channel.on_connection_error((t=>{this.connectionStateChanged.emit([r.Error,t])})),this.channel.on_connection_message((()=>{})),this.channel.on_protocol_message((t=>{const{web:s}=t.data;switch(s.type){case a.Error:this.handle_error(s);break;case a.AuthSuccess:this.handle_auth_success(s);break;case a.RDPAuthorized:this.handle_rdp_authorized(s);break;case a.TunnelClosed:this.handle_tunnel_closed(s);break;default:console.warn("Unknown protocol message type:",s)}}))}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[s]=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 s.init("info"),this.disposed||!this.containerEl||this.session_id!==t.sid)return;const e=document.createElement("iron-remote-desktop");e.module=s.Backend,e.scale=this.scale,e.flexcenter=!0,e.verbose=!1;const i=[s.enableCredssp(!0)];this.dynamicResize&&i.push(s.displayControl(!0)),e.addEventListener("ready",(s=>{this.start_session(s.detail.irgUserInteraction,t.ticket,i)})),this.ironEl=e,this.mount_client(e)}mount_client(t){this.el.appendChild(t)}async start_session(t,s,e){this.userInteraction=t,this.clipboard||t.setEnableClipboard(!1),t.onWarningCallback((t=>{console.warn("The remote desktop client reported a problem:",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(s);for(const t of e)i.withExtension(t);let o;this.dynamicResize&&(o=function(t){const s=t.getBoundingClientRect();if(Number.isFinite(s.width)&&Number.isFinite(s.height)&&!(s.width<c||s.height<c))return{width:l(Math.min(Math.floor(s.width),4096)),height:l(Math.min(Math.floor(s.height),4096))}}(this.el),o&&i.withDesktopSize(o));try{const s=await t.connect(i.build());if(this.disposed)return this.shutdown_session(t),void await s.run();t.setVisibility(!0),this.statusMessage=void 0,this.focus_desktop(),this.sync_keyboard_lock();const e=s.run();this.start_viewport_sync(o);const n=await e;this.statusMessage=n.reason()}catch(t){const s=this.describe_error(t);this.statusMessage=s,this.connectionStateChanged.emit([r.Error,t])}}start_viewport_sync(t){this.dynamicResize&&(this.viewport=new p((t=>this.resize_desktop(t))),this.viewport.observe(this.el,t))}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(){var t;t=this.ironEl,t?.focus({preventScroll:!0})}async sync_keyboard_lock(){this.captureKeyboard&&y(this.el)?(await async function(t){if(b()&&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([r.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(),w(),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 i(o,{key:"56354df7bd0d3f01fcd5ff65ca5618ceb6af1b91"},i("div",{key:"446dc83e41a29c3bc2c341a26092ed3581565967",class:"screen",ref:t=>this.containerEl=t},i("slot",{key:"2beafc92d81662dfac5c7b41356f6c6c802643b9"})),this.credentialsPrompt&&i("form",{key:"dcc29b21fba03bb97526ec3d1cf5a1fb51b483e9",class:"prompt",onSubmit:t=>this.submit_credentials(t)},i("label",{key:"b5a3e302089b2282aedbdbefd4fb5eaca7c34455",htmlFor:"rdp-username"},"Username"),i("input",{key:"3bd1c902a6bc41bc7e69c16258cac78035a949bd",id:"rdp-username",type:"text",autocomplete:"off",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),i("label",{key:"2defe12d73b609cbad27c06447c3c3221ff3e5aa",htmlFor:"rdp-password"},"Password"),i("input",{key:"55935891f24f0c1db71a14c42b2fc7a96c0c0ba6",id:"rdp-password",type:"password",autocomplete:"off",onInput:t=>this.passwordBuffer=t.target.value}),i("button",{key:"83439c0e8756001c7042fc3b6754889d62a8eada",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&i("div",{key:"294262625f44a3f45d54bcd492875a9b6fd03219",class:"status"},this.statusMessage))}static get watchers(){return{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}}};g.style=':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}';export{g as phirepass_rdp}
@@ -1 +1 @@
1
- import{p as e,b as r}from"./p-AP5XjS35.js";export{s as setNonce}from"./p-AP5XjS35.js";import{g as o}from"./p-DQuL1Twl.js";(()=>{const r=import.meta.url,s={};return""!==r&&(s.resourcesUrl=new URL(".",r).href),e(s)})().then((async e=>(await o(),r([["p-ee09d805",[[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"],clipboard:[4],serverId:[1,"server-id"],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64],sendCtrlAltDel:[64],sendMetaKey:[64]},null,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]]],["p-0e9afedb",[[513,"phirepass-sftp-client",{name:[1],description:[1],hideHeader:[4,"hide-header"],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],serverId:[1,"server-id"],max:[32],show_login_screen:[32],show_login_screen_username:[32],show_error:[32],error_message:[32],show_login_screen_password:[32],show_navigation:[32],breadcrumbs:[32],current_dir:[32],listing:[32],show_content:[32],show_loader:[32],version:[32],status:[32],selected_item:[32],show_upload_modal:[32],upload_progress:[32],upload_file_name:[32],upload_speed:[32],upload_finished:[32],show_download_modal:[32],download_progress:[32],download_file_name:[32],download_speed:[32],download_finished:[32],show_delete_modal:[32],delete_file_name:[32],delete_loading:[32],maximize:[64],minimize:[64]},null,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]]],["p-c4a31b26",[[513,"phirepass-terminal",{terminalOptions:[16],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],serverId:[1,"server-id"]},null,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]]]],e))));
1
+ import{p as e,b as r}from"./p-AP5XjS35.js";export{s as setNonce}from"./p-AP5XjS35.js";import{g as o}from"./p-DQuL1Twl.js";(()=>{const r=import.meta.url,s={};return""!==r&&(s.resourcesUrl=new URL(".",r).href),e(s)})().then((async e=>(await o(),r([["p-de23b6db",[[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"],clipboard:[4],serverId:[1,"server-id"],credentialsPrompt:[32],statusMessage:[32],toggleFullscreen:[64],keyboardLockSupported:[64],focusDesktop:[64],sendCtrlAltDel:[64],sendMetaKey:[64]},null,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]]],["p-0e9afedb",[[513,"phirepass-sftp-client",{name:[1],description:[1],hideHeader:[4,"hide-header"],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],serverId:[1,"server-id"],max:[32],show_login_screen:[32],show_login_screen_username:[32],show_error:[32],error_message:[32],show_login_screen_password:[32],show_navigation:[32],breadcrumbs:[32],current_dir:[32],listing:[32],show_content:[32],show_loader:[32],version:[32],status:[32],selected_item:[32],show_upload_modal:[32],upload_progress:[32],upload_file_name:[32],upload_speed:[32],upload_finished:[32],show_download_modal:[32],download_progress:[32],download_file_name:[32],download_speed:[32],download_finished:[32],show_delete_modal:[32],delete_file_name:[32],delete_loading:[32],maximize:[64],minimize:[64]},null,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]]],["p-c4a31b26",[[513,"phirepass-terminal",{terminalOptions:[16],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],serverId:[1,"server-id"]},null,{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}]]]],e))));
@@ -40,8 +40,18 @@ export declare class ViewportSync {
40
40
  /**
41
41
  * Starts watching `element`. The current size is reported immediately, so a
42
42
  * widget that was resized while disconnected catches up on reconnect.
43
+ *
44
+ * `openedAt` is the size the session was actually opened at, and passing it
45
+ * is what stops that immediate report from being a resize to the resolution
46
+ * the host is already showing. That redundant request is not free: a
47
+ * display-control PDU makes the host renegotiate capabilities and resend the
48
+ * screen, and arriving moments after the connection sequence it is the worst
49
+ * possible time to ask — the client can end up parsing a bitmap whose
50
+ * declared length no longer matches the stream. Seeded here rather than
51
+ * suppressed at the call site because "what has the host been told" is this
52
+ * class's state; the caller only knows what it asked for at connect.
43
53
  */
44
- observe(element: Element): void;
54
+ observe(element: Element, openedAt?: DesktopSize): void;
45
55
  disconnect(): void;
46
56
  private report;
47
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phirepass-widgets",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "description": "Phirepass widgets for the web application",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -1 +0,0 @@
1
- import{r as t,c as s,g as e,h as i,H as o}from"./p-AP5XjS35.js";import{_ as n,C as h,a as r,P as a}from"./p-DFhjP92A.js";const c=200;function d(t){return!Number.isFinite(t)||t<=0?c:Math.min(8192,Math.max(c,Math.floor(t)))}function l(t){return t-t%2}function u(t){const s=t.getBoundingClientRect();return e=s.height,{width:l(d(s.width)),height:l(d(e))};var e}class f{onResize;debounceMs;observer;handle;reported;constructor(t,s=250){this.onResize=t,this.debounceMs=s}observe(t){this.disconnect(),this.report(u(t)),"undefined"!=typeof ResizeObserver&&(this.observer=new ResizeObserver((()=>{clearTimeout(this.handle),this.handle=setTimeout((()=>this.report(u(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){var s,e;e=this.reported,(s=t)&&e&&s.width===e.width&&s.height===e.height||(this.reported=t,this.onResize(t))}}function p(){return navigator.keyboard}function m(){return"function"==typeof p()?.lock}function b(t){return document.fullscreenElement===t}function y(t){return document.fullscreenElement?.contains(t)??!1}function w(){if(m())try{p().unlock()}catch(t){console.warn("Failed to release the keyboard lock:",t)}}const g=class{constructor(e){t(this,e),this.connectionStateChanged=s(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 e(this)}serverHost="phirepass.com";serverPort=443;allowInsecure=!1;heartbeatInterval=3e4;nodeId;serviceId;token;username;password;destination;scale="fit";dynamicResize=!0;captureKeyboard=!0;clipboard=!0;onNodeIdChange(t,s){this.reset_session_state(),this.channel&&this.channel.is_connected()&&this.close_comms(),t&&(this.open_comms(),this.channel.connect())}serverId;onServerIdChange(t,s){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 n(),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 b(t)?(await document.exitFullscreen(),!1):(await t.requestFullscreen({navigationUI:"hide"}),!0)}catch(s){return console.warn("Failed to change the fullscreen state of the RDP session:",s),b(t)}}(this.el);return this.focus_desktop(),t}async keyboardLockSupported(){return m()}async focusDesktop(){this.focus_desktop()}async sendCtrlAltDel(){return!!this.userInteraction&&(this.userInteraction.ctrlAltDel(),this.focus_desktop(),!0)}async sendMetaKey(){return!!this.userInteraction&&(this.userInteraction.metaKey(),this.focus_desktop(),!0)}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([r.Connected]),this.channel.authenticate(this.token,this.nodeId)})),this.channel.on_connection_close((()=>{this.connectionStateChanged.emit([r.Disconnected]),this.teardown_client()})),this.channel.on_connection_error((t=>{this.connectionStateChanged.emit([r.Error,t])})),this.channel.on_connection_message((()=>{})),this.channel.on_protocol_message((t=>{const{web:s}=t.data;switch(s.type){case a.Error:this.handle_error(s);break;case a.AuthSuccess:this.handle_auth_success(s);break;case a.RDPAuthorized:this.handle_rdp_authorized(s);break;case a.TunnelClosed:this.handle_tunnel_closed(s);break;default:console.warn("Unknown protocol message type:",s)}}))}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[s]=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 s.init("info"),this.disposed||!this.containerEl||this.session_id!==t.sid)return;const e=document.createElement("iron-remote-desktop");e.module=s.Backend,e.scale=this.scale,e.flexcenter=!0,e.verbose=!1;const i=[s.enableCredssp(!0)];this.dynamicResize&&i.push(s.displayControl(!0)),e.addEventListener("ready",(s=>{this.start_session(s.detail.irgUserInteraction,t.ticket,i)})),this.ironEl=e,this.mount_client(e)}mount_client(t){this.el.appendChild(t)}async start_session(t,s,e){this.userInteraction=t,this.clipboard||t.setEnableClipboard(!1),t.onWarningCallback((t=>{console.warn("The remote desktop client reported a problem:",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(s);for(const t of e)i.withExtension(t);if(this.dynamicResize){const t=function(t){const s=t.getBoundingClientRect();if(Number.isFinite(s.width)&&Number.isFinite(s.height)&&!(s.width<c||s.height<c))return{width:l(Math.min(Math.floor(s.width),4096)),height:l(Math.min(Math.floor(s.height),4096))}}(this.el);t&&i.withDesktopSize(t)}try{const s=await t.connect(i.build());if(this.disposed)return this.shutdown_session(t),void await s.run();t.setVisibility(!0),this.statusMessage=void 0,this.focus_desktop(),this.start_viewport_sync(),this.sync_keyboard_lock();const e=await s.run();this.statusMessage=e.reason()}catch(t){const s=this.describe_error(t);this.statusMessage=s,this.connectionStateChanged.emit([r.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(){var t;t=this.ironEl,t?.focus({preventScroll:!0})}async sync_keyboard_lock(){this.captureKeyboard&&y(this.el)?(await async function(t){if(m()&&y(t))try{await p().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([r.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(),w(),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 i(o,{key:"9eb8ba7d53d4c9489df71a9da5bae59f348b3d8a"},i("div",{key:"2172cf49625768c585cb5a976f5164d0348e8426",class:"screen",ref:t=>this.containerEl=t},i("slot",{key:"46f7cffae68155552bb5262c94d8fa308dbcb5df"})),this.credentialsPrompt&&i("form",{key:"02da607149cf5d444389888bc4dc1422f7ed44bd",class:"prompt",onSubmit:t=>this.submit_credentials(t)},i("label",{key:"5e560dd128da72280e0711c545335ec3624a7934",htmlFor:"rdp-username"},"Username"),i("input",{key:"3969f84697c0112cb3a7eeab0a2f8238cff7cff5",id:"rdp-username",type:"text",autocomplete:"off",autofocus:!0,onInput:t=>this.usernameBuffer=t.target.value}),i("label",{key:"fec51856a4523c8713938cee20b0e0025ff32795",htmlFor:"rdp-password"},"Password"),i("input",{key:"e4dff2271b1eb7576bff701540f2566d0bbb897d",id:"rdp-password",type:"password",autocomplete:"off",onInput:t=>this.passwordBuffer=t.target.value}),i("button",{key:"b59d8a69c27e065831d815c9f5a7c8a3432594f6",type:"submit"},"Connect")),this.statusMessage&&!this.credentialsPrompt&&i("div",{key:"7439841369456b3d057a3c389cabeca6affa6f98",class:"status"},this.statusMessage))}static get watchers(){return{nodeId:[{onNodeIdChange:0}],serverId:[{onServerIdChange:0}]}}};g.style=':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}';export{g as phirepass_rdp}