refactor
This commit is contained in:
parent
50c8650c63
commit
63242a4f3a
@ -3,14 +3,12 @@ import * as message from "./message.js";
|
|||||||
import * as rendezvous from "./rendezvous.js";
|
import * as rendezvous from "./rendezvous.js";
|
||||||
import { loadVp9, loadOpus } from "./codec";
|
import { loadVp9, loadOpus } from "./codec";
|
||||||
|
|
||||||
const URI = "ws://207.148.17.15";
|
const PORT = 21116;
|
||||||
const PORT = 21118;
|
const HOST = "rs-sg.rustdesk.com";
|
||||||
const licenceKey = "";
|
const licenceKey = "";
|
||||||
|
const SCHEMA = "ws://";
|
||||||
|
|
||||||
loadVp9();
|
export default class Connection {
|
||||||
loadOpus();
|
|
||||||
|
|
||||||
export default class Client {
|
|
||||||
_msgs: any[];
|
_msgs: any[];
|
||||||
_ws: Websock | undefined;
|
_ws: Websock | undefined;
|
||||||
_interval: any;
|
_interval: any;
|
||||||
@ -18,7 +16,7 @@ export default class Client {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._msgs = [];
|
this._msgs = [];
|
||||||
this._id = '';
|
this._id = "";
|
||||||
this._interval = setInterval(() => {
|
this._interval = setInterval(() => {
|
||||||
while (this._msgs.length) {
|
while (this._msgs.length) {
|
||||||
this._ws?.sendMessage(this._msgs[0]);
|
this._ws?.sendMessage(this._msgs[0]);
|
||||||
@ -32,8 +30,8 @@ export default class Client {
|
|||||||
this._ws?.close();
|
this._ws?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect(id: string) {
|
async start(id: string) {
|
||||||
const ws = new Websock(URI + ":" + PORT);
|
const ws = new Websock(getDefaultUri());
|
||||||
this._ws = ws;
|
this._ws = ws;
|
||||||
this._id = id;
|
this._id = id;
|
||||||
await ws.open();
|
await ws.open();
|
||||||
@ -65,17 +63,15 @@ export default class Client {
|
|||||||
async connectRelay(rr: rendezvous.RelayResponse) {
|
async connectRelay(rr: rendezvous.RelayResponse) {
|
||||||
const pk = rr.pk;
|
const pk = rr.pk;
|
||||||
let uri = rr.relayServer;
|
let uri = rr.relayServer;
|
||||||
if (uri.indexOf(':') > 0) {
|
if (uri) {
|
||||||
const tmp = uri.split(':');
|
uri = getrUriFromRs(uri);
|
||||||
const port = parseInt(tmp[1]);
|
|
||||||
uri = tmp[0] + ':' + (port + 2);
|
|
||||||
} else {
|
} else {
|
||||||
uri += ':' + (PORT + 1);
|
uri = getDefaultUri(true);
|
||||||
}
|
}
|
||||||
const uuid = rr.uuid;
|
const uuid = rr.uuid;
|
||||||
const ws = new Websock('ws://' + uri);
|
const ws = new Websock(uri);
|
||||||
await ws.open();
|
await ws.open();
|
||||||
console.log('Connected to relay server')
|
console.log("Connected to relay server");
|
||||||
this._ws = ws;
|
this._ws = ws;
|
||||||
const requestRelay = rendezvous.RequestRelay.fromJSON({
|
const requestRelay = rendezvous.RequestRelay.fromJSON({
|
||||||
licenceKey,
|
licenceKey,
|
||||||
@ -91,10 +87,23 @@ export default class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function testDelay() {
|
async function testDelay() {
|
||||||
const ws = new Websock(URI + ":" + PORT);
|
const ws = new Websock(getDefaultUri(false));
|
||||||
await ws.open();
|
await ws.open();
|
||||||
console.log(ws.latency());
|
console.log(ws.latency());
|
||||||
}
|
}
|
||||||
|
|
||||||
testDelay();
|
function getDefaultUri(isRelay: Boolean = false): string {
|
||||||
new Client().connect("124931507");
|
const host = localStorage.getItem("host");
|
||||||
|
return SCHEMA + (host || HOST) + ":" + (PORT + (isRelay ? 3 : 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getrUriFromRs(uri: string): string {
|
||||||
|
if (uri.indexOf(":") > 0) {
|
||||||
|
const tmp = uri.split(":");
|
||||||
|
const port = parseInt(tmp[1]);
|
||||||
|
uri = tmp[0] + ":" + (port + 2);
|
||||||
|
} else {
|
||||||
|
uri += ":" + (PORT + 3);
|
||||||
|
}
|
||||||
|
return uri;
|
||||||
|
}
|
9
src/globals.js
Normal file
9
src/globals.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
window.currentConnection = undefined;
|
||||||
|
|
||||||
|
export function setConn(conn) {
|
||||||
|
window.currentConnection = conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getConn() {
|
||||||
|
return windows.currentConnection;
|
||||||
|
}
|
@ -1,3 +1,2 @@
|
|||||||
import "./style.css";
|
import "./globals";
|
||||||
import "./client";
|
|
||||||
import "./ui";
|
import "./ui";
|
@ -1,9 +1,13 @@
|
|||||||
|
import "./style.css";
|
||||||
|
import "./connection";
|
||||||
|
|
||||||
const app = document.querySelector("#app");
|
const app = document.querySelector("#app");
|
||||||
|
|
||||||
if (app) {
|
if (app) {
|
||||||
app.innerHTML = `
|
app.innerHTML = `
|
||||||
<div id="connect" style="text-align: center"><table style="display: inline-block">
|
<div id="connect" style="text-align: center"><table style="display: inline-block">
|
||||||
<tr><td><span>Host: </span></td><td><input id="host" /></td></tr>
|
<tr><td><span>Host: </span></td><td><input id="host" /></td></tr>
|
||||||
|
<tr><td><span>Key: </span></td><td><input id="key" /></td></tr>
|
||||||
<tr><td><span>Id: </span></td><td><input id="id" /></td></tr>
|
<tr><td><span>Id: </span></td><td><input id="id" /></td></tr>
|
||||||
<tr><td></td><td><button onclick="connect();">Connect</button></td></tr>
|
<tr><td></td><td><button onclick="connect();">Connect</button></td></tr>
|
||||||
</table></div>
|
</table></div>
|
||||||
@ -19,6 +23,8 @@ if (app) {
|
|||||||
host.value = localStorage.getItem('host');
|
host.value = localStorage.getItem('host');
|
||||||
const id = document.querySelector('#id');
|
const id = document.querySelector('#id');
|
||||||
id.value = localStorage.getItem('id');
|
id.value = localStorage.getItem('id');
|
||||||
|
const key = document.querySelector('#key');
|
||||||
|
key.value = localStorage.getItem('key');
|
||||||
};
|
};
|
||||||
|
|
||||||
window.connect = () => {
|
window.connect = () => {
|
||||||
@ -26,6 +32,8 @@ if (app) {
|
|||||||
localStorage.setItem('host', host.value);
|
localStorage.setItem('host', host.value);
|
||||||
const id = document.querySelector('#id');
|
const id = document.querySelector('#id');
|
||||||
localStorage.setItem('id', id.value);
|
localStorage.setItem('id', id.value);
|
||||||
|
const key = document.querySelector('#key');
|
||||||
|
localStorage.setItem('key', key.value);
|
||||||
document.querySelector('div#connect').style.display = 'none';
|
document.querySelector('div#connect').style.display = 'none';
|
||||||
document.querySelector('div#password').style.display = 'block';
|
document.querySelector('div#password').style.display = 'block';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user