Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live Stream Part Implementation #236

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"typescript": "^5.5.4"
},
"devDependencies": {
"@types/fluent-ffmpeg": "^2.1.27",
"@types/express": "^4.17.21",
"@types/node": "^20.16.1",
"fastify": "^4.28.1",
Expand Down
38 changes: 24 additions & 14 deletions apps/data-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fastifyIO from "fastify-socket.io";
import { Server as SocketIOServer } from "socket.io";
import path from "path";
import { config } from "./config";
import { setupWebSocket } from "./services/livestream/connection";
import { setupWebSocket } from "./services/livestream/socket";
import { authRoutes } from "./routes/auth";
import authPlugin from "./plugins/auth";
import jwt from "jsonwebtoken";
Expand Down Expand Up @@ -43,18 +43,6 @@ async function buildServer() {
},
});

//Create Public folder if doesnt exist
if (!fs.existsSync(publicDir)) {
fs.mkdirSync(publicDir, { recursive: true });
console.log("Public directory created at:", publicDir);
}

// Static files setup
await fastify.register(require("@fastify/static"), {
root: publicDir,
prefix: "/public/",
});

// Register core plugins
await fastify.register(prismaPlugin);
await fastify.register(authPlugin);
Expand Down Expand Up @@ -83,9 +71,11 @@ async function buildServer() {
return fastify;
}

let server: any = null;

async function start() {
try {
const server = await buildServer();
server = await buildServer();
const host =
process.env.NODE_ENV === "production" ? "0.0.0.0" : "127.0.0.1";

Expand All @@ -108,6 +98,26 @@ async function start() {
}
}

// Graceful shutdown handling
async function shutdown() {
console.log("Received shutdown signal");
if (server) {
try {
await server.close();
console.log("Server closed successfully");
process.exit(0);
} catch (err) {
console.error("Error during shutdown:", err);
process.exit(1);
}
}
}

// Handle shutdown signals
process.on("SIGTERM", shutdown);
process.on("SIGINT", shutdown);
process.on("SIGHUP", shutdown);

// Start server if not in test environment
if (process.env.NODE_ENV !== "test") {
start();
Expand Down
195 changes: 0 additions & 195 deletions apps/data-backend/src/services/livestream/connection.ts

This file was deleted.

112 changes: 0 additions & 112 deletions apps/data-backend/src/services/livestream/ffmpeg.setup.ts

This file was deleted.

Loading
Loading