This commit is contained in:
parent
d302522256
commit
0dfeb43124
@ -166,8 +166,10 @@ async function playMedia(donat, voiceSettings) {
|
||||
const mediaPromise = (async () => {
|
||||
if (donat.play_content && donat.audio_link) {
|
||||
await playAudio(donat.audio_link, (voiceSettings.voice_sound_percent || 100) / 100, controller.signal);
|
||||
if (donat.text) await playSpeech(donat.text, voiceSettings, controller.signal);
|
||||
} else if (donat.text && donat.voice_enabled) {
|
||||
if (donat.text && donat.show_text) {
|
||||
await playSpeech(donat.text, voiceSettings, controller.signal);
|
||||
}
|
||||
} else if (donat.text && donat.voice_enabled && donat.show_text) {
|
||||
await playSpeech(donat.text, voiceSettings, controller.signal);
|
||||
}
|
||||
})();
|
||||
@ -179,8 +181,6 @@ async function playMedia(donat, voiceSettings) {
|
||||
}, timeoutDuration);
|
||||
});
|
||||
|
||||
// Promise.race будет ждать либо завершения медиа, либо таймаута
|
||||
// Если медиа завершится с ошибкой (например, автоплей заблокирован), она пробросится дальше.
|
||||
return Promise.race([mediaPromise, timeoutPromise]);
|
||||
}
|
||||
|
||||
@ -226,16 +226,12 @@ async function widgetView() {
|
||||
contentDiv.appendChild(textElem);
|
||||
}
|
||||
|
||||
// --- Воспроизведение ---
|
||||
const voiceSettings = { voice_speed: currentDonat.voice_speed, scenery: currentDonat.scenery, voice_sound_percent: currentDonat.voice_sound_percent, min_price: currentDonat.min_price, languages: currentDonat.languages, voice_enabled: currentDonat.voice_enabled };
|
||||
await playMedia(currentDonat, voiceSettings);
|
||||
|
||||
} catch (error) {
|
||||
// Логируем ошибку, но не прерываем логику ожидания и очистки
|
||||
console.error('Ошибка обработки доната:', error.name === 'AbortError' ? 'Таймаут или блокировка звука' : error);
|
||||
} finally {
|
||||
// --- Очистка и завершение ---
|
||||
// Этот блок выполнится ВСЕГДА: и после успеха, и после ошибки.
|
||||
if (currentDonat) {
|
||||
// Отмечаем донат как просмотренный
|
||||
if (currentDonat.order_id) {
|
||||
@ -250,7 +246,6 @@ async function widgetView() {
|
||||
}
|
||||
}
|
||||
|
||||
// Ждем оставшееся время до конца показа доната
|
||||
const elapsedMs = Date.now() - iterationStart;
|
||||
const durationMs = (currentDonat.duration || 5) * 1000;
|
||||
const remainingTimeMs = Math.max(0, durationMs - elapsedMs);
|
||||
@ -259,7 +254,6 @@ async function widgetView() {
|
||||
await new Promise(r => setTimeout(r, remainingTimeMs));
|
||||
}
|
||||
|
||||
// Гарантированно очищаем контейнер
|
||||
clearContainer(contentDiv);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user