upd
This commit is contained in:
Vendored
-16
@@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const mongoose_1 = require("mongoose");
|
||||
async function connectDB() {
|
||||
try {
|
||||
await (0, mongoose_1.connect)(process.env.MONGO_URI, { dbName: "pixel_streaming2" });
|
||||
console.log("MongoDB connected...");
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
exports.default = connectDB;
|
||||
Vendored
-260
@@ -1,260 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv/config");
|
||||
const db_1 = __importDefault(require("./config/db"));
|
||||
const express_1 = __importStar(require("express"));
|
||||
const cors_1 = __importDefault(require("cors"));
|
||||
const os_1 = __importStar(require("os"));
|
||||
const util_1 = __importDefault(require("util"));
|
||||
const child_process_1 = require("child_process");
|
||||
const tree_kill_1 = __importDefault(require("tree-kill"));
|
||||
const SessionServer_1 = __importDefault(require("./models/SessionServer"));
|
||||
const ActiveSession_1 = __importDefault(require("./models/ActiveSession"));
|
||||
const node_cron_1 = require("node-cron");
|
||||
const sendMessage_1 = __importDefault(require("./routes/sendMessage"));
|
||||
const ServerStatusLog_1 = __importDefault(require("./models/ServerStatusLog"));
|
||||
(0, db_1.default)();
|
||||
const app = (0, express_1.default)();
|
||||
const port = process.env.PORT;
|
||||
app.use((0, express_1.json)());
|
||||
app.use((0, cors_1.default)());
|
||||
app.use("/sendMessage", sendMessage_1.default);
|
||||
const serverLocation = process.env.SERVER_LOCATION;
|
||||
const serverName = process.env.SERVER_NAME;
|
||||
const serverType = process.env.SERVER_TYPE;
|
||||
const serverHostname = os_1.default.hostname();
|
||||
const nets = (0, os_1.networkInterfaces)();
|
||||
const localIP = Object.entries(nets)
|
||||
.find((net) => net[0] === "Ethernet")?.[1]
|
||||
?.find((obj) => obj.family === "IPv4")?.address;
|
||||
async function updateSessionServerData(data) {
|
||||
try {
|
||||
await SessionServer_1.default.findOneAndUpdate({ hostname: serverHostname }, data);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log("Error: ", error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
const execAsync = util_1.default.promisify(child_process_1.exec);
|
||||
async function getGpuMemoryFree() {
|
||||
try {
|
||||
const { stdout } = await execAsync("nvidia-smi --query-gpu=memory.free --format=csv,noheader,nounits", { windowsHide: true });
|
||||
const gpuMemoryFree = stdout.trimEnd();
|
||||
await updateSessionServerData({ gpuMemoryFree });
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log("Error: ", error.message);
|
||||
}
|
||||
}
|
||||
setTimeout(async () => {
|
||||
await getGpuMemoryFree();
|
||||
}, 1000);
|
||||
}
|
||||
async function getAvailablePorts() {
|
||||
const cirrusPorts = [14000, 14001, 14002];
|
||||
for (const cirrusPort of cirrusPorts) {
|
||||
const activeSession = await ActiveSession_1.default.exists({
|
||||
location: serverLocation,
|
||||
name: serverName,
|
||||
cirrusPort,
|
||||
});
|
||||
if (activeSession)
|
||||
continue;
|
||||
const uePort = cirrusPort + 10;
|
||||
return { cirrusPort, uePort };
|
||||
}
|
||||
}
|
||||
async function startSession(buildName, ownerIp, endAt) {
|
||||
const filePath = `C:/pixel-streaming/builds/${buildName}/${buildName}.exe`;
|
||||
const availablePorts = await getAvailablePorts();
|
||||
if (!availablePorts) {
|
||||
console.log("No available ports");
|
||||
return;
|
||||
}
|
||||
const { cirrusPort, uePort } = availablePorts;
|
||||
const cirrusProcess = (0, child_process_1.execFile)("node", [
|
||||
`C:/pixel-streaming/signalling-server/cirrus.js`,
|
||||
`--StreamerPort`,
|
||||
`${uePort}`,
|
||||
`--HttpPort`,
|
||||
`${cirrusPort}`,
|
||||
]);
|
||||
const cirrusProcessId = cirrusProcess.pid;
|
||||
if (!cirrusProcessId) {
|
||||
console.log("Cirrus server was not started");
|
||||
return;
|
||||
}
|
||||
const ueProcess = (0, child_process_1.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 ueProcessId = ueProcess.pid;
|
||||
if (!ueProcessId) {
|
||||
console.log("UE application was not started");
|
||||
return;
|
||||
}
|
||||
const type = serverType;
|
||||
try {
|
||||
const activeSession = await ActiveSession_1.default.create({
|
||||
location: serverLocation,
|
||||
name: serverName,
|
||||
buildName,
|
||||
type,
|
||||
cirrusPort,
|
||||
uePort,
|
||||
cirrusProcessId,
|
||||
ueProcessId,
|
||||
ownerIp,
|
||||
endAt,
|
||||
localIP,
|
||||
});
|
||||
return activeSession;
|
||||
}
|
||||
catch (error) {
|
||||
(0, tree_kill_1.default)(cirrusProcessId);
|
||||
(0, tree_kill_1.default)(ueProcessId);
|
||||
console.log(error.message);
|
||||
}
|
||||
}
|
||||
async function endSession(activeSessionId) {
|
||||
try {
|
||||
const activeSession = await ActiveSession_1.default.findByIdAndDelete(activeSessionId);
|
||||
if (!activeSession) {
|
||||
console.log("Session with this ID not found");
|
||||
return;
|
||||
}
|
||||
(0, tree_kill_1.default)(activeSession.cirrusProcessId);
|
||||
(0, tree_kill_1.default)(activeSession.ueProcessId);
|
||||
console.log("Kill session");
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
}
|
||||
async function init() {
|
||||
try {
|
||||
await ServerStatusLog_1.default.create({
|
||||
hostname: serverHostname,
|
||||
action: "online",
|
||||
});
|
||||
await SessionServer_1.default.findOneAndUpdate({ hostname: serverHostname }, {
|
||||
location: serverLocation,
|
||||
name: serverName,
|
||||
type: serverType,
|
||||
hostname: serverHostname,
|
||||
localIP,
|
||||
}, { upsert: true, new: true });
|
||||
getGpuMemoryFree();
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log("Error: ", error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
app.post("/start", async (req, res) => {
|
||||
for (const [key, value] of Object.entries(req.body)) {
|
||||
if (value === "null")
|
||||
req.body[key] = undefined;
|
||||
}
|
||||
const { buildName, ownerIp, endAt } = req.body;
|
||||
console.log("req.body", req.body);
|
||||
if (!buildName || !ownerIp) {
|
||||
return res.json({ error: 1 });
|
||||
}
|
||||
const activeSession = await startSession(buildName, ownerIp, endAt);
|
||||
res.json(activeSession);
|
||||
});
|
||||
app.post("/end", async (req, res) => {
|
||||
const activeSessionId = req.body.activeSessionId;
|
||||
if (!activeSessionId) {
|
||||
return res.json({ error: 1 });
|
||||
}
|
||||
await endSession(activeSessionId);
|
||||
res.json({ ok: 1 });
|
||||
});
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is listening on port ${port}`);
|
||||
init();
|
||||
});
|
||||
(0, node_cron_1.schedule)("*/3 * * * * *", async () => {
|
||||
// TODO - hostname
|
||||
try {
|
||||
const activeSessions = await ActiveSession_1.default.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 = (0, child_process_1.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_1.default.findByIdAndUpdate(id, {
|
||||
ueProcessId: newUeProcesscessId,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
Vendored
-44
@@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const mongoose_1 = require("mongoose");
|
||||
const activeSessionSchema = new mongoose_1.Schema({
|
||||
location: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
buildName: {
|
||||
type: String,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
},
|
||||
uePort: {
|
||||
type: Number,
|
||||
},
|
||||
cirrusPort: {
|
||||
type: Number,
|
||||
},
|
||||
ueProcessId: {
|
||||
type: Number,
|
||||
},
|
||||
cirrusProcessId: {
|
||||
type: Number,
|
||||
},
|
||||
ownerIp: {
|
||||
type: String,
|
||||
},
|
||||
endAt: {
|
||||
type: Date || null,
|
||||
},
|
||||
localIP: {
|
||||
type: String,
|
||||
},
|
||||
}, {
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
});
|
||||
const ActiveSession = (0, mongoose_1.model)("Active_Session", activeSessionSchema);
|
||||
exports.default = ActiveSession;
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const mongoose_1 = require("mongoose");
|
||||
const sessionServerSchema = new mongoose_1.Schema({
|
||||
location: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
},
|
||||
hostname: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
gpuMemoryFree: {
|
||||
type: Number,
|
||||
},
|
||||
localIP: {
|
||||
type: String,
|
||||
},
|
||||
}, {
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
});
|
||||
const SessionServer = (0, mongoose_1.model)("Session_Server", sessionServerSchema);
|
||||
exports.default = SessionServer;
|
||||
Vendored
-9
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = require("express");
|
||||
const router = (0, express_1.Router)();
|
||||
router.get("/", async (_req, res) => {
|
||||
res.json({ ok: 1 });
|
||||
});
|
||||
const testRouter = router;
|
||||
exports.default = testRouter;
|
||||
+1
-1
@@ -30,7 +30,7 @@ const serverHostname = os.hostname();
|
||||
const nets = networkInterfaces();
|
||||
|
||||
const localIP = Object.entries(nets)
|
||||
.find((net) => net[0] === "Ethernet")?.[1]
|
||||
.find((net) => net[0].includes("Ethernet"))?.[1]
|
||||
?.find((obj) => obj.family === "IPv4")?.address;
|
||||
|
||||
async function updateSessionServerData(data: any) {
|
||||
|
||||
Reference in New Issue
Block a user