still working on video streaming
This commit is contained in:
@@ -4,6 +4,8 @@ import MongoService from "../services/ChunkService/MongoService";
|
||||
import FileSystemService from "../services/ChunkService/FileSystemService";
|
||||
import S3Service from "../services/ChunkService/S3Service";
|
||||
import {UserInterface} from "../models/user";
|
||||
import uuid from "uuid";
|
||||
import tempStorage from "../tempStorage/tempStorage";
|
||||
|
||||
const fileService = new FileService()
|
||||
|
||||
@@ -366,8 +368,10 @@ class FileController {
|
||||
const user = req.user;
|
||||
const fileID = req.params.id;
|
||||
const headers = req.headers;
|
||||
|
||||
//tempStorage[req.params.uuid] = uuid.v4();
|
||||
|
||||
console.log("stream request", req.params.id)
|
||||
console.log("stream request", tempStorage)
|
||||
|
||||
// req.on("close", () => {
|
||||
// console.log("req closed stream");
|
||||
|
||||
@@ -256,21 +256,23 @@ class FileSystemService implements ChunkInterface {
|
||||
|
||||
readStream.pipe(decipher);
|
||||
|
||||
req.on("close", () => {
|
||||
// console.log("Destroying read stream");
|
||||
// readStream.destroy();
|
||||
// console.log("Read Stream Destoryed");
|
||||
})
|
||||
|
||||
req.on("error", () => {
|
||||
console.log("req error");
|
||||
})
|
||||
const tempUUID = req.params.uuid;
|
||||
|
||||
req.on("pause", () => {
|
||||
console.log("req pause")
|
||||
})
|
||||
// req.on("close", () => {
|
||||
// // console.log("Destroying read stream");
|
||||
// // readStream.destroy();
|
||||
// // console.log("Read Stream Destoryed");
|
||||
// })
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, allStreamsToErrorCatch);
|
||||
// req.on("error", () => {
|
||||
// console.log("req error");
|
||||
// })
|
||||
|
||||
// req.on("pause", () => {
|
||||
// console.log("req pause")
|
||||
// })
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, tempUUID, allStreamsToErrorCatch);
|
||||
}
|
||||
|
||||
getPublicDownload = async(fileID: string, tempToken: any, res: Response) => {
|
||||
|
||||
@@ -213,7 +213,7 @@ class MongoService implements ChunkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
streamVideo = async(user: UserInterface, fileID: string, headers: any, res: Response) => {
|
||||
streamVideo = async(user: UserInterface, fileID: string, headers: any, res: Response, req: Request) => {
|
||||
|
||||
const userID = user._id;
|
||||
const currentFile = await dbUtilsFile.getFileInfo(fileID, userID);
|
||||
@@ -279,7 +279,9 @@ class MongoService implements ChunkInterface {
|
||||
|
||||
readStream.pipe(decipher);
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, allStreamsToErrorCatch);
|
||||
const tempUUID = req.params.uuid;
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, tempUUID, allStreamsToErrorCatch);
|
||||
}
|
||||
|
||||
deleteFile = async(userID: string, fileID: string) => {
|
||||
|
||||
@@ -192,27 +192,28 @@ class S3Service implements ChunkInterface {
|
||||
|
||||
s3ReadStream.pipe(decipher);
|
||||
|
||||
req.on("close", () => {
|
||||
// console.log("Destoying read stream");
|
||||
// s3ReadStream.destroy();
|
||||
// console.log("Read Stream Destroyed");
|
||||
})
|
||||
const tempUUID = req.params.uuid;
|
||||
// req.on("close", () => {
|
||||
// // console.log("Destoying read stream");
|
||||
// // s3ReadStream.destroy();
|
||||
// // console.log("Read Stream Destroyed");
|
||||
// })
|
||||
|
||||
req.on("end", () => {
|
||||
console.log("ending stream");
|
||||
s3ReadStream.destroy();
|
||||
console.log("ended stream")
|
||||
})
|
||||
// req.on("end", () => {
|
||||
// console.log("ending stream");
|
||||
// s3ReadStream.destroy();
|
||||
// console.log("ended stream")
|
||||
// })
|
||||
|
||||
req.on("error", () => {
|
||||
console.log("req error");
|
||||
})
|
||||
// req.on("error", () => {
|
||||
// console.log("req error");
|
||||
// })
|
||||
|
||||
req.on("pause", () => {
|
||||
console.log("req pause")
|
||||
})
|
||||
// req.on("pause", () => {
|
||||
// console.log("req pause")
|
||||
// })
|
||||
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, allStreamsToErrorCatch);
|
||||
await awaitStreamVideo(start, end, differenceStart, decipher, res, tempUUID, allStreamsToErrorCatch);
|
||||
}
|
||||
|
||||
getThumbnail = async(user: UserInterface, id: string) => {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import {Response, Request} from "express"
|
||||
import tempStorage from "../../../tempStorage/tempStorage";
|
||||
import uuid from "uuid";
|
||||
|
||||
const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
decipher: any, res: Response, streamsToErrorCatch: any[]) => {
|
||||
decipher: any, res: Response, tempUUID: string, streamsToErrorCatch: any[]) => {
|
||||
|
||||
const currentUUID = uuid.v4();
|
||||
tempStorage[tempUUID] = currentUUID;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -10,6 +15,31 @@ const awaitStreamVideo = (start: number, end:number, differenceStart: number,
|
||||
|
||||
decipher.on("data", (data: Buffer | string) => {
|
||||
|
||||
//console.log("check", tempStorage[tempUUID]);
|
||||
//console.log("check b", tempStorage[tempUUID] !== currentUUID && tempStorage[tempUUID] !== undefined);
|
||||
|
||||
//console.log(tempStorage[tempUUID] !== currentUUID, tempStorage[tempUUID])
|
||||
if (tempStorage[tempUUID] !== currentUUID) {
|
||||
|
||||
console.log("New Stream Requested, Desroying old stream");
|
||||
streamsToErrorCatch[0].destroy();
|
||||
console.log("Old Stream Desroyed");
|
||||
//delete tempStorage[tempUUID];
|
||||
}
|
||||
|
||||
// if (tempStorage[tempUUID] !== undefined && tempStorage[tempUUID] !== currentUUID) {
|
||||
|
||||
// console.log("New Stream Requested, Desroying old stream");
|
||||
// streamsToErrorCatch[0].destroy();
|
||||
// console.log("Old Stream Desroyed");
|
||||
// delete tempStorage[tempUUID];
|
||||
|
||||
// } else {
|
||||
|
||||
// tempStorage[tempUUID] = currentUUID;
|
||||
// }
|
||||
|
||||
|
||||
if (+start === 0 && +end === 1) {
|
||||
|
||||
const dataCoverted = data.toString("hex");
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
const tempStorage: any = {};
|
||||
|
||||
export default tempStorage;
|
||||
Reference in New Issue
Block a user