This commit is contained in:
2024-11-12 14:34:17 +05:00
parent 312082d94c
commit 1cf520814e
8 changed files with 205 additions and 20 deletions
+60
View File
@@ -8,6 +8,9 @@ import { exec, execFile } from "child_process";
import treeKill from "tree-kill";
import SessionServer from "./models/SessionServer";
import ActiveSession from "./models/ActiveSession";
import { schedule } from "node-cron";
import sendMessageRoute from "./routes/sendMessage";
import ServerStatusLog from "./models/ServerStatusLog";
connectDB();
@@ -17,6 +20,8 @@ const port = process.env.PORT;
app.use(json());
app.use(cors());
app.use("/sendMessage", sendMessageRoute);
const serverLocation = process.env.SERVER_LOCATION;
const serverName = process.env.SERVER_NAME;
const serverType = process.env.SERVER_TYPE;
@@ -182,6 +187,11 @@ async function endSession(activeSessionId: string) {
async function init() {
try {
await ServerStatusLog.create({
hostname: serverHostname,
action: "online",
});
await SessionServer.findOneAndUpdate(
{ hostname: serverHostname },
{
@@ -236,3 +246,53 @@ app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
init();
});
schedule("*/3 * * * * *", async () => {
// TODO - hostname
try {
const activeSessions = await ActiveSession.find({
location: serverLocation,
name: serverName,
});
for (const activeSession of activeSessions) {
const { ueProcessId, buildName, uePort, id } = activeSession;
const { stdout } = await execAsync(
`wmic process where processId=${ueProcessId}`,
{ windowsHide: true }
);
const ueProcessInfo = stdout.trim();
if (ueProcessInfo) return;
const filePath = `C:/pixel-streaming/builds/${buildName}/${buildName}.exe`;
const newUeProcess = execFile(filePath, [
"-PixelStreamingIP=127.0.0.1",
`-PixelStreamingPort=${uePort}`,
"-RenderOffScreen",
"-ForceRes",
"-ResX=1920",
"-ResY=1080",
"-Unattended",
"-PixelStreamingWebRTCMinBitrate=5000000",
"-PixelStreamingWebRTCMaxBitrate=20000000",
"-PixelStreamingH264Profile=HIGH",
"-PixelStreamingWebRTCDisableReceiveAudio=true",
"-PixelStreamingEncoderRateControl=VBR",
// "-PixelStreamingHudStats=true",
// `-SessionID=${session.id}`,
]);
const newUeProcesscessId = newUeProcess.pid;
await ActiveSession.findByIdAndUpdate(id, {
ueProcessId: newUeProcesscessId,
});
}
} catch (error) {
console.log(error);
}
});
+23
View File
@@ -0,0 +1,23 @@
import { model, Schema } from "mongoose";
const serverStatusLogSchema = new Schema(
{
hostname: {
type: String,
required: true,
},
action: {
type: String,
required: true,
},
},
{
timestamps: true,
toJSON: { virtuals: true },
toObject: { virtuals: true },
}
);
const ServerStatusLog = model("ServerStatusLog", serverStatusLogSchema);
export default ServerStatusLog;
+41
View File
@@ -0,0 +1,41 @@
import { Router } from "express";
import { createTransport } from "nodemailer";
import fs from "fs";
const router = Router();
router.post("/", async (req, res) => {
console.log(req.body);
try {
const transporter = createTransport({
host: req.body.host,
port: req.body.port,
secure: true, // true for 465, false for other ports
auth: {
user: req.body.from, // generated ethereal user
pass: req.body.password, // generated ethereal password
},
});
const files = fs.readdirSync(req.body.path);
// send mail with defined transport object
await transporter.sendMail({
from: req.body.from, // sender address
to: req.body.to, // list of receivers
subject: req.body.subject, // Subject line
html: req.body.text, // html body
attachments: files.map((file) => ({ path: `${req.body.path}/${file}` })), // attachment files
});
return res.json({ ok: 1 });
} catch (error) {
console.log(error);
return res.json({ error: 1 });
}
});
const sendMessageRoute = router;
export default sendMessageRoute;
-11
View File
@@ -1,11 +0,0 @@
import { Router } from "express";
const router = Router();
router.get("/", async (_req, res) => {
res.json({ ok: 1 });
});
const testRouter = router;
export default testRouter;