title: How do I detect a disconnect from an MJPEG stream in javascript
body: <p>I am showing an MJPEG stream from an IP camera on a web page. The stream is shown using an image element, which is set by jQuery:</p>
  <pre><code>view = $('&lt;img&gt;');
  
  view.load(function() {
       console.log('loaded');
  });
  view.error(function() {
       console.log('error');
  });
  
  view.attr('src', 'http://camera_ip/videostream.mjpeg');
  </code></pre>
  <p>Both events fire neatly when their respective situation occurs. Until I disconnect the camera. The image freezes (of course). I want to detect this disconnection, to show the user an error message. I thought up a solution, which was copying frames several seconds apart from the image to a canvas, and comparing the contents.</p>
  <p>Is there an easier option?</p>