-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.html
More file actions
263 lines (247 loc) · 13 KB
/
Copy pathremote.html
File metadata and controls
263 lines (247 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html lang="sr">
<head>
<meta charset="UTF-8">
<meta name="referrer" content="no-referrer">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#0b0d11">
<title>ProTimer — Daljinski</title>
<style>
:root{ --bg:#0b0d11; --panel:#13161c; --panel2:#1a1f28; --border:#232936;
--text:#e8edf3; --dim:#7d8794; --accent:#2ea043; --accent-h:#3fb950;
--amber:#d9a441; --red:#f0564d; --blue:#4493f8; }
*{box-sizing:border-box; margin:0; -webkit-tap-highlight-color:transparent; user-select:none;}
body{background:var(--bg); color:var(--text); overflow-x:hidden;
font:16px/1.4 -apple-system,"Helvetica Neue",system-ui,sans-serif;
padding:14px; max-width:560px; margin:0 auto; -webkit-user-select:none;}
input{user-select:auto; -webkit-user-select:auto;}
.head{display:flex; align-items:center; gap:8px; margin-bottom:12px;}
.brand{font-weight:800; letter-spacing:2px; font-size:14px;}
.brand b{color:var(--accent-h);}
.conn{margin-left:auto; font-size:12px; color:var(--dim); display:flex; align-items:center; gap:6px;}
.dot{width:8px; height:8px; border-radius:50%; background:var(--red);}
.dot.on{background:var(--accent-h);}
.disp{background:#000; border:1px solid var(--border); border-radius:14px;
padding:22px 12px; text-align:center; margin-bottom:14px;}
.disp .lbl{font-size:13px; color:var(--dim); min-height:16px; margin-bottom:4px;
white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.disp .t{font-family:"SF Mono",ui-monospace,Menlo,monospace; font-weight:700;
font-variant-numeric:tabular-nums; font-size:21vw; line-height:1; color:#fff;}
@media(min-width:560px){ .disp .t{font-size:118px;} }
.disp .t.neg{animation:pulse 1s steps(2,start) infinite;}
@keyframes pulse{50%{opacity:.3;}}
.disp .msg{font-size:15px; color:var(--amber); font-weight:600; min-height:18px; margin-top:6px;}
.grid{display:grid; gap:9px; margin-bottom:14px;}
.g2{grid-template-columns:1fr 1fr;} .g3{grid-template-columns:1fr 1fr 1fr;} .g4{grid-template-columns:repeat(4,1fr);}
button{background:var(--panel2); color:var(--text); border:1px solid var(--border);
border-radius:12px; padding:16px 8px; font-size:16px; font-weight:600; cursor:pointer;
-webkit-appearance:none; transition:transform .05s;}
button:active{transform:scale(.96);}
button.big{padding:22px 8px; font-size:20px; font-weight:800;}
button.start{background:var(--accent); border-color:var(--accent); color:#fff;}
button.start.run{background:#9a6a06; border-color:#bb8009;}
button.go{background:var(--accent); border-color:var(--accent); color:#fff;}
button.bk{background:transparent; border-color:#5a2b28; color:#e88;}
button.bk.on{background:var(--red); border-color:var(--red); color:#fff;}
button.adj{font-family:"SF Mono",Menlo,monospace; font-size:15px; padding:14px 4px;}
.sec{font-size:11px; letter-spacing:1.5px; color:var(--dim); text-transform:uppercase; margin:4px 2px 8px;}
.msgrow{display:flex; gap:8px;}
.msgrow input{flex:1; background:var(--panel2); border:1px solid var(--border); color:var(--text);
border-radius:12px; padding:14px; font-size:16px; outline:none;}
.preset{background:var(--panel); font-size:14px; padding:12px 6px;}
.foot{text-align:center; color:#566070; font-size:12px; margin:16px 0 8px;}
</style>
</head>
<body>
<div class="head">
<div class="brand">PRO<b>TIMER</b> · <span data-i18n="remoteWord">Daljinski</span></div>
<div class="conn"><span class="dot" id="dot"></span><span id="connTxt">…</span></div>
</div>
<div class="disp">
<div class="lbl" id="lbl"></div>
<div class="t" id="time">--:--</div>
<div class="msg" id="msg"></div>
</div>
<div class="grid g2">
<button class="big start" id="btnStart">▶ START</button>
<button class="big" id="btnReset">↺ RESET</button>
</div>
<div class="sec" data-i18n="correction">Korekcija</div>
<div class="grid g4">
<button class="adj" data-adj="-60">−1m</button>
<button class="adj" data-adj="-10">−10s</button>
<button class="adj" data-adj="10">+10s</button>
<button class="adj" data-adj="60">+1m</button>
</div>
<div class="grid g2">
<button class="go" id="btnGo" data-i18n="goNext">GO ▶ SLEDEĆI</button>
<button class="bk" id="btnBk">■ BLACKOUT</button>
</div>
<div class="sec" data-i18n="quickDur">Brzo trajanje</div>
<div class="grid g4" id="chips"></div>
<div class="sec" data-i18n="msgToSpeaker">Poruka govorniku</div>
<div class="grid g3" style="margin-bottom:9px">
<button class="preset" data-i18n="preset1">Ubrzaj</button>
<button class="preset" data-i18n="preset2">Završavaj</button>
<button class="preset" data-i18n="preset3">STOP</button>
</div>
<div class="msgrow">
<input type="text" id="msgIn" data-i18n-ph="ownMsg" placeholder="Svoja poruka…" enterkeyhint="send">
<button id="btnMsg" style="padding:14px 16px" data-i18n="send">Pošalji</button>
<button id="btnMsgClr" style="padding:14px 14px; background:transparent">✕</button>
</div>
<div class="foot" data-i18n="foot">Kontrola radi dok je glavni ProTimer otvoren na računaru.</div>
<script>
const $ = id => document.getElementById(id);
function pad(n){ return String(n).padStart(2,'0'); }
function fmtSecs(s,neg){ const h=Math.floor(s/3600),m=Math.floor((s%3600)/60),x=s%60;
return (neg?'−':'')+(h>0?`${h}:${pad(m)}:${pad(x)}`:`${m}:${pad(x)}`); }
function fmtMs(ms){ return ms>=0?fmtSecs(Math.ceil(ms/1000),false):fmtSecs(Math.floor(-ms/1000),true); }
// ---------- jezik / language ----------
const I18N = {
sr: { remoteWord:'Daljinski', connecting:'povezivanje…', live:'uživo', lost:'veza pala…',
start:'▶ START', pause:'⏸ PAUZA', correction:'Korekcija', goNext:'GO ▶ SLEDEĆI',
quickDur:'Brzo trajanje', msgToSpeaker:'Poruka govorniku',
preset1:'Ubrzaj', preset2:'Završavaj', preset3:'STOP', ownMsg:'Svoja poruka…', send:'Pošalji',
foot:'Kontrola radi dok je glavni ProTimer otvoren na računaru.' },
en: { remoteWord:'Remote', connecting:'connecting…', live:'live', lost:'connection lost…',
start:'▶ START', pause:'⏸ PAUSE', correction:'Adjust', goNext:'GO ▶ NEXT',
quickDur:'Quick duration', msgToSpeaker:'Message to speaker',
preset1:'Speed up', preset2:'Wrap up', preset3:'STOP', ownMsg:'Your message…', send:'Send',
foot:'Works while the main ProTimer is open on the computer.' }
};
let lang = 'sr';
function tr(key){ return (I18N[lang] && I18N[lang][key]) || I18N.sr[key] || key; }
function applyLang(){
document.documentElement.lang = lang;
document.querySelectorAll('[data-i18n]').forEach(el => el.textContent = tr(el.dataset.i18n));
document.querySelectorAll('[data-i18n-ph]').forEach(el => el.placeholder = tr(el.dataset.i18nPh));
}
applyLang();
let S = null, lastStateVersion = -1, lastServerInstance = null;
const TOKEN = new URLSearchParams(location.search).get('t') || '';
let clockOffsetMs=0, clockSynced=false, clockSyncing=false;
const hostNow=()=>Date.now()+clockOffsetMs;
async function syncClock(samples=3){
if(clockSyncing) return;
clockSyncing=true;
let best=null;
try{
for(let i=0;i<samples;i++){
const started=Date.now();
const aborter=new AbortController();
const timeout=setTimeout(()=>aborter.abort(),location.protocol==='https:'?7000:3000);
let data;
try{
const response=await fetch('/time',{cache:'no-store',signal:aborter.signal});
if(!response.ok) throw new Error('time '+response.status);
data=await response.json();
}finally{ clearTimeout(timeout); }
const received=Date.now(), rtt=received-started;
if(Number.isFinite(data.now)&&(!best||rtt<best.rtt)) best={rtt,offset:data.now-(started+received)/2};
}
if(best){ clockOffsetMs=best.offset; clockSynced=true; }
}catch(_){}
clockSyncing=false;
}
function cmd(type, value){
fetch('/cmd', { method:'POST', headers:{'Content-Type':'application/json','x-pt-token':TOKEN},
body: JSON.stringify({ type, value }) }).catch(()=>{});
}
function applyState(next){
if(!next||typeof next!=='object') return false;
if(typeof next._instance==='string'&&next._instance!==lastServerInstance){
lastServerInstance=next._instance;
lastStateVersion=-1;
}
const version=Number(next._version);
if(Number.isFinite(version)){
if(version<=lastStateVersion) return false;
lastStateVersion=version;
}
S=next;
if(!clockSynced&&Number.isFinite(S._serverNow)) clockOffsetMs=S._serverNow-Date.now();
if(S.lang&&S.lang!==lang){ lang=S.lang; applyLang(); if($('dot').classList.contains('on')) $('connTxt').textContent=tr('live'); }
return true;
}
// prijem stanja (SSE + HTTPS long-poll rezerva za javni link)
let lastPollSuccess=0, pollController=null;
const markLive=()=>{ $('dot').classList.add('on'); $('connTxt').textContent=tr('live'); };
const markLost=()=>{
if(location.protocol==='https:'&&Date.now()-lastPollSuccess<25000) return;
$('dot').classList.remove('on'); $('connTxt').textContent=tr('lost');
};
function connect(){
const es = new EventSource('/events');
es.onopen = () => { markLive(); syncClock(1); };
es.onmessage = e => { try { applyState(JSON.parse(e.data)); } catch(_){} };
es.onerror = () => { markLost(); es.close(); setTimeout(connect,1000); };
}
async function pollLoop(){
let failures=0;
while(true){
const aborter=new AbortController();
pollController=aborter;
const timeout=setTimeout(()=>aborter.abort(),30000);
try{
const response=await fetch('/poll?since='+encodeURIComponent(lastStateVersion)+'&r='+Date.now(),{cache:'no-store',signal:aborter.signal});
if(!response.ok) throw new Error('poll '+response.status);
const payload=await response.json();
if(payload.state) applyState(payload.state);
if(Number.isFinite(payload.version)&&payload.version>lastStateVersion) lastStateVersion=payload.version;
failures=0;
lastPollSuccess=Date.now(); markLive();
}catch(_){
markLost();
failures=Math.min(failures+1,5);
await new Promise(resolve=>setTimeout(resolve,Math.min(5000,500*(2**(failures-1)))+Math.random()*250));
}finally{ clearTimeout(timeout); if(pollController===aborter) pollController=null; }
}
}
$('connTxt').textContent = tr('connecting');
if(location.protocol==='https:') pollLoop(); else connect();
syncClock(location.protocol==='https:'?1:3);
setInterval(()=>syncClock(1),30000);
document.addEventListener('visibilitychange',()=>{ if(!document.hidden){ if(pollController)pollController.abort(); syncClock(); } });
window.addEventListener('online',()=>{ if(pollController)pollController.abort(); syncClock(); });
function render(){
if(!S) return;
const now=hostNow(); let text, neg=false, col='#fff';
if(S.mode==='clock'){ const d=new Date(now); text=`${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`; }
else if(S.mode==='countup'){ const el=S.running?S.elapsedMs+(now-S.startAt):S.elapsedMs; text=fmtSecs(Math.floor(el/1000),false); }
else {
let rem=S.running?S.endAt-now:S.remMs; if(!S.overtime&&rem<0) rem=0;
if(S.useWarnColors){ if(rem<=S.redSec*1000) col=S.warnRed||'#ff4540'; else if(rem<=S.yellowSec*1000) col=S.warnYellow||'#ffc23a'; }
if(rem<0){ col=S.warnRed||'#ff4540'; neg=true; }
text=fmtMs(rem);
}
const t=$('time'); if(t.textContent!==text)t.textContent=text; if(t.style.color!==col)t.style.color=col;
const tClass='t'+(neg?' neg':''); if(t.className!==tClass)t.className=tClass;
const label=S.text||'', message=S.message?S.message.text:'';
if($('lbl').textContent!==label)$('lbl').textContent=label;
if($('msg').textContent!==message)$('msg').textContent=message;
$('btnStart').classList.toggle('run', S.running);
const startText=S.running?tr('pause'):tr('start'); if($('btnStart').textContent!==startText)$('btnStart').textContent=startText;
$('btnBk').classList.toggle('on', S.blackout);
}
render();
setInterval(render,50);
// kontrole
$('btnStart').addEventListener('click', ()=>cmd('start'));
$('btnReset').addEventListener('click', ()=>cmd('reset'));
$('btnGo').addEventListener('click', ()=>cmd('go'));
$('btnBk').addEventListener('click', ()=>cmd('blackout'));
document.querySelectorAll('[data-adj]').forEach(b=>b.addEventListener('click',()=>cmd('adjust',+b.dataset.adj)));
[1,2,5,10,15,20,30,45].forEach(min=>{
const b=document.createElement('button'); b.className='adj'; b.textContent=min+'m';
b.addEventListener('click',()=>cmd('setDuration',min*60000)); $('chips').appendChild(b);
});
document.querySelectorAll('.preset').forEach(b=>b.addEventListener('click',()=>cmd('message',b.textContent)));
$('btnMsg').addEventListener('click', ()=>{ const v=$('msgIn').value.trim(); if(v){ cmd('message',v); $('msgIn').value=''; $('msgIn').blur(); } });
$('msgIn').addEventListener('keydown', e=>{ if(e.key==='Enter') $('btnMsg').click(); });
$('btnMsgClr').addEventListener('click', ()=>cmd('clearMessage'));
</script>
</body>
</html>