testDelay

This commit is contained in:
rustdesk 2022-02-06 03:38:32 +08:00
parent 38a468a5cc
commit e5b2f4ab4c

View File

@ -7,7 +7,8 @@ import * as globals from "./globals";
import { decompress, mapKey, sleep } from "./common"; import { decompress, mapKey, sleep } from "./common";
const PORT = 21116; const PORT = 21116;
const HOST = "rs-sg.rustdesk.com"; const HOSTS = ['rs-sg.rustdesk.com', 'rs-cn.rustdesk.com', 'rs-us.rustdesk.com'];
let HOST = localStorage.getItem('rendezvous-server') || HOSTS[0];
const SCHEMA = "ws://"; const SCHEMA = "ws://";
type MsgboxCallback = (type: string, title: string, text: string) => void; type MsgboxCallback = (type: string, title: string, text: string) => void;
@ -107,7 +108,7 @@ export default class Connection {
const pk = rr.pk; const pk = rr.pk;
let uri = rr.relay_server; let uri = rr.relay_server;
if (uri) { if (uri) {
uri = getrUriFromRs(uri); uri = getrUriFromRs(uri, true);
} else { } else {
uri = getDefaultUri(true); uri = getDefaultUri(true);
} }
@ -644,30 +645,36 @@ export default class Connection {
console.log(decoder); console.log(decoder);
}); });
} }
loadAudioDecoder(channels: number, sample_rate: number) {
}
} }
// @ts-ignore function testDelay() {
async function testDelay() { var nearest = '';
const ws = new Websock(getDefaultUri(false), true); HOSTS.forEach((host) => {
await ws.open(); const now = new Date().getTime();
console.log(ws.latency()); new Websock(getrUriFromRs(host), true).open().then(() => {
console.log('latency of ' + host + ': ' + (new Date().getTime() - now));
if (!nearest) {
HOST = host;
localStorage.setItem('rendezvous-server', host);
}
});
});
} }
testDelay();
function getDefaultUri(isRelay: Boolean = false): string { function getDefaultUri(isRelay: Boolean = false): string {
const host = localStorage.getItem("custom-rendezvous-server"); const host = localStorage.getItem("custom-rendezvous-server");
return SCHEMA + (host || HOST) + ":" + (PORT + (isRelay ? 3 : 2)); return SCHEMA + (host || HOST) + ":" + (PORT + (isRelay ? 3 : 2));
} }
function getrUriFromRs(uri: string): string { function getrUriFromRs(uri: string, isRelay: Boolean = false): string {
if (uri.indexOf(":") > 0) { if (uri.indexOf(":") > 0) {
const tmp = uri.split(":"); const tmp = uri.split(":");
const port = parseInt(tmp[1]); const port = parseInt(tmp[1]);
uri = tmp[0] + ":" + (port + 2); uri = tmp[0] + ":" + (port + (isRelay ? 3 : 2));
} else { } else {
uri += ":" + (PORT + 3); uri += ":" + (PORT + (isRelay ? 3 : 2));
} }
return SCHEMA + uri; return SCHEMA + uri;
} }