From 575fd161281fdbb74dc14e818495f7e402cd2c26 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Tue, 5 Nov 2024 08:33:12 +0100 Subject: [PATCH] thrimbletrimmer: When no end time set, show and auto-refresh chat We request current time + 1 minute, and re-request every 10 seconds. If I'm reading the code correctly, everything already correctly handles the chat being replaced by a new fetch (as though we loaded a new video range). --- thrimbletrimmer/scripts/common.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/thrimbletrimmer/scripts/common.js b/thrimbletrimmer/scripts/common.js index 852da85..229cd97 100644 --- a/thrimbletrimmer/scripts/common.js +++ b/thrimbletrimmer/scripts/common.js @@ -20,6 +20,8 @@ const VIDEO_FRAMES_PER_SECOND = 30; const PLAYBACK_RATES = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4, 8]; +const CHAT_REFRESH_INTERVAL_MS = 10000; + function commonPageSetup() { if (!Hls.isSupported()) { addError( @@ -517,10 +519,15 @@ function triggerDownload(url, filename) { function sendChatLogLoadData() { let startTime = getStartTime(); - let endTime = getEndTime(); - if (!startTime || !endTime) { + if (startTime === null) { return; } + let endTime = getEndTime(); + let refresh = false; + if (endTime === null) { + endTime = DateTime.now().setZone("utc").plus({minutes: 1}); + refresh = true; + } startTime = wubloaderTimeFromDateTime(startTime); endTime = wubloaderTimeFromDateTime(endTime); const segmentMetadata = getSegmentTimes(); @@ -536,6 +543,10 @@ function sendChatLogLoadData() { segmentMetadata: segmentMetadata, }; globalLoadChatWorker.postMessage(message); + + if (refresh) { + setTimeout(sendChatLogLoadData, CHAT_REFRESH_INTERVAL_MS); + } } function updateChatDataFromWorkerResponse(chatData) {