mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-14 03:56:27 +00:00
Refact. Flutter web, key input (#7511)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -4,6 +4,7 @@ import * as rendezvous from "./rendezvous.js";
|
||||
import { loadVp9 } from "./codec";
|
||||
import * as sha256 from "fast-sha256";
|
||||
import * as globals from "./globals";
|
||||
import * as consts from "./consts";
|
||||
import { decompress, mapKey, sleep } from "./common";
|
||||
|
||||
export const PORT = 21116;
|
||||
@@ -247,21 +248,7 @@ export default class Connection {
|
||||
this._ws?.sendMessage({ test_delay });
|
||||
}
|
||||
} else if (msg?.login_response) {
|
||||
const r = msg?.login_response;
|
||||
if (r.error) {
|
||||
if (r.error == "Wrong Password") {
|
||||
this._password = undefined;
|
||||
this.msgbox(
|
||||
"re-input-password",
|
||||
r.error,
|
||||
"Do you want to enter again?"
|
||||
);
|
||||
} else {
|
||||
this.msgbox("error", "Login Error", r.error);
|
||||
}
|
||||
} else if (r.peer_info) {
|
||||
this.handlePeerInfo(r.peer_info);
|
||||
}
|
||||
this.handleLoginResponse(msg?.login_response);
|
||||
} else if (msg?.video_frame) {
|
||||
this.handleVideoFrame(msg?.video_frame!);
|
||||
} else if (msg?.clipboard) {
|
||||
@@ -318,6 +305,103 @@ export default class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
handleLoginResponse(response: message.LoginResponse) {
|
||||
const loginErrorMap: Record<string, any> = {
|
||||
[consts.LOGIN_SCREEN_WAYLAND]: {
|
||||
msgtype: "error",
|
||||
title: "Login Error",
|
||||
text: "Login screen using Wayland is not supported",
|
||||
link: "https://rustdesk.com/docs/en/manual/linux/#login-screen",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_SESSION_NOT_READY]: {
|
||||
msgtype: "session-login",
|
||||
title: "",
|
||||
text: "",
|
||||
link: "",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_XSESSION_FAILED]: {
|
||||
msgtype: "session-re-login",
|
||||
title: "",
|
||||
text: "",
|
||||
link: "",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_SESSION_ANOTHER_USER]: {
|
||||
msgtype: "info-nocancel",
|
||||
title: "another_user_login_title_tip",
|
||||
text: "another_user_login_text_tip",
|
||||
link: "",
|
||||
try_again: false,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_XORG_NOT_FOUND]: {
|
||||
msgtype: "info-nocancel",
|
||||
title: "xorg_not_found_title_tip",
|
||||
text: "xorg_not_found_text_tip",
|
||||
link: "https://rustdesk.com/docs/en/manual/linux/#login-screen",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_NO_DESKTOP]: {
|
||||
msgtype: "info-nocancel",
|
||||
title: "no_desktop_title_tip",
|
||||
text: "no_desktop_text_tip",
|
||||
link: "https://rustdesk.com/docs/en/manual/linux/#login-screen",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_EMPTY]: {
|
||||
msgtype: "session-login-password",
|
||||
title: "",
|
||||
text: "",
|
||||
link: "",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_WRONG]: {
|
||||
msgtype: "session-login-re-password",
|
||||
title: "",
|
||||
text: "",
|
||||
link: "",
|
||||
try_again: true,
|
||||
},
|
||||
[consts.LOGIN_MSG_NO_PASSWORD_ACCESS]: {
|
||||
msgtype: "wait-remote-accept-nook",
|
||||
title: "Prompt",
|
||||
text: "Please wait for the remote side to accept your session request...",
|
||||
link: "",
|
||||
try_again: true,
|
||||
},
|
||||
};
|
||||
|
||||
const err = response.error;
|
||||
if (err) {
|
||||
if (err == consts.LOGIN_MSG_PASSWORD_EMPTY) {
|
||||
this._password = undefined;
|
||||
this.msgbox("input-password", "Password Required", "", "");
|
||||
}
|
||||
if (err == consts.LOGIN_MSG_PASSWORD_WRONG) {
|
||||
this._password = undefined;
|
||||
this.msgbox(
|
||||
"re-input-password",
|
||||
err,
|
||||
"Do you want to enter again?"
|
||||
);
|
||||
} else if (err == consts.LOGIN_MSG_2FA_WRONG || err == consts.REQUIRE_2FA) {
|
||||
this.msgbox("input-2fa", err, "");
|
||||
} else if (err in loginErrorMap) {
|
||||
const m = loginErrorMap[err];
|
||||
this.msgbox(m.msgtype, m.title, m.text, m.link);
|
||||
} else {
|
||||
if (err.includes(consts.SCRAP_X11_REQUIRED)) {
|
||||
this.msgbox("error", "Login Error", err, consts.SCRAP_X11_REF_URL);
|
||||
} else {
|
||||
this.msgbox("error", "Login Error", err);
|
||||
}
|
||||
}
|
||||
} else if (response.peer_info) {
|
||||
this.handlePeerInfo(response.peer_info);
|
||||
}
|
||||
}
|
||||
|
||||
msgbox(type_: string, title: string, text: string, link: string = '') {
|
||||
this._msgbox?.(type_, title, text, link);
|
||||
}
|
||||
@@ -620,17 +704,70 @@ export default class Connection {
|
||||
this._ws?.sendMessage({ key_event });
|
||||
}
|
||||
|
||||
restart() {
|
||||
const misc = message.Misc.fromPartial({});
|
||||
misc.restart_remote_device = true;
|
||||
this._ws?.sendMessage({ misc });
|
||||
}
|
||||
|
||||
inputString(seq: string) {
|
||||
const key_event = message.KeyEvent.fromPartial({ seq });
|
||||
this._ws?.sendMessage({ key_event });
|
||||
}
|
||||
|
||||
switchDisplay(display: number) {
|
||||
const switch_display = message.SwitchDisplay.fromPartial({ display });
|
||||
const misc = message.Misc.fromPartial({ switch_display });
|
||||
send2fa(code: string) {
|
||||
const auth_2fa = message.Auth2FA.fromPartial({ code });
|
||||
this._ws?.sendMessage({ auth_2fa });
|
||||
}
|
||||
|
||||
_captureDisplays({ add, sub, set }: {
|
||||
add?: number[], sub?: number[], set?: number[]
|
||||
}) {
|
||||
const capture_displays = message.CaptureDisplays.fromPartial({ add, sub, set });
|
||||
const misc = message.Misc.fromPartial({ capture_displays });
|
||||
this._ws?.sendMessage({ misc });
|
||||
}
|
||||
|
||||
switchDisplay(v: string) {
|
||||
try {
|
||||
const obj = JSON.parse(v);
|
||||
const value = obj.value;
|
||||
const isDesktop = obj.isDesktop;
|
||||
if (value.length == 1) {
|
||||
const switch_display = message.SwitchDisplay.fromPartial({ display: value[0] });
|
||||
const misc = message.Misc.fromPartial({ switch_display });
|
||||
this._ws?.sendMessage({ misc });
|
||||
|
||||
if (!isDesktop) {
|
||||
this._captureDisplays({ set: value });
|
||||
} else {
|
||||
// If support merging images, check_remove_unused_displays() in ui_session_interface.rs
|
||||
}
|
||||
} else {
|
||||
this._captureDisplays({ set: value });
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Failed to switch display, invalid param "' + v + '"');
|
||||
}
|
||||
}
|
||||
|
||||
elevateWithLogon(value: string) {
|
||||
try {
|
||||
const obj = JSON.parse(value);
|
||||
const logon = message.ElevationRequestWithLogon.fromPartial({
|
||||
username: obj.username,
|
||||
password: obj.password
|
||||
});
|
||||
const elevation_request = message.ElevationRequest.fromPartial({ logon });
|
||||
const misc = message.Misc.fromPartial({ elevation_request });
|
||||
this._ws?.sendMessage({ misc });
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Failed to elevate with logon, invalid param "' + value + '"');
|
||||
}
|
||||
}
|
||||
|
||||
async inputOsPassword(seq: string) {
|
||||
this.inputMouse();
|
||||
await sleep(50);
|
||||
@@ -714,6 +851,20 @@ export default class Connection {
|
||||
this._ws?.sendMessage({ misc });
|
||||
}
|
||||
|
||||
togglePrivacyMode(value: string) {
|
||||
try {
|
||||
const obj = JSON.parse(value);
|
||||
const toggle_privacy_mode = message.TogglePrivacyMode.fromPartial({
|
||||
impl_key: obj.impl_key,
|
||||
on: obj.on,
|
||||
});
|
||||
const misc = message.Misc.fromPartial({ toggle_privacy_mode });
|
||||
this._ws?.sendMessage({ misc });
|
||||
} catch (e) {
|
||||
console.log('Failed to toggle privacy mode, invalid param "' + value + '"')
|
||||
}
|
||||
}
|
||||
|
||||
getImageQuality() {
|
||||
return this.getOption("image-quality");
|
||||
}
|
||||
|
||||
19
flutter/web/js/src/consts.ts
Normal file
19
flutter/web/js/src/consts.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const LOGIN_MSG_DESKTOP_SESSION_NOT_READY = 'Desktop session not ready';
|
||||
export const LOGIN_MSG_DESKTOP_XSESSION_FAILED = 'Desktop xsession failed';
|
||||
export const LOGIN_MSG_DESKTOP_SESSION_ANOTHER_USER = 'Desktop session another user login';
|
||||
export const LOGIN_MSG_DESKTOP_XORG_NOT_FOUND = 'Desktop xorg not found';
|
||||
// ls /usr/share/xsessions/
|
||||
export const LOGIN_MSG_DESKTOP_NO_DESKTOP = 'Desktop none';
|
||||
export const LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_EMPTY =
|
||||
'Desktop session not ready, password empty';
|
||||
export const LOGIN_MSG_DESKTOP_SESSION_NOT_READY_PASSWORD_WRONG =
|
||||
'Desktop session not ready, password wrong';
|
||||
export const LOGIN_MSG_PASSWORD_EMPTY = 'Empty Password';
|
||||
export const LOGIN_MSG_PASSWORD_WRONG = 'Wrong Password';
|
||||
export const LOGIN_MSG_2FA_WRONG = 'Wrong 2FA Code';
|
||||
export const REQUIRE_2FA = '2FA Required';
|
||||
export const LOGIN_MSG_NO_PASSWORD_ACCESS = 'No Password Access';
|
||||
export const LOGIN_MSG_OFFLINE = 'Offline';
|
||||
export const LOGIN_SCREEN_WAYLAND = 'Wayland login screen is not supported';
|
||||
export const SCRAP_X11_REQUIRED = 'x11 expected';
|
||||
export const SCRAP_X11_REF_URL = 'https://rustdesk.com/docs/en/manual/linux/#x11-required';
|
||||
@@ -63,7 +63,7 @@ let testSpeed = [0, 0];
|
||||
export function draw(display, frame) {
|
||||
if (yuvWorker) {
|
||||
// frame's (y/u/v).bytes already detached, can not transferrable any more.
|
||||
yuvWorker.postMessage({display, frame});
|
||||
yuvWorker.postMessage({ display, frame });
|
||||
} else {
|
||||
var tm0 = new Date().getTime();
|
||||
yuvCanvas.drawFrame(frame);
|
||||
@@ -216,6 +216,9 @@ window.setByName = (name, value) => {
|
||||
case 'toggle_option':
|
||||
curConn.toggleOption(value);
|
||||
break;
|
||||
case 'toggle_privacy_mode':
|
||||
curConn.togglePrivacyMode(value);
|
||||
break;
|
||||
case 'image_quality':
|
||||
curConn.setImageQuality(value);
|
||||
break;
|
||||
@@ -266,6 +269,9 @@ window.setByName = (name, value) => {
|
||||
}
|
||||
curConn.inputMouse(mask, parseInt(value.x || '0'), parseInt(value.y || '0'), value.alt == 'true', value.ctrl == 'true', value.shift == 'true', value.command == 'true');
|
||||
break;
|
||||
case 'send_2fa':
|
||||
curConn.send2fa(value);
|
||||
break;
|
||||
case 'option':
|
||||
value = JSON.parse(value);
|
||||
localStorage.setItem(value.name, value.value);
|
||||
@@ -306,6 +312,20 @@ window.setByName = (name, value) => {
|
||||
case 'session_close':
|
||||
sessionClose(value);
|
||||
break;
|
||||
case 'elevate_with_logon':
|
||||
curConn.elevateWithLogon(value);
|
||||
break;
|
||||
case 'forget':
|
||||
curConn.setRemember(false);
|
||||
break;
|
||||
case 'peer_has_password':
|
||||
const options = getPeers()[value] || {};
|
||||
return (options['password'] ?? '') !== '';
|
||||
case 'peer_exists':
|
||||
return !(!getPeers()[value]);
|
||||
case 'restart':
|
||||
curConn.restart();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -402,6 +422,8 @@ function _getByName(name, arg) {
|
||||
return localStorage.getItem('peers-lan') ?? '{}';
|
||||
case 'api_server':
|
||||
return getApiServer();
|
||||
case 'is_using_public_server':
|
||||
return !localStorage.getItem('custom-rendezvous-server');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user