Re-scheduling currently playing item now stops currnet playback, and re-schedules a clone. Allowing for DB-Friendly schedule2scrub functionality.

This commit is contained in:
rainbow napkin 2025-09-09 08:19:46 -04:00
parent 92659929b9
commit 9eeed591ad
4 changed files with 112 additions and 58 deletions

View file

@ -596,7 +596,7 @@ class queue{
}
//Find our media, don't remove it yet since we want to do some more testing first
const media = this.getItemByUUID(uuid);
let media = this.getItemByUUID(uuid);
//If we got a bad request
if(media == null){
@ -611,27 +611,31 @@ class queue{
//If someone is trying to re-schedule something that starts in the past
if(media.startTime < new Date().getTime()){
//If an originating socket was provided for this request
if(socket != null){
//If the item is currently playing
if(media.getEndTime() > new Date().getTime()){
//Yell at the user for being an asshole
loggerUtils.socketErrorHandler(socket, "You cannot move an actively playing video!", "queue");
//Otherwise, if it's already ended
}else{
//If the item is currently playing
if(media.getEndTime() > new Date().getTime()){
//Dupe media for the rest of the function
media = media.clone();
//Stop current item
await this.stop(socket, chanDB);
//Otherwise, if it's already ended
}else{
//If an originating socket was provided for this request
if(socket != null){
//Yell at the user for being an asshole
loggerUtils.socketErrorHandler(socket, "You cannot alter the past!", "queue");
}
//Ignore it
return;
}
//Ignore it
return;
//If the item has yet to be played
}else{
//Remove the media from the schedule
await this.removeMedia(uuid, socket, chanDB);
}
//Remove the media from the schedule
await this.removeMedia(uuid, socket, chanDB);
//Grab the old start time for safe keeping
const oldStart = media.startTime;
@ -1438,9 +1442,10 @@ class queue{
/**
* Stops currently playing media item
* @param {Socket} socket - Requesting Socket
* @param {Mongoose.Document} chanDB - Pass through Channel Document to save on DB Transactions
* @returns returns false if there is nothing to stop
*/
stop(socket){
async stop(socket, chanDB){
//If we're not currently playing anything
if(this.nowPlaying == null){
//If an originating socket was provided for this request
@ -1462,7 +1467,7 @@ class queue{
}
//End the media
this.end();
await this.end(false, false, false, chanDB);
}
/**

View file

@ -119,6 +119,25 @@ class queuedMedia extends media{
this.uuid = crypto.randomUUID();
}
/**
* Generates a unique clone of a given media object
* @returns unique clone of media object
*/
clone(){
return new queuedMedia(
this.title,
this.fileName,
this.url,
this.id,
this.type,
this.duration,
this.rawLink,
this.startTime,
this.startTimeStamp,
this.earlyEnd
);
}
/**
* return the end time of a given queuedMedia object
* @param {boolean} fullTime - Overrides early ends