mmaelzer / mjpeg-camera

A node.js library and/or server for connecting to, recording from, and streaming mjpeg cameras.
71 stars 23 forks source link

camera.getScreenshot example null/timeout issue #3

Closed jlbribeiro closed 9 years ago

jlbribeiro commented 9 years ago

The camera.getScreenshot example code doesn't seem to be working correctly. It correctly saves a frame into the camera-screenshot.jpg file, but it "hangs" until the following error is thrown:

TypeError: Cannot call method 'abort' of null
    at Camera.stop (/mjpeg-camera-example/node_modules/mjpeg-camera/mjpeg-camera.js:97:19)
    at Camera.<anonymous> (/mjpeg-camera-example/node_modules/mjpeg-camera/mjpeg-camera.js:119:10)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

Since the Camera.prototype.stopmethod is setting the connection to null after aborting it, it seems to me that two consecutive stop calls would cause the error, most likely caused by the camera.getScreenshot call followed by the keepalive timer call.

My use case allows me to "fix" the stop call by checking if the connection is null before aborting, but this doesn't seem to be the proper fix (or at least not enough to fix it), since the same example code will hang forever (i.e., no error is thrown but the program never quits).

Thank you for mjpeg-camera by the way, I was looking for a module capable of grabbing a single MJPEG frame and this was exactly it.

mmaelzer commented 9 years ago

Great catch. This bug came about from several changes I recently added to better handle reconnects to cameras due to network connectivity issues.

Also, I'm really happy that you find mjpeg-camera useful. It's always delightful to hear that these modules are being used.