From e1528c01551b271cf7f630fe3b94a9fd4ff46ec0 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Mon, 21 Apr 2025 06:21:07 -0400 Subject: [PATCH 1/3] Added verbose queue --- README.md | 8 +++++++- src/app/channel/media/queue.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7ed09f0..692e49a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ -Canopy - 0.2.1-INDEV +Canopy - 0.2.1-INDEV (verbose queue) ====== +--- + +This branch exists to seperate the extra shit I added to the queue for bug-hunting so it wouldn't make a mess of the main development branch :P + +--- + Canopy - /ˈkæ.nə.pi/: - The upper layer of foliage and branches of a forest, containing the majority of animal life. diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index fa489ae..7e342dd 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -60,8 +60,22 @@ module.exports = class{ socket.on("clear", (data) => {this.deleteRange(socket, data)}); socket.on("move", (data) => {this.moveMedia(socket, data)}); socket.on("lock", () => {this.toggleLock(socket)}); + + + socket.on("chanDump", () => {this.chanDump(socket)}); } + chanDump(socket){ + socket.emit('chanDump', + { + nowPlaying: this.nowPlaying, + schedule: Array.from(this.schedule), + //timer: this.nextTimer + } + ) + } + + //--- USER FACING QUEUEING FUNCTIONS --- async queueURL(socket, data){ //Get the current channel from the database @@ -149,6 +163,7 @@ module.exports = class{ //End the media this.end(); + console.log(`Media set to end due at the request of ${socket.user}`); } } @@ -298,6 +313,9 @@ module.exports = class{ clearTimeout(this.nextTimer); //Set the next timer this.nextTimer = setTimeout(()=>{this.start(nextItem, nextItem.startTimeStamp, volatile)}, startsIn); + console.log(`next item '${nextItem.title}' timer set to start in ${startsIn} seconds`); + }else{ + console.log('next timer is unset'); } } @@ -461,6 +479,7 @@ module.exports = class{ if(this.nowPlaying != null && this.nowPlaying.uuid == uuid){ //End playback this.end(false, true); + console.log("Media ended due to removal of media"); //otherwise }else{ try{ @@ -661,6 +680,7 @@ module.exports = class{ //Silently end the media in RAM so the database isn't stepping on itself up ahead //Alternatively we could've used await, but then we'd be doubling up on DB transactions :P this.end(true, true, true); + console.log("Media ended due to start of new media"); } //reset current timestamp @@ -732,6 +752,7 @@ module.exports = class{ //Call the end function once the video is over this.syncTimer = setTimeout(this.end.bind(this), leftover); + console.log(`Media set to end by sync function in ${leftover} milliseconds`); } } @@ -768,13 +789,17 @@ module.exports = class{ //FUCK throw new Error(`Unable to find channel document ${this.channel.name} while ending queue item!`); } - - //If we haven't changed 'nowPlaying' in the play list + + //If we haven't changed 'nowPlaying' in the DB if(chanDB.media.nowPlaying.uuid == wasPlaying.uuid){ //Take it out await chanDB.media.nowPlaying.deleteOne(); } + //NOTE: Keep an eye on this + //It seems this was part of my original design (don't remember was high) + //Though it is weird we keep it in both this.schedule and this.nowPlaying at the same time... + //More testing will have to be done... //Take it out of the active schedule this.schedule.delete(wasPlaying.startTime); From 91c89ba28faf18242cf3dc8430b5acd0e7e073e3 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Mon, 21 Apr 2025 06:49:01 -0400 Subject: [PATCH 2/3] Added verbosity and fixed bug in refreshNextTimer --- src/app/channel/media/queue.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index 7e342dd..0e2627e 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -302,10 +302,11 @@ module.exports = class{ if(currentItem != null && (this.nowPlaying == null || currentItem.uuid != this.nowPlaying.uuid)){ //Start the found item at w/ a pre-calculated time stamp to reflect the given start time this.start(currentItem, Math.round((new Date().getTime() - currentItem.startTime) / 1000) + currentItem.startTimeStamp, volatile); - } - - //If we have a next item - if(nextItem != null){ + console.log("starting now from refreshNextTimer") + //Otherwise, if we have a next item + //CODE CHANGE CODE CHANGE + //Changes this over to an else if so refreshNextTimer wouldn't start it twice when there was no current item or next item + }else if(nextItem != null){ //Calculate the amount of time in ms that the next item will start in const startsIn = nextItem.startTime - new Date().getTime(); @@ -721,6 +722,7 @@ module.exports = class{ //Kick off the sync timer this.syncTimer = setTimeout(this.sync.bind(this), this.syncDelta); + console.log('kicking off sync timer from start'); //Setup the next video this.refreshNextTimer(); @@ -746,6 +748,7 @@ module.exports = class{ //Call the sync function in another second this.syncTimer = setTimeout(this.sync.bind(this), this.syncDelta); + console.log('re-kicking sync timer from sync'); }else{ //Get leftover video length in ms const leftover = (this.nowPlaying.duration - this.timestamp) * 1000; From 3426d6764a8ccc090134f98a08da98d05896937a Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Tue, 22 Apr 2025 01:18:24 -0400 Subject: [PATCH 3/3] Fixed ghost media caused by stale nextTimers --- src/app/channel/media/queue.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index 0e2627e..2ae14ec 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -298,6 +298,9 @@ module.exports = class{ //Get current item const currentItem = this.getItemAtEpoch() + //Clear out any stale timer to prevent ghost queueing + clearTimeout(this.nextTimer); + //If we have a current item and it isn't currently playing if(currentItem != null && (this.nowPlaying == null || currentItem.uuid != this.nowPlaying.uuid)){ //Start the found item at w/ a pre-calculated time stamp to reflect the given start time @@ -310,8 +313,6 @@ module.exports = class{ //Calculate the amount of time in ms that the next item will start in const startsIn = nextItem.startTime - new Date().getTime(); - //Clear out any item that might be up next - clearTimeout(this.nextTimer); //Set the next timer this.nextTimer = setTimeout(()=>{this.start(nextItem, nextItem.startTimeStamp, volatile)}, startsIn); console.log(`next item '${nextItem.title}' timer set to start in ${startsIn} seconds`);