From cb5d4140a5e9be0fa8a4905f9504db4aaaccab15 Mon Sep 17 00:00:00 2001 From: deflax Date: Sun, 8 Sep 2024 01:29:31 +0000 Subject: [PATCH] improve console.log --- src/api/templates/index.html | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/api/templates/index.html b/src/api/templates/index.html index 60c91e6..27132fe 100644 --- a/src/api/templates/index.html +++ b/src/api/templates/index.html @@ -81,35 +81,34 @@ document.addEventListener('DOMContentLoaded', () => { // Check if the response is successful (status code 200) if (!response.ok) { - throw new Error(`HTTP error! Status: ${response.status}`); + throw new Error(`HLS.js: HTTP error! Status: ${response.status}`); } // Parse JSON from the response const data = await response.json(); // Now 'data' contains the parsed JSON - console.log("Fetched JSON data:", data); + // console.log("Fetched JSON data:", data); const oldsrc = hls.url; const newsrc = data.head; if (newsrc === oldsrc) { - //console.log(oldsrc); - //console.log(newsrc); + console.log('HLS.js: playing from ' newsrc); } else { - console.log('playhead: switching to ' + newsrc) + console.log('HLS.js: switching to ' + newsrc) hls.loadSource(newsrc); video.load(); // Reload the video element to apply the new source video.play().catch(error => { - console.error('Autoplay was prevented:', error); + console.error('HLS.js: Autoplay was prevented:', error); }); } } catch (error) { - console.error("Error fetching data:", error); + console.error("HLS.js: Error fetching data:", error); } } - fetchData(); + // Set the interval for periodic execution (e.g., every 5 seconds) const interval = 4200; // in milliseconds setInterval(fetchData, interval); @@ -122,7 +121,7 @@ document.addEventListener('DOMContentLoaded', () => { // all available video qualities. This is important; in this approach, // we will have one source on the Plyr player. hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) { - console.log('hls: manifest parsed'); + console.log('HLS.js: manifest parsed'); // Transform available levels into an array of integers (height values). const availableQualities = hls.levels.map((l) => l.height) @@ -144,7 +143,7 @@ document.addEventListener('DOMContentLoaded', () => { } hls.on(Hls.Events.LEVEL_SWITCHED, function (event, data) { - console.log('hls: level switched'); + console.log('HLS.js: level switched'); var span = document.querySelector(".plyr__menu__container [data-plyr='quality'][value='0'] span") if (hls.autoLevelEnabled) { span.innerHTML = `AUTO (${hls.levels[data.level].height}p)` @@ -169,19 +168,21 @@ document.addEventListener('DOMContentLoaded', () => { // Check if the response is successful (status code 200) if (!response.ok) { - throw new Error(`HTTP error! Status: ${response.status}`); + throw new Error(`Video: HTTP error! Status: ${response.status}`); } // Parse JSON from the response const data = await response.json(); // Now 'data' contains the parsed JSON - console.log("Fetched JSON data:", data); + //console.log("Fetched JSON data:", data); video.src = data.head; + console.log('Video: switching to ', data.head) + const player = new Plyr(video, defaultOptions); } catch (error) { - console.error("Error fetching data:", error); + console.error("Video: Error fetching data:", error); } } fetchInitData(); @@ -193,7 +194,7 @@ document.addEventListener('DOMContentLoaded', () => { } else { window.hls.levels.forEach((level, levelIndex) => { if (level.height === newQuality) { - console.log("hls: Found quality match with " + newQuality); + console.log("HLS.js: Found quality match with " + newQuality); window.hls.currentLevel = levelIndex; } });