Skip to content

Commit

Permalink
Fix: detect stream finished correctly (mtripg6666tdr#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
new committed Sep 11, 2022
1 parent 1275276 commit 3c4a336
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Component/PlayManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class PlayManager extends ServerManagerBase {
});
// setup volume
this.setVolume(this.volume);
((connection.piper as any)["_endStream"]).once("end", this.onStreamFinished.bind(this));
stream.on("end", this.onStreamFinished.bind(this));
// wait for entering playing state
await Util.general.waitForEnteringState(() => this.server.connection.playing);
this.preparing = false;
Expand Down
7 changes: 6 additions & 1 deletion src/Component/streams/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { FFmpeg } from "prism-media";

import { destroyStream } from ".";
import Util from "../../Util";
import { createPassThrough } from "../../Util/general";
import { DefaultUserAgent, FFmpegDefaultNetworkArgs } from "../../definition";

export function transformThroughFFmpeg(readable:StreamInfo, bitrate:number, effectArgs:string[], seek:number, output:"ogg"|"pcm"){
Expand Down Expand Up @@ -58,10 +59,14 @@ export function transformThroughFFmpeg(readable:StreamInfo, bitrate:number, effe
const ffmpeg = new FFmpeg({args});
if(Util.config.debug) ffmpeg.process.stderr.on("data", chunk => Util.logger.log("[FFmpeg]" + chunk.toString(), "debug"));
if(readable.type === "readable"){
const normalizeThrough = createPassThrough();
readable.stream
.on("error", e => destroyStream(normalizeThrough, e))
.pipe(normalizeThrough)
.on("error", e => destroyStream(ffmpeg, e))
.pipe(ffmpeg)
.on("close", () => destroyStream(readable.stream))
.pipe(ffmpeg)
.on("close", () => destroyStream(normalizeThrough))
;
}
return ffmpeg;
Expand Down

0 comments on commit 3c4a336

Please sign in to comment.