diff --git a/web/js/MonitorStream.js b/web/js/MonitorStream.js index e2c366d117..c1e03135ef 100644 --- a/web/js/MonitorStream.js +++ b/web/js/MonitorStream.js @@ -59,6 +59,7 @@ function MonitorStream(monitorData) { request: 'stream', connkey: this.connKey }; + this.fatalError = false; this.playerPriority = { 1: { // This setting should always be priority #1. name: 'default', @@ -591,6 +592,7 @@ function MonitorStream(monitorData) { }; this.start = function(streamChannel = 'default') { + this.fatalError = false; this.writeTextInfoBlock("Loading..."); this.go2rtcTranscodeTried = false; // a fresh start re-probes the native stream first if (streamChannel === null || streamChannel === '' || currentView == 'montage') streamChannel = 'default'; @@ -866,10 +868,29 @@ function MonitorStream(monitorData) { this.restart = function(channelStream = "default", delay = 200) { this.stop(); - const this_ = this; - setTimeout(function() {// During the downtime, the monitor may have already started to work. - if (!this_.started) this_.start(channelStream); - }, delay); + const countErrors = this.getCountStreamErrors(this.player); + if (countErrors < this.limitCountErrors) { + setTimeout(function(self) {// During the downtime, the monitor may have already started to work. + if (!self.started) self.start(channelStream); + }, delay, this); + } else { + if (typeof streamCmdStop === 'function') { + // Let's set the correct state for the player control buttons (for example, on the Watch page) + streamCmdStop(); + } + + if (-1 !== this.player.indexOf('zms')) { + this.writeTextInfoBlock("Error", {showImg: false}); + } else { + this.writeTextInfoBlock("Error"); + } + this.updateStreamInfo('', 'Error'); + this.fatalError = true; + this.resetCountStreamErrors(this.player); + const msg = `Out of ${this.limitCountErrors} consecutive attempts to start a stream for monitor ID=${this.id} using player "${this.player}", none were successful. The stream has been stopped.`; + console.warn(msg); + this.showText(msg); + } }; this.pause = function() { diff --git a/web/skins/classic/views/js/watch.js b/web/skins/classic/views/js/watch.js index 87c0f87865..e78b291a12 100644 --- a/web/skins/classic/views/js/watch.js +++ b/web/skins/classic/views/js/watch.js @@ -1210,8 +1210,9 @@ var cycleIntervalId; var secondsToCycle = 0; function nextCycleView() { - secondsToCycle --; - if (secondsToCycle<=0) { + const stream = (monitorStream) ? monitorStream.getAVStream() : null; + if (stream && stream.readyState >= 2 || -1 !== monitorStream.activePlayer.indexOf('zms')) secondsToCycle --; + if (secondsToCycle<=0 || (monitorStream.fatalError && monitorStream.selectedPlayer)) { cycleNext(); } $j('#secondsToCycle').text(secondsToCycle);