Skip to content

Commit 9988acf

Browse files
committed
Check RTSP stream selection control is valid
Add a check to make sure the RTSP Stream control is valid before adding the 'onchange' event to avoid breaking the other controls
1 parent 56f168a commit 9988acf

1 file changed

Lines changed: 41 additions & 39 deletions

File tree

scripts/spectrogram.php

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -481,45 +481,47 @@ function loop(time) {
481481

482482
<script>
483483
var rtsp_stream_select = document.getElementById("rtsp_stream_select");
484-
//When the dropdown selection is changed set the new value is settings, then restart the livestream service so it broadcasts newly selected RTSP stream
485-
rtsp_stream_select.onchange = function() {
486-
if (this.value !== 'undefined'){
487-
// Get the audio player element
488-
var audio_player = document.querySelector('audio#player');
489-
var central_controls_element = document.getElementsByClassName('centered')[0];
490-
491-
//Create the loading header again as a placeholder while we're waiting to reload the stream
492-
var h1_loading = document.createElement("H1");
493-
var h1_loading_text = document.createTextNode("Loading...");
494-
h1_loading.setAttribute("id","loading-h1");
495-
h1_loading.setAttribute("style","font-size:48px; font-weight: bolder; color: #FFF");
496-
h1_loading.appendChild(h1_loading_text);
497-
498-
// Create the XMLHttpRequest object.
499-
const xhr = new XMLHttpRequest();
500-
// Initialize the request
501-
xhr.open("GET", './views.php?rtsp_stream_to_livestream='+ this.value +'&view=Advanced&submit=advanced');
502-
// Send the request
503-
xhr.send();
504-
// Fired once the request completes successfully
505-
xhr.onload = function(e) {
506-
// Check if the request was a success
507-
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
508-
// Restart the audio player in case it stopped working while the livestream service was restarted
509-
if(audio_player !== 'undefined'){
510-
central_controls_element.appendChild(h1_loading);
511-
//Wait 5 seconds before restarting the stream
512-
setTimeout(function () {
513-
audio_player.pause();
514-
audio_player.setAttribute('src', '/stream');
515-
audio_player.load();
516-
audio_player.play();
517-
518-
document.getElementById('loading-h1').remove()
519-
},
520-
10000
521-
)
522-
}
484+
if (typeof (rtsp_stream_select) !== 'undefined' && rtsp_stream_select !== null) {
485+
//When the dropdown selection is changed set the new value is settings, then restart the livestream service so it broadcasts newly selected RTSP stream
486+
rtsp_stream_select.onchange = function () {
487+
if (this.value !== 'undefined') {
488+
// Get the audio player element
489+
var audio_player = document.querySelector('audio#player');
490+
var central_controls_element = document.getElementsByClassName('centered')[0];
491+
492+
//Create the loading header again as a placeholder while we're waiting to reload the stream
493+
var h1_loading = document.createElement("H1");
494+
var h1_loading_text = document.createTextNode("Loading...");
495+
h1_loading.setAttribute("id", "loading-h1");
496+
h1_loading.setAttribute("style", "font-size:48px; font-weight: bolder; color: #FFF");
497+
h1_loading.appendChild(h1_loading_text);
498+
499+
// Create the XMLHttpRequest object.
500+
const xhr = new XMLHttpRequest();
501+
// Initialize the request
502+
xhr.open("GET", './views.php?rtsp_stream_to_livestream=' + this.value + '&view=Advanced&submit=advanced');
503+
// Send the request
504+
xhr.send();
505+
// Fired once the request completes successfully
506+
xhr.onload = function (e) {
507+
// Check if the request was a success
508+
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
509+
// Restart the audio player in case it stopped working while the livestream service was restarted
510+
if (audio_player !== 'undefined') {
511+
central_controls_element.appendChild(h1_loading);
512+
//Wait 5 seconds before restarting the stream
513+
setTimeout(function () {
514+
audio_player.pause();
515+
audio_player.setAttribute('src', '/stream');
516+
audio_player.load();
517+
audio_player.play();
518+
519+
document.getElementById('loading-h1').remove()
520+
},
521+
10000
522+
)
523+
}
524+
}
523525
}
524526
}
525527
}

0 commit comments

Comments
 (0)