// Display Management for SnowWorld Client
class DisplayManager {
constructor() {
this.currentContent = [];
this.currentIndex = 0;
this.contentTimer = null;
this.transitionDuration = 1000; // 1 second
this.isPlaying = false;
this.zone = this.getZoneFromURL() || 'reception';
this.init();
}
init() {
this.setupEventListeners();
this.updateZoneDisplay();
this.hideLoadingScreen();
}
setupEventListeners() {
// Handle visibility change (tab switching)
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
this.pause();
} else {
this.resume();
}
});
// Handle window focus/blur
window.addEventListener('blur', () => this.pause());
window.addEventListener('focus', () => this.resume());
// Handle errors
window.addEventListener('error', (e) => {
console.error('Display error:', e.error);
this.handleError(e.error);
});
}
getZoneFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('zone');
}
updateZoneDisplay() {
const zoneElement = document.getElementById('currentZone');
if (zoneElement) {
zoneElement.textContent = this.getZoneDisplayName(this.zone);
}
}
getZoneDisplayName(zoneId) {
const zoneNames = {
'reception': 'Receptie',
'restaurant': 'Restaurant',
'skislope': 'Skibaan',
'lockers': 'Kluisjes',
'shop': 'Winkel',
'all': 'Algemeen'
};
return zoneNames[zoneId] || zoneId;
}
async loadContent(contentList) {
try {
console.log('Loading content for zone:', this.zone);
// Filter content for current zone
this.currentContent = contentList.filter(item =>
item.zone === this.zone || item.zone === 'all'
);
if (this.currentContent.length === 0) {
this.showPlaceholder();
return;
}
// Sort content by priority and creation date
this.currentContent.sort((a, b) => {
const priorityA = a.priority || 0;
const priorityB = b.priority || 0;
if (priorityA !== priorityB) return priorityB - priorityA;
return new Date(b.createdAt) - new Date(a.createdAt);
});
console.log(`Loaded ${this.currentContent.length} content items`);
// Start playback
this.startPlayback();
} catch (error) {
console.error('Error loading content:', error);
this.showError();
}
}
startPlayback() {
if (this.currentContent.length === 0) {
this.showPlaceholder();
return;
}
this.isPlaying = true;
this.currentIndex = 0;
// Show first content item
this.showContentItem(this.currentContent[0]);
// Set up automatic progression
this.scheduleNextContent();
}
showContentItem(contentItem) {
const display = document.getElementById('contentDisplay');
if (!display) return;
// Create content element
const contentElement = this.createContentElement(contentItem);
// Clear previous content with fade out
this.clearCurrentContent(() => {
display.appendChild(contentElement);
// Fade in new content
setTimeout(() => {
contentElement.classList.add('active');
}, 50);
});
}
createContentElement(contentItem) {
const element = document.createElement('div');
element.className = 'content-item';
element.dataset.contentId = contentItem.id;
switch (contentItem.type) {
case 'image':
element.innerHTML = `
`;
// Handle image load errors
element.querySelector('img').onerror = () => {
this.handleContentError(contentItem, 'image');
};
break;
case 'video':
element.innerHTML = `
`;
// Handle video errors
element.querySelector('video').onerror = () => {
this.handleContentError(contentItem, 'video');
};
break;
case 'livestream':
element.innerHTML = `
${contentItem.title}
Type: ${contentItem.type}
${type} kon niet worden geladen
Er is momenteel geen content beschikbaar voor deze zone.
Er is een fout opgetreden. Probeer het opnieuw.