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

Fix: NCP Object Storage에 mp3 파일 업로드 안되는 부분 수정 #297

Merged
merged 1 commit into from
Dec 13, 2023
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
3 changes: 3 additions & 0 deletions mediaServer/src/models/FfmpegCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class FfmpegCommand {
.on('start', () => {
console.log(`${roomId} 강의실 음성 녹화 시작`);
})
.on('error', (err) => {
console.log(err);
})
.on('end', async () => {
streamInfo.recordEnd = true;
await endRecording(roomId);
Expand Down
12 changes: 5 additions & 7 deletions mediaServer/src/utils/MediaConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,23 @@ class MediaConverter {
}
};

setFfmpeg = (roomId: string): void => {
setFfmpeg = async (roomId: string): Promise<void> => {
const streamInfo = this.peerStreamInfoList.get(roomId);
if (!streamInfo) {
console.log('해당 강의실 발표자가 존재하지 않습니다.');
return;
}
this.mediaStreamToFile(streamInfo.audio, streamInfo.audioTempFileName);
await this.mediaStreamToFile(streamInfo.audio, streamInfo.audioTempFileName);
streamInfo.proc = new FfmpegCommand(
this.getOutputAbsolutePath(streamInfo.audioTempFileName),
this.getOutputAbsolutePath(streamInfo.recordFileName),
roomId,
streamInfo,
this.endRecording
);
streamInfo.proc.run();
};

mediaStreamToFile = (stream: PassThrough, fileName: string): string => {
mediaStreamToFile = async (stream: PassThrough, fileName: string): Promise<string> => {
const outputPath = path.join(outputDir, fileName);
const outputFile = fs.createWriteStream(outputPath);
stream.pipe(outputFile);
Expand All @@ -78,8 +77,8 @@ class MediaConverter {
}
streamInfo.stopRecording();
this.deleteTempFile(streamInfo.audioTempFileName);
this.peerStreamInfoList.delete(roomId);
await this.requestToServer(roomId);
this.peerStreamInfoList.delete(roomId);
};

getOutputAbsolutePath = (fileName: string) => {
Expand All @@ -100,15 +99,14 @@ class MediaConverter {
console.log('해당 강의실 발표자가 존재하지 않습니다.');
return;
}
const url = await uploadFileToObjectStorage(streamInfo.recordFileName, roomId);
const url = await uploadFileToObjectStorage(path.join(outputDir, streamInfo.recordFileName), roomId);
console.log(`${url}에 파일 저장`);
return url;
};

requestToServer = async (roomId: string) => {
// TODO: API 서버에 강의 종료 요청하기
const url = await this.saveAudioFile(roomId);
console.log(url);
fetch((process.env.SERVER_API_URL + '/lecture/end') as string, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
Expand Down
2 changes: 1 addition & 1 deletion mediaServer/src/utils/ncp-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const uploadFileToObjectStorage = async (file: any, filename: string) => {
Body: fs.createReadStream(file)
}).promise();

const url = endpoint + '/' + bucketName + '/' + filename;
const url = endpoint + '/' + bucketName + '/' + filename + '.mp3';
return url;
};

Expand Down