Monday, 3 May 2021

How to detect when mjpeg stream stops with javascript

I have a html/javascript client that is listening to a mjpeg video stream:

myImg = document.getElementById('my-image');
myImg.src = 'http://myserver.com/camera.mjpeg';

Works fine but if the video stream dies for whatever reason the video feed "freezes" on the last received image and I have no opportunity to display an error to the user. I've see this post that offers a solution (creating a long running ajax request alongside the stream) that appears to work but seems hacky at best. I was hoping there would be a more supported method like through a disconnect event or something.

Any ideas?

Update:

Based on comments I have tried the following approaches, none of which has worked:

myImg.addEventListener('error', event => { ... });
myImg.addEventListener('stalled', event => { ... });
myImg.addEventListener('suspend', event => { ... });


from How to detect when mjpeg stream stops with javascript

No comments:

Post a Comment