updating sound

This commit is contained in:
Flatlogic Bot 2026-04-04 17:23:13 +00:00
parent 1148add8f4
commit a9cc4a74a5
3 changed files with 64 additions and 42 deletions

View File

@ -126,6 +126,17 @@ document.addEventListener('DOMContentLoaded', () => {
console.warn('AudioContext init failed', e);
}
};
// Global listener to unlock audio on first interaction (helpful for TV boxes)
const unlockAudio = (e) => {
if (e && e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') return;
if (window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false') {
initAudio();
}
document.removeEventListener('click', unlockAudio);
document.removeEventListener('keydown', unlockAudio);
};
document.addEventListener('click', unlockAudio);
document.addEventListener('keydown', unlockAudio);
let availableVoices = [];
if ('speechSynthesis' in window) {
@ -139,7 +150,7 @@ document.addEventListener('DOMContentLoaded', () => {
const audioBtn = document.querySelector('.js-audio-toggle');
if (audioBtn) {
const updateAudioBtnState = () => {
const isEnabled = window.localStorage.getItem('hospitalQueue:audioEnabled') === 'true';
const isEnabled = window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false';
const icon = audioBtn.querySelector('i');
if (icon) {
icon.className = isEnabled ? 'bi bi-megaphone-fill' : 'bi bi-megaphone';
@ -155,7 +166,7 @@ document.addEventListener('DOMContentLoaded', () => {
updateAudioBtnState();
audioBtn.addEventListener('click', () => {
const isEnabled = window.localStorage.getItem('hospitalQueue:audioEnabled') === 'true';
const isEnabled = window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false';
const nextState = !isEnabled;
window.localStorage.setItem('hospitalQueue:audioEnabled', nextState.toString());
updateAudioBtnState();
@ -199,7 +210,7 @@ document.addEventListener('DOMContentLoaded', () => {
const checkAnnouncements = () => {
const cards = Array.from(document.querySelectorAll('.announcement-card'));
const latest = cards[0];
const audioEnabled = window.localStorage.getItem('hospitalQueue:audioEnabled') === 'true';
const audioEnabled = window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false';
if (latest) {
const announcementKey = latest.dataset.announcementKey || '';

View File

@ -168,15 +168,62 @@ qh_page_start(
}
}, { once: true });
if (window.localStorage.getItem('hospitalQueue:audioEnabled') === 'true') {
if (window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false') {
player.muted = false;
}
player.play().catch(function(e) {
player.play().catch(function(e) {
console.error("Error playing video:", e);
if (!player.muted) {
player.muted = true;
player.play().catch(e => console.error("Fallback play failed:", e));
player.play().catch(err => console.error("Fallback play failed:", err));
}
if (!window.audioPromptShown && window.localStorage.getItem('hospitalQueue:audioEnabled') !== 'false') {
window.audioPromptShown = true;
const prompt = document.createElement('div');
prompt.style.position = 'fixed';
prompt.style.bottom = '20px';
prompt.style.left = '50%';
prompt.style.transform = 'translateX(-50%)';
prompt.style.zIndex = '9999';
prompt.style.backgroundColor = '#dc3545'; // danger red
prompt.style.color = 'white';
prompt.style.padding = '15px 30px';
prompt.style.borderRadius = '50px';
prompt.style.cursor = 'pointer';
prompt.style.display = 'flex';
prompt.style.alignItems = 'center';
prompt.style.gap = '15px';
prompt.style.boxShadow = '0 10px 25px rgba(0,0,0,0.5)';
const msg = "<?= qh_h(qh_t('Sound blocked by TV/Browser. Click here or press OK on remote to enable.', 'تم حظر الصوت بواسطة المتصفح/التلفاز. انقر هنا أو اضغط OK في الريموت للتفعيل.')) ?>";
prompt.innerHTML = '<i class="bi bi-volume-mute-fill fs-3"></i> <span class="fs-5 fw-bold">' + msg + '</span>';
const enableSound = function(ev) {
if (ev && ev.type === 'keydown' && ev.key !== 'Enter' && ev.key !== ' ') return;
player.muted = false;
player.play().catch(e => console.warn("Still cannot play:", e));
if (document.body.contains(prompt)) {
document.body.removeChild(prompt);
}
if (ev && ev.type === 'keydown') {
document.body.click();
}
};
prompt.addEventListener('click', enableSound);
document.body.appendChild(prompt);
document.addEventListener('keydown', enableSound);
// Also listen for any click anywhere to dismiss it
document.addEventListener('click', function(ev2) {
if (document.body.contains(prompt) && ev2.target !== prompt && !prompt.contains(ev2.target)) {
enableSound(ev2);
}
}, { once: true });
}
});

View File

@ -1,36 +0,0 @@
<?php
$content = file_get_contents('display.php');
$search = <<<'HTML'
<div class="card-body text-center p-2">
<div class="fs-2 fw-bold text-primary mb-1"><?= qh_h($ticket['ticket_number']) ?></div>
<div class="small text-muted mb-1 text-truncate" style="max-width: 100%;" title="<?= qh_h(qh_name($ticket, 'doctor_name', qh_t('Doctor', 'الطبيب'))) ?>"><?= qh_h(qh_name($ticket, 'doctor_name', qh_t('Doctor', 'الطبيب'))) ?></div>
<div class="d-inline-block bg-primary text-white rounded px-2 py-1 small fw-bold mt-1">
<?= qh_h(qh_t('Room', 'غرفة')) ?> <?= qh_h($ticket['doctor_room'] ?? '--') ?>
</div>
</div>
<div class="card-footer bg-white text-center text-muted small py-1" style="font-size: 0.65rem;">
<?= qh_format_datetime($ticket['called_at'] ?? $ticket['updated_at']) ?>
</div>
HTML;
$replace = <<<'HTML'
<div class="card-body text-center p-2 d-flex flex-column align-items-center justify-content-center">
<div class="fs-2 fw-bold text-primary mb-1"><?= qh_h($ticket['ticket_number']) ?></div>
<div class="small text-muted mb-1 text-truncate w-100" title="<?= qh_h(qh_name($ticket, 'doctor_name', qh_t('Doctor', 'الطبيب'))) ?>"><?= qh_h(qh_name($ticket, 'doctor_name', qh_t('Doctor', 'الطبيب'))) ?></div>
<div class="bg-primary text-white rounded px-2 py-1 small fw-bold mt-1 mb-2">
<?= qh_h(qh_t('Room', 'غرفة')) ?> <?= qh_h($ticket['doctor_room'] ?? '--') ?>
</div>
<div class="text-muted mt-auto" style="font-size: 0.65rem;">
<?= qh_format_datetime($ticket['called_at'] ?? $ticket['updated_at']) ?>
</div>
</div>
HTML;
$newContent = str_replace($search, $replace, $content);
if ($newContent !== $content) {
file_put_contents('display.php', $newContent);
echo "Replaced successfully\n";
} else {
echo "Pattern not found\n";
}