This commit is contained in:
rustdesk 2022-01-27 13:24:40 +08:00
parent 6c0030bbe2
commit 74c53f17ae
4 changed files with 22 additions and 19 deletions

View File

@ -60,7 +60,7 @@ export default class Connection {
const ws = new Websock(uri); const ws = new Websock(uri);
this._ws = ws; this._ws = ws;
this._id = id; this._id = id;
console.log(new Date() + ": Conntecting to rendezvoous server: " + uri); console.log(new Date() + ": Conntecting to rendezvoous server: " + uri + ", for " + id);
await ws.open(); await ws.open();
console.log(new Date() + ": Connected to rendezvoous server"); console.log(new Date() + ": Connected to rendezvoous server");
const connType = rendezvous.ConnType.DEFAULT_CONN; const connType = rendezvous.ConnType.DEFAULT_CONN;
@ -197,8 +197,8 @@ export default class Connection {
const msg = this._ws?.parseMessage(await this._ws?.next()); const msg = this._ws?.parseMessage(await this._ws?.next());
if (msg?.hash) { if (msg?.hash) {
this._hash = msg?.hash; this._hash = msg?.hash;
if (!this._password) this.msgbox("input-password", "Password Required", "");
await this.login(this._password); await this.login(this._password);
this.msgbox("input-password", "Password Required", "");
} else if (msg?.testDelay) { } else if (msg?.testDelay) {
const testDelay = msg?.testDelay; const testDelay = msg?.testDelay;
if (!testDelay.fromClient) { if (!testDelay.fromClient) {
@ -266,15 +266,13 @@ export default class Connection {
async login(password: string | undefined, _remember: Boolean = false) { async login(password: string | undefined, _remember: Boolean = false) {
this._password = password; this._password = password;
this.msgbox("connecting", "Connecting...", "Logging in..."); if (password) {
const salt = this._hash?.salt; const salt = this._hash?.salt;
if (salt && password) { let p = hash([password, salt!]);
let p = hash([password, salt]);
const challenge = this._hash?.challenge; const challenge = this._hash?.challenge;
if (challenge) { p = hash([p, challenge!]);
p = hash([p, challenge]); this.msgbox("connecting", "Connecting...", "Logging in...");
await this._sendLoginMessage(p); await this._sendLoginMessage(p);
}
} else { } else {
await this._sendLoginMessage(); await this._sendLoginMessage();
} }

View File

@ -13,6 +13,8 @@ window.getRgba = () => currentFrame;
window.getLanguage = () => navigator.language; window.getLanguage = () => navigator.language;
export function msgbox(type, title, text) { export function msgbox(type, title, text) {
if (!events) return;
if (!type) return;
const text2 = text.toLowerCase(); const text2 = text.toLowerCase();
var hasRetry = type == "error" var hasRetry = type == "error"
&& title == "Connection Error" && title == "Connection Error"
@ -27,6 +29,7 @@ export function msgbox(type, title, text) {
} }
export function pushEvent(name, payload) { export function pushEvent(name, payload) {
if (!events) return;
payload.name = name; payload.name = name;
events.push(payload); events.push(payload);
} }
@ -56,10 +59,12 @@ export function close() {
getConn()?.close(); getConn()?.close();
setConn(undefined); setConn(undefined);
currentFrame = undefined; currentFrame = undefined;
events = undefined;
} }
export function newConn() { export function newConn() {
window.curConn?.close(); window.curConn?.close();
events = [];
const conn = new Connection(); const conn = new Connection();
setConn(conn); setConn(conn);
return conn; return conn;
@ -120,7 +125,7 @@ export function decrypt(signed, nonce, key) {
export function decompress(compressedArray) { export function decompress(compressedArray) {
const MAX = 1024 * 1024 * 64; const MAX = 1024 * 1024 * 64;
const MIN = 1024 * 1024; const MIN = 1024 * 1024;
let n = 30 * data.length; let n = 30 * compressedArray.length;
if (n > MAX) { if (n > MAX) {
n = MAX; n = MAX;
} }
@ -141,7 +146,7 @@ window.setByName = (name, value) => {
switch (name) { switch (name) {
case 'connect': case 'connect':
newConn(); newConn();
startConn(value); startConn(String(value));
break; break;
case 'login': case 'login':
curConn.login(value.password, value.remember || false); curConn.login(value.password, value.remember || false);
@ -235,7 +240,7 @@ window.getByName = (name, arg) => {
return curConn.getRemember(); return curConn.getRemember();
break; break;
case 'event': case 'event':
if (events.length) { if (events && events.length) {
const e = events[0]; const e = events[0];
events.splice(0, 1); events.splice(0, 1);
return JSON.stringify(e); return JSON.stringify(e);

View File

@ -28,6 +28,7 @@ if (app) {
`; `;
let player; let player;
window.init();
document.body.onload = () => { document.body.onload = () => {
const host = document.querySelector('#host'); const host = document.querySelector('#host');
@ -55,11 +56,7 @@ if (app) {
document.querySelector('div#status').style.display = 'block'; document.querySelector('div#status').style.display = 'block';
document.querySelector('div#connect').style.display = 'none'; document.querySelector('div#connect').style.display = 'none';
document.querySelector('div#text').innerHTML = 'Connecting ...'; document.querySelector('div#text').innerHTML = 'Connecting ...';
try { await conn.start(id.value);
await conn.start(id.value);
} catch (e) {
msgbox('error', 'Error', e);
}
}; };
func(); func();
} }

View File

@ -96,10 +96,12 @@ export default class Websock {
resolve(this); resolve(this);
}; };
this._websocket.onclose = (e) => { this._websocket.onclose = (e) => {
if (this._status == 'open') {
reject(e);
}
this._status = e; this._status = e;
console.error("WebSock.onclose: " + e); console.error("WebSock.onclose: " + e);
this._eventHandlers.close(e); this._eventHandlers.close(e);
reject(e);
}; };
this._websocket.onerror = (e) => { this._websocket.onerror = (e) => {
if (!this._status) { if (!this._status) {
@ -141,6 +143,7 @@ export default class Websock {
} }
close() { close() {
this._status = '';
if (this._websocket) { if (this._websocket) {
if ( if (
this._websocket.readyState === WebSocket.OPEN || this._websocket.readyState === WebSocket.OPEN ||