Skip to content

Commit

Permalink
Merge pull request #167 from Ragzouken/playing
Browse files Browse the repository at this point in the history
entry now playing adjustments
  • Loading branch information
Ragzouken authored Nov 18, 2023
2 parents 37374a0 + 3c4b0c5 commit 2e378f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/client/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ html
#entry-panel
#entry-logo-container
img#entry-logo(src="./zone-logo.png")
#entry-playing ...
#entry-playing(hidden) ...
#entry-users.user-container ...
form#entry
input#join-name(type="text" placeholder="your name..." minlength="1" maxlength="16" required)
Expand Down
41 changes: 27 additions & 14 deletions src/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,32 +959,45 @@ function setupEntrySplash() {
updateEntryUsers();
setInterval(updateEntryUsers, 5000);

let lastItem: QueueItem;
let lastTime: number;
let lastItem: QueueItem | undefined;
let lastItemStartTime: number;

function refreshEntryPlaying() {
function updateEntryPlaying() {
if (lastItem) {
const time = performance.now() - lastTime;
const time = (performance.now() - lastItemStartTime) / 1000;
const durr = lastItem.media.duration / 1000;

if (time >= durr) {
lastItem = undefined;
fetchEntryPlaying();
updateEntryPlaying();
} else {
entryPlaying.replaceChildren(
lastItem.media.title,
document.createElement("br"),
`${secondsToTime(time)} / ${secondsToTime(durr)}`,
);
}

const stamp = secondsToTime(time / 1000);
const duration = secondsToTime(lastItem.media.duration / 1000);
entryPlaying.replaceChildren(`${lastItem.media.title}`, document.createElement("br"), `${stamp} / ${duration}`);
entryPlaying.hidden = durr < 600;
} else {
entryPlaying.replaceChildren(`nothing playing`);
entryPlaying.hidden = true;
}
}

function updateEntryPlaying() {
fetch('./playing')
function fetchEntryPlaying() {
if (entrySplash.hidden) return;

fetch("https://tinybird.zone/playing")
.then((res) => res.json())
.then(({ item, time }) => {
lastItem = item;
lastTime = performance.now() - time;
lastItemStartTime = performance.now() - time;
});
}
updateEntryPlaying();
setInterval(updateEntryPlaying, 5000);
setInterval(refreshEntryPlaying, 500);
fetchEntryPlaying();
setInterval(fetchEntryPlaying, 5000);
setInterval(updateEntryPlaying, 500);

entryButton.disabled = !entryForm.checkValidity();
nameInput.addEventListener('input', () => (entryButton.disabled = !entryForm.checkValidity()));
Expand Down
1 change: 1 addition & 0 deletions src/client/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ button > img {

#entry-playing {
margin: 1em;
color: cyan;
}

.user-dj {
Expand Down

0 comments on commit 2e378f6

Please sign in to comment.