discord remote | discord remote proxy server | remote desktop client | Search

This Node.js module exports four functions for a remote desktop client: getMonitor, doClick, doKeys, and serveHomepage, which handle screenshot retrieval, mouse and keyboard interactions, and client homepage serving. The module uses various imported functions and scripts to interact with the remote desktop and Discord authentication, and returns responses in formats such as PNG images, empty responses, and modified HTML code.

Run example

npm run import -- "express automation routes"

express automation routes

const {DEFAULT_APPLICATION} = importer.import("discord configuration")
const screenshotMonitor = importer.import("node screenshots")
const mouseMove = importer.import("mouse move")
const mouseClick = importer.import("mouse click")
const sendKeys = importer.import("send keys")

async function getMonitor(req, res, next) {
  let index = parseInt(req.path.replace(/^\/|\/$/gi, '').split('/')[1])
  if(Number.isNaN(index)) {
    index = 0
  }
  let screenshot = await screenshotMonitor(index)
  if(!screenshot) {
    return next()
  }
  res.setHeader('Content-Type', 'image/png')
  res.setHeader('Cache-Control', 'public, max-age=3');
  return res.send(screenshot)
}


let lastClick = 0
let lastX
let lastY
async function doClick(req, res, next) {
  if(!req.authenticated) {
    return res.status(403).send('Forbidden')
  }
  if(Date.now() - lastClick < 2000) {
    await mouseClick(lastX, lastY)
  } else {
    await mouseMove(req.body.x, req.body.y)
  }
  lastClick = Date.now()
  lastX = req.body.x
  lastY = req.body.y
  return res.send('')
}

async function doKeys(req, res, next) {
  if(!req.authenticated) {
    return res.status(403).send('Forbidden')
  }
  sendKeys(req.body.text, req.body.special)
  return res.send('')
}

function serveHomepage(baseURI, req, res, next) {
  if(req.path.length <= 1) {
    let htmlCode = importer.interpret('remote desktop client').code
    htmlCode = htmlCode.replaceAll('{BASE_URI}', baseURI)
    htmlCode = htmlCode.replace('<head>', `<head>
      <script type="text/javascript">
      ${importer.interpret('discord client auth code').code
        .replaceAll('{CLIENT_ID}', DEFAULT_APPLICATION)
        .replaceAll('{BASE_URI}', baseURI)}
      </script>
      <script type="text/javascript">
      ${importer.interpret('client input remote code').code
        .replaceAll('{CLIENT_ID}', DEFAULT_APPLICATION)
        .replaceAll('{BASE_URI}', baseURI)}
      </script>`)
    return res.send(htmlCode)
  }
  return next()
}

module.exports = {
  doKeys,
  doClick,
  getMonitor,
  serveHomepage,
}

What the code could have been:

const { DEFAULT_APPLICATION } = require('./discord-configuration');
const { screenshotMonitor, nodeScreenshots } = require('./node-screenshots');
const { mouseMove, mouseClick } = require('./mouse-move');
const { sendKeys } = require('./send-keys');
const { interpret } = require('./importer');

// Extract constants for better readability and maintainability
const MONITOR_DEFAULT_INDEX = 0;

// Refactor function names for clarity
async function getScreenShot(req, res, next) {
  const index = getMonitorIndex(req.path);
  const screenshot = await screenshotMonitor(index);
  if (!screenshot) return next();
  res.setHeader('Content-Type', 'image/png');
  res.setHeader('Cache-Control', 'public, max-age=3');
  return res.send(screenshot);
}

// Improve performance by caching mouse positions
let lastClick = 0;
let lastX;
let lastY = [0, 0];

// Refactor function names for clarity
async function performClick(req, res, next) {
  if (!req.authenticated) {
    return res.status(403).send('Forbidden');
  }
  if (Date.now() - lastClick < 2000) {
    await mouseClick(lastX, lastY);
  } else {
    await mouseMove(req.body.x, req.body.y);
  }
  lastClick = Date.now();
  lastX = req.body.x;
  lastY = [req.body.x, req.body.y];
  return res.send('');
}

// Refactor function names for clarity
async function sendInput(req, res, next) {
  if (!req.authenticated) {
    return res.status(403).send('Forbidden');
  }
  sendKeys(req.body.text, req.body.special);
  return res.send('');
}

// Refactor function names for clarity
function serveIndexPage(baseURI, req, res, next) {
  if (req.path.length <= 1) {
    const htmlCode = interpret('remote-desktop-client').code;
    htmlCode = htmlCode.replaceAll('{BASE_URI}', baseURI);
    htmlCode = htmlCode.replace('', `
      
      `);
    return res.send(htmlCode);
  }
  return next();
}

// Simplify exports
module.exports = {
  performClick,
  sendInput,
  getScreenShot,
  serveIndexPage,
};

// Helper function to get monitor index from URL path
function getMonitorIndex(path) {
  const index = parseInt(path.replace(/^\/|\/$/gi, '').split('/')[1]);
  return isNaN(index)? MONITOR_DEFAULT_INDEX : index;
}

Overview

The code is a Node.js module that exports four functions related to a remote desktop client. The functions are:

  1. getMonitor(req, res, next): Returns a screenshot of a monitor at a specified index.
  2. doClick(req, res, next): Simulates a click at a specified location on the screen.
  3. doKeys(req, res, next): Sends keystrokes to the remote desktop.
  4. serveHomepage(baseURI, req, res, next): Serves the homepage of the remote desktop client, which includes a Discord authentication script and a client input script.

Functions

getMonitor(req, res, next)

doClick(req, res, next)

doKeys(req, res, next)

serveHomepage(baseURI, req, res, next)

Imports

The code imports the following modules: