Fix changeScale not updating zms url when the page initially loads as not scale to fit

This commit is contained in:
Isaac Connor 2021-01-11 13:38:04 -05:00
parent 9a821e1fb9
commit 35b5bb7b85
1 changed files with 15 additions and 8 deletions

View File

@ -95,13 +95,17 @@ function changeScale() {
var scale = $j('#scale').val(); var scale = $j('#scale').val();
var newWidth; var newWidth;
var newHeight; var newHeight;
// Always turn it off, we will re-add it below. I don't know if you can add a callback multiple
// times and what the consequences would be
$j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active
if ( scale == '0' || scale == 'auto' ) { if ( scale == '0' || scale == 'auto' ) {
var newSize = scaleToFit(monitorWidth, monitorHeight, $j('#liveStream'+monitorId), $j('#replayStatus')); var newSize = scaleToFit(monitorWidth, monitorHeight, $j('#liveStream'+monitorId), $j('#replayStatus'));
newWidth = newSize.width; newWidth = newSize.width;
newHeight = newSize.height; newHeight = newSize.height;
autoScale = newSize.autoScale; autoScale = newSize.autoScale;
$j(window).on('resize', endOfResize); //remove resize handler when Scale to Fit is not active
} else { } else {
$j(window).off('resize', endOfResize); //remove resize handler when Scale to Fit is not active
newWidth = monitorWidth * scale / SCALE_BASE; newWidth = monitorWidth * scale / SCALE_BASE;
newHeight = monitorHeight * scale / SCALE_BASE; newHeight = monitorHeight * scale / SCALE_BASE;
} }
@ -111,15 +115,16 @@ function changeScale() {
var streamImg = $j('#liveStream'+monitorId); var streamImg = $j('#liveStream'+monitorId);
if ( streamImg ) { if ( streamImg ) {
var oldSrc = streamImg.attr('src'); var oldSrc = streamImg.attr('src');
var newSrc = oldSrc.replace(/scale=\d+/i, 'scale='+(scale== 'auto' ? autoScale : scale)); var newSrc = oldSrc.replace(/scale=\d+/i, 'scale='+(scale == 'auto' ? autoScale : scale));
streamImg.width( newWidth ); streamImg.width(newWidth);
streamImg.height( newHeight ); streamImg.height(newHeight);
streamImg.src = ''; // Some browsers need it to be cleared first
streamImg.src = newSrc; streamImg.src = newSrc;
} else { } else {
console.error('No element found for liveStream'+monitorId); console.error('No element found for liveStream'+monitorId);
} }
} } // end function changeScale
function setAlarmState( currentAlarmState ) { function setAlarmState( currentAlarmState ) {
alarmState = currentAlarmState; alarmState = currentAlarmState;
@ -175,7 +180,8 @@ function setAlarmState( currentAlarmState ) {
function getStreamCmdError(text, error) { function getStreamCmdError(text, error) {
console.log(error); console.log(error);
// Error are normally due to failed auth. reload the page. // Error are normally due to failed auth. reload the page.
window.location.reload();
//window.location.reload();
} }
function getStreamCmdResponse(respObj, respText) { function getStreamCmdResponse(respObj, respText) {
@ -285,7 +291,8 @@ function getStreamCmdResponse(respObj, respText) {
checkStreamForErrors('getStreamCmdResponse', respObj);//log them checkStreamForErrors('getStreamCmdResponse', respObj);//log them
// Try to reload the image stream. // Try to reload the image stream.
// If it's an auth error, we should reload the whole page. // If it's an auth error, we should reload the whole page.
window.location.reload(); console.log("have error");
//window.location.reload();
if ( 0 ) { if ( 0 ) {
var streamImg = $j('#liveStream'+monitorId); var streamImg = $j('#liveStream'+monitorId);
if ( streamImg ) { if ( streamImg ) {
@ -854,13 +861,13 @@ function initPage() {
if ( refreshApplet && appletRefreshTime ) { if ( refreshApplet && appletRefreshTime ) {
appletRefresh.delay(appletRefreshTime*1000); appletRefresh.delay(appletRefreshTime*1000);
} }
if ( scale == '0' || scale == 'auto' ) changeScale();
if ( window.history.length == 1 ) { if ( window.history.length == 1 ) {
$j('#closeControl').html(''); $j('#closeControl').html('');
} }
document.querySelectorAll('select[name="scale"]').forEach(function(el) { document.querySelectorAll('select[name="scale"]').forEach(function(el) {
el.onchange = window['changeScale']; el.onchange = window['changeScale'];
}); });
changeScale();
} else if ( monitorRefresh > 0 ) { } else if ( monitorRefresh > 0 ) {
setInterval(reloadWebSite, monitorRefresh*1000); setInterval(reloadWebSite, monitorRefresh*1000);
} }