diff --git a/web/js/MonitorStream.js b/web/js/MonitorStream.js index 45de21dd76..342166a140 100644 --- a/web/js/MonitorStream.js +++ b/web/js/MonitorStream.js @@ -83,6 +83,7 @@ function MonitorStream(monitorData) { }; this.player = ''; + this.activePlayer = ''; // Variants: go2rtc, janus, rtsp2web_hls, rtsp2web_mse, rtsp2web_webrtc, zms. Relevant for this.player = ''/Auto this.setPlayer = function(p) { if (-1 != p.indexOf('go2rtc')) { @@ -100,6 +101,46 @@ function MonitorStream(monitorData) { return this.player = p; }; + this.manageAvailablePlayersOptions = function(action, opt) { + if (action == 'disable') { + opt.setAttribute('disabled', ''); + opt.setAttribute('title', playerDisabledInMonitorSettings); + } else if (action == 'enable') { + opt.removeAttribute('disabled'); + opt.removeAttribute('title'); + } + }; + + this.manageAvailablePlayers = function() { + const selectPlayers = document.querySelector('[id="player"][name="codec"]'); + const opts = selectPlayers.options; + + for (var opt, j = 0; opt = opts[j]; j++) { + if (-1 !== opt.value.indexOf('go2rtc')) { + if (this.Go2RTCEnabled) { + this.manageAvailablePlayersOptions('enable', opt); + } else { + this.manageAvailablePlayersOptions('disable', opt); + } + } else if (-1 !== opt.value.indexOf('rtsp2web')) { + if (this.RTSP2WebEnabled) { + this.manageAvailablePlayersOptions('enable', opt); + } else { + this.manageAvailablePlayersOptions('disable', opt); + } + } + } + if (selectPlayers.options[selectPlayers.selectedIndex].value == '') { + // Perhaps "Auto" is left from the previous monitor, we will change it according to the cookies. + selectPlayers.value = getCookie('zmWatchPlayer'); + } + if (selectPlayers.options[selectPlayers.selectedIndex].disabled) { + // Selected player is not available for the current monitor + selectPlayers.value = ''; // Auto + } + this.player = selectPlayers.value; + }; + this.element = null; this.getElement = function() { if (this.element) return this.element; @@ -263,7 +304,14 @@ function MonitorStream(monitorData) { } }; // setStreamScale + /* + * streamChannel = 0 || Primary; 1 || Secondary. + */ this.start = function(streamChannel = 'default') { + if (streamChannel === null || streamChannel === '' || currentView == 'montage') streamChannel = 'default'; + if (!['default', 0, 1].includes(streamChannel)) { + streamChannel = (streamChannel.toLowerCase() == 'primary') ? 0 : 1; + } this.streamListenerBind = streamListener.bind(null, this); console.log('start', this.Go2RTCEnabled, (!this.player), (-1 != this.player.indexOf('go2rtc')), ((!this.player) || (-1 != this.player.indexOf('go2rtc')))); @@ -281,7 +329,7 @@ function MonitorStream(monitorData) { stream.background = true; // We do not use the document hiding/showing analysis from "video-rtc.js", because we have our own analysis const Go2RTCModUrl = url; const webrtcUrl = Go2RTCModUrl; - this.currentChannelStream = (streamChannel == 'default') ? 0 : streamChannel; + this.currentChannelStream = (streamChannel == 'default') ? ((this.RTSP2WebStream == 'Secondary') ? 1 : 0) : streamChannel; webrtcUrl.protocol = (url.protocol=='https:') ? 'wss:' : 'ws'; webrtcUrl.pathname += "/ws"; //webrtcUrl.search = 'src='+this.id; @@ -304,6 +352,7 @@ function MonitorStream(monitorData) { $j('#volumeControls').show(); if (typeof observerMontage !== 'undefined') observerMontage.observe(stream); + this.activePlayer = 'go2rtc'; return; } else { alert("ZM_GO2RTC_PATH is empty. Go to Options->System and set ZM_GO2RTC_PATH accordingly."); @@ -332,6 +381,7 @@ function MonitorStream(monitorData) { this.statusCmdTimer = setInterval(this.statusCmdQuery.bind(this), statusRefreshTimeout); this.started = true; this.streamListenerBind(); + this.activePlayer = 'janus'; return; } @@ -376,16 +426,19 @@ function MonitorStream(monitorData) { } else if (stream.canPlayType('application/vnd.apple.mpegurl')) { stream.src = hlsUrl.href; } + this.activePlayer = 'rtsp2web_hls'; } else if (this.RTSP2WebType == 'MSE') { const mseUrl = rtsp2webModUrl; mseUrl.protocol = useSSL ? 'wss' : 'ws'; mseUrl.pathname = "/stream/" + this.id + "/channel/" + this.currentChannelStream + "/mse"; mseUrl.search = "uuid=" + this.id + "&channel=" + this.currentChannelStream + ""; startMsePlay(this, stream, mseUrl.href); + this.activePlayer = 'rtsp2web_mse'; } else if (this.RTSP2WebType == 'WebRTC') { const webrtcUrl = rtsp2webModUrl; webrtcUrl.pathname = "/stream/" + this.id + "/channel/" + this.currentChannelStream + "/webrtc"; startRTSP2WebPlay(stream, webrtcUrl.href, this); + this.activePlayer = 'rtsp2web_webrtc'; } clearInterval(this.statusCmdTimer); // Fix for issues in Chromium when quickly hiding/showing a page. Doesn't clear statusCmdTimer when minimizing a page https://stackoverflow.com/questions/9501813/clearinterval-not-working this.statusCmdTimer = setInterval(this.statusCmdQuery.bind(this), statusRefreshTimeout); @@ -435,6 +488,7 @@ function MonitorStream(monitorData) { stream.onload = this.img_onload.bind(this); this.started = true; this.streamListenerBind(); + this.activePlayer = 'zms'; }; // this.start this.stop = function() { diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 2d03d0024b..23ef369cc6 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -487,6 +487,7 @@ 'Pixels' => 'pixels', 'PlayAll' => 'Play All', 'PlayCycle' => 'Play Cycle', + 'PlayerDisabledInMonitorSettings' => 'The player is disabled in the monitor settings.', 'PleaseWait' => 'Please Wait', 'PostEventImageBuffer' => 'Post Event Image Count', 'PreEventImageBuffer' => 'Pre Event Image Count', diff --git a/web/lang/ru_ru.php b/web/lang/ru_ru.php index 3157192b55..7f7adc3a9e 100644 --- a/web/lang/ru_ru.php +++ b/web/lang/ru_ru.php @@ -832,7 +832,7 @@ 'ZoomIn' => 'Приблизить', 'ZoomOut' => 'Отдалить', // *********07-2022************************************ - 'Storage' => 'Хранилище', + 'Storage' => 'Хранилище', 'Back' => 'Вернуться', 'ParentGroup' => 'Родительская группа', 'FilterUnarchiveEvents' => 'Разархивировать все совпадения', @@ -847,6 +847,7 @@ 'PreviousMonitor' => 'Предыдущий монитор', 'PauseCycle' => 'Приостановить цикл', 'PlayCycle' => 'Запуск цикла', + 'PlayerDisabledInMonitorSettings' => 'Этот плеер отключен в настройках монитора.', 'NextMonitor' => 'Следующий монитор', 'Server' => 'Сервер', 'Servers' => 'Сервера', diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index 33a8fd0676..db982f692c 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -1081,7 +1081,7 @@ function manageShutdownBtns(element) { } /* Controls the availability of options for selection*/ -function manageRTSP2WebChannelStream() { +function manageChannelStream() { let select = null; let secondPath_ = null; if (currentView == 'watch') { @@ -1721,7 +1721,7 @@ function findPos(obj, foundScrollLeft, foundScrollTop) { /* Handling change */ function handleChangeInputTag(evt) { // Managing availability of channel stream selection - manageRTSP2WebChannelStream(); + manageChannelStream(); } /* Handling a mouse click */ diff --git a/web/skins/classic/js/skin.js.php b/web/skins/classic/js/skin.js.php index 1a64026aaa..7069ca6dc5 100644 --- a/web/skins/classic/js/skin.js.php +++ b/web/skins/classic/js/skin.js.php @@ -36,6 +36,7 @@ const exportFailedString = ''; const exportSucceededString = ''; const cancelString = ''; +const playerDisabledInMonitorSettings = ''; RTSP2WebStream(); +if (isset($_REQUEST['streamChannel'])) { + $streamChannelSelected = $_REQUEST['streamChannel']; +} else if (isset($_COOKIE['zmStreamChannel'])) { + $streamChannelSelected = $_COOKIE['zmStreamChannel']; +} else if (isset($_SESSION['zmStreamChannel']) ) { + $streamChannelSelected = $_SESSION['zmStreamChannel']; +} +$streamChannelSelected = validHtmlStr($streamChannelSelected); if (isset($_REQUEST['width'])) { $options['width'] = validInt($_REQUEST['width']); @@ -293,7 +303,7 @@ RTSP2WebStream(), array('data-on-change'=>'monitorChangeStreamChannel','id'=>'streamChannel')); + echo htmlSelect('streamChannel', ZM\Monitor::getRTSP2WebStreamOptions(), $streamChannelSelected, array('data-on-change'=>'monitorChangeStreamChannel','id'=>'streamChannel')); echo htmlSelect('streamQuality', $streamQuality, $streamQualitySelected, array('data-on-change'=>'changeStreamQuality','id'=>'streamQuality')); ?> @@ -301,20 +311,13 @@ translate('Auto'), 'zms'=>'ZMS MJPEG']; - if ($monitor->Go2RTCEnabled()) { - $players['go2rtc'] = 'Go2RTC Auto'; - $players['go2rtc_webrtc'] = 'Go2RTC WEBRTC'; - $players['go2rtc_mse'] = 'Go2RTC MSE'; - $players['go2rtc_hls'] = 'Go2RTC HLS'; - } - - if ($monitor->RTSP2WebEnabled()) { - $players = array_merge($players,[ - 'rtsp2web_webrtc' => 'RTSP2Web WEBRTC', - 'rtsp2web_mse' => 'RTSP2Web MSE', - 'rtsp2web_hls' => 'RTSP2Web HLS', - ]); - } # + $players['go2rtc'] = 'Go2RTC Auto'; + $players['go2rtc_webrtc'] = 'Go2RTC WEBRTC'; + $players['go2rtc_mse'] = 'Go2RTC MSE'; + $players['go2rtc_hls'] = 'Go2RTC HLS'; + $players['rtsp2web_webrtc'] = 'RTSP2Web WEBRTC'; + $players['rtsp2web_mse'] = 'RTSP2Web MSE'; + $players['rtsp2web_hls'] = 'RTSP2Web HLS'; $player = ''; # Auto if (isset($_REQUEST['player']) and isset($players[$_REQUEST['player']])) { $player = validHtmlStr($_REQUEST['player']);