feat: add vnc app

This commit is contained in:
2024-03-18 02:33:04 +07:00
parent d1ecd6d00b
commit d3b89113ae
15 changed files with 187 additions and 31 deletions
+50
View File
@@ -0,0 +1,50 @@
import type { WebSocket } from "ws";
import net from "node:net";
// const log = console.log;
const log = (..._args: any[]) => null;
export const websockify = (
client: WebSocket,
targetHost: string,
targetPort: number
) => {
const target = net.createConnection(targetPort, targetHost, function () {
log("connected to target");
});
target.on("data", function (data) {
try {
client.send(data);
} catch (e) {
log("Client closed, cleaning up target");
target.end();
}
});
target.on("end", function () {
log("target disconnected");
client.close();
});
target.on("error", function () {
log("target connection error");
target.end();
client.close();
});
client.on("message", function (msg) {
// log("CLIENT message: " + msg);
target.write(msg as never);
});
client.on("close", function (code, reason) {
log("WebSocket client disconnected: " + code + " [" + reason + "]");
target.end();
});
client.on("error", function (a) {
log("WebSocket client error: " + a);
target.end();
});
};