trying to find memory leak video streaming
This commit is contained in:
@@ -33,13 +33,13 @@ class DbUtil {
|
||||
// query = {...query, "personalFolder": null}
|
||||
// }
|
||||
|
||||
// if (type) {
|
||||
// if (type === "mongo") {
|
||||
// query = {...query, "personalFolder": null}
|
||||
// } else if (type === "s3") {
|
||||
// query = {...query, "personalFolder": true}
|
||||
// }
|
||||
// }
|
||||
if (type) {
|
||||
if (type === "mongo") {
|
||||
query = {...query, "personalFolder": null}
|
||||
} else if (type === "s3") {
|
||||
query = {...query, "personalFolder": true}
|
||||
}
|
||||
}
|
||||
|
||||
// if (storageType === "s3") {
|
||||
// query = {...query, "personalFolder": true}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {Router} from "express";
|
||||
import auth from "../middleware/auth";
|
||||
import PersonalFileController from "../controllers/personalFile";
|
||||
import authFullUser from "../middleware/authFullUser";
|
||||
import authStreamVideo from "../middleware/authStreamVideo";
|
||||
|
||||
const personalFileController = new PersonalFileController();
|
||||
|
||||
@@ -15,7 +16,7 @@ router.get("/file-service-personal/thumbnail/:id", authFullUser, personalFileCon
|
||||
|
||||
router.get("/file-service-personal/full-thumbnail/:id", authFullUser, personalFileController.getFullPersonalThumbnail);
|
||||
|
||||
router.get("/file-service-personal/stream-video/:id/:tempToken/:uuid", authFullUser, personalFileController.streamPersonalVideo);
|
||||
router.get("/file-service-personal/stream-video/:id", authStreamVideo, personalFileController.streamPersonalVideo);
|
||||
|
||||
router.get("/file-service-personal/public/download/:id/:tempToken", personalFileController.getPublicPersonalDownload);
|
||||
|
||||
|
||||
@@ -307,6 +307,7 @@ class FileSystemService implements ChunkInterface {
|
||||
const readStream = fs.createReadStream(currentFile.metadata.filePath!, {
|
||||
start: fixedStart,
|
||||
end: fixedEnd,
|
||||
highWaterMark: 128 * 1024
|
||||
});
|
||||
|
||||
const CIPHER_KEY = crypto.createHash('sha256').update(password).digest()
|
||||
@@ -321,6 +322,10 @@ class FileSystemService implements ChunkInterface {
|
||||
|
||||
readStream.pipe(decipher);
|
||||
|
||||
readStream.on("close", () => {
|
||||
console.log("read stream closed")
|
||||
})
|
||||
|
||||
// req.on("close", () => {
|
||||
// // console.log("req closed");
|
||||
// readStream.destroy();
|
||||
@@ -328,7 +333,10 @@ class FileSystemService implements ChunkInterface {
|
||||
|
||||
const tempUUID = req.params.uuid;
|
||||
|
||||
//console.log("temp uuid", tempUUID);
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, req, tempUUID, allStreamsToErrorCatch);
|
||||
console.log("await stream finished")
|
||||
readStream.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -305,6 +305,8 @@ class S3Service implements ChunkInterface {
|
||||
|
||||
const tempUUID = req.params.uuid;
|
||||
|
||||
console.log("temp uuid", tempUUID);
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, req, tempUUID, allStreamsToErrorCatch);
|
||||
s3ReadStream.destroy();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import uuid from "uuid";
|
||||
const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
decipher: any, res: Response, req: Request, tempUUID: string, streamsToErrorCatch: any[]) => {
|
||||
|
||||
const currentUUID = uuid.v4();
|
||||
tempStorage[tempUUID] = currentUUID;
|
||||
// const currentUUID = uuid.v4();
|
||||
// tempStorage[tempUUID] = currentUUID;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -14,7 +14,7 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
//let sizeCounter = 0;
|
||||
|
||||
req.on("close", () => {
|
||||
//console.log("close resolved");
|
||||
console.log("close resolved");
|
||||
streamsToErrorCatch.forEach((stream) => {
|
||||
stream.destroy();
|
||||
})
|
||||
@@ -22,29 +22,27 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
})
|
||||
|
||||
req.on("end", () => {
|
||||
//console.log("End resolved");
|
||||
console.log("End resolved");
|
||||
streamsToErrorCatch.forEach((stream) => {
|
||||
stream.destroy();
|
||||
})
|
||||
resolve();
|
||||
})
|
||||
|
||||
decipher.on("data", (data: Buffer | string) => {
|
||||
|
||||
//console.log("check", tempStorage[tempUUID]);
|
||||
//console.log("check b", tempStorage[tempUUID] !== currentUUID && tempStorage[tempUUID] !== undefined);
|
||||
//console.log("data", uuid.v4());
|
||||
|
||||
//console.log(tempStorage[tempUUID] !== currentUUID, tempStorage[tempUUID])
|
||||
if (tempStorage[tempUUID] !== currentUUID) {
|
||||
|
||||
//console.log("New Stream Requested, Desroying old stream");
|
||||
// if (tempStorage[tempUUID] !== currentUUID) {
|
||||
|
||||
|
||||
streamsToErrorCatch.forEach((stream) => {
|
||||
stream.destroy();
|
||||
})
|
||||
// streamsToErrorCatch.forEach((stream) => {
|
||||
// stream.destroy();
|
||||
// })
|
||||
|
||||
//console.log("Old Stream Desroyed");
|
||||
//console.log("Old Stream Resolved");
|
||||
resolve();
|
||||
//delete tempStorage[tempUUID];
|
||||
}
|
||||
// resolve();
|
||||
// }
|
||||
|
||||
//console.log("data", currentUUID);
|
||||
|
||||
@@ -62,6 +60,7 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
// tempStorage[tempUUID] = currentUUID;
|
||||
// }
|
||||
|
||||
console.log("data size", data.length)
|
||||
|
||||
if (+start === 0 && +end === 1) {
|
||||
|
||||
@@ -99,10 +98,14 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
//sizeCounter += data.length;
|
||||
})
|
||||
|
||||
decipher.on("close", () => {
|
||||
console.log("decipher closed");
|
||||
})
|
||||
|
||||
decipher.on("end", () => {
|
||||
//console.log("decipher resolved");
|
||||
console.log("decipher resolved");
|
||||
res.end();
|
||||
resolve();
|
||||
//resolve();
|
||||
})
|
||||
|
||||
streamsToErrorCatch.forEach((currentStream) => {
|
||||
|
||||
@@ -162,7 +162,7 @@ class HomePageContainer extends React.Component {
|
||||
|
||||
setSessionStorage = () => {
|
||||
|
||||
window.sessionStorage.setItem("uuid", uuid());
|
||||
window.sessionStorage.setItem("uuid", uuid.v4());
|
||||
}
|
||||
|
||||
componentWillUnmount = () => {
|
||||
|
||||
Reference in New Issue
Block a user