mylisabox / flutter_mjpeg

Flutter widget to show mjpeg stream from URL
BSD 2-Clause "Simplified" License
30 stars 23 forks source link

Is it possible to reconnect when stream is closed. #36

Open saknarak opened 7 months ago

saknarak commented 7 months ago

How to reconnect/refresh when stream server is closed or restart

when image shown and then I restart my stream server there is no error so I cannot refresh image

It's would be nice to have flag that try to reconnect to stream source.

cybrox commented 7 months ago

A restartWhenClosed option would definitely be a good addition to the library!


In the meantime, you could create a timeout-timer that is reset by a frame pre-processor every time a frame is received.
If no new frame is received for a given duration, the widget is reloaded.

Something like:

class ResetTimeoutPreprocessor extends MjpegPreprocessor {
  /// The external timeout timer
  Timer timeoutTimer;

  ResetTimeoutPreprocessor(this.timer);

  @override
  List<int>? process(List<int> frame) {
    // reset timer here
    return frame;
  }

and

Mjpeg(stream: "...", preprocessor: ResetTimeoutPreprocessor(myTimer));
cybrox commented 6 months ago

For anyone interested, I implemented a proof-of-concept of a frameTimeout option in https://github.com/Koch-AG/flutter_mjpeg/commit/0d602e73988f63eb39e3699ba9d11adca3fcfa6b.

I'll MR this as soon as we've tested it for a while and are sure it does not interfere with anything else. Unfortunately, I don't have a lot of time to work on this at the moment but the solution is functional and we're testing it in-house at the moment.