@socketio.on("get_time", namespace="/app/auction")
def get_time_auction(json):
time = database.get_row("timer")[0]
if time['active'] == "0":
socketio.emit("second", {'second': -1})
if time['start_time'] == "0":
now = datetime.now().strftime("%d.%m.%Y %H:%M:%S")
database.update_row("timer", start_time=now)
a = time['active']
time = datetime.strptime(time['start_time'], "%d.%m.%Y %H:%M:%S")
time_2 = datetime.now()
response_time = time_2 - time
response_time = 10 - response_time.seconds
socketio.emit("second", {'second': response_time, "active": a}, namespace='/app/auction')
socket.on("second", function (msg) {
console.log(msg);
if (msg['second'] != "-1" && msg['active'] == "1") {
clearInterval(timer);
auction_bet(msg['second']);
}
});
function auction_bet(timeLeft) {
var display = $("#timer"); // меняющаяся цифра
var head = $(".auction-timer-head");
$('.auctiom-timer-time').addClass("active");
timer = setInterval(function () {
timeLeft == --timeLeft;
if (timeLeft >= 0) {
// если таймер всё еще больше нуля
display.text(timeLeft); // обновляем цифру
} else {
$('.auctiom-timer-time').removeClass("active");
$('.auction-summ-score').text("0");
$("#last-auction-name").text("нет");
$("#last-auction-summ").text("0");
socket.emit("end_timer", {})
clearInterval(timer); // удаляем таймер
}
}, 1000); // таймер срабатывает каждые 1000 msec (1 sec)
}