Update public/script.js
Browse files- public/script.js +25 -32
public/script.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
function changeChannel(channel) {
|
| 2 |
document.getElementById("channelName").textContent = `Channel ${channel}`;
|
| 3 |
document.getElementById("currentShow").textContent = `Now Playing: Loading...`;
|
|
@@ -22,35 +45,5 @@ function changeChannel(channel) {
|
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
if (video.paused) {
|
| 28 |
-
video.play();
|
| 29 |
-
} else {
|
| 30 |
-
video.pause();
|
| 31 |
-
}
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
function toggleFullscreen() {
|
| 35 |
-
const video = document.getElementById("tvPlayer");
|
| 36 |
-
if (video.requestFullscreen) {
|
| 37 |
-
video.requestFullscreen();
|
| 38 |
-
} else if (video.mozRequestFullScreen) {
|
| 39 |
-
video.mozRequestFullScreen();
|
| 40 |
-
} else if (video.webkitRequestFullscreen) {
|
| 41 |
-
video.webkitRequestFullscreen();
|
| 42 |
-
} else if (video.msRequestFullscreen) {
|
| 43 |
-
video.msRequestFullscreen();
|
| 44 |
-
}
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
function toggleMute() {
|
| 48 |
-
const video = document.getElementById("tvPlayer");
|
| 49 |
-
video.muted = !video.muted;
|
| 50 |
-
document.getElementById("muteBtn").textContent = video.muted ? "🔇 Unmute" : "🔊 Mute";
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
// Set default channel on page load
|
| 54 |
-
window.onload = () => {
|
| 55 |
-
changeChannel(1);
|
| 56 |
-
};
|
|
|
|
| 1 |
+
async function fetchChannels() {
|
| 2 |
+
const response = await fetch("/channels");
|
| 3 |
+
const data = await response.json();
|
| 4 |
+
|
| 5 |
+
const channelButtons = document.querySelector(".channel-buttons");
|
| 6 |
+
channelButtons.innerHTML = ""; // Clear existing buttons
|
| 7 |
+
|
| 8 |
+
data.channels.forEach(channel => {
|
| 9 |
+
const button = document.createElement("button");
|
| 10 |
+
button.textContent = `Channel ${channel}`;
|
| 11 |
+
button.onclick = () => changeChannel(channel);
|
| 12 |
+
channelButtons.appendChild(button);
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
// Set default channel to the first available one
|
| 16 |
+
if (data.channels.length > 0) {
|
| 17 |
+
changeChannel(data.channels[0]);
|
| 18 |
+
} else {
|
| 19 |
+
document.getElementById("channelName").textContent = "No channels available";
|
| 20 |
+
document.getElementById("currentShow").textContent = "No active streams.";
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
function changeChannel(channel) {
|
| 25 |
document.getElementById("channelName").textContent = `Channel ${channel}`;
|
| 26 |
document.getElementById("currentShow").textContent = `Now Playing: Loading...`;
|
|
|
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
+
// Fetch channels on page load
|
| 49 |
+
window.onload = fetchChannels;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|