first commit
This commit is contained in:
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
"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
+189
@@ -0,0 +1,189 @@
|
||||
"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 = __importDefault(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"));
|
||||
(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)());
|
||||
const serverLocation = process.env.SERVER_LOCATION;
|
||||
const serverName = process.env.SERVER_NAME;
|
||||
const serverType = process.env.SERVER_TYPE;
|
||||
const serverHostname = os_1.default.hostname();
|
||||
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) {
|
||||
console.log(cirrusPort);
|
||||
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) {
|
||||
const filePath = `C:/PixelStreaming/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:/PixelStreaming/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 activeSession = await ActiveSession_1.default.create({
|
||||
location: serverLocation,
|
||||
name: serverName,
|
||||
buildName,
|
||||
cirrusPort,
|
||||
uePort,
|
||||
cirrusProcessId,
|
||||
ueProcessId,
|
||||
});
|
||||
const activeSessionId = activeSession.id;
|
||||
return activeSessionId;
|
||||
}
|
||||
async function endSession(activeSessionId) {
|
||||
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");
|
||||
}
|
||||
async function init() {
|
||||
try {
|
||||
await SessionServer_1.default.findOneAndUpdate({ hostname: serverHostname }, {
|
||||
location: serverLocation,
|
||||
name: serverName,
|
||||
type: serverType,
|
||||
hostname: serverHostname,
|
||||
}, { upsert: true, new: true });
|
||||
getGpuMemoryFree();
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log("Error: ", error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
app.post("/start", async (req, res) => {
|
||||
console.log(req.query);
|
||||
const buildName = req.body.buildName;
|
||||
if (!buildName) {
|
||||
return res.json({ error: 1 });
|
||||
}
|
||||
const result = await startSession(buildName);
|
||||
console.log("Result: ", result);
|
||||
res.json({ ok: 1 });
|
||||
});
|
||||
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();
|
||||
});
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
"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,
|
||||
},
|
||||
uePort: {
|
||||
type: Number,
|
||||
},
|
||||
cirrusPort: {
|
||||
type: Number,
|
||||
},
|
||||
ueProcessId: {
|
||||
type: Number,
|
||||
},
|
||||
cirrusProcessId: {
|
||||
type: Number,
|
||||
},
|
||||
}, {
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
});
|
||||
const ActiveSession = (0, mongoose_1.model)("Active_Session", activeSessionSchema);
|
||||
exports.default = ActiveSession;
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
"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,
|
||||
},
|
||||
}, {
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
});
|
||||
const SessionServer = (0, mongoose_1.model)("Session_Server", sessionServerSchema);
|
||||
exports.default = SessionServer;
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = require("express");
|
||||
const router = (0, express_1.Router)();
|
||||
router.post("/", async (req, res) => {
|
||||
res.json({ ok: 1 });
|
||||
});
|
||||
const registerRouter = router;
|
||||
exports.default = registerRouter;
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
"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;
|
||||
Reference in New Issue
Block a user