-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathweb_ui.html
More file actions
1209 lines (1060 loc) · 64.3 KB
/
web_ui.html
File metadata and controls
1209 lines (1060 loc) · 64.3 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LG Horizon Test UI</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
background: '#13141c',
card: '#1e212f',
accent: '#0f7dff',
accentHover: '#3894ff',
success: '#22c55e',
warning: '#f59e0b',
danger: '#ef4444',
offline: '#6b7280',
},
fontFamily: {
mono: ['ui-monospace', 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', "Liberation Mono", "Courier New", 'monospace'],
}
}
}
}
</script>
<style>
body {
background-color: #13141c;
color: #e2e8f0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
overflow-x: hidden;
}
.glass-panel {
background: rgba(30, 33, 47, 0.7);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.05);
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
.input-field {
background: rgba(15, 23, 42, 0.5);
border: 1px solid rgba(255, 255, 255, 0.1);
color: white;
transition: all 0.2s;
}
.input-field:focus {
outline: none;
border-color: #0f7dff;
box-shadow: 0 0 0 2px rgba(15, 125, 255, 0.2);
}
.btn { transition: all 0.2s ease; }
.btn:active { transform: scale(0.97); }
.btn-control {
background: rgba(255,255,255,0.05);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 0.375rem;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
user-select: none;
}
.btn-control:hover {
background: rgba(255,255,255,0.1);
border-color: rgba(255,255,255,0.2);
}
.btn-control:active { background: rgba(255,255,255,0.15); transform: scale(0.95); }
/* Remote specific */
.d-pad-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 0.5rem;
width: fit-content;
margin: 0 auto;
}
.numpad-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0.5rem;
max-width: 200px;
margin: 0 auto;
}
/* Color Buttons */
.btn-color-red { background: #ef4444; border-color: #b91c1c; color: white; }
.btn-color-green { background: #22c55e; border-color: #15803d; color: white; }
.btn-color-yellow { background: #eab308; border-color: #a16207; color: white; }
.btn-color-blue { background: #3b82f6; border-color: #1d4ed8; color: white; }
.btn-color-red:hover { background: #dc2626; }
.btn-color-green:hover { background: #16a34a; }
.btn-color-yellow:hover { background: #ca8a04; }
.btn-color-blue:hover { background: #2563eb; }
/* Progress Bar */
.progress-container {
width: 100%;
height: 6px;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 3px;
overflow: hidden;
margin-top: 1rem;
}
.progress-bar {
height: 100%;
background-color: #0f7dff;
transition: width 0.3s ease;
}
/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }
/* Status Indicator Pulse */
@keyframes pulse-status {
0% { box-shadow: 0 0 0 0 rgba(var(--status-color), 0.4); }
70% { box-shadow: 0 0 0 6px rgba(var(--status-color), 0); }
100% { box-shadow: 0 0 0 0 rgba(var(--status-color), 0); }
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-green { background-color: #22c55e; --status-color: 34, 197, 94; animation: pulse-status 2s infinite; }
.status-orange { background-color: #f59e0b; --status-color: 245, 158, 11; }
.status-red { background-color: #ef4444; }
.status-gray { background-color: #6b7280; }
/* Toast */
.toast-container { position: fixed; bottom: 1rem; right: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
padding: 0.75rem 1rem; border-radius: 0.375rem; background: #1e212f; border-left: 4px solid #0f7dff;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3); animation: slideIn 0.3s forwards, fadeOut 0.3s 2.7s forwards; min-width: 250px;
}
.toast.error { border-left-color: #ef4444; }
.toast.success { border-left-color: #22c55e; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
/* Tabs */
.tab-item {
padding: 0.75rem 1rem; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s;
display: flex; align-items: center; gap: 0.5rem; color: #94a3b8; font-weight: 500; white-space: nowrap;
}
.tab-item:hover { color: #e2e8f0; background: rgba(255,255,255,0.02); }
.tab-item.active { color: #0f7dff; border-bottom-color: #0f7dff; background: rgba(15, 125, 255, 0.05); }
/* Log Panel */
.log-panel {
transition: height 0.3s ease;
height: 40px; /* Collapsed */
}
.log-panel.expanded { height: 250px; }
/* Loading Spinner */
.spinner {
border: 3px solid rgba(255,255,255,0.1); border-radius: 50%; border-top: 3px solid #0f7dff;
width: 24px; height: 24px; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
</style>
</head>
<body class="h-screen flex flex-col overflow-hidden">
<!-- Toast Container -->
<div id="toastContainer" class="toast-container"></div>
<!-- Header -->
<header class="glass-panel z-40 px-6 py-3 flex justify-between items-center hidden shrink-0" id="appHeader">
<div class="flex items-center gap-3">
<div class="text-accent text-2xl">📺</div>
<h1 class="text-xl font-bold tracking-wide">LG Horizon <span class="font-light opacity-70">Test UI</span></h1>
</div>
<div class="flex items-center gap-4">
<div id="wsStatus" class="flex items-center gap-2 text-sm text-offline">
<span class="status-dot status-gray"></span> Disconnected
</div>
<button onclick="app.logout()" class="btn px-3 py-1.5 bg-red-500/10 text-red-400 hover:bg-red-500/20 rounded-md text-sm font-medium border border-red-500/20">
Logout
</button>
</div>
</header>
<!-- Main Content -->
<main class="flex-grow flex flex-col relative w-full h-full overflow-hidden" id="mainContainer">
<!-- ================= LOGIN SCREEN ================= -->
<div id="loginScreen" class="h-full flex items-center justify-center p-4">
<div class="glass-panel w-full max-w-md p-8 rounded-xl relative overflow-hidden">
<div class="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-accent to-purple-500"></div>
<div class="text-center mb-8">
<div class="text-5xl mb-4">📺</div>
<h2 class="text-2xl font-bold mb-1">LG Horizon</h2>
<p class="text-slate-400 text-sm">Python Library Test Tool</p>
</div>
<form id="loginForm" onsubmit="app.handleLogin(event)" class="space-y-5">
<div id="loginErrorMsg" class="hidden bg-red-500/10 border border-red-500/30 text-red-400 p-3 rounded-md text-sm mb-4"></div>
<div>
<label class="block text-sm font-medium text-slate-300 mb-1">Provider / Country</label>
<select id="countrySelect" onchange="app.updateLoginForm()" class="input-field w-full rounded-md p-2.5 text-sm" required>
<option value="">Loading countries...</option>
</select>
</div>
<div id="userPassFields" class="space-y-5 hidden">
<div>
<label class="block text-sm font-medium text-slate-300 mb-1">Username</label>
<input type="text" id="usernameInput" class="input-field w-full rounded-md p-2.5 text-sm" placeholder="user@example.com">
</div>
<div>
<label class="block text-sm font-medium text-slate-300 mb-1">Password</label>
<input type="password" id="passwordInput" class="input-field w-full rounded-md p-2.5 text-sm" placeholder="••••••••">
</div>
</div>
<div id="tokenField" class="hidden">
<label class="block text-sm font-medium text-slate-300 mb-1">Refresh Token</label>
<textarea id="tokenInput" class="input-field w-full rounded-md p-2.5 text-sm h-32 font-mono text-xs" placeholder="Paste refresh token here..."></textarea>
</div>
<button type="submit" id="loginBtn" class="btn w-full bg-accent hover:bg-accentHover text-white font-medium py-2.5 rounded-md mt-6 flex justify-center items-center gap-2">
<span>Connect to API</span>
<div id="loginSpinner" class="spinner hidden" style="width: 18px; height: 18px; border-width: 2px;"></div>
</button>
</form>
</div>
</div>
<!-- ================= DASHBOARD SCREEN ================= -->
<div id="dashboardScreen" class="hidden flex-col h-full overflow-hidden">
<!-- Account-level Recording Bar -->
<div id="recordingBar" class="bg-slate-900 border-b border-slate-700/50 px-4 py-2.5 shrink-0 flex flex-col md:flex-row items-start md:items-center justify-between gap-4 relative z-10 shadow-sm">
<div class="flex items-center gap-3 w-full md:w-auto shrink-0">
<h3 class="text-xs uppercase tracking-wider text-slate-400 font-bold whitespace-nowrap">Recording Capacity</h3>
<div id="recordingLoader" class="animate-spin h-3.5 w-3.5 border-2 border-accent border-t-transparent rounded-full hidden"></div>
<button onclick="app.fetchRecordingCapacity()" class="text-slate-500 hover:text-white transition-colors ml-auto md:ml-0" title="Refresh">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>
</button>
</div>
<div id="noRecordingMsg" class="hidden text-xs text-slate-500 italic w-full md:w-auto text-center md:text-left">
No recording features available
</div>
<div id="recordingContent" class="hidden w-full md:flex-1 flex flex-col md:flex-row items-start md:items-center gap-4 md:gap-6 justify-end">
<div class="flex flex-wrap gap-1.5 shrink-0" id="recordingFeatures">
<!-- Badges injected here -->
</div>
<!-- Cloud -->
<div id="cloudQuotaSection" class="hidden items-center gap-3 w-full md:w-64 shrink-0">
<span class="text-xs text-slate-400 font-medium whitespace-nowrap">Cloud</span>
<div class="flex-grow">
<div class="flex justify-between items-end text-[10px] mb-0.5">
<span id="cloudMb" class="text-slate-400">0 MB / 0 MB</span>
<span id="cloudPct" class="font-bold text-white">0%</span>
</div>
<div class="progress-container h-1.5">
<div id="cloudProgressBar" class="progress-bar rounded-full" style="width: 0%"></div>
</div>
</div>
</div>
<!-- Local -->
<div id="localQuotaSection" class="hidden items-center gap-3 w-full md:w-auto shrink-0 border-t md:border-t-0 md:border-l border-slate-700/50 pt-2 md:pt-0 md:pl-4">
<span class="text-xs text-slate-400 font-medium whitespace-nowrap">Local</span>
<div id="localDevicesList" class="flex flex-wrap gap-3">
<!-- Local devices injected here -->
</div>
</div>
</div>
</div>
<!-- Tab Bar -->
<div class="bg-slate-900/80 border-b border-slate-700/50 overflow-x-auto shrink-0 flex items-end px-4" id="tabContainer">
<!-- Tabs injected here -->
</div>
<!-- Active Device View Container -->
<div class="flex-grow overflow-y-auto p-4 lg:p-6" id="deviceViewContainer">
<div id="noDeviceView" class="h-full flex items-center justify-center text-slate-500">
Select a device to view controls.
</div>
<div id="activeDeviceView" class="hidden max-w-5xl mx-auto grid grid-cols-1 lg:grid-cols-12 gap-6 pb-20">
<!-- Left Column: Status & Now Playing -->
<div class="lg:col-span-5 flex flex-col gap-6">
<!-- Header Card -->
<div class="glass-panel p-5 rounded-xl border border-slate-700/50 relative overflow-hidden">
<div class="flex justify-between items-start z-10 relative">
<div>
<div class="flex items-center gap-2 mb-1">
<span id="devStatusDot" class="status-dot"></span>
<h2 id="devName" class="text-2xl font-bold tracking-tight"></h2>
</div>
<div class="text-sm text-slate-400 font-mono flex items-center gap-2">
<span id="devModel"></span>
<span class="text-slate-600">|</span>
<span id="devStateBadge" class="text-xs px-2 py-0.5 rounded bg-slate-800 border border-slate-700"></span>
</div>
</div>
<button onclick="app.sendKey('Power')" id="powerBtn" class="btn btn-control w-12 h-12 rounded-full border-2 transition-colors flex shrink-0" title="Power Toggle">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"></path><line x1="12" y1="2" x2="12" y2="12"></line></svg>
</button>
</div>
</div>
<!-- Now Playing Card -->
<div class="glass-panel p-4 rounded-xl border border-slate-700/50 flex flex-col">
<h3 class="text-xs uppercase tracking-wider text-slate-500 font-bold mb-3">Now Playing</h3>
<div id="nowPlayingContent" class="hidden flex-col gap-3">
<div class="relative w-full aspect-video rounded-lg overflow-hidden bg-black/50 border border-slate-700">
<img id="npImage" src="" class="w-full h-full object-cover">
<div id="npAppBadge" class="hidden absolute top-2 right-2 bg-black/70 backdrop-blur text-[10px] px-2 py-0.5 rounded font-medium border border-white/10"></div>
</div>
<div>
<div id="npChannel" class="text-accent text-sm font-semibold uppercase tracking-wider truncate"></div>
<div id="npTitle" class="text-lg font-bold text-white leading-tight mt-1"></div>
<div id="npEpisode" class="text-sm text-slate-400 mt-1"></div>
</div>
<div id="npProgressWrap" class="mt-2">
<div class="flex justify-between text-xs text-slate-400 font-mono mb-1">
<span id="npTimeCurrent">0:00</span>
<span id="npSpeedBadge" class="hidden bg-accent/20 text-accent px-1 rounded text-[10px]">x1</span>
<span id="npTimeTotal">0:00</span>
</div>
<div class="progress-container">
<div id="npProgressBar" class="progress-bar rounded-r" style="width: 0%"></div>
</div>
</div>
</div>
<div id="noContentMsg" class="py-8 text-center text-slate-500 italic">
No content playing
</div>
</div>
<!-- Message & Channel -->
<div class="glass-panel p-4 rounded-xl border border-slate-700/50 space-y-4">
<div class="flex flex-col gap-1.5">
<label class="text-xs text-slate-400 uppercase tracking-wider font-bold">Switch Channel</label>
<div class="flex gap-2">
<select id="channelSelect" class="input-field flex-grow text-sm rounded-md p-2 h-10">
<!-- Populated dynamically -->
</select>
<button onclick="app.setChannel()" class="btn btn-control w-10 h-10 text-accent">▶</button>
</div>
</div>
<div class="flex flex-col gap-1.5">
<label class="text-xs text-slate-400 uppercase tracking-wider font-bold">Send Message</label>
<div class="flex gap-2">
<input type="text" id="msgInput" class="input-field flex-grow text-sm rounded-md p-2 h-10" placeholder="Hello TV...">
<button onclick="app.sendMessage()" class="btn btn-control w-10 h-10 text-accent">✉</button>
</div>
</div>
</div>
</div>
<!-- Right Column: Remote Control -->
<div class="lg:col-span-7 flex justify-center">
<div class="glass-panel p-6 rounded-[2rem] border border-slate-700/50 w-full max-w-sm flex flex-col gap-8 bg-slate-900 shadow-2xl">
<!-- Remote: Top Extra -->
<div class="flex justify-between px-2">
<button class="btn btn-control w-10 h-8 rounded text-xs" onclick="app.sendKey('Standby')">STB</button>
<button class="btn btn-control w-10 h-8 rounded text-xs" onclick="app.sendKey('WakeUp')">WAKE</button>
<button class="btn btn-control w-10 h-8 rounded text-xs" onclick="app.sendKey('NextUserProfile')">USR</button>
</div>
<!-- Remote: Media Playback -->
<div class="flex justify-center gap-2 bg-slate-800/50 p-3 rounded-full border border-slate-700/50">
<button class="btn btn-control w-10 h-10 rounded-full" onclick="app.sendKey('MediaRewind')">⏪</button>
<button class="btn btn-control w-10 h-10 rounded-full" onclick="app.sendKey('MediaPlay')">▶</button>
<button class="btn btn-control w-10 h-10 rounded-full" onclick="app.sendKey('MediaPause')">⏸</button>
<button class="btn btn-control w-10 h-10 rounded-full" onclick="app.sendKey('MediaStop')">⏹</button>
<button class="btn btn-control w-10 h-10 rounded-full" onclick="app.sendKey('MediaFastForward')">⏩</button>
<button class="btn btn-control w-10 h-10 rounded-full text-red-400" onclick="app.sendKey('MediaRecord')">⏺</button>
</div>
<!-- Remote: Navigation / Quick Actions -->
<div class="grid grid-cols-3 gap-3 text-sm font-medium px-4">
<button class="btn btn-control py-2 rounded-lg" onclick="app.sendKey('MediaTopMenu')">Home</button>
<button class="btn btn-control py-2 rounded-lg" onclick="app.sendKey('Guide')">Guide</button>
<button class="btn btn-control py-2 rounded-lg" onclick="app.sendKey('TV')">TV</button>
<button class="btn btn-control py-2 rounded-lg" onclick="app.sendKey('Info')">Info</button>
<button class="btn btn-control py-2 rounded-lg" onclick="app.sendKey('ContextMenu')">Menu</button>
<button class="btn btn-control py-2 rounded-lg" onclick="app.sendKey('Escape')">Back</button>
</div>
<!-- Remote: D-Pad & Volume/Channel -->
<div class="flex justify-between items-center px-2">
<div class="flex flex-col gap-2 bg-slate-800/30 p-2 rounded-full border border-slate-700/30">
<button class="btn btn-control w-10 h-12 rounded-t-full font-bold" onclick="app.sendKey('ChannelUp')">CH+</button>
<div class="h-px bg-slate-700 w-full"></div>
<button class="btn btn-control w-10 h-12 rounded-b-full font-bold" onclick="app.sendKey('ChannelDown')">CH-</button>
</div>
<div class="d-pad-grid">
<div></div>
<button class="btn btn-control w-14 h-14 rounded-t-xl bg-slate-800" onclick="app.sendKey('ArrowUp')">▲</button>
<div></div>
<button class="btn btn-control w-14 h-14 rounded-l-xl bg-slate-800" onclick="app.sendKey('ArrowLeft')">◀</button>
<button class="btn btn-control w-14 h-14 rounded-full bg-slate-700 text-white font-bold shadow-inner" onclick="app.sendKey('Enter')">OK</button>
<button class="btn btn-control w-14 h-14 rounded-r-xl bg-slate-800" onclick="app.sendKey('ArrowRight')">▶</button>
<div></div>
<button class="btn btn-control w-14 h-14 rounded-b-xl bg-slate-800" onclick="app.sendKey('ArrowDown')">▼</button>
<div></div>
</div>
<div class="flex flex-col gap-2 bg-slate-800/30 p-2 rounded-full border border-slate-700/30 opacity-50 cursor-not-allowed" title="Volume usually controlled via TV, not box">
<button class="btn w-10 h-12 rounded-t-full font-bold">V+</button>
<div class="h-px bg-slate-700 w-full"></div>
<button class="btn w-10 h-12 rounded-b-full font-bold">V-</button>
</div>
</div>
<!-- Remote: Colors -->
<div class="flex justify-center gap-4 px-4">
<button class="btn btn-control btn-color-red w-12 h-6 rounded-full" onclick="app.sendKey('Red')"></button>
<button class="btn btn-control btn-color-green w-12 h-6 rounded-full" onclick="app.sendKey('Green')"></button>
<button class="btn btn-control btn-color-yellow w-12 h-6 rounded-full" onclick="app.sendKey('Yellow')"></button>
<button class="btn btn-control btn-color-blue w-12 h-6 rounded-full" onclick="app.sendKey('Blue')"></button>
</div>
<!-- Remote: Numpad -->
<div class="numpad-grid mb-4">
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('1')">1</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('2')">2</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('3')">3</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('4')">4</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('5')">5</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('6')">6</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('7')">7</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('8')">8</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('9')">9</button>
<button class="btn btn-control h-12 rounded-full text-xs" onclick="app.sendKey('Subtitle')">SUB</button>
<button class="btn btn-control h-12 rounded-full text-lg font-mono" onclick="app.sendKey('0')">0</button>
<button class="btn btn-control h-12 rounded-full text-xs" onclick="app.sendKey('AudioTrack')">AUD</button>
</div>
</div>
</div>
</div>
</div>
<!-- Event Log (Collapsible Bottom Panel) -->
<div id="logPanel" class="glass-panel log-panel shrink-0 border-t border-slate-700/50 flex flex-col absolute bottom-0 w-full z-50">
<div class="px-4 h-[40px] flex justify-between items-center cursor-pointer bg-slate-800/80 hover:bg-slate-700/80 transition-colors" onclick="app.toggleLog()">
<h3 class="text-sm font-medium flex items-center gap-2">
<span class="text-accent">⚡</span> Event Log <span id="logCounter" class="bg-accent text-white text-[10px] px-1.5 rounded-full hidden">0</span>
</h3>
<div class="flex gap-4 items-center">
<button onclick="event.stopPropagation(); app.clearLog()" class="text-xs text-slate-400 hover:text-white transition-colors">Clear</button>
<span id="logChevron" class="text-slate-400 transform transition-transform">▲</span>
</div>
</div>
<div id="eventLog" class="p-4 overflow-y-auto flex-grow font-mono text-xs space-y-1.5 text-slate-300 bg-background/90 backdrop-blur">
<!-- Logs injected here -->
</div>
</div>
</div>
</main>
<script>
const app = {
state: {
countries: [],
channels: [],
devices: {},
keys: {},
activeDeviceId: null,
ws: null,
isLoggedIn: false,
logExpanded: false,
unreadLogs: 0
},
init() {
this.mockApiIfLocal();
this.loadSavedCredentials();
this.fetchCountries();
this.checkSession();
},
// --- API & Auth ---
loadSavedCredentials() {
const savedUser = localStorage.getItem('lg_username');
const savedCountry = localStorage.getItem('lg_country');
if(savedUser) document.getElementById('usernameInput').value = savedUser;
// Country selected after fetch
this.state.savedCountry = savedCountry;
},
async fetchCountries() {
try {
const res = await fetch('/api/countries');
if (!res.ok) throw new Error('Fetch failed');
const data = await res.json();
this.state.countries = data.countries || [];
this.renderCountrySelect();
} catch (e) {
this.showToast('Failed to load providers.', 'error');
}
},
renderCountrySelect() {
const select = document.getElementById('countrySelect');
select.innerHTML = '<option value="" disabled selected>Select Provider...</option>';
this.state.countries.forEach(c => {
const opt = document.createElement('option');
opt.value = c.code;
opt.dataset.useToken = c.use_refreshtoken;
opt.textContent = `${c.name} (${c.code.toUpperCase()})`;
select.appendChild(opt);
});
if (this.state.savedCountry) {
select.value = this.state.savedCountry;
this.updateLoginForm();
}
},
updateLoginForm() {
const select = document.getElementById('countrySelect');
if(!select.value) return;
const useToken = select.options[select.selectedIndex].dataset.useToken === 'true';
document.getElementById('userPassFields').classList.toggle('hidden', useToken);
document.getElementById('tokenField').classList.toggle('hidden', !useToken);
},
async checkSession() {
try {
const res = await fetch('/api/status');
const data = await res.json();
if (data.connected) {
this.handleLoginSuccess(data);
}
} catch(e) {} // Not logged in
},
async handleLogin(e) {
e.preventDefault();
const select = document.getElementById('countrySelect');
if(!select.value) return;
const country = select.value;
const useToken = select.options[select.selectedIndex].dataset.useToken === 'true';
const payload = { country };
if (useToken) {
payload.refresh_token = document.getElementById('tokenInput').value;
} else {
payload.username = document.getElementById('usernameInput').value;
payload.password = document.getElementById('passwordInput').value;
localStorage.setItem('lg_username', payload.username);
}
localStorage.setItem('lg_country', country);
this.setLoginLoading(true);
try {
const res = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await res.json();
if (data.success) {
this.handleLoginSuccess(data);
} else {
this.showLoginError(data.error || "Login failed");
}
} catch (err) {
this.showLoginError("Connection error.");
} finally {
this.setLoginLoading(false);
}
},
handleLoginSuccess(data) {
this.state.isLoggedIn = true;
this.state.channels = data.channels || [];
if (data.keys) this.state.keys = data.keys;
if (data.devices) {
data.devices.forEach(d => { this.state.devices[d.device_id] = d; });
}
document.getElementById('loginScreen').classList.add('hidden');
document.getElementById('appHeader').classList.remove('hidden');
document.getElementById('dashboardScreen').classList.remove('hidden');
document.getElementById('dashboardScreen').classList.add('flex');
this.addLogEntry("System", "Connected to API", "success");
this.populateChannelSelect();
this.renderTabs();
// Select first device if none active
if (!this.state.activeDeviceId && data.devices && data.devices.length > 0) {
this.setActiveDevice(data.devices[0].device_id);
}
this.connectWebSocket();
this.fetchRecordingCapacity();
},
async fetchRecordingCapacity() {
const loader = document.getElementById('recordingLoader');
const content = document.getElementById('recordingContent');
const noMsg = document.getElementById('noRecordingMsg');
if (loader) {
loader.classList.remove('hidden');
content.classList.add('hidden');
content.classList.remove('flex');
noMsg.classList.add('hidden');
}
try {
const res = await fetch('/api/recording-capacity');
if (res.ok) {
const data = await res.json();
this.renderRecordingCapacity(data);
} else {
throw new Error('Failed to fetch');
}
} catch (e) {
if (loader) loader.classList.add('hidden');
if (noMsg) {
noMsg.textContent = 'Failed to load recording info';
noMsg.classList.remove('hidden');
}
}
},
renderRecordingCapacity(data) {
const loader = document.getElementById('recordingLoader');
const content = document.getElementById('recordingContent');
const noMsg = document.getElementById('noRecordingMsg');
if (loader) loader.classList.add('hidden');
if (!data.entitlements || !data.entitlements.has_recording) {
if (noMsg) {
noMsg.textContent = 'No recording features available';
noMsg.classList.remove('hidden');
}
if (content) {
content.classList.add('hidden');
content.classList.remove('flex');
}
return;
}
if (noMsg) noMsg.classList.add('hidden');
if (content) {
content.classList.remove('hidden');
content.classList.add('flex');
}
// Features badges
const featuresContainer = document.getElementById('recordingFeatures');
if (featuresContainer) {
featuresContainer.innerHTML = '';
if (data.entitlements.features) {
data.entitlements.features
.filter(f => ['PVR', 'LOCALDVR'].includes(f.toUpperCase()))
.forEach(f => {
const badge = document.createElement('span');
badge.className = 'text-[10px] px-1.5 py-0.5 rounded bg-slate-800 border border-slate-700 text-slate-300 font-medium';
badge.textContent = f;
featuresContainer.appendChild(badge);
});
}
}
// Cloud Quota
const cloudSection = document.getElementById('cloudQuotaSection');
if (cloudSection) {
if (data.entitlements.has_pvr && data.cloud_quota) {
cloudSection.classList.remove('hidden');
cloudSection.classList.add('flex');
const pct = data.cloud_quota.percentage_used || 0;
document.getElementById('cloudPct').textContent = `${pct.toFixed(1)}%`;
// Show in GB if large enough, else MB
let occ = data.cloud_quota.occupied_mb;
let total = data.cloud_quota.quota_mb;
let unit = 'MB';
if (total > 1024) {
occ = (occ / 1024).toFixed(1);
total = (total / 1024).toFixed(1);
unit = 'GB';
}
document.getElementById('cloudMb').textContent = `${occ} ${unit} / ${total} ${unit}`;
const bar = document.getElementById('cloudProgressBar');
if (bar) {
bar.style.width = `${Math.min(100, Math.max(0, pct))}%`;
// Colors
bar.className = 'progress-bar rounded-full transition-all duration-500';
if (pct > 90) bar.style.backgroundColor = 'var(--danger, #ef4444)';
else if (pct > 75) bar.style.backgroundColor = 'var(--warning, #f59e0b)';
else bar.style.backgroundColor = 'var(--accent, #0f7dff)';
}
} else {
cloudSection.classList.add('hidden');
cloudSection.classList.remove('flex');
}
}
// Local Devices
const localSection = document.getElementById('localQuotaSection');
const localList = document.getElementById('localDevicesList');
if (localSection && localList) {
localList.innerHTML = '';
if (data.entitlements.has_local_dvr && data.local_devices && Object.keys(data.local_devices).length > 0) {
localSection.classList.remove('hidden');
localSection.classList.add('flex');
Object.values(data.local_devices).forEach(dev => {
const row = document.createElement('div');
row.className = 'flex items-center gap-1.5 text-xs bg-slate-800/50 border border-slate-700/50 px-2 py-1 rounded';
const nameSpan = document.createElement('span');
nameSpan.className = 'text-slate-400';
nameSpan.textContent = dev.name || 'Device';
const valSpan = document.createElement('span');
if (dev.local_recording_capacity_used !== null && dev.local_recording_capacity_used !== undefined) {
valSpan.className = 'font-mono text-white font-medium';
valSpan.textContent = `${dev.local_recording_capacity_used}%`;
} else {
valSpan.className = 'text-slate-500 italic text-[10px]';
valSpan.textContent = 'waiting...';
}
row.appendChild(nameSpan);
row.appendChild(valSpan);
localList.appendChild(row);
});
} else {
localSection.classList.add('hidden');
localSection.classList.remove('flex');
}
}
},
async logout() {
try { await fetch('/api/logout', { method: 'POST' }); } catch(e) {}
if (this.state.ws) this.state.ws.close();
this.state.isLoggedIn = false;
this.state.devices = {};
this.state.activeDeviceId = null;
document.getElementById('loginScreen').classList.remove('hidden');
document.getElementById('appHeader').classList.add('hidden');
document.getElementById('dashboardScreen').classList.add('hidden');
document.getElementById('dashboardScreen').classList.remove('flex');
this.addLogEntry("System", "Logged out");
},
// --- UI Rendering ---
renderTabs() {
const container = document.getElementById('tabContainer');
container.innerHTML = '';
Object.values(this.state.devices).forEach(dev => {
const tab = document.createElement('div');
tab.className = `tab-item ${this.state.activeDeviceId === dev.device_id ? 'active' : ''}`;
tab.onclick = () => this.setActiveDevice(dev.device_id);
const color = this.getStatusColorClass(dev.state);
tab.innerHTML = `<span class="status-dot ${color}"></span> ${dev.name || 'Device'}`;
container.appendChild(tab);
});
},
setActiveDevice(deviceId) {
this.state.activeDeviceId = deviceId;
this.renderTabs();
this.updateActiveDeviceView();
},
updateActiveDeviceView() {
const dev = this.state.devices[this.state.activeDeviceId];
const noView = document.getElementById('noDeviceView');
const activeView = document.getElementById('activeDeviceView');
if (!dev) {
noView.classList.remove('hidden');
activeView.classList.add('hidden');
return;
}
noView.classList.add('hidden');
activeView.classList.remove('hidden');
activeView.classList.add('grid');
// Header
document.getElementById('devName').textContent = dev.name;
document.getElementById('devModel').textContent = `${dev.manufacturer || ''} ${dev.model || ''}`;
document.getElementById('devStateBadge').textContent = dev.state;
const dot = document.getElementById('devStatusDot');
dot.className = 'status-dot ' + this.getStatusColorClass(dev.state);
// Power Btn styling
const pwrBtn = document.getElementById('powerBtn');
if (dev.state === 'ONLINE_RUNNING') {
pwrBtn.className = 'btn btn-control w-12 h-12 rounded-full border-2 text-success border-success bg-success/10';
} else {
pwrBtn.className = 'btn btn-control w-12 h-12 rounded-full border-2 text-slate-400 border-slate-700 bg-slate-800 hover:text-white hover:border-accent';
}
// Now Playing
const isOnline = dev.state === 'ONLINE_RUNNING';
const hasContent = isOnline && (dev.channel_name || dev.show_title || dev.app_name);
const npContent = document.getElementById('nowPlayingContent');
const noContentMsg = document.getElementById('noContentMsg');
if (hasContent) {
npContent.classList.remove('hidden');
npContent.classList.add('flex');
noContentMsg.classList.add('hidden');
const img = document.getElementById('npImage');
img.src = dev.image || 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="%23334155" stroke-width="1"><rect x="2" y="7" width="20" height="15" rx="2" ry="2"></rect><polyline points="17 2 12 7 7 2"></polyline></svg>';
document.getElementById('npChannel').textContent = dev.channel_name || '';
document.getElementById('npTitle').textContent = dev.show_title || dev.app_name || '';
let epStr = '';
if (dev.season_number) epStr += `S${dev.season_number.toString().padStart(2, '0')} `;
if (dev.episode_number) epStr += `E${dev.episode_number.toString().padStart(2, '0')} `;
if (dev.episode_title) epStr += `- ${dev.episode_title}`;
document.getElementById('npEpisode').textContent = epStr;
const badge = document.getElementById('npAppBadge');
if (dev.media_type === 'app' && dev.app_name) {
badge.textContent = dev.app_name;
badge.classList.remove('hidden');
} else {
badge.classList.add('hidden');
}
// Progress
const progWrap = document.getElementById('npProgressWrap');
if (dev.duration > 0 && dev.position >= 0) {
progWrap.classList.remove('hidden');
document.getElementById('npTimeCurrent').textContent = this.formatTime(dev.position);
document.getElementById('npTimeTotal').textContent = this.formatTime(dev.duration);
const pct = Math.min(100, Math.max(0, (dev.position / dev.duration) * 100));
document.getElementById('npProgressBar').style.width = `${pct}%`;
} else {
progWrap.classList.add('hidden');
}
// Speed
const spd = document.getElementById('npSpeedBadge');
if(dev.speed !== undefined && dev.speed !== 1) {
spd.textContent = `x${dev.speed}`;
spd.classList.remove('hidden');
} else {
spd.classList.add('hidden');
}
} else {
npContent.classList.add('hidden');
npContent.classList.remove('flex');
noContentMsg.classList.remove('hidden');
if(dev.state === 'OFFLINE') noContentMsg.textContent = 'Device is offline';
else if (dev.state === 'ONLINE_STANDBY') noContentMsg.textContent = 'Device is in standby';
else noContentMsg.textContent = 'No content available';
}
},
populateChannelSelect() {
const select = document.getElementById('channelSelect');
select.innerHTML = '<option value="" disabled selected>Select channel...</option>';
this.state.channels.forEach(ch => {
const opt = document.createElement('option');
opt.value = ch.number || ch.title;
opt.textContent = `${ch.number ? ch.number+'. ' : ''}${ch.title}`;
select.appendChild(opt);
});
},
getStatusColorClass(state) {
switch(state) {
case 'ONLINE_RUNNING': return 'status-green';
case 'ONLINE_STANDBY': return 'status-orange';
case 'OFFLINE': return 'status-red';
default: return 'status-gray';
}
},
formatTime(seconds) {
if (!seconds || isNaN(seconds)) return "0:00";
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.floor(seconds % 60);
if (h > 0) return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
return `${m}:${s.toString().padStart(2, '0')}`;
},
// --- WebSockets ---
connectWebSocket() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//${window.location.host}/ws`;
this.updateWsStatus('connecting');
try {
this.state.ws = new WebSocket(wsUrl);
this.state.ws.onopen = () => {
this.updateWsStatus('connected');
this.addLogEntry("System", "WebSocket connected");
};
this.state.ws.onmessage = (event) => {
try {
const msg = JSON.parse(event.data);
if (msg.type === 'state_change' && msg.device) {
this.state.devices[msg.device.device_id] = msg.device;
this.logDeviceStateChange(msg.device);
if (this.state.activeDeviceId === msg.device.device_id) {
this.updateActiveDeviceView();
}
this.renderTabs(); // update dots
} else if (msg.type === 'disconnected') {
this.addLogEntry("System", "Disconnected by backend", "error");
this.showToast("Connection to provider lost", "error");
}
} catch (e) {}
};
this.state.ws.onclose = () => {
this.updateWsStatus('disconnected');
if (this.state.isLoggedIn) setTimeout(() => this.connectWebSocket(), 5000);
};
} catch(e) {}
},
updateWsStatus(status) {
const el = document.getElementById('wsStatus');
if (status === 'connected') {
el.innerHTML = '<span class="status-dot status-green"></span> Live';
el.className = 'flex items-center gap-2 text-sm text-success font-medium';
} else if (status === 'connecting') {
el.innerHTML = '<span class="status-dot status-orange"></span> Connecting';
el.className = 'flex items-center gap-2 text-sm text-warning';
} else {
el.innerHTML = '<span class="status-dot status-gray"></span> Offline';
el.className = 'flex items-center gap-2 text-sm text-offline';
}
},
// --- Commands ---
async sendCommand(command, params = {}) {
if(!this.state.activeDeviceId) return;
const dev = this.state.devices[this.state.activeDeviceId];
// Override power button if needed based on state
if (command === 'send_key' && params.key === 'Power') {
if (dev.state === 'ONLINE_RUNNING') command = 'turn_off';
else command = 'turn_on';
delete params.key;
}
const payload = { device_id: this.state.activeDeviceId, command, ...params };
try {