Refactor code structure for improved readability and maintainability
All checks were successful
Build and Push Docker Image / docker (push) Successful in 21s

This commit is contained in:
2025-09-04 21:53:54 +02:00
parent 80f8c4ca90
commit 8c5ca0044f
27 changed files with 3398 additions and 326 deletions

View File

@@ -8,7 +8,8 @@ export function initAudioUI() {
if ('webkitPreservesPitch' in $audio) $audio.webkitPreservesPitch = true;
} catch {}
$audio.addEventListener('timeupdate', () => {
const dur = $audio.duration || 0; if (!dur || !$progressFill) return;
const dur = $audio.duration || 0;
if (!dur || !$progressFill) return;
const pct = Math.min(100, Math.max(0, ($audio.currentTime / dur) * 100));
$progressFill.style.width = pct + '%';
});
@@ -21,7 +22,10 @@ export function initAudioUI() {
$audio.addEventListener('stalled', () => showBuffer(true));
$audio.addEventListener('canplay', () => showBuffer(false));
$audio.addEventListener('playing', () => showBuffer(false));
$audio.addEventListener('ended', () => { if ($recordDisc) $recordDisc.classList.remove('spin-record'); $audio.playbackRate = 1.0; });
$audio.addEventListener('ended', () => {
if ($recordDisc) $recordDisc.classList.remove('spin-record');
$audio.playbackRate = 1.0;
});
}
export function applySync(startAt, serverNow) {
@@ -34,7 +38,7 @@ export function applySync(startAt, serverNow) {
const abs = Math.abs(drift);
if (abs > 1.0) {
$audio.currentTime = Math.max(0, elapsed);
if ($audio.paused) $audio.play().catch(()=>{});
if ($audio.paused) $audio.play().catch(() => {});
$audio.playbackRate = 1.0;
} else if (abs > 0.12) {
const maxNudge = 0.03;
@@ -42,16 +46,32 @@ export function applySync(startAt, serverNow) {
const rate = 1 + sign * Math.min(maxNudge, abs * 0.5);
$audio.playbackRate = Math.max(0.8, Math.min(1.2, rate));
} else {
if (Math.abs($audio.playbackRate - 1) > 0.001) { $audio.playbackRate = 1.0; }
if (Math.abs($audio.playbackRate - 1) > 0.001) {
$audio.playbackRate = 1.0;
}
}
}
export function stopAudioPlayback() {
try { $audio.pause(); } catch {}
try { $audio.currentTime = 0; } catch {}
try { $audio.src = ''; } catch {}
try { $audio.playbackRate = 1.0; } catch {}
try { if ($recordDisc) $recordDisc.classList.remove('spin-record'); } catch {}
try { if ($progressFill) $progressFill.style.width = '0%'; } catch {}
try { if ($bufferBadge) $bufferBadge.classList.add('hidden'); } catch {}
try {
$audio.pause();
} catch {}
try {
$audio.currentTime = 0;
} catch {}
try {
$audio.src = '';
} catch {}
try {
$audio.playbackRate = 1.0;
} catch {}
try {
if ($recordDisc) $recordDisc.classList.remove('spin-record');
} catch {}
try {
if ($progressFill) $progressFill.style.width = '0%';
} catch {}
try {
if ($bufferBadge) $bufferBadge.classList.add('hidden');
} catch {}
}