Skip to content

Commit

Permalink
Merge pull request #5 from TiagoDGomes/version-2.3
Browse files Browse the repository at this point in the history
Version 2.3
  • Loading branch information
TiagoDGomes authored Oct 10, 2024
2 parents 40fdaa3 + 4b75db4 commit 97c57b7
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 64 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# painel-debate
Painel para gerência de tempo e perguntas em debates para eleições. Você poderá utilizar como fonte para transmissões com OBS.

Painel para gerência de tempo em debates para eleições. O sistema fornece links para uso múltiplo, que permite compartilhar o painel para outros usuários ou até mesmo utilizar como fonte para transmissões com OBS.

## Requisitos

- um servidor Web com suporte a PHP ativo (pode ser Apache HTTP Server, nginx etc.);
- suporte a SQLite no PHP;
- sistema operacional compatível (nos testes foram usados Windows e Linux);
- caso você deseje compartilhar os recursos de usuários externos, seu servidor Web deve estar com firewall configurado para ser acessível externamente.
- caso você deseje compartilhar os recursos de usuários externos, seu servidor Web deve estar acessível externamente (verifique seu firewall).

## Instalação

- Baixe os arquivos para seu diretório Web (`git clone https://github.com/TiagoDGomes/painel-debate.git`);
- Clone o projeto usando `git clone https://github.com/TiagoDGomes/painel-debate.git` em seu diretório Web (ou baixe [aqui](https://github.com/TiagoDGomes/painel-debate/releases/latest) a última versão);
- Copie o arquivo `config.php-default` como `config.php`;
- Abra o arquivo `config.php` e configure a seu gosto:
- verifique se há permissões de escrita para a pasta "database" no arquivo de configuração (ex.: `chown -R www-data:www-data databases`);
- Edite o arquivo `config.php` e configure a seu gosto:
- Verifique se há permissões de escrita para a pasta "database" no arquivo de configuração (ex.: `chown -R www-data:www-data databases`);
- Abra o navegador e navegue em http://seu-servidor/painel-debate/.

## Créditos
Expand Down
17 changes: 15 additions & 2 deletions core/core.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
<?php

$APP_VERSION = "2.2";
$APP_VERSION = "2.3";
$APP_TITLE = "Painel";

define('PCORE', true);

session_start();

require_once 'config.php';
@include_once 'config.php';

if (!isset($DATABASE_PATH)){
exit('$DATABASE_PATH is not definied.');
}
if (!isset($MAX_DATABASES)){
$MAX_DATABASES = 6;
}
if (!isset($MAX_DATABASES)){
$ID_LENGTH = 12;
}
if (!isset($MAX_DATABASES)){
$SYNC_PING_COUNT = 4;
}
require_once 'classes.php';


Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<button onclick="Timer.prepareTime(Timer.getRemainingSeconds())" class="big pause">
<span class="shadow"></span>
<span class="edge"></span>
<span class="front text">⏸️</span>
<span class="front text"><i class="icon pause"></i></span>
</button>
</div>
<div class="timer-buttons prepare-buttons">
Expand Down
6 changes: 3 additions & 3 deletions media/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ button.big .shadow {

button.big .edge {
position: absolute;
top: 0;
top: 2px;
left: 0;
width: 100%;
height: 100%;
height: 95%;
border-radius: 12px;
background: linear-gradient(to left,
#202020 0%,
Expand All @@ -99,7 +99,7 @@ button.big .edge {
button.big .front {
display: block;
position: relative;
padding: 12px 27px;
padding: 14px 27px;
border-radius: 12px;
font-size: 1.1rem;
color: white;
Expand Down
16 changes: 16 additions & 0 deletions media/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
--status-error-color: rgb(204, 0, 255);
--status-color: rgba(87, 86, 86, 0.25);
--status-font-color: rgba(255, 255, 255, 0.75);
--timer-sync-error-color: red;
}

a {
Expand Down Expand Up @@ -55,6 +56,12 @@ body.timer-ending .container-timer {
background-color: var(--timer-ending-color);
}


body.user.timer-sync.timer-sync-error,
body.timer-sync.timer-sync-error .container-timer{
background-color: var(--timer-sync-error-color);
}

body.user.timer-semaphore.set,
body.user.timer-ending.timer-alert,
body.timer-semaphore.set .container-timer,
Expand Down Expand Up @@ -161,6 +168,12 @@ i.icon {
opacity: .5;
}

button i.icon{
width: 1em;
height: 1em;
opacity: 1;
}

i.icon:hover {
opacity: 1;
}
Expand All @@ -171,4 +184,7 @@ i.icon.full-screen {

i.icon.qrcode {
background-image: url(qrcode.png);
}
i.icon.pause {
background-image: url(pause.svg);
}
30 changes: 30 additions & 0 deletions media/pause.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 76 additions & 51 deletions scripts/classes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Timer = {
localTime: 0,
localTimeMillis: 0,
serverTimeMillis: 0,
_syncing: false,
pingCount: SYNC_PING_COUNT,
Expand All @@ -9,6 +10,7 @@ var Timer = {
endTime: null,
preparedTime: null,
updateFailed: false,

isSyncing: function () {
return Timer._syncing;
},
Expand Down Expand Up @@ -39,71 +41,92 @@ var Timer = {
Timer.preparedTime = 0;
Timer.startTime = 0;
Timer.endTime = 0;
Timer.localTime = 0;
Timer.serverTime = 0;
Timer.localTimeMillis = 0;
Timer.serverTimeMillis = 0;
Timer._syncCount = 0;
Timer._diffServer = 0;
Timer._diffSum = 0;
Timer.setText('');
Timer._syncTicTacLoop(function () {

});
Timer._syncTicTacLoop(function (resultSuccess) { });
},
_syncTicTacLoop: function (callback_sync) {
HTTPRequest.getJSON('?timer=1&syncCount=' + Timer._syncCount + "&localTime=" + Timer.localTime, function (data) {
var diff = data['diff'];
Timer.serverTimeMillis = data['serverTimeMillis'];
if (diff != Timer.serverTimeMillis) {
Timer._diffSum += diff;
}
var diffToZero = Timer.serverTimeMillis % 1000;
Timer.localTime = Timer.serverTimeMillis;
Timer._syncCount++;
var nextTimeout = 1000 - diffToZero;
console.log("Timer._syncCount,diff, diffToZero, nextTimeout", Timer._syncCount, diff, diffToZero, nextTimeout);
setTimeout(function () {
if (Timer._syncCount >= Timer.pingCount) {
var avgDiff = Timer._diffSum / Timer._syncCount;
var miliRounded = Math.floor(avgDiff / 1000) * 1000;
Timer.localTime += miliRounded;
setTimeout(function () {
Timer.initTicTac();
try {
callback_sync();
} catch (e) {
console.error(e);
}
}, miliRounded - avgDiff * 2)
} else {
Timer._syncTicTacLoop(callback_sync);
_syncTicTacLoop: function (callback_result_success) {
HTTPRequest.getJSON('?timer=1&syncCount=' + Timer._syncCount + "&localTime=" + Timer.localTimeMillis, function (data) {
if (data === null){
// console.error("Sincronização falhou.");
Timer._syncTicTacLoop(callback_result_success);
} else {

var diff = data['diff'];
Timer.serverTimeMillis = data['serverTimeMillis'];
if (diff != Timer.serverTimeMillis) {
Timer._diffSum += diff;
}
}, nextTimeout);
var diffToZero = Timer.serverTimeMillis % 1000;
Timer.localTimeMillis = Timer.serverTimeMillis + 1000;
Timer._syncCount++;
var nextTimeout = 1000 - diffToZero;
console.log("_syncCount ", Timer._syncCount,
"\ndiff ", diff,
"\ndiffToZero ", diffToZero,
"\n_diffSum ", Timer._diffSum,
"\nnextTimeout ", nextTimeout,
"\nserverTimeMillis ", Timer.serverTimeMillis,
"\nlocalTimeMillis ", Timer.localTimeMillis,
);

setTimeout(function () {
var requireNewPing = Timer._syncCount >= Timer.pingCount;
if (requireNewPing) {
var avgDiff = Timer._diffSum / Timer._syncCount;
var miliRounded = Math.floor(avgDiff / 1000) * 1000;
Timer.localTimeMillis += miliRounded;
setTimeout(function () {
Timer.initTicTac();
try {
callback_result_success(true);
} catch (e) {
console.error(e);
}
}, miliRounded - avgDiff * 2)
} else {
Timer._syncTicTacLoop(callback_result_success);
}
}, nextTimeout);
}
});
},
initTicTac: function () {
console.log('Timer.initTicTac');
console.log("initTicTac:",
"\nTimer.localTime: ", Timer.localTime,
"\nTimer.serverTime: ", Timer.serverTime);
Timer.setSyncing(false);
delete Timer._syncCount;
delete Timer._diffServer;
delete Timer._diffSum;
delete Timer.serverTimeMillis;
Timer.localTime = Math.round(Timer.localTime / 1000);
Timer._interval1s = setInterval(function () {
Timer.localTime += 1;
}, 1000);
Timer._interval1sUpdate = setInterval(function () {
Timer.updateData();
Timer.refreshInterface();
Status.setDebugMessage('L: ' + Timer.localTime + '\nS: ' + Timer.serverTime);
if (!Timer.isRunning() || !Timer.updateFailed) {
if (Math.abs(Timer.serverTime - Timer.localTime) >= 1.5 || Timer.localTime > Timer.serverTime) {
Timer.syncTicTac();
}
}
}, 500);
Timer.localTime = Math.round(Timer.localTimeMillis / 1000);
Timer._interval1s = setInterval(Timer.tic, 1000);
Timer._interval1sUpdate = setInterval(Timer.updateTicTac, 500);
Timer.updateData(Timer.refreshInterface);
},
tic: function(){
Timer.localTime += 1;
Status.setDebugMessage('L: ' + Timer.localTime + '\nS: ' + Timer.serverTime);
},
updateTicTac: function(){
Timer.updateData();
Timer.refreshInterface();
if (Timer.isRunning()) {
//console.log('Timer is Running!');
} else {
//console.log('Timer is not Running!');
//console.log("Timer.serverTime: ", Timer.serverTime, "\nTimer.localTime: ", Timer.localTime)
if (Math.abs(Timer.serverTime - Timer.localTime) >= 1.5 || Timer.localTime > Timer.serverTime) {
Timer.syncTicTac();
}
}
},
updateData: function (callback) {
Property.getAll(function (data) {
if (data) {
Expand All @@ -113,7 +136,7 @@ var Timer = {
Timer.serverTime = data['serverTimeMillis'] / 1000;
Timer.updateFailed = false;
} else {
Timer.updateFailed = true;
Timer.updateFailed = true;
document.body.classList.add('timer-sync-error');
if (!Timer.isRunning) {
Timer.syncTicTac();
Expand Down Expand Up @@ -234,8 +257,8 @@ var Timer = {
return seconds >= 0 && seconds < 10;
},
isRunning: function () {
seconds = Timer.getRemainingSeconds();
return seconds > 0 && seconds < 86400;
seconds = Timer.getRemainingSecondsDiff();
return seconds > -3 && seconds < 86400;
},
isPrepared: function () {
return Timer.endTime <= 0;
Expand All @@ -261,6 +284,8 @@ var Timer = {
}
}

Timer.localTimeMillis = (new Date()).getTime();

var Property = {
getAll: function (callbackdata) {
HTTPRequest.getJSON('?up=1', function (data) {
Expand Down Expand Up @@ -302,7 +327,7 @@ var HTTPRequest = {
var r = JSON.parse(xhr.responseText);
callback_func(r);
} catch (e) {
console.info(url, '\n', e, xhr.responseText);
//console.info(url, '\n', e, xhr.responseText);
callback_func(null);
}
}
Expand Down

0 comments on commit 97c57b7

Please sign in to comment.