remcotjeerdsma / UnifiProtectCrx

Chrome app for Unifi Protect Live View
20 stars 4 forks source link

Failed to load stream #1

Open GieltjE opened 5 years ago

GieltjE commented 5 years ago

First of all thanks for this module, it makes life a lot easier.

We are using a custom view with 9 camera's in 24/7 mode, but after a few hours some random camera's go into "Failed to load stream" (the controller says they are online and can display them, so I guess they just hickupped). And they don't return untill we restart the plugin.

Can we help debug this?

remcotjeerdsma commented 5 years ago

Hi GieltjE,

In our deployment, the whole React app (UniFi Protect) will reload automatically if cameras fail. There is actually a little bug there still, where after such a refresh, the app does not hide the menu bar and sidebar anymore and you are left with a 90% fullscreen instead of the proper fullscreen.

I believe the trigger for failing streams is mainly due to network stability/capacity, but failing camera's should be resolved by above refresh. You might be able to adapt the code a little and add a refresh every hour, for example?

Regards, Remco

GieltjE commented 5 years ago

An hourly reload was my next option, do you happen to have some sample code for automated reloads?

chriskooken commented 5 years ago

@Torrentus @GieltjE I am having the same issue, were you able to add a refresh?

GieltjE commented 5 years ago

Just wrote an secondary app that kills it every hour and restarts it.

GieltjE commented 5 years ago

Something like this should do the trick (don't forget to properly link the event and such).

        private readonly Timer _timer = new Timer();
        private readonly ContextMenu _contextMenu = new ContextMenu();
        private void MainShown(Object sender, EventArgs e)
        {
            Hide();
            Visible = false;
            _notifyIcon.Icon = Icon;
            _notifyIcon.Visible = true;
            _notifyIcon.ContextMenu = _contextMenu;
            _contextMenu.MenuItems.Add(new MenuItem("Exit", (o, args) => { _notifyIcon.Visible = false; Environment.Exit(0); }));

            Tick(null, null);

            _timer.Interval = 10 * 1000;
            _timer.Tick += Tick;
            _timer.Start();
        }

        private DateTime _lastRestart = DateTime.Now;
        private void Tick(Object sender, EventArgs e)
        {
            _timer.Stop();

            Boolean running = false;

            try
            {
                Process[] processes = Process.GetProcesses();
                if (processes.Any(process => String.Equals(process.ProcessName, "chrome", StringComparison.OrdinalIgnoreCase)))
                {
                    running = true;
                }
            }
            catch {}

            if (!running || _lastRestart.AddMinutes(20) <= DateTime.Now)
            {
                if (running)
                {
                    Stop();
                }
                Start();
                _lastRestart = DateTime.Now;
            }

            _timer.Start();
        }

        private static void Stop()
        {
retry:
            Boolean running = false, complete = false;

            try
            {
                Process[] processes = Process.GetProcesses();
                foreach (Process process in processes)
                {
                    if (!String.Equals(process.ProcessName, "chrome", StringComparison.OrdinalIgnoreCase)) continue;
                    running = true;
                    process.Kill();
                }

                complete = true;
            }
            catch {}

            if (running || !complete)
            {
                goto retry;
            }
        }
        private static void Start()
        {
            Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe", "--ignore-certificate-errors --profile-directory=Default --app-id=hlfiibnanckjnnlidgdbmbgmobjidoac");
        }

Yes I use goto, sue me or fix it yourself ;)

JoshuaBroad commented 5 years ago

Not sure how this is going to solve anyones issue as the hole purpose of this app is to run on a Chrome device? and your script seems to reference a windows directory and process...

What language is your script and is it compatible with non-windows based deives?

GieltjE commented 5 years ago

@JoshuaBroad This is C# and used for windows (probably Linux too with some effort) with chrome. Don't know about chrome devices.