diff --git a/server/player/index.html b/server/player/index.html
index 54e451b..a7626cb 100644
--- a/server/player/index.html
+++ b/server/player/index.html
@@ -287,6 +287,7 @@
startHeartbeat();
startPlaylistRefresh();
+ startVersionCheck();
});
socket.on('device:paired', (data) => {
@@ -465,6 +466,27 @@
}, 300000); // 5 minutes fallback
}
+ // ==================== Auto-reload on code update ====================
+ let knownServerHash = null;
+ let versionCheckTimer = null;
+ function startVersionCheck() {
+ if (versionCheckTimer) clearInterval(versionCheckTimer);
+ // Initial fetch to learn current hash
+ fetch(config.serverUrl + '/api/version').then(r => r.json()).then(data => {
+ knownServerHash = data.hash;
+ console.log('Server version:', data.version, 'hash:', data.hash);
+ }).catch(() => {});
+ // Poll every 30s
+ versionCheckTimer = setInterval(() => {
+ fetch(config.serverUrl + '/api/version').then(r => r.json()).then(data => {
+ if (knownServerHash && data.hash !== knownServerHash) {
+ console.log('Server code updated, reloading...', knownServerHash, '->', data.hash);
+ location.reload();
+ }
+ }).catch(() => {});
+ }, 30000);
+ }
+
// ==================== Playlist ====================
function handlePlaylistUpdate(data) {
// Check if device is suspended (trial expired / over limit)
diff --git a/server/server.js b/server/server.js
index 5ef3928..1e5a1ab 100644
--- a/server/server.js
+++ b/server/server.js
@@ -235,6 +235,9 @@ function updateFrontendHash() {
'js/views/activity.js', 'js/views/kiosk.js'].map(f => {
try { return fs.readFileSync(path.join(config.frontendDir, f)); } catch { return ''; }
});
+ // Include player files in hash so web players detect code updates
+ try { files.push(fs.readFileSync(path.join(__dirname, 'player', 'index.html'))); } catch {}
+ try { files.push(fs.readFileSync(path.join(__dirname, 'player', 'sw.js'))); } catch {}
frontendHash = crypto.createHash('md5').update(Buffer.concat(files.map(f => Buffer.from(f)))).digest('hex').slice(0, 8);
} catch { frontendHash = Date.now().toString(36); }
}