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,6 +9,7 @@ function update_clock() {
}
update_clock();
function normalise(i) {
if (i < 10) {
i = "0" + 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,6 +7,7 @@ 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) {
case 'active':
seconds = start + duration - time;
@ -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;
});
}