agsh / rtsp-ffmpeg

Node.js FFMpeg wrapper for streaming RTSP into MotionJPEG
MIT License
249 stars 84 forks source link

Prevent NPE if a child is already dead #38

Closed SilverFire closed 2 years ago

SilverFire commented 3 years ago

Sometimes a child process dies earlier than the data listener gets disconnected. It may happen because of FFmpeg internal problems, or because of the network connection problems.

Before this change, disconnecting from a dead FFmpeg stream caused the following JS error:

app_1         | TypeError: Cannot read property 'kill' of undefined
app_1         |     at FFMpeg.stop (/app/node_modules/rtsp-ffmpeg/lib/rtsp-ffmpeg.js:128:13)
app_1         |     at FFMpeg.removeListener (/app/node_modules/rtsp-ffmpeg/lib/rtsp-ffmpeg.js:56:8)
app_1         |     at FFMpeg.emit (events.js:315:20)
app_1         |     at FFMpeg.EventEmitter.emit (domain.js:467:12)
app_1         |     at FFMpeg.removeListener (events.js:468:18)
agsh commented 2 years ago

@SilverFire Hi! Sorry for the very late reply, just missed your PR in the email box. :disappointed: Thanks a lot!