@xiboplayer/pwa 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/dist/assets/cache-proxy-Cx4Z8XMC.js +2 -0
- package/dist/assets/cache-proxy-Cx4Z8XMC.js.map +1 -0
- package/dist/assets/cms-api-kzy_Sw-u.js +2 -0
- package/dist/assets/cms-api-kzy_Sw-u.js.map +1 -0
- package/dist/assets/html2canvas.esm-CBrSDip1.js +23 -0
- package/dist/assets/html2canvas.esm-CBrSDip1.js.map +1 -0
- package/dist/assets/index-BEhNaWZ4.js +2 -0
- package/dist/assets/index-BEhNaWZ4.js.map +1 -0
- package/dist/assets/index-BPNsrSEv.js +2 -0
- package/dist/assets/index-BPNsrSEv.js.map +1 -0
- package/dist/assets/index-BY2j60YZ.js +2 -0
- package/dist/assets/index-BY2j60YZ.js.map +1 -0
- package/dist/assets/index-CTmjUTVM.js +8 -0
- package/dist/assets/index-CTmjUTVM.js.map +1 -0
- package/dist/assets/index-_q2HbdAU.js +2 -0
- package/dist/assets/index-_q2HbdAU.js.map +1 -0
- package/dist/assets/index-_uzldOpz.js +16 -0
- package/dist/assets/index-_uzldOpz.js.map +1 -0
- package/dist/assets/main-C4ABDfkq.js +27 -0
- package/dist/assets/main-C4ABDfkq.js.map +1 -0
- package/dist/assets/modulepreload-polyfill-B5Qt9EMX.js +2 -0
- package/dist/assets/modulepreload-polyfill-B5Qt9EMX.js.map +1 -0
- package/dist/assets/pdf-BnPRJEQ6.js +13 -0
- package/dist/assets/pdf-BnPRJEQ6.js.map +1 -0
- package/dist/assets/setup-rqZh5qYs.js +2 -0
- package/dist/assets/setup-rqZh5qYs.js.map +1 -0
- package/dist/index.html +130 -0
- package/dist/setup.html +371 -0
- package/dist/sw-pwa.js +2 -0
- package/dist/sw-pwa.js.map +1 -0
- package/dist/sw-utils.js +210 -0
- package/dist/sw.test.js +271 -0
- package/package.json +39 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./modulepreload-polyfill-B5Qt9EMX.js";import{a as t,C as v}from"./cms-api-kzy_Sw-u.js";import{XmdsClient as y}from"./index-_uzldOpz.js";const C=document.getElementById("setup-form"),d=document.getElementById("error"),c=document.getElementById("submit-btn"),f=document.getElementById("phase-setup"),h=document.getElementById("phase-waiting"),g=document.getElementById("countdown"),B=document.getElementById("waiting-display-name"),b=document.getElementById("btn-back"),x=document.getElementById("success-flash"),p=t.hardwareKey;document.getElementById("hw-key-display").textContent=p;document.getElementById("hw-key-waiting").textContent=p;let r=null,i=null,w=15;function I(e){f.classList.remove("active"),h.classList.remove("active"),e.classList.add("active")}function k(e){d.textContent=e,d.style.display="block"}function A(){d.style.display="none"}function u(){let e=w;g.textContent=e,clearInterval(i),i=setInterval(()=>{e--,g.textContent=Math.max(0,e),e<=0&&clearInterval(i)},1e3)}function m(){x.classList.add("active"),setTimeout(()=>{window.location.href="./index.html"},800)}async function S(){try{const n=await new y(t).registerDisplay();if(console.log("[Setup] Poll result:",n.code,n.message),n.code==="READY"){clearInterval(r),clearInterval(i),m();return}u()}catch(e){console.warn("[Setup] Poll failed:",e.message),u()}}function E(e){B.textContent=e,I(h),u(),r=setInterval(S,w*1e3)}function D(){clearInterval(r),clearInterval(i),r=null}async function K(e,n){const s=document.getElementById("api-client-id").value.trim(),o=document.getElementById("api-client-secret").value.trim();if(!s||!o)return!1;try{const a=new v({baseUrl:e,clientId:s,clientSecret:o});await a.authenticate();const l=await a.findDisplay(n);return l?l.licensed===1?(console.log("[Setup] Display already authorized"),!0):(await a.authorizeDisplay(l.displayId),console.log("[Setup] Display auto-authorized via API!"),t.apiClientId=s,t.apiClientSecret=o,!0):(console.log("[Setup] Display not found via API (may not be registered yet)"),!1)}catch(a){return console.warn("[Setup] Auto-authorize failed:",a.message),!1}}t.isConfigured()&&(document.getElementById("cms-address").value=t.cmsAddress,document.getElementById("cms-key").value=t.cmsKey,document.getElementById("display-name").value=t.displayName);t.apiClientId&&(document.getElementById("api-client-id").value=t.apiClientId,document.getElementById("api-client-secret").value=t.apiClientSecret||"");C.addEventListener("submit",async e=>{e.preventDefault(),A();const n=document.getElementById("cms-address").value.trim().replace(/\/$/,""),s=document.getElementById("cms-key").value.trim(),o=document.getElementById("display-name").value.trim();t.cmsAddress=n,t.cmsKey=s,t.displayName=o,z(t.hardwareKey);try{c.textContent="Connecting...",c.disabled=!0;const a=new y(t);if((await a.registerDisplay()).code==="READY")m();else{if(c.textContent="Authorizing...",await K(n,p)&&(await a.registerDisplay()).code==="READY"){m();return}E(o)}}catch(a){k(`Connection failed: ${a.message}`),c.textContent="Connect",c.disabled=!1}});b.addEventListener("click",()=>{D(),I(f),c.textContent="Connect",c.disabled=!1});async function z(e){try{const n=indexedDB.open("xibo-hw-backup",1);n.onupgradeneeded=()=>{const s=n.result;s.objectStoreNames.contains("keys")||s.createObjectStore("keys")},n.onsuccess=()=>{const s=n.result,o=s.transaction("keys","readwrite");o.objectStore("keys").put(e,"hardwareKey"),o.oncomplete=()=>s.close()}}catch(n){console.warn("[Setup] IndexedDB backup failed:",n)}}c.disabled=!1;c.textContent="Connect";t.isConfigured()&&(async()=>{try{(await new y(t).registerDisplay()).code==="READY"?window.location.href="./index.html":E(t.displayName)}catch{console.log("[Setup] Auto-check failed, showing form")}})();
|
|
2
|
+
//# sourceMappingURL=setup-rqZh5qYs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-rqZh5qYs.js","sources":["../../setup.html?html-proxy&index=1.js"],"sourcesContent":["\n import { config, CmsApiClient } from '@xiboplayer/utils';\n import { XmdsClient } from '@xiboplayer/xmds';\n\n // ── Elements ──\n const form = document.getElementById('setup-form');\n const errorEl = document.getElementById('error');\n const submitBtn = document.getElementById('submit-btn');\n const phaseSetup = document.getElementById('phase-setup');\n const phaseWaiting = document.getElementById('phase-waiting');\n const countdownEl = document.getElementById('countdown');\n const waitingNameEl = document.getElementById('waiting-display-name');\n const btnBack = document.getElementById('btn-back');\n const successFlash = document.getElementById('success-flash');\n\n // Show hardware key\n const hwKey = config.hardwareKey;\n document.getElementById('hw-key-display').textContent = hwKey;\n document.getElementById('hw-key-waiting').textContent = hwKey;\n\n // ── State ──\n let pollTimer = null;\n let countdownTimer = null;\n let pollSeconds = 15;\n\n // ── Helpers ──\n function showPhase(phase) {\n phaseSetup.classList.remove('active');\n phaseWaiting.classList.remove('active');\n phase.classList.add('active');\n }\n\n function showError(msg) {\n errorEl.textContent = msg;\n errorEl.style.display = 'block';\n }\n\n function hideError() {\n errorEl.style.display = 'none';\n }\n\n function startCountdown() {\n let remaining = pollSeconds;\n countdownEl.textContent = remaining;\n clearInterval(countdownTimer);\n countdownTimer = setInterval(() => {\n remaining--;\n countdownEl.textContent = Math.max(0, remaining);\n if (remaining <= 0) clearInterval(countdownTimer);\n }, 1000);\n }\n\n function showSuccess() {\n successFlash.classList.add('active');\n setTimeout(() => {\n window.location.href = './index.html';\n }, 800);\n }\n\n // ── Authorization Polling ──\n async function checkAuthorization() {\n try {\n const xmds = new XmdsClient(config);\n const result = await xmds.registerDisplay();\n console.log('[Setup] Poll result:', result.code, result.message);\n\n if (result.code === 'READY') {\n // Authorized!\n clearInterval(pollTimer);\n clearInterval(countdownTimer);\n showSuccess();\n return;\n }\n\n // Still waiting — restart countdown\n startCountdown();\n } catch (error) {\n console.warn('[Setup] Poll failed:', error.message);\n startCountdown();\n }\n }\n\n function startPolling(displayName) {\n waitingNameEl.textContent = displayName;\n showPhase(phaseWaiting);\n startCountdown();\n pollTimer = setInterval(checkAuthorization, pollSeconds * 1000);\n }\n\n function stopPolling() {\n clearInterval(pollTimer);\n clearInterval(countdownTimer);\n pollTimer = null;\n }\n\n // ── Auto-authorize via CMS API ──\n async function tryAutoAuthorize(cmsAddress, hardwareKey) {\n const clientId = document.getElementById('api-client-id').value.trim();\n const clientSecret = document.getElementById('api-client-secret').value.trim();\n if (!clientId || !clientSecret) return false;\n\n try {\n const api = new CmsApiClient({ baseUrl: cmsAddress, clientId, clientSecret });\n await api.authenticate();\n\n const display = await api.findDisplay(hardwareKey);\n if (!display) {\n console.log('[Setup] Display not found via API (may not be registered yet)');\n return false;\n }\n\n if (display.licensed === 1) {\n console.log('[Setup] Display already authorized');\n return true;\n }\n\n // Auto-authorize\n await api.authorizeDisplay(display.displayId);\n console.log('[Setup] Display auto-authorized via API!');\n\n // Save API credentials for future use\n config.apiClientId = clientId;\n config.apiClientSecret = clientSecret;\n\n return true;\n } catch (error) {\n console.warn('[Setup] Auto-authorize failed:', error.message);\n return false;\n }\n }\n\n // ── Pre-fill if already configured ──\n if (config.isConfigured()) {\n document.getElementById('cms-address').value = config.cmsAddress;\n document.getElementById('cms-key').value = config.cmsKey;\n document.getElementById('display-name').value = config.displayName;\n }\n // Pre-fill API credentials if saved\n if (config.apiClientId) {\n document.getElementById('api-client-id').value = config.apiClientId;\n document.getElementById('api-client-secret').value = config.apiClientSecret || '';\n }\n\n // ── Form Submit ──\n form.addEventListener('submit', async (e) => {\n e.preventDefault();\n hideError();\n\n const cmsAddress = document.getElementById('cms-address').value.trim().replace(/\\/$/, '');\n const cmsKey = document.getElementById('cms-key').value.trim();\n const displayName = document.getElementById('display-name').value.trim();\n\n // Save config\n config.cmsAddress = cmsAddress;\n config.cmsKey = cmsKey;\n config.displayName = displayName;\n\n // Also backup hardware key to IndexedDB for stability\n backupHardwareKey(config.hardwareKey);\n\n // Test connection\n try {\n submitBtn.textContent = 'Connecting...';\n submitBtn.disabled = true;\n\n const xmds = new XmdsClient(config);\n const result = await xmds.registerDisplay();\n\n if (result.code === 'READY') {\n showSuccess();\n } else {\n // Try auto-authorize via CMS API if credentials provided\n submitBtn.textContent = 'Authorizing...';\n const autoAuthed = await tryAutoAuthorize(cmsAddress, hwKey);\n\n if (autoAuthed) {\n // Verify with XMDS\n const recheck = await xmds.registerDisplay();\n if (recheck.code === 'READY') {\n showSuccess();\n return;\n }\n }\n\n // Not authorized yet — switch to polling phase\n startPolling(displayName);\n }\n } catch (error) {\n showError(`Connection failed: ${error.message}`);\n submitBtn.textContent = 'Connect';\n submitBtn.disabled = false;\n }\n });\n\n // ── Back button ──\n btnBack.addEventListener('click', () => {\n stopPolling();\n showPhase(phaseSetup);\n submitBtn.textContent = 'Connect';\n submitBtn.disabled = false;\n });\n\n // ── IndexedDB hardware key backup ──\n async function backupHardwareKey(key) {\n try {\n const req = indexedDB.open('xibo-hw-backup', 1);\n req.onupgradeneeded = () => {\n const db = req.result;\n if (!db.objectStoreNames.contains('keys')) {\n db.createObjectStore('keys');\n }\n };\n req.onsuccess = () => {\n const db = req.result;\n const tx = db.transaction('keys', 'readwrite');\n tx.objectStore('keys').put(key, 'hardwareKey');\n tx.oncomplete = () => db.close();\n };\n } catch (e) {\n console.warn('[Setup] IndexedDB backup failed:', e);\n }\n }\n\n // ── Enable submit ──\n submitBtn.disabled = false;\n submitBtn.textContent = 'Connect';\n\n // ── Auto-resume polling if already registered but not authorized ──\n if (config.isConfigured()) {\n (async () => {\n try {\n const xmds = new XmdsClient(config);\n const result = await xmds.registerDisplay();\n if (result.code === 'READY') {\n window.location.href = './index.html';\n } else {\n // Not authorized — go straight to polling\n startPolling(config.displayName);\n }\n } catch (e) {\n // Connection failed, show form\n console.log('[Setup] Auto-check failed, showing form');\n }\n })();\n }\n "],"names":["form","errorEl","submitBtn","phaseSetup","phaseWaiting","countdownEl","waitingNameEl","btnBack","successFlash","hwKey","config","pollTimer","countdownTimer","pollSeconds","showPhase","phase","showError","msg","hideError","startCountdown","remaining","showSuccess","checkAuthorization","result","XmdsClient","error","startPolling","displayName","stopPolling","tryAutoAuthorize","cmsAddress","hardwareKey","clientId","clientSecret","api","CmsApiClient","display","cmsKey","backupHardwareKey","xmds","key","req","db","tx","e"],"mappings":"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"}
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Xibo Player</title>
|
|
7
|
+
<style>
|
|
8
|
+
* {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
16
|
+
background: #000;
|
|
17
|
+
color: #fff;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#player-container {
|
|
22
|
+
width: 100vw;
|
|
23
|
+
height: 100vh;
|
|
24
|
+
position: relative;
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#overlay {
|
|
29
|
+
position: fixed;
|
|
30
|
+
top: 0;
|
|
31
|
+
left: 0;
|
|
32
|
+
right: 0;
|
|
33
|
+
background: rgba(0, 0, 0, 0.7);
|
|
34
|
+
padding: 10px 20px;
|
|
35
|
+
display: flex;
|
|
36
|
+
justify-content: space-between;
|
|
37
|
+
align-items: center;
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
z-index: 9999;
|
|
40
|
+
opacity: 0;
|
|
41
|
+
transition: opacity 0.3s;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#overlay.visible {
|
|
45
|
+
opacity: 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#config-info {
|
|
49
|
+
color: #4CAF50;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#status {
|
|
53
|
+
color: #fff;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.status-error {
|
|
57
|
+
color: #f44336 !important;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.status-info {
|
|
61
|
+
color: #2196F3 !important;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Hide overlay by default - show only on hover */
|
|
65
|
+
#overlay {
|
|
66
|
+
display: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
body:hover #overlay {
|
|
70
|
+
display: flex;
|
|
71
|
+
opacity: 1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Layout styles */
|
|
75
|
+
.xibo-layout {
|
|
76
|
+
width: 100%;
|
|
77
|
+
height: 100%;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.xibo-region {
|
|
81
|
+
position: absolute;
|
|
82
|
+
overflow: hidden;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.xibo-widget {
|
|
86
|
+
width: 100%;
|
|
87
|
+
height: 100%;
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
90
|
+
<script type="module" crossorigin src="./assets/main-C4ABDfkq.js"></script>
|
|
91
|
+
<link rel="modulepreload" crossorigin href="./assets/modulepreload-polyfill-B5Qt9EMX.js">
|
|
92
|
+
<link rel="modulepreload" crossorigin href="./assets/cms-api-kzy_Sw-u.js">
|
|
93
|
+
<link rel="modulepreload" crossorigin href="./assets/cache-proxy-Cx4Z8XMC.js">
|
|
94
|
+
</head>
|
|
95
|
+
<body>
|
|
96
|
+
<!-- Status overlay -->
|
|
97
|
+
<div id="overlay">
|
|
98
|
+
<div id="config-info">Initializing...</div>
|
|
99
|
+
<div id="status">Loading player...</div>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<!-- Player rendering container -->
|
|
103
|
+
<div id="player-container"></div>
|
|
104
|
+
|
|
105
|
+
<!-- Check for configuration before loading player -->
|
|
106
|
+
<script>
|
|
107
|
+
// TEMP: Force debug level for testing (shows video controls, verbose logging)
|
|
108
|
+
// Remove this line when debugging is no longer needed
|
|
109
|
+
localStorage.setItem('xibo_log_level', 'DEBUG');
|
|
110
|
+
|
|
111
|
+
// Check if player is configured
|
|
112
|
+
const params = new URLSearchParams(window.location.search);
|
|
113
|
+
const hasUrlConfig = params.has('cmsAddress') && params.has('cmsKey');
|
|
114
|
+
const hasStoredConfig = localStorage.getItem('xibo_config');
|
|
115
|
+
|
|
116
|
+
console.log('[Player] Has URL config:', hasUrlConfig);
|
|
117
|
+
console.log('[Player] Has stored config:', !!hasStoredConfig);
|
|
118
|
+
|
|
119
|
+
if (!hasUrlConfig && !hasStoredConfig) {
|
|
120
|
+
// Not configured, redirect to setup
|
|
121
|
+
console.log('[Player] Not configured, redirecting to setup...');
|
|
122
|
+
window.location.href = './setup.html';
|
|
123
|
+
} else {
|
|
124
|
+
console.log('[Player] Configuration found, loading player...');
|
|
125
|
+
}
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<!-- Main player script -->
|
|
129
|
+
</body>
|
|
130
|
+
</html>
|
package/dist/setup.html
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Xibo Player Setup</title>
|
|
7
|
+
<style>
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
|
|
10
|
+
body {
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
12
|
+
background: #1D1D1D;
|
|
13
|
+
color: #E0E0E0;
|
|
14
|
+
min-height: 100vh;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
padding: 20px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.container {
|
|
22
|
+
background: #2A2A2A;
|
|
23
|
+
border-radius: 16px;
|
|
24
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
|
|
25
|
+
padding: 48px;
|
|
26
|
+
max-width: 480px;
|
|
27
|
+
width: 100%;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.logo {
|
|
31
|
+
text-align: center;
|
|
32
|
+
margin-bottom: 32px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.logo-text {
|
|
36
|
+
font-size: 36px;
|
|
37
|
+
font-weight: 700;
|
|
38
|
+
color: #fff;
|
|
39
|
+
letter-spacing: -0.5px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.logo-text span {
|
|
43
|
+
color: #0097D8;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.logo-sub {
|
|
47
|
+
font-size: 14px;
|
|
48
|
+
color: #888;
|
|
49
|
+
margin-top: 4px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* Phases */
|
|
53
|
+
.phase { display: none; }
|
|
54
|
+
.phase.active { display: block; }
|
|
55
|
+
|
|
56
|
+
/* Form styles */
|
|
57
|
+
.form-group {
|
|
58
|
+
margin-bottom: 20px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
label {
|
|
62
|
+
display: block;
|
|
63
|
+
margin-bottom: 6px;
|
|
64
|
+
color: #AAA;
|
|
65
|
+
font-size: 13px;
|
|
66
|
+
font-weight: 500;
|
|
67
|
+
text-transform: uppercase;
|
|
68
|
+
letter-spacing: 0.5px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
input {
|
|
72
|
+
width: 100%;
|
|
73
|
+
padding: 12px 14px;
|
|
74
|
+
background: #1D1D1D;
|
|
75
|
+
border: 2px solid #3A3A3A;
|
|
76
|
+
border-radius: 8px;
|
|
77
|
+
font-size: 15px;
|
|
78
|
+
color: #E0E0E0;
|
|
79
|
+
transition: border-color 0.2s;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
input:focus {
|
|
83
|
+
outline: none;
|
|
84
|
+
border-color: #0097D8;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
input::placeholder { color: #555; }
|
|
88
|
+
|
|
89
|
+
button {
|
|
90
|
+
width: 100%;
|
|
91
|
+
padding: 14px;
|
|
92
|
+
background: #0097D8;
|
|
93
|
+
color: white;
|
|
94
|
+
border: none;
|
|
95
|
+
border-radius: 8px;
|
|
96
|
+
font-size: 15px;
|
|
97
|
+
font-weight: 600;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
transition: background 0.2s, transform 0.1s;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
button:hover { background: #0084BE; }
|
|
103
|
+
button:active { transform: scale(0.98); }
|
|
104
|
+
button:disabled {
|
|
105
|
+
background: #3A3A3A;
|
|
106
|
+
color: #666;
|
|
107
|
+
cursor: not-allowed;
|
|
108
|
+
transform: none;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.error-msg {
|
|
112
|
+
margin-top: 16px;
|
|
113
|
+
padding: 12px 14px;
|
|
114
|
+
background: rgba(244, 67, 54, 0.15);
|
|
115
|
+
border: 1px solid rgba(244, 67, 54, 0.3);
|
|
116
|
+
border-radius: 8px;
|
|
117
|
+
color: #EF9A9A;
|
|
118
|
+
font-size: 14px;
|
|
119
|
+
display: none;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* Hardware key display */
|
|
123
|
+
.hw-key {
|
|
124
|
+
margin-top: 24px;
|
|
125
|
+
padding: 12px 14px;
|
|
126
|
+
background: #1D1D1D;
|
|
127
|
+
border-radius: 8px;
|
|
128
|
+
font-size: 12px;
|
|
129
|
+
color: #666;
|
|
130
|
+
text-align: center;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.hw-key code {
|
|
134
|
+
color: #0097D8;
|
|
135
|
+
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
136
|
+
font-size: 13px;
|
|
137
|
+
user-select: all;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* Waiting phase */
|
|
141
|
+
.waiting-card {
|
|
142
|
+
text-align: center;
|
|
143
|
+
padding: 16px 0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.spinner {
|
|
147
|
+
width: 48px;
|
|
148
|
+
height: 48px;
|
|
149
|
+
border: 3px solid #3A3A3A;
|
|
150
|
+
border-top-color: #0097D8;
|
|
151
|
+
border-radius: 50%;
|
|
152
|
+
animation: spin 1s linear infinite;
|
|
153
|
+
margin: 0 auto 24px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
157
|
+
|
|
158
|
+
.waiting-title {
|
|
159
|
+
font-size: 20px;
|
|
160
|
+
font-weight: 600;
|
|
161
|
+
color: #fff;
|
|
162
|
+
margin-bottom: 12px;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.waiting-desc {
|
|
166
|
+
font-size: 14px;
|
|
167
|
+
color: #888;
|
|
168
|
+
line-height: 1.6;
|
|
169
|
+
margin-bottom: 24px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.waiting-desc strong {
|
|
173
|
+
color: #E0E0E0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.waiting-steps {
|
|
177
|
+
text-align: left;
|
|
178
|
+
padding: 16px 20px;
|
|
179
|
+
background: #1D1D1D;
|
|
180
|
+
border-radius: 8px;
|
|
181
|
+
margin-bottom: 24px;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.waiting-steps li {
|
|
185
|
+
list-style: none;
|
|
186
|
+
padding: 6px 0;
|
|
187
|
+
font-size: 14px;
|
|
188
|
+
color: #AAA;
|
|
189
|
+
position: relative;
|
|
190
|
+
padding-left: 24px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.waiting-steps li::before {
|
|
194
|
+
content: '';
|
|
195
|
+
position: absolute;
|
|
196
|
+
left: 0;
|
|
197
|
+
top: 12px;
|
|
198
|
+
width: 8px;
|
|
199
|
+
height: 8px;
|
|
200
|
+
border-radius: 50%;
|
|
201
|
+
background: #3A3A3A;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.waiting-steps li.done::before {
|
|
205
|
+
background: #4CAF50;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.waiting-steps li.active::before {
|
|
209
|
+
background: #0097D8;
|
|
210
|
+
box-shadow: 0 0 8px rgba(0, 151, 216, 0.5);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.poll-status {
|
|
214
|
+
font-size: 12px;
|
|
215
|
+
color: #555;
|
|
216
|
+
margin-top: 12px;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.poll-status .countdown {
|
|
220
|
+
color: #0097D8;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.btn-secondary {
|
|
224
|
+
background: transparent;
|
|
225
|
+
border: 1px solid #3A3A3A;
|
|
226
|
+
color: #AAA;
|
|
227
|
+
margin-top: 8px;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.btn-secondary:hover { background: #333; }
|
|
231
|
+
|
|
232
|
+
/* Success flash */
|
|
233
|
+
.success-flash {
|
|
234
|
+
position: fixed;
|
|
235
|
+
inset: 0;
|
|
236
|
+
background: rgba(0, 151, 216, 0.15);
|
|
237
|
+
display: none;
|
|
238
|
+
align-items: center;
|
|
239
|
+
justify-content: center;
|
|
240
|
+
z-index: 100;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.success-flash.active {
|
|
244
|
+
display: flex;
|
|
245
|
+
animation: flashIn 0.5s ease-out;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.success-check {
|
|
249
|
+
width: 80px;
|
|
250
|
+
height: 80px;
|
|
251
|
+
border-radius: 50%;
|
|
252
|
+
background: #4CAF50;
|
|
253
|
+
display: flex;
|
|
254
|
+
align-items: center;
|
|
255
|
+
justify-content: center;
|
|
256
|
+
font-size: 40px;
|
|
257
|
+
color: white;
|
|
258
|
+
animation: scaleIn 0.3s ease-out 0.1s both;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
@keyframes flashIn { from { opacity: 0; } to { opacity: 1; } }
|
|
262
|
+
@keyframes scaleIn { from { transform: scale(0); } to { transform: scale(1); } }
|
|
263
|
+
|
|
264
|
+
/* Footer */
|
|
265
|
+
.footer {
|
|
266
|
+
margin-top: 24px;
|
|
267
|
+
text-align: center;
|
|
268
|
+
font-size: 12px;
|
|
269
|
+
color: #444;
|
|
270
|
+
}
|
|
271
|
+
</style>
|
|
272
|
+
<script type="module" crossorigin src="./assets/setup-rqZh5qYs.js"></script>
|
|
273
|
+
<link rel="modulepreload" crossorigin href="./assets/modulepreload-polyfill-B5Qt9EMX.js">
|
|
274
|
+
<link rel="modulepreload" crossorigin href="./assets/cms-api-kzy_Sw-u.js">
|
|
275
|
+
<link rel="modulepreload" crossorigin href="./assets/index-_uzldOpz.js">
|
|
276
|
+
</head>
|
|
277
|
+
<body>
|
|
278
|
+
<div class="container">
|
|
279
|
+
<div class="logo">
|
|
280
|
+
<div class="logo-text"><span>xibo</span> player</div>
|
|
281
|
+
<div class="logo-sub">PWA Digital Signage</div>
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
<!-- Phase 1: Configuration Form -->
|
|
285
|
+
<div id="phase-setup" class="phase active">
|
|
286
|
+
<form id="setup-form">
|
|
287
|
+
<div class="form-group">
|
|
288
|
+
<label for="cms-address">CMS Address</label>
|
|
289
|
+
<input type="url" id="cms-address" placeholder="https://cms.example.com" required>
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
<div class="form-group">
|
|
293
|
+
<label for="cms-key">CMS Key</label>
|
|
294
|
+
<input type="text" id="cms-key" placeholder="Your CMS secret key" required>
|
|
295
|
+
</div>
|
|
296
|
+
|
|
297
|
+
<div class="form-group">
|
|
298
|
+
<label for="display-name">Display Name</label>
|
|
299
|
+
<input type="text" id="display-name" placeholder="My Display" required>
|
|
300
|
+
</div>
|
|
301
|
+
|
|
302
|
+
<!-- Optional: Auto-authorize via CMS API -->
|
|
303
|
+
<details id="api-details" style="margin-bottom: 16px;">
|
|
304
|
+
<summary style="cursor: pointer; color: #0097D8; font-size: 13px; margin-bottom: 8px;">
|
|
305
|
+
Auto-authorize via API (optional)
|
|
306
|
+
</summary>
|
|
307
|
+
<div class="form-group" style="margin-top: 8px;">
|
|
308
|
+
<label for="api-client-id">API Client ID</label>
|
|
309
|
+
<input type="text" id="api-client-id" placeholder="From CMS > Applications">
|
|
310
|
+
</div>
|
|
311
|
+
<div class="form-group">
|
|
312
|
+
<label for="api-client-secret">API Client Secret</label>
|
|
313
|
+
<input type="password" id="api-client-secret" placeholder="Application secret">
|
|
314
|
+
</div>
|
|
315
|
+
<div style="font-size: 11px; color: #666; margin-bottom: 8px;">
|
|
316
|
+
Create an Application in CMS > Administration > Applications with client_credentials grant.
|
|
317
|
+
If provided, the display will be auto-authorized after registration.
|
|
318
|
+
</div>
|
|
319
|
+
</details>
|
|
320
|
+
|
|
321
|
+
<button type="submit" id="submit-btn" disabled>Loading...</button>
|
|
322
|
+
</form>
|
|
323
|
+
|
|
324
|
+
<div id="error" class="error-msg"></div>
|
|
325
|
+
|
|
326
|
+
<div class="hw-key">
|
|
327
|
+
Hardware Key: <code id="hw-key-display">...</code>
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
|
|
331
|
+
<!-- Phase 2: Waiting for Authorization -->
|
|
332
|
+
<div id="phase-waiting" class="phase">
|
|
333
|
+
<div class="waiting-card">
|
|
334
|
+
<div class="spinner"></div>
|
|
335
|
+
<div class="waiting-title">Waiting for Authorization</div>
|
|
336
|
+
<div class="waiting-desc">
|
|
337
|
+
Display <strong id="waiting-display-name"></strong> has been registered.<br>
|
|
338
|
+
Authorize it in your CMS to start playback.
|
|
339
|
+
</div>
|
|
340
|
+
|
|
341
|
+
<ul class="waiting-steps">
|
|
342
|
+
<li class="done">Connected to CMS</li>
|
|
343
|
+
<li class="done">Display registered</li>
|
|
344
|
+
<li class="active">Awaiting authorization in CMS</li>
|
|
345
|
+
<li>Start playback</li>
|
|
346
|
+
</ul>
|
|
347
|
+
|
|
348
|
+
<div class="hw-key">
|
|
349
|
+
Hardware Key: <code id="hw-key-waiting">...</code>
|
|
350
|
+
</div>
|
|
351
|
+
|
|
352
|
+
<div class="poll-status">
|
|
353
|
+
Checking again in <span class="countdown" id="countdown">15</span>s...
|
|
354
|
+
</div>
|
|
355
|
+
|
|
356
|
+
<button id="btn-back" class="btn-secondary">Back to Settings</button>
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
|
|
360
|
+
<div class="footer">
|
|
361
|
+
Xibo Player v0.1.0
|
|
362
|
+
</div>
|
|
363
|
+
</div>
|
|
364
|
+
|
|
365
|
+
<!-- Success Flash Overlay -->
|
|
366
|
+
<div id="success-flash" class="success-flash">
|
|
367
|
+
<div class="success-check">✓</div>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
370
|
+
</body>
|
|
371
|
+
</html>
|
package/dist/sw-pwa.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./assets/cache-proxy-Cx4Z8XMC.js";import{DownloadManager as I}from"./assets/index-BY2j60YZ.js";import"./assets/cms-api-kzy_Sw-u.js";const d=(()=>{var l;return typeof self<"u"&&((l=self.registration)!=null&&l.scope)?new URL(self.registration.scope).pathname.replace(/\/$/,""):"/player/pwa"})();function k(l,t=1){if(l===0)return"0 Bytes";if(l<1024)return`${l} Bytes`;const e=l/1024;if(e<1024)return`${e.toFixed(t)} KB`;const n=e/1024;return n<1024?`${n.toFixed(t)} MB`:`${(n/1024).toFixed(t)} GB`}function W(l,t){const e=l.replace(/bytes=/,"").split("-"),n=parseInt(e[0],10),a=e[1]?parseInt(e[1],10):t-1;return{start:n,end:a}}function G(l,t,e){const n=Math.floor(l/e),a=Math.floor(t/e);return{startChunk:n,endChunk:a,count:a-n+1}}class L{constructor(t){this.name=t,this.level=self.swLogLevel||"INFO"}debug(...t){this.level==="DEBUG"&&console.log(`[${this.name}] DEBUG:`,...t)}info(...t){(this.level==="DEBUG"||this.level==="INFO")&&console.log(`[${this.name}]`,...t)}warn(...t){console.warn(`[${this.name}]`,...t)}error(...t){console.error(`[${this.name}]`,...t)}}const o=new L("SW"),O="2026-02-13-090851",q="xibo-media-v1",E="xibo-static-v1",j=new Map,M=new Map,z=new Map;function V(){const l=navigator.deviceMemory||null;let t=4;if(l)t=l,o.info("Detected device memory:",l,"GB");else{const s=navigator.userAgent.toLowerCase();s.includes("raspberry pi")||s.includes("armv6")?(t=.5,o.info("Detected Pi Zero (512 MB RAM estimated)")):s.includes("armv7")?(t=1,o.info("Detected ARM device (1 GB RAM estimated)")):o.info("Using default RAM estimate:",t,"GB")}let e,n,a,i;return t<=.5?(e=10*1024*1024,n=25,a=25*1024*1024,i=1,o.info("Low-memory config: 10 MB chunks, 25 MB cache, 1 concurrent download")):t<=1?(e=20*1024*1024,n=50,a=50*1024*1024,i=2,o.info("1GB-RAM config: 20 MB chunks, 50 MB cache, 2 concurrent downloads")):t<=2?(e=30*1024*1024,n=100,a=75*1024*1024,i=2,o.info("2GB-RAM config: 30 MB chunks, 100 MB cache, 2 concurrent downloads")):t<=4?(e=50*1024*1024,n=200,a=100*1024*1024,i=4,o.info("4GB-RAM config: 50 MB chunks, 200 MB cache, 4 concurrent downloads")):(e=100*1024*1024,n=500,a=200*1024*1024,i=6,o.info("High-RAM config: 100 MB chunks, 500 MB cache, 6 concurrent downloads")),{chunkSize:e,blobCacheSize:n,threshold:a,concurrency:i}}const D=V(),b=D.chunkSize,J=D.threshold,_=D.blobCacheSize,X=D.concurrency,Y=D.concurrency,Z=[d+"/",d+"/index.html",d+"/setup.html"];o.info("Loading modular Service Worker:",O);class Q{constructor(){this.cache=null,this.log=new L("Cache")}async init(){this.cache=await caches.open(q)}async get(t){return this.cache||await this.init(),await this.cache.match(t,{ignoreSearch:!0,ignoreVary:!0})}async put(t,e,n){this.cache||await this.init();const a=new Response(e,{headers:{"Content-Type":n,"Content-Length":e.size,"Access-Control-Allow-Origin":"*","Accept-Ranges":"bytes"}});await this.cache.put(t,a)}async delete(t){this.cache||await this.init();const e=M.get(t);if(M.delete(t),e){const n=[this.cache.delete(`${t}/metadata`)];for(let a=0;a<e.numChunks;a++)n.push(this.cache.delete(`${t}/chunk-${a}`));return await Promise.all(n),!0}return await this.cache.delete(t)}async clear(){this.cache||await this.init();const t=await this.cache.keys();await Promise.all(t.map(e=>this.cache.delete(e))),M.clear(),this.log.info("Cleared",t.length,"cached files")}async fileExists(t){this.cache||await this.init();const e=M.get(t);if(e)return{exists:!0,chunked:!0,metadata:e};if(await this.get(t))return{exists:!0,chunked:!1,metadata:null};const a=await this.getMetadata(t);return a&&a.chunked?(M.set(t,a),{exists:!0,chunked:!0,metadata:a}):{exists:!1,chunked:!1,metadata:null}}async getFileSize(t){const e=await this.fileExists(t);if(!e.exists)return null;if(e.chunked)return e.metadata.totalSize;const n=await this.get(t),a=n==null?void 0:n.headers.get("Content-Length");return a?parseInt(a):null}async putChunked(t,e,n){this.cache||await this.init();const a=e.size,i=Math.ceil(a/b);this.log.info(`Storing as ${i} chunks: ${t} (${k(a)})`);const s={totalSize:a,chunkSize:b,numChunks:i,contentType:n,chunked:!0,createdAt:Date.now()},h=new Response(JSON.stringify(s),{headers:{"Content-Type":"application/json"}});await this.cache.put(`${t}/metadata`,h),M.set(t,s);for(let c=0;c<i;c++){const C=c*b,u=Math.min(C+b,a),m=e.slice(C,u),r=new Response(m,{headers:{"Content-Type":n,"Content-Length":m.size,"X-Chunk-Index":c,"X-Total-Chunks":i}});await this.cache.put(`${t}/chunk-${c}`,r),((c+1)%5===0||c===i-1)&&this.log.info(`Stored chunk ${c+1}/${i} (${k(m.size)})`)}this.log.info(`Chunked storage complete: ${t}`)}async getMetadata(t){const e=M.get(t);if(e)return e;this.cache||await this.init();const n=await this.cache.match(`${t}/metadata`);if(!n)return null;const a=await n.text(),i=JSON.parse(a);return M.set(t,i),i}async isChunked(t){const e=await this.getMetadata(t);return(e==null?void 0:e.chunked)===!0}async getChunk(t,e){return this.cache||await this.init(),await this.cache.match(`${t}/chunk-${e}`)}}class K{constructor(t=_){this.cache=new Map,this.maxBytes=t*1024*1024,this.currentBytes=0,this.log=new L("BlobCache")}async get(t,e){if(this.cache.has(t)){const a=this.cache.get(t);return a.lastAccess=Date.now(),this.log.debug(`HIT: ${t} (${k(a.size)})`),a.blob}this.log.debug(`MISS: ${t} - loading from Cache API`);const n=await e();for(;this.currentBytes+n.size>this.maxBytes&&this.cache.size>0;)this.evictLRU();if(this.currentBytes+n.size<=this.maxBytes){this.cache.set(t,{blob:n,lastAccess:Date.now(),size:n.size}),this.currentBytes+=n.size;const a=(this.currentBytes/this.maxBytes*100).toFixed(1);this.log.debug(`CACHED: ${t} (${k(n.size)}) - utilization: ${a}%`)}else this.log.debug(`Skipping memory cache (too large): ${t} (${k(n.size)} > ${k(this.maxBytes)})`);return n}evictLRU(){let t=null,e=null;for(const[n,a]of this.cache)(!t||a.lastAccess<t.lastAccess)&&(t=a,e=n);e&&(this.currentBytes-=t.size,this.cache.delete(e),this.log.debug(`EVICTED LRU: ${e} (${k(t.size)})`))}clear(){this.cache.clear(),this.currentBytes=0,this.log.info("Cleared all cached blobs")}getStats(){return{entries:this.cache.size,bytes:this.currentBytes,maxBytes:this.maxBytes,utilization:(this.currentBytes/this.maxBytes*100).toFixed(1)+"%"}}}class ee{constructor(t,e,n){this.downloadManager=t,this.cacheManager=e,this.blobCache=n,this.pendingFetches=new Map,this.log=o}async routeFileRequest(t,e,n){const a=await this.cacheManager.fileExists(t);if(!a.exists)return{found:!1,handler:null,data:null};if(a.chunked){const i={metadata:a.metadata,cacheKey:t};return e==="HEAD"?{found:!0,handler:"head-chunked",data:i}:n?{found:!0,handler:"range-chunked",data:{...i,rangeHeader:n}}:{found:!0,handler:"full-chunked",data:i}}else{const s={cached:await this.cacheManager.get(t),cacheKey:t};return e==="HEAD"?{found:!0,handler:"head-whole",data:s}:n?{found:!0,handler:"range-whole",data:{...s,rangeHeader:n}}:{found:!0,handler:"full-whole",data:s}}}async handleRequest(t){var m;const e=new URL(t.request.url);if(o.info("handleRequest called for:",e.href),o.info("pathname:",e.pathname),e.pathname===d+"/"||e.pathname===d+"/index.html"||e.pathname===d+"/setup.html"){const y=await(await caches.open(E)).match(t.request);return y?(o.info("Serving static file from cache:",e.pathname),y):(o.info("Fetching static file from network:",e.pathname),fetch(t.request))}if(e.pathname.includes("xmds.php")&&(e.searchParams.get("fileType")==="bundle"||e.searchParams.get("fileType")==="fontCss"||e.searchParams.get("fileType")==="font")){const r=e.searchParams.get("file"),y=`${d}/cache/static/${r}`,f=await caches.open(E),g=await f.match(y);if(g)return o.info("Serving widget resource from cache:",r),g.clone();if(this.pendingFetches.has(r))return o.info("Deduplicating widget resource fetch:",r),(await this.pendingFetches.get(r)).clone();o.info("Fetching widget resource from CMS:",r);const w=(async()=>{try{const p=await fetch(t.request);if(p.ok){o.info("Caching widget resource:",r,`(${p.headers.get("Content-Type")})`);const S=p.clone();return await f.put(y,S),p}else return o.warn("Widget resource not available (",p.status,"):",r,"- NOT caching"),p}catch(p){return o.error("Failed to fetch widget resource:",r,p),new Response("Failed to fetch widget resource",{status:502,statusText:"Bad Gateway",headers:{"Content-Type":"text/plain"}})}})();this.pendingFetches.set(r,w);try{return(await w).clone()}finally{this.pendingFetches.delete(r)}}if(e.pathname.includes("xmds.php")&&e.searchParams.has("file")){const r=e.searchParams.get("file"),y=r.split(".")[0],f=e.searchParams.get("type"),g=f==="L"?"layout":"media";o.info("XMDS request:",r,"type:",f,"→",d+"/cache/"+g+"/"+y);const w=`${d}/cache/${g}/${y}`,p=await this.cacheManager.get(w);return p?new Response(p.clone().body,{headers:{"Content-Type":p.headers.get("Content-Type")||"video/mp4","Access-Control-Allow-Origin":"*","Cache-Control":"public, max-age=31536000","Accept-Ranges":"bytes"}}):(o.info("XMDS file not cached, passing through:",r),fetch(t.request))}if(e.pathname.startsWith(d+"/cache/static/")){const r=e.pathname.split("/").pop();o.info("Static resource request:",r);const f=await(await caches.open(E)).match(`${d}/cache/static/${r}`);if(f)return o.info("Serving static resource from static cache:",r),f.clone();const g=await this.cacheManager.get(e.pathname);return g?(o.info("Serving static resource from media cache:",r),new Response(g.clone().body,{headers:{"Content-Type":g.headers.get("Content-Type")||"application/octet-stream","Access-Control-Allow-Origin":"*","Cache-Control":"public, max-age=31536000"}})):(o.warn("Static resource not cached:",r),new Response("Resource not cached",{status:404}))}if(!e.pathname.startsWith(d+"/cache/"))return o.info("NOT a cache request, returning null:",e.pathname),null;if(o.info("IS a cache request, proceeding...",e.pathname),e.pathname.startsWith(d+"/cache/widget/")){o.info("Widget HTML request:",e.pathname);const r=await this.cacheManager.get(e.pathname);return r?new Response(r.clone().body,{headers:{"Content-Type":"text/html; charset=utf-8","Access-Control-Allow-Origin":"*","Cache-Control":"public, max-age=31536000"}}):new Response("<!DOCTYPE html><html><body>Widget not found</body></html>",{status:404,headers:{"Content-Type":"text/html"}})}const n=e.pathname,a=t.request.method,i=t.request.headers.get("Range");o.debug("Request URL:",e.pathname),o.debug("Cache key:",n),i?o.info(a,n,`Range: ${i}`):o.info(a,n);const s=await this.routeFileRequest(n,a,i);if(s.found)switch(s.handler){case"head-whole":return this.handleHeadWhole((m=s.data.cached)==null?void 0:m.headers.get("Content-Length"));case"head-chunked":return this.handleHeadChunked(s.data.metadata,s.data.cacheKey);case"range-whole":return this.handleRangeRequest(s.data.cached,s.data.rangeHeader,s.data.cacheKey);case"range-chunked":return this.handleChunkedRangeRequest(s.data.cacheKey,s.data.rangeHeader,s.data.metadata);case"full-whole":return this.handleFullWhole(s.data.cached,s.data.cacheKey);case"full-chunked":return this.handleFullChunked(s.data.cacheKey,s.data.metadata);default:return o.error("Unknown handler:",s.handler),new Response("Internal error: unknown handler",{status:500})}const h=n.split("/"),c=h[2],C=h[3];let u=null;for(const[r,y]of this.downloadManager.queue.active.entries())if(y.fileInfo.type===c&&y.fileInfo.id===C){u=y;break}if(u){o.info("Download in progress, waiting:",n);try{await u.wait();const r=await this.routeFileRequest(n,a,i);if(r.found)switch(o.info("Download complete, serving via",r.handler),r.handler){case"full-whole":return this.handleFullWhole(r.data.cached,r.data.cacheKey);case"full-chunked":return this.handleFullChunked(r.data.cacheKey,r.data.metadata);default:return this.handleRequest(t)}}catch(r){return o.error("Download failed:",n,r),new Response("Download failed: "+r.message,{status:500})}}return o.info("Not found:",n),new Response("Not found",{status:404})}handleHeadWhole(t){return o.info("HEAD response: File exists (whole file)"),new Response(null,{status:200,headers:{"Content-Length":t?t.toString():"","Accept-Ranges":"bytes","Access-Control-Allow-Origin":"*"}})}async handleHeadChunked(t,e){return await this.cacheManager.getChunk(e,0)?(o.info("HEAD response: File exists (chunked)"),new Response(null,{status:200,headers:{"Content-Length":t.totalSize.toString(),"Accept-Ranges":"bytes","Access-Control-Allow-Origin":"*"}})):(o.info("HEAD response: Chunked file not yet playable (chunk 0 missing):",e),new Response(null,{status:404}))}handleFullWhole(t,e){const n=t.headers.get("Content-Length"),a=n?k(parseInt(n)):"unknown size";return o.info("Serving from cache:",e,`(${a})`),new Response(t.body,{headers:{"Content-Type":t.headers.get("Content-Type")||"application/octet-stream","Content-Length":n||"","Accept-Ranges":"bytes","Access-Control-Allow-Origin":"*","Cache-Control":"public, max-age=31536000"}})}async handleFullChunked(t,e){o.info("Chunked file GET without Range:",t,`- serving full file from ${e.numChunks} chunks`);const n=`bytes=0-${e.totalSize-1}`;return this.handleChunkedRangeRequest(t,n,e)}async handleRangeRequest(t,e,n){const a=await this.blobCache.get(n,async()=>await t.clone().blob()),i=a.size,{start:s,end:h}=W(e,i),c=a.slice(s,h+1);return this.log.debug(`Range: bytes ${s}-${h}/${i} (${k(c.size)} of ${k(i)})`),new Response(c,{status:206,statusText:"Partial Content",headers:{"Content-Type":t.headers.get("Content-Type")||"video/mp4","Content-Length":c.size.toString(),"Content-Range":`bytes ${s}-${h}/${i}`,"Accept-Ranges":"bytes","Access-Control-Allow-Origin":"*"}})}async handleChunkedRangeRequest(t,e,n){const{totalSize:a,chunkSize:i,numChunks:s,contentType:h}=n,{start:c,end:C}=W(e,a);let u=C;const m=e.replace(/bytes=/,"");if(m.indexOf("-")===m.length-1){const R=Math.floor(c/i),$=Math.min((R+1)*i-1,a-1);$<u&&(u=$,o.info(`Progressive streaming: capping bytes=${c}- to chunk ${R} (bytes ${c}-${u}/${a})`))}const{startChunk:y,endChunk:f,count:g}=G(c,u,i);this.log.debug(`Chunked range: bytes ${c}-${u}/${a} (chunks ${y}-${f}, ${g} chunks)`);const w=await Promise.all(Array.from({length:f-y+1},(R,$)=>{const x=y+$,T=`${t}/chunk-${x}`;return this.blobCache.get(T,()=>{if(z.has(T))return z.get(T);const P=(async()=>{let B=null;for(let v=0;v<120&&(B=await this.cacheManager.getChunk(t,x),!B);v++)v%10===0&&o.info(`Chunk ${x}/${s} not yet available for ${t}, waiting... (attempt ${v+1})`),await new Promise(U=>setTimeout(U,500));if(!B)throw new Error(`Chunk ${x} not found for ${t} after retries`);return await B.blob()})();return z.set(T,P),P.finally(()=>z.delete(T)),P})})),p=c%i,S=u%i;let A;if(g===1)A=w[0].slice(p,p+(u-c+1));else{const R=[];R.push(w[0].slice(p));for(let $=1;$<g-1;$++)R.push(w[$]);g>1&&R.push(w[g-1].slice(0,S+1)),A=new Blob(R,{type:h})}return this.log.debug(`Serving chunked range: ${k(A.size)} from ${g} chunk(s)`),new Response(A,{status:206,statusText:"Partial Content",headers:{"Content-Type":h,"Content-Length":A.size.toString(),"Content-Range":`bytes ${c}-${u}/${a}`,"Accept-Ranges":"bytes","Access-Control-Allow-Origin":"*"}})}}class te{constructor(t,e){this.downloadManager=t,this.cacheManager=e,this.log=new L("SW Message")}async handleMessage(t){const{type:e,data:n}=t.data;switch(e==="GET_DOWNLOAD_PROGRESS"?this.log.debug("Received:",e):this.log.info("Received:",e),e){case"PING":return this.log.info("PING received, broadcasting SW_READY"),(await self.clients.matchAll()).forEach(i=>{i.postMessage({type:"SW_READY"})}),{success:!0};case"DOWNLOAD_FILES":return await this.handleDownloadFiles(n.files);case"PRIORITIZE_DOWNLOAD":return this.handlePrioritizeDownload(n.fileType,n.fileId);case"CLEAR_CACHE":return await this.handleClearCache();case"GET_DOWNLOAD_PROGRESS":return await this.handleGetProgress();case"DELETE_FILES":return await this.handleDeleteFiles(n.files);case"PREWARM_VIDEO_CHUNKS":return await this.handlePrewarmVideoChunks(n.mediaIds);default:return this.log.warn("Unknown message type:",e),{success:!1,error:"Unknown message type"}}}async handleDeleteFiles(t){if(!t||!Array.isArray(t))return{success:!1,error:"No files provided"};let e=0;for(const n of t){const a=`${d}/cache/${n.type}/${n.id}`;await this.cacheManager.delete(a)?(this.log.info("Purged:",a),e++):this.log.debug("Not cached (skip purge):",a)}return this.log.info(`Purge complete: ${e}/${t.length} files deleted`),{success:!0,deleted:e,total:t.length}}async handlePrewarmVideoChunks(t){if(!t||!Array.isArray(t)||t.length===0)return{success:!1,error:"No mediaIds provided"};let e=0;for(const n of t){const a=`${d}/cache/media/${n}`,i=await this.cacheManager.getMetadata(a);if(i!=null&&i.chunked){const s=i.numChunks-1,h=[0];s>0&&h.push(s);for(const c of h){const C=`${a}/chunk-${c}`;await F.get(C,async()=>{const u=await this.cacheManager.getChunk(a,c);return u?await u.blob():new Blob})}this.log.info(`Pre-warmed ${h.length} chunks for media ${n} (${i.numChunks} total)`),e++}else{const s=await this.cacheManager.get(a);s&&(await F.get(a,async()=>await s.clone().blob()),this.log.info(`Pre-warmed whole file for media ${n}`),e++)}}return{success:!0,warmed:e,total:t.length}}handlePrioritizeDownload(t,e){this.log.info("Prioritize request:",`${t}/${e}`);const n=this.downloadManager.queue.prioritize(t,e);return this.downloadManager.queue.processQueue(),{success:!0,found:n}}async handleDownloadFiles(t){this.log.info("Enqueueing",t.length,"files for download"),t.sort((s,h)=>s.type==="layout"&&h.type!=="layout"?-1:s.type!=="layout"&&h.type==="layout"?1:0);let e=0;const n=[];for(const s of t){if(!s.path||s.path==="null"||s.path==="undefined"){this.log.debug("Skipping file with no path:",s.id);continue}const h=`${d}/cache/${s.type}/${s.id}`,c=await this.cacheManager.fileExists(h);if(c.exists){this.log.debug("File already cached:",h,c.chunked?"(chunked)":"(whole file)"),await this.ensureStaticCacheEntry(s);continue}if(this.downloadManager.getTask(s.path)){this.log.debug("File already downloading:",h,"- skipping duplicate");continue}const u=this.downloadManager.enqueue(s);n.push(this.cacheFileAfterDownload(u,s)),e++}this.log.info("Enqueued",e,"files, waiting for downloads to start..."),await new Promise(s=>setTimeout(s,100));const a=this.downloadManager.queue.running,i=this.downloadManager.queue.queue.length;return this.log.info("Downloads started:",a,"active,",i,"queued"),{success:!0,enqueuedCount:e,activeCount:a,queuedCount:i}}async cacheFileAfterDownload(t,e){try{const n=`${d}/cache/${e.type}/${e.id}`,a=e.type==="layout"?"text/xml":e.type==="widget"?"text/html":"application/octet-stream",i=parseInt(e.size)||0;if(i>J)return await this._progressiveCacheFile(t,e,n,a,i);const s=await t.wait();return await this.cacheManager.put(n,s,a),o.info("Cached after download:",n,`(${s.size} bytes)`),(await self.clients.matchAll()).forEach(c=>{c.postMessage({type:"FILE_CACHED",fileId:e.id,fileType:e.type,size:s.size})}),this._cacheStaticResource(e,s),s}catch(n){throw this.log.error("Failed to cache after download:",e.id,n),n}}async _progressiveCacheFile(t,e,n,a,i){const s=await caches.open(q);let h=!1,c=0,C=!1;const u=Math.ceil(i/b);o.info(`Progressive download: ${n} (${k(i)}, ~${u} chunks)`);const m={totalSize:i,chunkSize:b,numChunks:u,contentType:a,chunked:!0,createdAt:Date.now()};await s.put(`${n}/metadata`,new Response(JSON.stringify(m),{headers:{"Content-Type":"application/json"}})),M.set(n,m),h=!0,o.info("Metadata stored, ready for progressive streaming:",n),t.onChunkDownloaded=async(f,g,w)=>{const p=new Response(g,{headers:{"Content-Type":a,"Content-Length":g.size,"X-Chunk-Index":f,"X-Total-Chunks":w}});if(await s.put(`${n}/chunk-${f}`,p),c++,(c%2===0||c===w)&&o.info(`Progressive: chunk ${c}/${w} cached for ${e.id}`),!C&&(f===0||f===w-1)){const S=f===0||await this.cacheManager.getChunk(n,0),A=f===w-1||await this.cacheManager.getChunk(n,w-1);S&&A&&(C=!0,(await self.clients.matchAll()).forEach($=>{$.postMessage({type:"FILE_CACHED",fileId:e.id,fileType:e.type,size:i,progressive:!0,chunksReady:c,totalChunks:w})}),o.info("Chunk 0 + last chunk cached — client notified, early playback ready:",n))}w!==u&&!h&&(m.numChunks=w,await s.put(`${n}/metadata`,new Response(JSON.stringify(m),{headers:{"Content-Type":"application/json"}})))};const r=await t.wait();return c===0?(o.warn("Progressive callback never fired, falling back to putChunked:",n),r.size>0?await this.cacheManager.putChunked(n,r,a):await this.cacheManager.put(n,r,a),(await self.clients.matchAll()).forEach(g=>{g.postMessage({type:"FILE_CACHED",fileId:e.id,fileType:e.type,size:r.size||i})}),r):(o.info(`Progressive download complete: ${n} (${c} chunks stored)`),(await self.clients.matchAll()).forEach(f=>{f.postMessage({type:"FILE_CACHED",fileId:e.id,fileType:e.type,size:i,complete:!0})}),j.delete(n),new Blob([],{type:a}))}_cacheStaticResource(t,e){const n=t.path?(()=>{try{return new URL(t.path).searchParams.get("file")}catch{return null}})():null;n&&(n.endsWith(".js")||n.endsWith(".css")||/\.(otf|ttf|woff2?|eot|svg)$/i.test(n))&&(async()=>{try{const a=await caches.open(E),i=`${d}/cache/static/${n}`,s=n.split(".").pop().toLowerCase(),h={js:"application/javascript",css:"text/css",otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",eot:"application/vnd.ms-fontobject",svg:"image/svg+xml"}[s]||"application/octet-stream";await Promise.all([a.put(i,new Response(e.slice(0,e.size,e.type),{headers:{"Content-Type":h}})),this.cacheManager.put(i,e.slice(0,e.size,e.type),h)]),o.info("Also cached as static resource:",n,`(${h})`)}catch(a){o.warn("Failed to cache static resource:",n,a)}})()}async ensureStaticCacheEntry(t){const e=t.path?(()=>{try{return new URL(t.path).searchParams.get("file")}catch{return null}})():null;if(!e||!(e.endsWith(".js")||e.endsWith(".css")||/\.(otf|ttf|woff2?|eot|svg)$/i.test(e)))return;const n=await caches.open(E),a=`${d}/cache/static/${e}`;if(await n.match(a))return;const s=`${d}/cache/${t.type}/${t.id}`,h=await this.cacheManager.get(s);if(!h)return;const c=await h.blob(),C=e.split(".").pop().toLowerCase(),u={js:"application/javascript",css:"text/css",otf:"font/otf",ttf:"font/ttf",woff:"font/woff",woff2:"font/woff2",eot:"application/vnd.ms-fontobject",svg:"image/svg+xml"}[C]||"application/octet-stream",m=`${d}/cache/static/${e}`;await Promise.all([n.put(a,new Response(c.slice(0,c.size,c.type),{headers:{"Content-Type":u}})),this.cacheManager.put(m,c.slice(0,c.size,c.type),u)]),o.info("Backfilled static cache for:",e,`(${u}, ${c.size} bytes)`)}async handleClearCache(){return this.log.info("Clearing cache"),await this.cacheManager.clear(),{success:!0}}async handleGetProgress(){return{success:!0,progress:this.downloadManager.getProgress()}}}const H=new I({concurrency:X,chunkSize:b,chunksPerFile:Y}),N=new Q,F=new K(_),ne=new ee(H,N,F),ae=new te(H,N);self.addEventListener("install",l=>{o.info("Installing... Version:",O),l.waitUntil(Promise.all([N.init(),caches.open(E).then(t=>(o.info("Caching static files"),t.addAll(Z)))]).then(()=>(o.info("Cache initialized"),self.skipWaiting())))});self.addEventListener("activate",l=>{o.info("Activating... Version:",O),l.waitUntil(caches.keys().then(t=>Promise.all(t.filter(e=>e.startsWith("xibo-")&&e!==q&&e!==E).map(e=>(o.info("Deleting old cache:",e),caches.delete(e))))).then(()=>(o.info("Taking control of all clients immediately"),self.clients.claim())).then(async()=>{o.info("Notifying all clients that fetch handler is ready"),(await self.clients.matchAll()).forEach(e=>{e.postMessage({type:"SW_READY"})})}))});async function se(l){const t=new URL(l.request.url),e=t.pathname.replace(d+"/ic",""),n=l.request.method;o.info("Interactive Control request:",n,e);let a=null;if(n==="POST"||n==="PUT")try{a=await l.request.text()}catch{}const i=await self.clients.matchAll({type:"window"});if(i.length===0)return new Response(JSON.stringify({error:"No active player"}),{status:503,headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}});const s=i[0];try{const h=await new Promise((c,C)=>{const u=new MessageChannel,m=setTimeout(()=>C(new Error("IC timeout")),5e3);u.port1.onmessage=r=>{clearTimeout(m),c(r.data)},s.postMessage({type:"INTERACTIVE_CONTROL",method:n,path:e,search:t.search,body:a},[u.port2])});return new Response(h.body||"",{status:h.status||200,headers:{"Content-Type":h.contentType||"application/json","Access-Control-Allow-Origin":"*"}})}catch(h){return o.error("IC handler error:",h),new Response(JSON.stringify({error:h.message}),{status:500,headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}})}}self.addEventListener("fetch",l=>{const t=new URL(l.request.url);if(t.pathname.startsWith(d+"/cache/")||t.pathname.startsWith(d+"/ic/")||t.pathname.startsWith("/player/")&&(t.pathname.endsWith(".html")||t.pathname==="/player/")||t.pathname.includes("xmds.php")&&t.searchParams.has("file")&&l.request.method==="GET"){if(t.pathname.startsWith(d+"/ic/")){l.respondWith(se(l));return}l.respondWith(ne.handleRequest(l))}});self.addEventListener("message",l=>{l.waitUntil(ae.handleMessage(l).then(t=>{var e;(e=l.ports[0])==null||e.postMessage(t)}))});o.info("Modular Service Worker ready");
|
|
2
|
+
//# sourceMappingURL=sw-pwa.js.map
|