Merge pull request 'Update src/server.mjs' (#8) from ztimson-patch-8 into master

Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
2026-09-14 16:27:49 -04:00
+2 -25
View File
@@ -67,36 +67,13 @@ wss.on('connection', ws => {
const socket = net.createConnection(VNC_PORT, VNC_HOST); const socket = net.createConnection(VNC_PORT, VNC_HOST);
socket.on('connect', () => {
console.log(`Connected to VNC ${VNC_HOST}:${VNC_PORT}`);
});
socket.on('data', data => { socket.on('data', data => {
console.log(`VNC -> browser: ${data.length} bytes`); if (ws.readyState === ws.OPEN) ws.send(data, {binary: true});
if (data.length <= 64) {
console.log(` hex: ${data.toString('hex')}`);
console.log(` text: ${JSON.stringify(data.toString())}`);
}
if (ws.readyState === ws.OPEN) {
ws.send(data, {binary: true});
}
}); });
ws.on('message', (data, isBinary) => { ws.on('message', (data, isBinary) => {
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data); const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data);
if (socket.writable) socket.write(buffer);
console.log(`Browser -> VNC: ${buffer.length} bytes (${isBinary ? 'binary' : 'text'})`);
if (buffer.length <= 64) {
console.log(` hex: ${buffer.toString('hex')}`);
console.log(` text: ${JSON.stringify(buffer.toString())}`);
}
if (socket.writable) {
socket.write(buffer);
}
}); });
ws.on('error', error => { ws.on('error', error => {