Skip to content

Commit

Permalink
Merge pull request #1476 from jumpserver/pr@dev@fix_slow_connect
Browse files Browse the repository at this point in the history
fixed: Fixed the slow connection issues
  • Loading branch information
ZhaoJiSen authored Sep 10, 2024
2 parents 7ef541f + 9567042 commit 6675f2c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 6 additions & 2 deletions ui/src/components/CustomTerminal/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ export const sendEventToLuna = (
name: string,
data: any,
lunaId: string | null = '',
origin: string | null = null
origin: string | null = ''
) => {
if (lunaId !== null && origin !== null) {
window.parent.postMessage({ name, id: lunaId, data }, origin);
try {
window.parent.postMessage({ name, id: lunaId, data }, origin);
} catch (e) {
console.info(e);
}
}
};

Expand Down
13 changes: 10 additions & 3 deletions ui/src/hooks/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,22 @@ export const handleTerminalResize = (
*
* @param e
* @param terminal
* @param lunaId
* @param origin
*/
export const handleCustomKey = (e: KeyboardEvent, terminal: Terminal): boolean => {
export const handleCustomKey = (
e: KeyboardEvent,
terminal: Terminal,
lunaId: string,
origin: string
): boolean => {
if (e.altKey && e.shiftKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) {
switch (e.key) {
case 'ArrowRight':
window.parent.postMessage({ name: 'KEYEVENT', data: 'alt+shift+right' });
sendEventToLuna('KEYEVENT', 'alt+shift+right', lunaId, origin);
break;
case 'ArrowLeft':
window.parent.postMessage({ name: 'KEYEVENT', data: 'alt+shift+left' });
sendEventToLuna('KEYEVENT', 'alt+shift+left', lunaId, origin);
break;
}

Expand Down
4 changes: 1 addition & 3 deletions ui/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr

switch (message.name) {
case 'PING': {
if (lunaId.value != null) return;

lunaId.value = message.id;
origin.value = e.origin;

Expand Down Expand Up @@ -409,7 +407,7 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
handleTerminalSelection(terminal!, termSelectionText);
});
terminal.attachCustomKeyEventHandler((e: KeyboardEvent) => {
return handleCustomKey(e, terminal!);
return handleCustomKey(e, terminal!, lunaId.value, origin.value);
});
terminal.onData((data: string) => {
lastSendTime.value = new Date();
Expand Down

0 comments on commit 6675f2c

Please sign in to comment.