From a927b319192e752b1e6c0d424f8f18b78a41a03d Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Mon, 12 May 2025 20:48:53 -0400 Subject: [PATCH] Added streamlock to disable refreshNextTimer() while streaming. Fixed bug in HLS Livestream Media Handler. --- src/app/channel/media/queue.js | 29 +++++++++++++++-------------- www/js/channel/mediaHandler.js | 7 ++++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/app/channel/media/queue.js b/src/app/channel/media/queue.js index 0887723..c97aff3 100644 --- a/src/app/channel/media/queue.js +++ b/src/app/channel/media/queue.js @@ -49,6 +49,8 @@ module.exports = class{ this.preSwitchTimer = null; //Create variable to hold currently playing media object this.nowPlaying = null; + //Create variable to lock standard queuing functions during livestreams + this.streamLock = false; //create boolean to hold schedule lock this.locked = false; @@ -302,6 +304,9 @@ module.exports = class{ //Broadcast new media object to users this.sendMedia(); + + //Throw stream lock + this.streamLock = true; }catch(err){ return loggerUtils.socketExceptionHandler(socket, err); } @@ -359,13 +364,18 @@ module.exports = class{ } refreshNextTimer(volatile = false){ + //If we're streamlocked + if(this.streamLock){ + //Stop while we're ahead since the stream hasn't ended yet + return; + } + //Grab the next item const nextItem = this.getNextItem(); //Get current item const currentItem = this.getItemAtEpoch() - //Clear out any stale timers to prevent ghost queueing clearTimeout(this.nextTimer); clearTimeout(this.preSwitchTimer); @@ -946,6 +956,9 @@ module.exports = class{ async endLivestream(chanDB){ try{ + //Disable stream lock + this.streamLock = false; + //Refresh next timer this.refreshNextTimer(); @@ -960,19 +973,7 @@ module.exports = class{ } } - async stop(chanDB){ - //If we wheren't handed a channel - if(chanDB == null){ - //DO everything ourselves since we don't have a fance end() function to do it - chanDB = await channelModel.findOne({name:this.channel.name}); - } - - //If we wheren't handed a channel - if(chanDB == null){ - //Complain about the lack of a channel - throw loggerUtils.exceptionSmith(`Channel not found!`, "queue"); - } - + stop(){ //If we're not currently playing anything if(this.nowPlaying == null){ //If an originating socket was provided for this request diff --git a/www/js/channel/mediaHandler.js b/www/js/channel/mediaHandler.js index aa272c5..ab92989 100644 --- a/www/js/channel/mediaHandler.js +++ b/www/js/channel/mediaHandler.js @@ -605,10 +605,15 @@ class hlsLiveStreamHandler extends hlsBase{ //Call derived method super.onSeek(event); + //If we stopped playing the video + if(this.video == null){ + //Don't worry about it + return; + } + //Calculate distance to end of stream const difference = this.video.duration - this.video.currentTime; - //If we where buffering under sync lock if(this.reSync){ //Set reSync to false