phirepass-widgets 0.0.81 → 0.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{index-D-l8xaCI.js → index-Dtiw2goq.js} +28 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/phirepass-rdp.cjs.entry.js +378 -17
- package/dist/cjs/phirepass-sftp-client.cjs.entry.js +18 -18
- package/dist/cjs/phirepass-terminal.cjs.entry.js +3 -3
- package/dist/cjs/phirepass-widgets.cjs.js +2 -2
- package/dist/cjs/{protocol-DS0qXomZ.js → protocol-CLPcBss-.js} +3 -3
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.css +16 -5
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +263 -14
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.keyboard.js +88 -0
- package/dist/collection/components/phirepass-rdp/phirepass-rdp.viewport.js +119 -0
- package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.js +16 -16
- package/dist/collection/components/phirepass-terminal/phirepass-terminal.js +1 -1
- package/dist/collection/phirepass-channel_bg.wasm +0 -0
- package/dist/components/index.js +1 -1
- package/dist/{phirepass-widgets/p-CWIhN33k.js → components/p-B29jN5hK.js} +1 -1
- package/dist/components/phirepass-rdp.js +1 -1
- package/dist/components/phirepass-sftp-client.js +1 -1
- package/dist/components/phirepass-terminal.js +2 -2
- package/dist/esm/{index-DovZQ7sb.js → index-Buu-IaNK.js} +28 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/phirepass-rdp.entry.js +378 -17
- package/dist/esm/phirepass-sftp-client.entry.js +18 -18
- package/dist/esm/phirepass-terminal.entry.js +3 -3
- package/dist/esm/phirepass-widgets.js +3 -3
- package/dist/esm/{protocol-CWIhN33k.js → protocol-B29jN5hK.js} +2 -2
- package/dist/phirepass-widgets/{p-19789356.entry.js → p-72791b1f.entry.js} +1 -1
- package/dist/{components/p-CWIhN33k.js → phirepass-widgets/p-B29jN5hK.js} +1 -1
- package/dist/phirepass-widgets/p-Buu-IaNK.js +2 -0
- package/dist/phirepass-widgets/p-b23756c5.entry.js +1 -0
- package/dist/phirepass-widgets/{p-2478a6eb.entry.js → p-ddd48131.entry.js} +2 -2
- package/dist/phirepass-widgets/phirepass-channel_bg.wasm +0 -0
- package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
- package/dist/types/components/phirepass-rdp/phirepass-rdp.d.ts +80 -0
- package/dist/types/components/phirepass-rdp/phirepass-rdp.keyboard.d.ts +42 -0
- package/dist/types/components/phirepass-rdp/phirepass-rdp.viewport.d.ts +47 -0
- package/dist/types/components.d.ts +34 -0
- package/package.json +2 -2
- package/dist/phirepass-widgets/p-DovZQ7sb.js +0 -2
- package/dist/phirepass-widgets/p-a5528005.entry.js +0 -1
|
@@ -666,6 +666,7 @@ function sortedAttrNames(attrNames) {
|
|
|
666
666
|
);
|
|
667
667
|
}
|
|
668
668
|
var hostTagName;
|
|
669
|
+
var useNativeShadowDom = false;
|
|
669
670
|
var isSvgMode = false;
|
|
670
671
|
var refCallbacksToRemove = [];
|
|
671
672
|
var refCallbacksToAttach = [];
|
|
@@ -713,6 +714,25 @@ var createElm = (oldParentVNode, newParentVNode, childIndex) => {
|
|
|
713
714
|
elm["s-hn"] = hostTagName;
|
|
714
715
|
return elm;
|
|
715
716
|
};
|
|
717
|
+
var relocateToHostRoot = (parentElm) => {
|
|
718
|
+
plt.$flags$ |= 1 /* isTmpDisconnected */;
|
|
719
|
+
const host = parentElm.closest(hostTagName.toLowerCase());
|
|
720
|
+
if (host != null) {
|
|
721
|
+
const contentRefNode = Array.from(host.__childNodes || host.childNodes).find(
|
|
722
|
+
(ref) => ref["s-cr"]
|
|
723
|
+
);
|
|
724
|
+
const childNodeArray = Array.from(
|
|
725
|
+
parentElm.__childNodes || parentElm.childNodes
|
|
726
|
+
);
|
|
727
|
+
for (const childNode of contentRefNode ? childNodeArray.reverse() : childNodeArray) {
|
|
728
|
+
if (childNode["s-sh"] != null) {
|
|
729
|
+
insertBefore(host, childNode, contentRefNode != null ? contentRefNode : null);
|
|
730
|
+
childNode["s-sh"] = void 0;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
plt.$flags$ &= -2 /* isTmpDisconnected */;
|
|
735
|
+
};
|
|
716
736
|
var addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
717
737
|
let containerElm = parentElm;
|
|
718
738
|
let childNode;
|
|
@@ -852,6 +872,12 @@ var patch = (oldVNode, newVNode2, isInitialRender = false) => {
|
|
|
852
872
|
isSvgMode = tag === "svg" ? true : tag === "foreignObject" ? false : isSvgMode;
|
|
853
873
|
}
|
|
854
874
|
{
|
|
875
|
+
if (tag === "slot" && !useNativeShadowDom) {
|
|
876
|
+
if (oldVNode.$name$ !== newVNode2.$name$) {
|
|
877
|
+
newVNode2.$elm$["s-sn"] = newVNode2.$name$ || "";
|
|
878
|
+
relocateToHostRoot(newVNode2.$elm$.parentElement);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
855
881
|
updateElement(oldVNode, newVNode2, isSvgMode);
|
|
856
882
|
}
|
|
857
883
|
if (oldChildren !== null && newChildren !== null) {
|
|
@@ -904,6 +930,7 @@ var insertBefore = (parent, newNode, reference, isInitialLoad) => {
|
|
|
904
930
|
};
|
|
905
931
|
var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
|
|
906
932
|
const hostElm = hostRef.$hostElement$;
|
|
933
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
907
934
|
const oldVNode = hostRef.$vnode$ || newVNode(null, null);
|
|
908
935
|
const isHostElement = isHost(renderFnResults);
|
|
909
936
|
const rootVnode = isHostElement ? renderFnResults : h(null, null, renderFnResults);
|
|
@@ -919,6 +946,7 @@ var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
|
|
|
919
946
|
rootVnode.$flags$ |= 4 /* isHost */;
|
|
920
947
|
hostRef.$vnode$ = rootVnode;
|
|
921
948
|
rootVnode.$elm$ = oldVNode.$elm$ = hostElm.shadowRoot || hostElm ;
|
|
949
|
+
useNativeShadowDom = !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) && !(cmpMeta.$flags$ & 128 /* shadowNeedsScopedCss */);
|
|
922
950
|
patch(oldVNode, rootVnode, isInitialLoad);
|
|
923
951
|
flushQueuedRefCallbacks();
|
|
924
952
|
};
|
package/dist/cjs/loader.cjs.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-Dtiw2goq.js');
|
|
4
4
|
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
5
|
|
|
6
6
|
const defineCustomElements = async (win, options) => {
|
|
7
7
|
if (typeof window === 'undefined') return undefined;
|
|
8
8
|
await appGlobals.globalScripts();
|
|
9
|
-
return index.bootstrapLazy([["phirepass-rdp.cjs",[[
|
|
9
|
+
return index.bootstrapLazy([["phirepass-rdp.cjs",[[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]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]],["phirepass-sftp-client.cjs",[[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}]}]]],["phirepass-terminal.cjs",[[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}]}]]]], options);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
exports.setNonce = index.setNonce;
|
|
@@ -1,9 +1,218 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
4
|
-
var protocol = require('./protocol-
|
|
3
|
+
var index = require('./index-Dtiw2goq.js');
|
|
4
|
+
var protocol = require('./protocol-CLPcBss-.js');
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* RDP's display-control PDU describes a monitor in whole, even pixels within
|
|
8
|
+
* these bounds. A layout outside them is refused by the host rather than
|
|
9
|
+
* negotiated down, and the client reports nothing when that happens — so the
|
|
10
|
+
* clamping has to be done here, before the request leaves.
|
|
11
|
+
*/
|
|
12
|
+
const MIN_DIMENSION = 200;
|
|
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;
|
|
22
|
+
/** How long a drag has to settle before the host is asked for a new size. */
|
|
23
|
+
const RESIZE_DEBOUNCE_MS = 250;
|
|
24
|
+
function clamp(value) {
|
|
25
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
26
|
+
return MIN_DIMENSION;
|
|
27
|
+
}
|
|
28
|
+
return Math.min(MAX_DIMENSION, Math.max(MIN_DIMENSION, Math.floor(value)));
|
|
29
|
+
}
|
|
30
|
+
function even(value) {
|
|
31
|
+
return value - (value % 2);
|
|
32
|
+
}
|
|
33
|
+
function clamp_desktop_size(width, height) {
|
|
34
|
+
return { width: even(clamp(width)), height: even(clamp(height)) };
|
|
35
|
+
}
|
|
36
|
+
/** The size the remote desktop would need to be to fill `element` exactly. */
|
|
37
|
+
function measure_desktop_size(element) {
|
|
38
|
+
const rect = element.getBoundingClientRect();
|
|
39
|
+
return clamp_desktop_size(rect.width, rect.height);
|
|
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
|
+
}
|
|
67
|
+
function same_desktop_size(a, b) {
|
|
68
|
+
return !!a && !!b && a.width === b.width && a.height === b.height;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Reports the widget's size to whoever can act on it, as the widget is resized.
|
|
72
|
+
*
|
|
73
|
+
* Two behaviours are deliberate. It **debounces**, because dragging a panel
|
|
74
|
+
* edge emits a resize per frame while every report costs a display-control
|
|
75
|
+
* round trip to the host — and a host that is still applying one layout ignores
|
|
76
|
+
* the next. And it **drops repeats**, because a resize observer also fires for
|
|
77
|
+
* changes that do not move the desktop at all (a scrollbar appearing, the
|
|
78
|
+
* canvas being re-laid-out in response to the resize this class just asked for,
|
|
79
|
+
* which would otherwise loop).
|
|
80
|
+
*/
|
|
81
|
+
class ViewportSync {
|
|
82
|
+
onResize;
|
|
83
|
+
debounceMs;
|
|
84
|
+
observer;
|
|
85
|
+
handle;
|
|
86
|
+
reported;
|
|
87
|
+
constructor(onResize, debounceMs = RESIZE_DEBOUNCE_MS) {
|
|
88
|
+
this.onResize = onResize;
|
|
89
|
+
this.debounceMs = debounceMs;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Starts watching `element`. The current size is reported immediately, so a
|
|
93
|
+
* widget that was resized while disconnected catches up on reconnect.
|
|
94
|
+
*/
|
|
95
|
+
observe(element) {
|
|
96
|
+
this.disconnect();
|
|
97
|
+
this.report(measure_desktop_size(element));
|
|
98
|
+
// Absent under the spec test environment, and on nothing else worth
|
|
99
|
+
// supporting — a missing observer costs the dynamic resize, not the
|
|
100
|
+
// session.
|
|
101
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.observer = new ResizeObserver(() => {
|
|
105
|
+
clearTimeout(this.handle);
|
|
106
|
+
this.handle = setTimeout(() => this.report(measure_desktop_size(element)), this.debounceMs);
|
|
107
|
+
});
|
|
108
|
+
this.observer.observe(element);
|
|
109
|
+
}
|
|
110
|
+
disconnect() {
|
|
111
|
+
clearTimeout(this.handle);
|
|
112
|
+
this.handle = undefined;
|
|
113
|
+
this.observer?.disconnect();
|
|
114
|
+
this.observer = undefined;
|
|
115
|
+
this.reported = undefined;
|
|
116
|
+
}
|
|
117
|
+
report(size) {
|
|
118
|
+
if (same_desktop_size(size, this.reported)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.reported = size;
|
|
122
|
+
this.onResize(size);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Keyboard capture for the RDP widget, in two layers.
|
|
128
|
+
*
|
|
129
|
+
* **Ordinary keys** are IronRDP's own doing: it listens on `window` and
|
|
130
|
+
* forwards a key event only while its element is `document.activeElement`. That
|
|
131
|
+
* check is why the client element is mounted in the widget's *light* DOM — see
|
|
132
|
+
* the note on `mount_client` in the component — and why it has to be focused,
|
|
133
|
+
* which `focus_client` below is for.
|
|
134
|
+
*
|
|
135
|
+
* **Keys the browser reserves** (Ctrl+W, Ctrl+T, Ctrl+N, Alt+Tab, F11, Escape)
|
|
136
|
+
* never reach the page at all, so no amount of focus will forward them. The
|
|
137
|
+
* only way to have them is the Keyboard Lock API, and browsers grant that only
|
|
138
|
+
* to a document that is already fullscreen. So "capture my keyboard" is really
|
|
139
|
+
* "go fullscreen, then lock" — hence `toggle_fullscreen`.
|
|
140
|
+
*/
|
|
141
|
+
function keyboard_api() {
|
|
142
|
+
return navigator.keyboard;
|
|
143
|
+
}
|
|
144
|
+
/** Chromium-only at the time of writing; Firefox and Safari have no equivalent. */
|
|
145
|
+
function keyboard_lock_supported() {
|
|
146
|
+
return typeof keyboard_api()?.lock === 'function';
|
|
147
|
+
}
|
|
148
|
+
/** Strictly this element — what deciding whether to enter or exit turns on. */
|
|
149
|
+
function is_fullscreen(element) {
|
|
150
|
+
return document.fullscreenElement === element;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* This element *or* something around it. The lock is granted per document, so
|
|
154
|
+
* a host app that made a whole panel fullscreen should get it too.
|
|
155
|
+
*/
|
|
156
|
+
function shown_fullscreen(element) {
|
|
157
|
+
return document.fullscreenElement?.contains(element) ?? false;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Takes every key the browser is willing to give up. Called with no arguments
|
|
161
|
+
* `lock()` claims the lot, including Escape — which is also the key that leaves
|
|
162
|
+
* fullscreen, so the browser substitutes a press-and-hold gesture for it.
|
|
163
|
+
*/
|
|
164
|
+
async function lock_keyboard(element) {
|
|
165
|
+
// There is no capability query, and the request rejects outside fullscreen,
|
|
166
|
+
// so the caller's state is the only guard available.
|
|
167
|
+
if (!keyboard_lock_supported() || !shown_fullscreen(element)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
await keyboard_api().lock();
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
console.warn('Failed to lock the keyboard for the RDP session:', err);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function unlock_keyboard() {
|
|
178
|
+
if (!keyboard_lock_supported()) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
keyboard_api().unlock();
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
console.warn('Failed to release the keyboard lock:', err);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** Returns whether `element` is fullscreen once the request has settled. */
|
|
189
|
+
async function toggle_fullscreen(element) {
|
|
190
|
+
try {
|
|
191
|
+
if (is_fullscreen(element)) {
|
|
192
|
+
await document.exitFullscreen();
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
await element.requestFullscreen({ navigationUI: 'hide' });
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
console.warn('Failed to change the fullscreen state of the RDP session:', err);
|
|
200
|
+
return is_fullscreen(element);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Gives the client element focus so IronRDP starts forwarding keys.
|
|
205
|
+
*
|
|
206
|
+
* The element's shadow root is opened with `delegatesFocus`, so focusing the
|
|
207
|
+
* host lands on the canvas inside it; the canvas is what IronRDP watches. Doing
|
|
208
|
+
* this on connect saves the user the mouse-over that would otherwise be needed
|
|
209
|
+
* before the first keystroke lands.
|
|
210
|
+
*/
|
|
211
|
+
function focus_client(element) {
|
|
212
|
+
element?.focus({ preventScroll: true });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const phirepassRdpCss = () => `: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}`;
|
|
7
216
|
|
|
8
217
|
const PhirepassRdp = class {
|
|
9
218
|
constructor(hostRef) {
|
|
@@ -14,10 +223,13 @@ const PhirepassRdp = class {
|
|
|
14
223
|
containerEl;
|
|
15
224
|
ironEl;
|
|
16
225
|
userInteraction;
|
|
226
|
+
viewport;
|
|
17
227
|
domReady = false;
|
|
18
228
|
runtimeReady = false;
|
|
19
229
|
connected = false;
|
|
230
|
+
disposed = false;
|
|
20
231
|
session_id;
|
|
232
|
+
onFullscreenChange = () => this.sync_keyboard_lock();
|
|
21
233
|
/** Credentials in force for this session, from props or from the prompt. */
|
|
22
234
|
credentials;
|
|
23
235
|
credentialsPrompt = false;
|
|
@@ -52,6 +264,26 @@ const PhirepassRdp = class {
|
|
|
52
264
|
destination;
|
|
53
265
|
/** `fit` scales the desktop to the widget, `real` keeps 1:1 pixels. */
|
|
54
266
|
scale = 'fit';
|
|
267
|
+
/**
|
|
268
|
+
* Ask the remote host to change its resolution to match the widget whenever
|
|
269
|
+
* the widget is resized, so the desktop is rendered at native size rather
|
|
270
|
+
* than scaled.
|
|
271
|
+
*
|
|
272
|
+
* The host has the last word: this needs the display-control channel, and a
|
|
273
|
+
* host that does not offer it simply keeps the resolution it started with —
|
|
274
|
+
* which `scale` then fits into the widget, as before.
|
|
275
|
+
*/
|
|
276
|
+
dynamicResize = true;
|
|
277
|
+
/**
|
|
278
|
+
* While the widget is fullscreen, take the keys the browser normally keeps
|
|
279
|
+
* for itself (Ctrl+W, Ctrl+T, Alt+Tab, F11) and send them to the remote
|
|
280
|
+
* host instead. Escape is taken too, so leaving fullscreen becomes a
|
|
281
|
+
* press-and-hold.
|
|
282
|
+
*
|
|
283
|
+
* Ordinary keys do not depend on this — they are forwarded whenever the
|
|
284
|
+
* desktop has focus.
|
|
285
|
+
*/
|
|
286
|
+
captureKeyboard = true;
|
|
55
287
|
onNodeIdChange(newValue, _oldValue) {
|
|
56
288
|
this.reset_session_state();
|
|
57
289
|
if (this.channel && this.channel.is_connected()) {
|
|
@@ -78,6 +310,10 @@ const PhirepassRdp = class {
|
|
|
78
310
|
return `${protocol}://${this.serverHost}:${this.serverPort}`;
|
|
79
311
|
}
|
|
80
312
|
async connectedCallback() {
|
|
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;
|
|
81
317
|
await protocol.__wbg_init();
|
|
82
318
|
this.open_comms();
|
|
83
319
|
this.runtimeReady = true;
|
|
@@ -91,12 +327,42 @@ const PhirepassRdp = class {
|
|
|
91
327
|
this.domReady = true;
|
|
92
328
|
this.try_connect();
|
|
93
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
|
+
*/
|
|
94
338
|
async disconnectedCallback() {
|
|
339
|
+
document.removeEventListener('fullscreenchange', this.onFullscreenChange);
|
|
340
|
+
this.disposed = true;
|
|
341
|
+
this.session_id = undefined;
|
|
95
342
|
this.connected = false;
|
|
96
343
|
this.domReady = false;
|
|
97
344
|
this.runtimeReady = false;
|
|
98
345
|
this.close_comms();
|
|
99
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Puts the widget in and out of fullscreen, returning the state it settled
|
|
349
|
+
* in. Fullscreen is also what makes `captureKeyboard` possible, so a host
|
|
350
|
+
* app wanting the browser's own shortcuts to reach the remote desktop has
|
|
351
|
+
* to come through here.
|
|
352
|
+
*/
|
|
353
|
+
async toggleFullscreen() {
|
|
354
|
+
const fullscreen = await toggle_fullscreen(this.el);
|
|
355
|
+
this.focus_desktop();
|
|
356
|
+
return fullscreen;
|
|
357
|
+
}
|
|
358
|
+
/** Whether the browser can hand over its reserved keys at all. */
|
|
359
|
+
async keyboardLockSupported() {
|
|
360
|
+
return keyboard_lock_supported();
|
|
361
|
+
}
|
|
362
|
+
/** Directs keystrokes at the remote desktop without waiting for a click. */
|
|
363
|
+
async focusDesktop() {
|
|
364
|
+
this.focus_desktop();
|
|
365
|
+
}
|
|
100
366
|
try_connect() {
|
|
101
367
|
if (this.connected || !this.domReady || !this.runtimeReady) {
|
|
102
368
|
return;
|
|
@@ -204,11 +470,11 @@ const PhirepassRdp = class {
|
|
|
204
470
|
import('@devolutions/iron-remote-desktop'),
|
|
205
471
|
]);
|
|
206
472
|
// The element may have gone away while the modules were loading.
|
|
207
|
-
if (!this.containerEl || this.session_id !== web.sid) {
|
|
473
|
+
if (this.disposed || !this.containerEl || this.session_id !== web.sid) {
|
|
208
474
|
return;
|
|
209
475
|
}
|
|
210
476
|
await backend.init('info');
|
|
211
|
-
if (!this.containerEl || this.session_id !== web.sid) {
|
|
477
|
+
if (this.disposed || !this.containerEl || this.session_id !== web.sid) {
|
|
212
478
|
return;
|
|
213
479
|
}
|
|
214
480
|
// Built imperatively rather than in `render()` so `module` is set
|
|
@@ -223,23 +489,63 @@ const PhirepassRdp = class {
|
|
|
223
489
|
void this.start_session(detail.irgUserInteraction, web.ticket, backend.enableCredssp(true));
|
|
224
490
|
});
|
|
225
491
|
this.ironEl = element;
|
|
226
|
-
this.
|
|
492
|
+
this.mount_client(element);
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Mounts the client in the widget's **light** DOM, slotted into `.screen`,
|
|
496
|
+
* rather than as a child of the shadow root.
|
|
497
|
+
*
|
|
498
|
+
* This is what makes the keyboard work. IronRDP forwards a key event only
|
|
499
|
+
* while `document.activeElement` is its own element, and `activeElement`
|
|
500
|
+
* retargets focus to the outermost shadow host: with the client inside this
|
|
501
|
+
* widget's shadow root the answer is always `<phirepass-rdp>`, the check
|
|
502
|
+
* never passes, and not one keystroke reaches the remote host — while the
|
|
503
|
+
* mouse, which is bound to the canvas directly, works fine. Slotting the
|
|
504
|
+
* client leaves it in the document tree, so `activeElement` resolves to the
|
|
505
|
+
* client itself.
|
|
506
|
+
*/
|
|
507
|
+
mount_client(element) {
|
|
508
|
+
this.el.appendChild(element);
|
|
227
509
|
}
|
|
228
510
|
async start_session(userInteraction, ticket, credssp) {
|
|
229
511
|
this.userInteraction = userInteraction;
|
|
230
|
-
const
|
|
512
|
+
const builder = userInteraction
|
|
231
513
|
.configBuilder()
|
|
232
514
|
.withUsername(this.credentials?.username ?? '')
|
|
233
515
|
.withPassword(this.credentials?.password ?? '')
|
|
234
516
|
.withDestination(this.destination ?? this.nodeId)
|
|
235
517
|
.withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`)
|
|
236
518
|
.withAuthToken(ticket)
|
|
237
|
-
.withExtension(credssp)
|
|
238
|
-
|
|
519
|
+
.withExtension(credssp);
|
|
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.
|
|
526
|
+
if (this.dynamicResize) {
|
|
527
|
+
const size = measure_initial_desktop_size(this.el);
|
|
528
|
+
if (size) {
|
|
529
|
+
builder.withDesktopSize(size);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
239
532
|
try {
|
|
240
|
-
const session = await userInteraction.connect(
|
|
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
|
+
}
|
|
241
544
|
userInteraction.setVisibility(true);
|
|
242
545
|
this.statusMessage = undefined;
|
|
546
|
+
this.focus_desktop();
|
|
547
|
+
this.start_viewport_sync();
|
|
548
|
+
void this.sync_keyboard_lock();
|
|
243
549
|
const termination = await session.run();
|
|
244
550
|
this.statusMessage = termination.reason();
|
|
245
551
|
}
|
|
@@ -249,6 +555,51 @@ const PhirepassRdp = class {
|
|
|
249
555
|
this.connectionStateChanged.emit([protocol.ConnectionState.Error, err]);
|
|
250
556
|
}
|
|
251
557
|
}
|
|
558
|
+
/**
|
|
559
|
+
* Keeps the remote resolution equal to the widget's size.
|
|
560
|
+
*
|
|
561
|
+
* `setVisibility(true)` is what gives the widget its layout, so the first
|
|
562
|
+
* measurement has to happen after it — measuring earlier reads a hidden,
|
|
563
|
+
* zero-sized box.
|
|
564
|
+
*/
|
|
565
|
+
start_viewport_sync() {
|
|
566
|
+
if (!this.dynamicResize) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
this.viewport = new ViewportSync((size) => this.resize_desktop(size));
|
|
570
|
+
this.viewport.observe(this.el);
|
|
571
|
+
}
|
|
572
|
+
stop_viewport_sync() {
|
|
573
|
+
this.viewport?.disconnect();
|
|
574
|
+
this.viewport = undefined;
|
|
575
|
+
}
|
|
576
|
+
resize_desktop(size) {
|
|
577
|
+
try {
|
|
578
|
+
this.userInteraction?.resize(size.width, size.height);
|
|
579
|
+
}
|
|
580
|
+
catch (err) {
|
|
581
|
+
// A host without the display-control channel refuses the request;
|
|
582
|
+
// the session carries on at the resolution it already has.
|
|
583
|
+
console.warn('The remote host would not resize its desktop:', err);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
focus_desktop() {
|
|
587
|
+
focus_client(this.ironEl);
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Holds the keyboard lock exactly while the widget is fullscreen. Both
|
|
591
|
+
* edges matter: the browser drops the lock on its own when fullscreen ends,
|
|
592
|
+
* but not when the session does, and a lock left behind would keep
|
|
593
|
+
* swallowing shortcuts for the rest of the page.
|
|
594
|
+
*/
|
|
595
|
+
async sync_keyboard_lock() {
|
|
596
|
+
if (!this.captureKeyboard || !shown_fullscreen(this.el)) {
|
|
597
|
+
unlock_keyboard();
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
await lock_keyboard(this.el);
|
|
601
|
+
this.focus_desktop();
|
|
602
|
+
}
|
|
252
603
|
/** IronRDP rejects with its own error shape rather than an `Error`. */
|
|
253
604
|
describe_error(err) {
|
|
254
605
|
const iron = err;
|
|
@@ -267,14 +618,24 @@ const PhirepassRdp = class {
|
|
|
267
618
|
this.statusMessage = error.message;
|
|
268
619
|
this.connectionStateChanged.emit([protocol.ConnectionState.Error, error]);
|
|
269
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
|
+
}
|
|
270
634
|
teardown_client() {
|
|
635
|
+
this.stop_viewport_sync();
|
|
636
|
+
unlock_keyboard();
|
|
271
637
|
if (this.userInteraction) {
|
|
272
|
-
|
|
273
|
-
this.userInteraction.shutdown();
|
|
274
|
-
}
|
|
275
|
-
catch (err) {
|
|
276
|
-
console.warn('Failed to shut the RDP session down cleanly:', err);
|
|
277
|
-
}
|
|
638
|
+
this.shutdown_session(this.userInteraction);
|
|
278
639
|
this.userInteraction = undefined;
|
|
279
640
|
}
|
|
280
641
|
this.ironEl?.remove();
|
|
@@ -292,7 +653,7 @@ const PhirepassRdp = class {
|
|
|
292
653
|
this.request_tunnel();
|
|
293
654
|
}
|
|
294
655
|
render() {
|
|
295
|
-
return (index.h(index.Host, { key: '
|
|
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))));
|
|
296
657
|
}
|
|
297
658
|
static get watchers() { return {
|
|
298
659
|
"nodeId": [{
|