From: Calin Crisan Date: Sun, 19 Jan 2014 13:17:40 +0000 (+0200) Subject: refresh requests are now properly limited when the loading is slow X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=815334335bfbbb9f07103c72c864c7f088102da5;p=motioneye-debian refresh requests are now properly limited when the loading is slow --- diff --git a/static/js/main.js b/static/js/main.js index 2bbb6da..db5e5b2 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -4,6 +4,7 @@ var refreshDisabled = {}; /* dictionary indexed by cameraId, tells if refresh is var fullScreenCameraId = null; var thresholdSlider = null; var inProgress = false; +var refreshInterval = 50; /* milliseconds */ /* utils */ @@ -1910,8 +1911,6 @@ function doFullScreenCamera(cameraId) { return; /* no full screen for erroneous cameras */ } - fullScreenCameraId = cameraId; - var width; if (windowAspectRatio > aspectRatio) { width = aspectRatio * Math.round(0.8 * windowHeight); @@ -1925,6 +1924,7 @@ function doFullScreenCamera(cameraId) { var cameraImg = cameraFrameDiv.find('img.camera'); cameraImg.load(function showFullScreenCamera() { cameraFrameDiv.css('width', width); + fullScreenCameraId = cameraId; runModalDialog({ title: cameraName, @@ -1955,11 +1955,11 @@ function refreshCameraFrames() { return; } - + if (img.loading) { img.loading++; /* increases each time the camera would refresh but is still loading */ - if (img.loading > 5) { + if (img.loading > 2 * 1000 / refreshInterval) { /* limits the retry at one every two seconds */ img.loading = 0; } else { @@ -1986,17 +1986,15 @@ function refreshCameraFrames() { cameraFrames = $('div.page-container').find('div.camera-frame'); } - var refreshInterval = 50; - cameraFrames.each(function () { /* limit the refresh rate to 20 fps */ - var count = Math.max(1 / this.config['streaming_framerate'] * 1000 / refreshInterval); + var count = Math.max(1, 1 / this.config['streaming_framerate'] * 1000 / refreshInterval); var serverSideResize = this.config['streaming_server_resize']; var img = $(this).find('img.camera')[0]; if (img.error) { /* in case of error, decrease the refresh rate to 1 fps */ - count = 10; + count = 1000 / refreshInterval; } if (this.refreshDivider < count) {