use the server_time for countdown and clock

This commit is contained in:
Oskar Hahn 2013-10-26 12:59:39 +02:00
parent ef687ad23c
commit ffe612359f
4 changed files with 24 additions and 8 deletions

View File

@ -9,6 +9,8 @@
:copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from time import time
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.core.context_processors import csrf
from django.dispatch import receiver, Signal
@ -167,7 +169,8 @@ def projector_clock(sender, **kwargs):
"""
Returns JavaScript for the projector
"""
return {'load_file': static('javascript/clock.js')}
return {'load_file': static('javascript/clock.js'),
'server_time': int(time())}
return Overlay(name, None, get_projector_html, get_projector_js,
allways_active=True)

View File

@ -1,5 +1,5 @@
function update_clock() {
var currentTime = new Date();
var currentTime = projector.get_server_time()
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
currentHours = normalise(currentHours);
@ -9,8 +9,9 @@ function update_clock() {
}
update_clock();
function normalise(i) {
if(i < 10) {
if (i < 10) {
i = "0" + i;
}
return i;

View File

@ -1,5 +1,5 @@
function update_countdown() {
var time = new Date().getTime() / 1000;
var time = projector.get_server_time().getTime() / 1000;
var seconds;
var minutes_digit;
var seconds_digit;
@ -7,7 +7,8 @@ function update_countdown() {
var start = projector.projector_countdown_start;
var duration = projector.projector_countdown_duration;
var pause = projector.projector_countdown_pause;
switch(projector.projector_countdown_state) {
switch (projector.projector_countdown_state) {
case 'active':
seconds = start + duration - time;
break;
@ -18,13 +19,13 @@ function update_countdown() {
seconds = duration;
break;
}
if(seconds > 60) {
if (seconds > 60) {
hours_digit = Math.floor(seconds / 3600);
minutes_digit = Math.floor((seconds - (hours_digit * 3600)) / 60);
seconds_digit = Math.floor(seconds - (hours_digit * 3600) - (minutes_digit * 60));
minutes_digit = normalise(minutes_digit);
seconds_digit = normalise(seconds_digit);
if(hours_digit > 0) {
if (hours_digit > 0) {
hours_digit = normalise(hours_digit);
seconds = hours_digit + ":" + minutes_digit + ":" + seconds_digit;
} else {
@ -33,11 +34,13 @@ function update_countdown() {
} else {
seconds = Math.max(0, Math.floor(seconds));
}
if(seconds !== undefined) {
$('#overlay_countdown_inner').html(seconds);
}
setTimeout('update_countdown()', 200);
}
update_countdown();
function normalise(i) {

View File

@ -31,11 +31,20 @@ var projector = {
$('#content').css('font-size', 100 + 20 * value + '%');
},
get_server_time: function () {
var date = new Date();
date.setTime(date.getTime() + projector.server_time_offset);
return date;
},
update_data: function(data) {
$.each(data, function (key, value) {
if (key === 'load_file')
projector.load_file(value);
else
else if (key === 'server_time') {
var local_time = Date.parse(new Date().toUTCString());
projector.server_time_offset = local_time - value * 1000;
} else
projector[key] = value;
});
}