Skip to content

Commit

Permalink
Live Stream Part Implementation (#236)
Browse files Browse the repository at this point in the history
* feat: added better flow for studio

* fix: added todo comment
  • Loading branch information
addegbenga authored Nov 5, 2024
1 parent bf459d1 commit e85adc3
Show file tree
Hide file tree
Showing 35 changed files with 2,312 additions and 1,482 deletions.
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

0 comments on commit e85adc3

Please sign in to comment.