add fix for widget template
This commit is contained in:
parent
d6180ddc3e
commit
d1c536acbc
@ -165,6 +165,7 @@ function playSpeechAfterAudio(audioUrl, text) {
|
||||
async function widgetView() {
|
||||
const streamerID = '%v';
|
||||
const contentDiv = document.getElementById('content');
|
||||
const REQUEST_INTERVAL = 5000; // Фиксированный интервал 5 секунд
|
||||
|
||||
if (!contentDiv) {
|
||||
console.error('Content container not found!');
|
||||
@ -172,6 +173,8 @@ async function widgetView() {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const iterationStart = Date.now(); // Замер времени начала итерации
|
||||
|
||||
try {
|
||||
const donat = await getDonatInfo(streamerID);
|
||||
console.log('Donat received:', donat);
|
||||
@ -183,10 +186,12 @@ async function widgetView() {
|
||||
|
||||
clearContainer(contentDiv);
|
||||
|
||||
// Добавление элементов в DOM
|
||||
if (donat.image_link) {
|
||||
addImage(contentDiv, donat.image_link);
|
||||
}
|
||||
|
||||
// Создание текста с суммой
|
||||
if (donat.text && donat.amount) {
|
||||
const textWithAmount = createTextWithAmount(donat.text, donat.amount);
|
||||
contentDiv.appendChild(textWithAmount);
|
||||
@ -194,36 +199,39 @@ async function widgetView() {
|
||||
addText(contentDiv, donat.text);
|
||||
}
|
||||
|
||||
// Воспроизведение аудио
|
||||
if (donat.audio_link) {
|
||||
playSpeechAfterAudio(donat.audio_link, donat.text);
|
||||
} else if (donat.text) {
|
||||
playSpeech(donat.text);
|
||||
}
|
||||
|
||||
// Ожидаем указанную длительность
|
||||
await new Promise(r => setTimeout(r, donat.duration * 1000));
|
||||
|
||||
// Отправка подтверждения просмотра
|
||||
if (donat.order_id) {
|
||||
try {
|
||||
const response = await fetch(widgetUrl + '/widget/donat/viewed', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({order_id: donat.order_id}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error('Failed to mark donat as viewed:', response.status);
|
||||
} else {
|
||||
console.log('Donat marked as viewed:', donat.order_id);
|
||||
}
|
||||
if (!response.ok) console.error('Ошибка подтверждения просмотра');
|
||||
} catch (error) {
|
||||
console.error('Error marking donat as viewed:', error);
|
||||
console.error('Ошибка:', error);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Main loop error:', error);
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
console.error('Ошибка в цикле:', error);
|
||||
} finally {
|
||||
// Гарантируем задержку между итерациями
|
||||
const elapsed = Date.now() - iterationStart;
|
||||
const remaining = REQUEST_INTERVAL - elapsed;
|
||||
if (remaining > 0) {
|
||||
await new Promise(r => setTimeout(r, remaining));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -234,7 +242,6 @@ document.addEventListener('DOMContentLoaded', widgetView);`, donatHost, ttsHost,
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>%s</style>
|
||||
</head>
|
||||
<body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user