cameraPlaceholder.css('opacity', 0);
cameraProgress.removeClass('visible');
- if (getCookie('motion_detected_' + cameraId) == 'true') {
- cameraFrameDiv.addClass('motion-detected');
- }
- else {
- cameraFrameDiv.removeClass('motion-detected');
+ /* there's no point in looking for a cookie update more often than once every second */
+ var now = new Date().getTime();
+ if (!this.lastCookieTime || now - this.lastCookieTime > 1000) {
+ if (getCookie('motion_detected_' + cameraId) == 'true') {
+ cameraFrameDiv.addClass('motion-detected');
+ }
+ else {
+ cameraFrameDiv.removeClass('motion-detected');
+ }
+
+ this.lastCookieTime = now;
}
if (this.naturalWidth / this.naturalHeight > body.width() / body.height()) {
var img = $cameraFrame.find('img.camera')[0];
var cameraId = cameraFrame.id.substring(6);
- /* limit the refresh rate to 20 fps */
- var count = Math.max(1, 1 / cameraFrame.streamingFramerate * 1000 / refreshInterval);
+ /* at a refresh interval of 50ms, the refresh rate is limited to 20 fps */
+ var count = 1000 / (refreshInterval * cameraFrame.streamingFramerate);
+ if (count <= 2) {
+ /* skipping frames (showing the same frame twice) at this rate won't be visible,
+ * while the effective framerate will be as close as possible to the motion's one */
+ count -= 1;
+ }
if (img.error) {
/* in case of error, decrease the refresh rate to 1 fps */
cameraPlaceholder.css('opacity', 0);
cameraProgress.removeClass('visible');
- if (getCookie('motion_detected_' + cameraId) == 'true') {
- cameraFrameDiv.addClass('motion-detected');
- }
- else {
- cameraFrameDiv.removeClass('motion-detected');
+ /* there's no point in looking for a cookie update more often than once every second */
+ var now = new Date().getTime();
+ if (!this.lastCookieTime || now - this.lastCookieTime > 1000) {
+ if (getCookie('motion_detected_' + cameraId) == 'true') {
+ cameraFrameDiv.addClass('motion-detected');
+ }
+ else {
+ cameraFrameDiv.removeClass('motion-detected');
+ }
+
+ this.lastCookieTime = now;
}
if (fullScreenCameraId) {
}
function doFullScreenCamera(cameraId) {
- if (inProgress || refreshCameraFrames[cameraId]) {
+ if (inProgress || refreshDisabled[cameraId]) {
return;
}
if (img.loading) {
img.loading++; /* increases each time the camera would refresh but is still loading */
- if (img.loading > 2 * 1000 / refreshInterval) { /* limits the retry at one every two seconds */
+ if (img.loading > 2 * 1000 / refreshInterval) { /* limits the retries to one every two seconds */
img.loading = 0;
}
else {
}
cameraFrames.each(function () {
- /* limit the refresh rate to 20 fps */
- var count = Math.max(0, 1 / this.config['streaming_framerate'] * 1000 / refreshInterval);
+ if (!this.img) {
+ this.img = $(this).find('img.camera')[0];
+ }
+
+ /* at a refresh interval of 50ms, the refresh rate is limited to 20 fps */
+ var count = 1000 / (refreshInterval * this.config['streaming_framerate']);
var serverSideResize = this.config['streaming_server_resize'];
- var img = $(this).find('img.camera')[0];
- if (img.error) {
+ if (count <= 2) {
+ /* skipping frames (showing the same frame twice) at this rate won't be visible,
+ * while the effective framerate will be as close as possible to the motion's one */
+ count -= 1;
+ }
+
+ if (this.img.error) {
/* in case of error, decrease the refresh rate to 1 fps */
count = 1000 / refreshInterval;
}
}
else {
var cameraId = this.id.substring(6);
- refreshCameraFrame(cameraId, img, serverSideResize);
+ refreshCameraFrame(cameraId, this.img, serverSideResize);
this.refreshDivider = 0;
}