more api
This commit is contained in:
parent
6e711c25b9
commit
fad130b29a
@ -2,7 +2,7 @@
|
|||||||
"name": "web_hbb",
|
"name": "web_hbb",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "curl -O https://raw.githubusercontent.com/rgov/js-theora-decoder/main/yuv-canvas-1.2.6.js; vite",
|
"dev": "curl -O https://raw.githubusercontent.com/rgov/js-theora-decoder/main/yuv-canvas-1.2.6.js && vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
@ -6,9 +6,8 @@ import * as sha256 from "fast-sha256";
|
|||||||
import * as globals from "./globals";
|
import * as globals from "./globals";
|
||||||
|
|
||||||
const PORT = 21116;
|
const PORT = 21116;
|
||||||
const HOST = "rs-sg.rustdesk.com";
|
const HOST = 'rs-sg.rustdesk.com';
|
||||||
const licenceKey = "";
|
const SCHEMA = 'ws://';
|
||||||
const SCHEMA = "ws://";
|
|
||||||
|
|
||||||
type MsgboxCallback = (type: string, title: string, text: string) => void;
|
type MsgboxCallback = (type: string, title: string, text: string) => void;
|
||||||
type DrawCallback = (data: Uint8Array) => void;
|
type DrawCallback = (data: Uint8Array) => void;
|
||||||
@ -26,6 +25,7 @@ export default class Connection {
|
|||||||
_videoDecoder: any;
|
_videoDecoder: any;
|
||||||
_audioDecoder: any;
|
_audioDecoder: any;
|
||||||
_password: string | undefined;
|
_password: string | undefined;
|
||||||
|
_options: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._msgbox = globals.msgbox;
|
this._msgbox = globals.msgbox;
|
||||||
@ -35,6 +35,11 @@ export default class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start(id: string) {
|
async start(id: string) {
|
||||||
|
try {
|
||||||
|
this._options = JSON.parse((localStorage.getItem('peers') || '{}'))[id] || {};
|
||||||
|
} catch (e) {
|
||||||
|
this._options = {};
|
||||||
|
}
|
||||||
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]);
|
||||||
@ -61,7 +66,7 @@ export default class Connection {
|
|||||||
const natType = rendezvous.NatType.SYMMETRIC;
|
const natType = rendezvous.NatType.SYMMETRIC;
|
||||||
const punchHoleRequest = rendezvous.PunchHoleRequest.fromPartial({
|
const punchHoleRequest = rendezvous.PunchHoleRequest.fromPartial({
|
||||||
id,
|
id,
|
||||||
licenceKey,
|
licenceKey: localStorage.getItem('key') || undefined,
|
||||||
connType,
|
connType,
|
||||||
natType,
|
natType,
|
||||||
});
|
});
|
||||||
@ -109,7 +114,7 @@ export default class Connection {
|
|||||||
console.log(new Date() + ": Connected to relay server");
|
console.log(new Date() + ": Connected to relay server");
|
||||||
this._ws = ws;
|
this._ws = ws;
|
||||||
const requestRelay = rendezvous.RequestRelay.fromPartial({
|
const requestRelay = rendezvous.RequestRelay.fromPartial({
|
||||||
licenceKey,
|
licenceKey: localStorage.getItem('key') || undefined,
|
||||||
uuid,
|
uuid,
|
||||||
});
|
});
|
||||||
ws.sendRendezvous({ requestRelay });
|
ws.sendRendezvous({ requestRelay });
|
||||||
@ -209,11 +214,11 @@ export default class Connection {
|
|||||||
this.handleVideoFrame(msg?.videoFrame!);
|
this.handleVideoFrame(msg?.videoFrame!);
|
||||||
} else if (msg?.clipboard) {
|
} else if (msg?.clipboard) {
|
||||||
const cb = msg?.clipboard;
|
const cb = msg?.clipboard;
|
||||||
if (cb.compress) cb.content = globals.decompress(cb.content);
|
if (cb.compress) cb.content = globals.decompress(cb.content)!;
|
||||||
globals.pushEvent("clipboard", cb);
|
globals.pushEvent("clipboard", cb);
|
||||||
} else if (msg?.cursorData) {
|
} else if (msg?.cursorData) {
|
||||||
const cd = msg?.cursorData;
|
const cd = msg?.cursorData;
|
||||||
cd.colors = globals.decompress(cd.colors);
|
cd.colors = globals.decompress(cd.colors)!;
|
||||||
globals.pushEvent("cursor_data", cd);
|
globals.pushEvent("cursor_data", cd);
|
||||||
} else if (msg?.cursorId) {
|
} else if (msg?.cursorId) {
|
||||||
globals.pushEvent("cursor_id", { id: msg?.cursorId });
|
globals.pushEvent("cursor_id", { id: msg?.cursorId });
|
||||||
@ -344,6 +349,14 @@ export default class Connection {
|
|||||||
this.msgbox("error", "Connection Error", misc.closeReason);
|
this.msgbox("error", "Connection Error", misc.closeReason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRemember(): any {
|
||||||
|
return this._options['remember'];
|
||||||
|
}
|
||||||
|
|
||||||
|
getOption(name: string): any {
|
||||||
|
return this._options[name];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -354,7 +367,7 @@ async function testDelay() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultUri(isRelay: Boolean = false): string {
|
function getDefaultUri(isRelay: Boolean = false): string {
|
||||||
const host = localStorage.getItem("host");
|
const host = localStorage.getItem("custom-rendezvous-server");
|
||||||
return SCHEMA + (host || HOST) + ":" + (PORT + (isRelay ? 3 : 2));
|
return SCHEMA + (host || HOST) + ":" + (PORT + (isRelay ? 3 : 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
116
src/globals.js
116
src/globals.js
@ -1,14 +1,14 @@
|
|||||||
import Connection from "./connection";
|
import Connection from "./connection";
|
||||||
import _sodium from "libsodium-wrappers";
|
import _sodium from "libsodium-wrappers";
|
||||||
import { ZSTDecoder } from 'zstddec';
|
import * as zstd from 'zstddec';
|
||||||
|
import { CursorData } from "./message";
|
||||||
|
|
||||||
const decompressor = new ZSTDDecoder();
|
const decompressor = new zstd.ZSTDDecoder();
|
||||||
await decompressor.init();
|
|
||||||
|
|
||||||
var currentFrame = undefined;
|
var currentFrame = undefined;
|
||||||
var events = [];
|
var events = [];
|
||||||
|
|
||||||
window.currentConnection = undefined;
|
window.curConn = undefined;
|
||||||
window.getRgba = () => currentFrame;
|
window.getRgba = () => currentFrame;
|
||||||
window.getLanguage = () => navigator.language;
|
window.getLanguage = () => navigator.language;
|
||||||
|
|
||||||
@ -36,11 +36,11 @@ export function draw(frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setConn(conn) {
|
export function setConn(conn) {
|
||||||
window.currentConnection = conn;
|
window.curConn = conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConn() {
|
export function getConn() {
|
||||||
return window.currentConnection;
|
return window.curConn;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function close() {
|
export function close() {
|
||||||
@ -50,7 +50,7 @@ export function close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function newConn() {
|
export function newConn() {
|
||||||
window.currentConnection?.close();
|
window.curConn?.close();
|
||||||
const conn = new Connection();
|
const conn = new Connection();
|
||||||
setConn(conn);
|
setConn(conn);
|
||||||
return conn;
|
return conn;
|
||||||
@ -126,38 +126,130 @@ export function decompress(compressedArray) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.setByName = (name, value) => {
|
window.setByName = (name, value) => {
|
||||||
|
try {
|
||||||
|
value = JSON.parse(value);
|
||||||
|
} catch (e) {}
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'connect':
|
case 'connect':
|
||||||
newConn();
|
newConn();
|
||||||
|
curConn.start(value);
|
||||||
break;
|
break;
|
||||||
case 'login':
|
case 'login':
|
||||||
currentConnection.login(value.password, value.remember);
|
curConn.login(value.password, value.remember || false);
|
||||||
break;
|
break;
|
||||||
case 'close':
|
case 'close':
|
||||||
close();
|
close();
|
||||||
break;
|
break;
|
||||||
case 'refresh':
|
case 'refresh':
|
||||||
currentConnection.refresh();
|
curConn.refresh();
|
||||||
break;
|
break;
|
||||||
case 'reconnect':
|
case 'reconnect':
|
||||||
currentConnection.reconnect();
|
curConn.reconnect();
|
||||||
|
break;
|
||||||
|
case 'toggle_option':
|
||||||
|
curConn.toggleOption(value);
|
||||||
|
break;
|
||||||
|
case 'image_quality':
|
||||||
|
curConn.setImageQuality(value);
|
||||||
|
break;
|
||||||
|
case 'lock_screen':
|
||||||
|
curConn.lockScreen();
|
||||||
|
break;
|
||||||
|
case 'ctrl_alt_del':
|
||||||
|
curConn.ctrlAltDe();
|
||||||
|
break;
|
||||||
|
case 'switch_display':
|
||||||
|
curConn.switchDisplay(value);
|
||||||
|
break;
|
||||||
|
case 'remove':
|
||||||
|
const peers = JSON.parse(localStorage.getItem('peers') || '{}');
|
||||||
|
delete peers[value];
|
||||||
|
localStorage.setItem('peers', JSON.stringify(peers));
|
||||||
|
break;
|
||||||
|
case 'input_key':
|
||||||
|
curConn.inputKey(value.name, value.alt || false, value.ctrl || false, value.shift || false, value.command || false);
|
||||||
|
break;
|
||||||
|
case 'input_string':
|
||||||
|
curConn.inputString(value);
|
||||||
|
break;
|
||||||
|
case 'send_mouse':
|
||||||
|
let mask = 0;
|
||||||
|
switch (value.type) {
|
||||||
|
case 'down':
|
||||||
|
mask = 1;
|
||||||
|
break;
|
||||||
|
case 'up':
|
||||||
|
mask = 2;
|
||||||
|
break;
|
||||||
|
case 'wheel':
|
||||||
|
mask = 3;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (value.buttons) {
|
||||||
|
case 'left':
|
||||||
|
mask |= 1 << 3;
|
||||||
|
break;
|
||||||
|
case 'right':
|
||||||
|
mask |= 2 << 3;
|
||||||
|
break;
|
||||||
|
case 'wheel':
|
||||||
|
mask |= 4 << 3;
|
||||||
|
}
|
||||||
|
curConn.inputMouse(mask, value.x || 0, value.y || 0, value.alt || false, value.ctrl || false, value.shift || false, value.command || false);
|
||||||
|
break;
|
||||||
|
case 'option':
|
||||||
|
localStorage.setItem(value.name, value.value);
|
||||||
|
break;
|
||||||
|
case 'peer_option':
|
||||||
|
curConn.setPeerOption(value.name, value.value);
|
||||||
|
break;
|
||||||
|
case 'input_os_password':
|
||||||
|
curConn.inputOsPassword(value, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.getByName = (name, value) => {
|
window.getByName = (name, arg) => {
|
||||||
|
try {
|
||||||
|
arg = JSON.parse(arg);
|
||||||
|
} catch (e) {}
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'peers':
|
case 'peers':
|
||||||
return localStorage.getItem('peers');
|
return localStorage.getItem('peers');
|
||||||
break;
|
break;
|
||||||
|
case 'remote_id':
|
||||||
|
return localStorage.getItem('remote-id') || '';
|
||||||
|
break;
|
||||||
|
case 'remember':
|
||||||
|
return curConn.getRemember();
|
||||||
|
break;
|
||||||
case 'event':
|
case 'event':
|
||||||
if (events.length) {
|
if (events.length) {
|
||||||
const e = events[0];
|
const e = events[0];
|
||||||
events.splice(0, 1);
|
events.splice(0, 1);
|
||||||
return e;
|
return JSON.stringify(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'toggle_option':
|
||||||
|
return curConn.getOption(arg);
|
||||||
|
break;
|
||||||
|
case 'option':
|
||||||
|
return localStorage.getItem(arg);
|
||||||
|
break;
|
||||||
|
case 'image_quality':
|
||||||
|
return curConn.getImageQuality();
|
||||||
|
break;
|
||||||
|
case 'translate':
|
||||||
|
return arg.text;
|
||||||
|
break;
|
||||||
|
case 'peer_option':
|
||||||
|
return curConn.getOption(arg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.init = () => {
|
||||||
|
decompressor.init();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user