fix retry etc
This commit is contained in:
parent
e5b2f4ab4c
commit
809719b8c2
@ -5,7 +5,6 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="favicon.svg?v2" />
|
<link rel="icon" type="image/svg+xml" href="favicon.svg?v2" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<script src="ogvjs-1.8.6/ogv.js"></script>
|
<script src="ogvjs-1.8.6/ogv.js"></script>
|
||||||
<script src="libopus.js"></script>
|
|
||||||
<script src="./yuv-canvas-1.2.6.js"></script>
|
<script src="./yuv-canvas-1.2.6.js"></script>
|
||||||
<title>Vite App</title>
|
<title>Vite App</title>
|
||||||
</head>
|
</head>
|
||||||
|
@ -7,8 +7,12 @@ import * as globals from "./globals";
|
|||||||
import { decompress, mapKey, sleep } from "./common";
|
import { decompress, mapKey, sleep } from "./common";
|
||||||
|
|
||||||
const PORT = 21116;
|
const PORT = 21116;
|
||||||
const HOSTS = ['rs-sg.rustdesk.com', 'rs-cn.rustdesk.com', 'rs-us.rustdesk.com'];
|
const HOSTS = [
|
||||||
let HOST = localStorage.getItem('rendezvous-server') || HOSTS[0];
|
"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;
|
||||||
@ -38,6 +42,18 @@ export default class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start(id: string) {
|
async start(id: string) {
|
||||||
|
try {
|
||||||
|
await this._start(id);
|
||||||
|
} catch (e: any) {
|
||||||
|
this.msgbox(
|
||||||
|
"error",
|
||||||
|
"Connection Error",
|
||||||
|
e.type == "close" ? "Reset by the peer" : String(e)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _start(id: string) {
|
||||||
if (!this._options) {
|
if (!this._options) {
|
||||||
this._options = globals.getPeers()[id] || {};
|
this._options = globals.getPeers()[id] || {};
|
||||||
}
|
}
|
||||||
@ -114,7 +130,7 @@ export default class Connection {
|
|||||||
}
|
}
|
||||||
const uuid = rr.uuid;
|
const uuid = rr.uuid;
|
||||||
console.log(new Date() + ": Connecting to relay server: " + uri);
|
console.log(new Date() + ": Connecting to relay server: " + uri);
|
||||||
const ws = new Websock(uri, false, this.handleVideoFrame.bind(this));
|
const ws = new Websock(uri, false);
|
||||||
await ws.open();
|
await ws.open();
|
||||||
console.log(new Date() + ": Connected to relay server");
|
console.log(new Date() + ": Connected to relay server");
|
||||||
this._ws = ws;
|
this._ws = ws;
|
||||||
@ -214,7 +230,16 @@ export default class Connection {
|
|||||||
} else if (msg?.login_response) {
|
} else if (msg?.login_response) {
|
||||||
const r = msg?.login_response;
|
const r = msg?.login_response;
|
||||||
if (r.error) {
|
if (r.error) {
|
||||||
this.msgbox("error", "Error", 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) {
|
} else if (r.peer_info) {
|
||||||
this.handlePeerInfo(r.peer_info);
|
this.handlePeerInfo(r.peer_info);
|
||||||
}
|
}
|
||||||
@ -239,7 +264,7 @@ export default class Connection {
|
|||||||
} else if (msg?.cursor_position) {
|
} else if (msg?.cursor_position) {
|
||||||
globals.pushEvent("cursor_position", msg?.cursor_position);
|
globals.pushEvent("cursor_position", msg?.cursor_position);
|
||||||
} else if (msg?.misc) {
|
} else if (msg?.misc) {
|
||||||
this.handleMisc(msg?.misc);
|
if (!this.handleMisc(msg?.misc)) break;
|
||||||
} else if (msg?.audio_frame) {
|
} else if (msg?.audio_frame) {
|
||||||
globals.playAudio(msg?.audio_frame.data);
|
globals.playAudio(msg?.audio_frame.data);
|
||||||
}
|
}
|
||||||
@ -421,7 +446,10 @@ export default class Connection {
|
|||||||
|
|
||||||
handleMisc(misc: message.Misc) {
|
handleMisc(misc: message.Misc) {
|
||||||
if (misc.audio_format) {
|
if (misc.audio_format) {
|
||||||
globals.initAudio(misc.audio_format.channels, misc.audio_format.sample_rate);
|
globals.initAudio(
|
||||||
|
misc.audio_format.channels,
|
||||||
|
misc.audio_format.sample_rate
|
||||||
|
);
|
||||||
} else if (misc.chat_message) {
|
} else if (misc.chat_message) {
|
||||||
globals.pushEvent("chat", misc.chat_message.text);
|
globals.pushEvent("chat", misc.chat_message.text);
|
||||||
} else if (misc.permission_info) {
|
} else if (misc.permission_info) {
|
||||||
@ -447,7 +475,10 @@ export default class Connection {
|
|||||||
globals.pushEvent("switch_display", misc.switch_display);
|
globals.pushEvent("switch_display", misc.switch_display);
|
||||||
} else if (misc.close_reason) {
|
} else if (misc.close_reason) {
|
||||||
this.msgbox("error", "Connection Error", misc.close_reason);
|
this.msgbox("error", "Connection Error", misc.close_reason);
|
||||||
|
this.close();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRemember(): Boolean {
|
getRemember(): Boolean {
|
||||||
@ -485,16 +516,16 @@ export default class Connection {
|
|||||||
) {
|
) {
|
||||||
const key_event = mapKey(name, globals.isDesktop());
|
const key_event = mapKey(name, globals.isDesktop());
|
||||||
if (!key_event) return;
|
if (!key_event) return;
|
||||||
if (alt && (name == "Alt" || name == 'RAlt')) {
|
if (alt && (name == "Alt" || name == "RAlt")) {
|
||||||
alt = false;
|
alt = false;
|
||||||
}
|
}
|
||||||
if (ctrl && (name == "Control" || name == 'RControl')) {
|
if (ctrl && (name == "Control" || name == "RControl")) {
|
||||||
ctrl = false;
|
ctrl = false;
|
||||||
}
|
}
|
||||||
if (shift && (name == "Shift" || name == 'RShift')) {
|
if (shift && (name == "Shift" || name == "RShift")) {
|
||||||
shift = false;
|
shift = false;
|
||||||
}
|
}
|
||||||
if (command && (name == "Meta" || name == 'RWin')) {
|
if (command && (name == "Meta" || name == "RWin")) {
|
||||||
command = false;
|
command = false;
|
||||||
}
|
}
|
||||||
key_event.down = down;
|
key_event.down = down;
|
||||||
@ -648,14 +679,14 @@ export default class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testDelay() {
|
function testDelay() {
|
||||||
var nearest = '';
|
var nearest = "";
|
||||||
HOSTS.forEach((host) => {
|
HOSTS.forEach((host) => {
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
new Websock(getrUriFromRs(host), true).open().then(() => {
|
new Websock(getrUriFromRs(host), true).open().then(() => {
|
||||||
console.log('latency of ' + host + ': ' + (new Date().getTime() - now));
|
console.log("latency of " + host + ": " + (new Date().getTime() - now));
|
||||||
if (!nearest) {
|
if (!nearest) {
|
||||||
HOST = host;
|
HOST = host;
|
||||||
localStorage.setItem('rendezvous-server', host);
|
localStorage.setItem("rendezvous-server", host);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -28,7 +28,7 @@ export function msgbox(type, title, text) {
|
|||||||
if (!events) return;
|
if (!events) return;
|
||||||
if (!type || (type == 'error' && !text)) return;
|
if (!type || (type == 'error' && !text)) return;
|
||||||
const text2 = text.toLowerCase();
|
const text2 = text.toLowerCase();
|
||||||
var hasRetry = checkIfRetry(type, title, text);
|
var hasRetry = checkIfRetry(type, title, text) ? 'true' : '';
|
||||||
events.push({ name: 'msgbox', type, title, text, hasRetry });
|
events.push({ name: 'msgbox', type, title, text, hasRetry });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,15 +63,10 @@ export function getConn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function startConn(id) {
|
export async function startConn(id) {
|
||||||
try {
|
|
||||||
currentFrame = undefined;
|
currentFrame = undefined;
|
||||||
events = [];
|
events = [];
|
||||||
setByName('remote_id', id);
|
setByName('remote_id', id);
|
||||||
await curConn.start(id);
|
await curConn.start(id);
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
msgbox('error', 'Error', String(e));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function close() {
|
export function close() {
|
||||||
@ -308,6 +303,7 @@ window.init = async () => {
|
|||||||
}
|
}
|
||||||
loadVp9(() => { });
|
loadVp9(() => { });
|
||||||
await initZstd();
|
await initZstd();
|
||||||
|
console.log('init done');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPeers() {
|
export function getPeers() {
|
||||||
|
@ -13,13 +13,8 @@ export default class Websock {
|
|||||||
_secretKey: [Uint8Array, number, number] | undefined;
|
_secretKey: [Uint8Array, number, number] | undefined;
|
||||||
_uri: string;
|
_uri: string;
|
||||||
_isRendezvous: boolean;
|
_isRendezvous: boolean;
|
||||||
_videoCallback: ((v: message.VideoFrame) => void) | undefined;
|
|
||||||
|
|
||||||
constructor(
|
constructor(uri: string, isRendezvous: boolean = true) {
|
||||||
uri: string,
|
|
||||||
isRendezvous: boolean = true,
|
|
||||||
fn: ((v: message.VideoFrame) => void) | undefined = undefined
|
|
||||||
) {
|
|
||||||
this._eventHandlers = {
|
this._eventHandlers = {
|
||||||
message: (_: any) => {},
|
message: (_: any) => {},
|
||||||
open: () => {},
|
open: () => {},
|
||||||
@ -34,7 +29,6 @@ export default class Websock {
|
|||||||
this._websocket.binaryType = "arraybuffer";
|
this._websocket.binaryType = "arraybuffer";
|
||||||
this._latency = new Date().getTime();
|
this._latency = new Date().getTime();
|
||||||
this._isRendezvous = isRendezvous;
|
this._isRendezvous = isRendezvous;
|
||||||
this._videoCallback = fn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
latency(): number {
|
latency(): number {
|
||||||
@ -106,11 +100,13 @@ export default class Websock {
|
|||||||
this._websocket.onclose = (e) => {
|
this._websocket.onclose = (e) => {
|
||||||
if (this._status == "open") {
|
if (this._status == "open") {
|
||||||
// e.code 1000 means that the connection was closed normally.
|
// e.code 1000 means that the connection was closed normally.
|
||||||
reject("Reset by the peer");
|
//
|
||||||
}
|
}
|
||||||
this._status = e;
|
this._status = e;
|
||||||
console.error("WebSock.onclose: " + e);
|
console.error("WebSock.onclose: ");
|
||||||
|
console.error(e);
|
||||||
this._eventHandlers.close(e);
|
this._eventHandlers.close(e);
|
||||||
|
reject("Reset by the peer");
|
||||||
};
|
};
|
||||||
this._websocket.onerror = (e: any) => {
|
this._websocket.onerror = (e: any) => {
|
||||||
if (!this._status) {
|
if (!this._status) {
|
||||||
@ -118,9 +114,9 @@ export default class Websock {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._status = e;
|
this._status = e;
|
||||||
console.error("WebSock.onerror: " + e);
|
console.error("WebSock.onerror: ")
|
||||||
|
console.error(e);
|
||||||
this._eventHandlers.error(e);
|
this._eventHandlers.error(e);
|
||||||
reject(e["data"]);
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -176,16 +172,11 @@ export default class Websock {
|
|||||||
k[2] += 1;
|
k[2] += 1;
|
||||||
bytes = globals.decrypt(bytes, k[2], k[0]);
|
bytes = globals.decrypt(bytes, k[2], k[0]);
|
||||||
}
|
}
|
||||||
if (this._isRendezvous) {
|
this._buf.push(
|
||||||
this._buf.push(this.parseRendezvous(bytes));
|
this._isRendezvous
|
||||||
} else {
|
? this.parseRendezvous(bytes)
|
||||||
const m = this.parseMessage(bytes);
|
: this.parseMessage(bytes)
|
||||||
if (this._videoCallback && m.video_frame) {
|
);
|
||||||
this._videoCallback(m.video_frame);
|
|
||||||
} else {
|
|
||||||
this._buf.push(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this._eventHandlers.message(e.data);
|
this._eventHandlers.message(e.data);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user