magmastream
Advanced tools
Comparing version 2.6.0-beta.4 to 2.6.0-beta.5
@@ -896,13 +896,12 @@ /// <reference types="node" /> | ||
get useableNodes(): Node; | ||
private lastProcessedGuilds; | ||
private lastSaveTimes; | ||
private saveInterval; | ||
private saveQueues; | ||
private eventBatchInterval; | ||
private eventBatchDuration; | ||
private latestPlayerStates; | ||
/** Register savePlayerStates events */ | ||
private registerPlayerStateEvents; | ||
private handleEvent; | ||
/** Queues a player state save */ | ||
private queuePlayerStateSave; | ||
/** Processes the next queued save for a specific guild */ | ||
private processNextQueue; | ||
/** Collects player state events */ | ||
private collectPlayerStateEvent; | ||
/** Processes the collected player state events */ | ||
private processBatchEvents; | ||
/** | ||
@@ -909,0 +908,0 @@ * Initiates the Manager class. |
@@ -82,3 +82,3 @@ "use strict"; | ||
selfDeafen: state.options.selfDeafen, | ||
volume: state.options.volume, | ||
volume: lavaPlayer.volume || state.options.volume, | ||
}; | ||
@@ -261,6 +261,6 @@ this.create(playerOptions); | ||
} | ||
lastProcessedGuilds = new Set(); | ||
lastSaveTimes = new Map(); | ||
saveInterval = 1000; | ||
saveQueues = new Map(); | ||
eventBatchInterval = null; | ||
eventBatchDuration = 1000; | ||
latestPlayerStates = new Map(); | ||
/** Register savePlayerStates events */ | ||
@@ -270,53 +270,33 @@ registerPlayerStateEvents() { | ||
for (const event of events) { | ||
this.on(event, (player) => this.handleEvent(event, player)); | ||
this.on(event, (player) => this.collectPlayerStateEvent(event, player)); | ||
} | ||
} | ||
handleEvent(event, player) { | ||
switch (event) { | ||
case "playerDestroy": | ||
this.lastSaveTimes.delete(player.guild); | ||
this.players.delete(player.guild); | ||
this.cleanupInactivePlayers(); | ||
break; | ||
case "playerStateUpdate": | ||
this.queuePlayerStateSave(player); | ||
break; | ||
default: | ||
this.savePlayerState(player.guild); | ||
break; | ||
/** Collects player state events */ | ||
collectPlayerStateEvent(event, player) { | ||
if (event === "playerDestroy") { | ||
this.lastSaveTimes.delete(player.guild); | ||
this.players.delete(player.guild); | ||
this.cleanupInactivePlayers(); | ||
} | ||
} | ||
/** Queues a player state save */ | ||
queuePlayerStateSave(player) { | ||
const guildId = player.guild; | ||
// If the current guild is not being processed, save immediately | ||
if (!this.lastProcessedGuilds.has(guildId)) { | ||
this.lastProcessedGuilds.add(guildId); | ||
this.savePlayerState(guildId); | ||
setTimeout(() => { | ||
this.lastProcessedGuilds.delete(guildId); | ||
this.processNextQueue(guildId); | ||
}, this.saveInterval); | ||
else if (event === "playerStateUpdate") { | ||
// Store the latest player state for the guild | ||
this.latestPlayerStates.set(player.guild, player); | ||
} | ||
else { | ||
if (!this.saveQueues.has(guildId)) { | ||
this.saveQueues.set(guildId, []); | ||
} | ||
this.saveQueues.get(guildId).push(player); | ||
// Start the batch timer if it's not already running | ||
if (!this.eventBatchInterval) { | ||
this.eventBatchInterval = setTimeout(() => this.processBatchEvents(), this.eventBatchDuration); | ||
} | ||
} | ||
/** Processes the next queued save for a specific guild */ | ||
processNextQueue(guildId) { | ||
const queue = this.saveQueues.get(guildId); | ||
if (queue && queue.length > 0) { | ||
const player = queue.shift(); | ||
this.savePlayerState(player.guild); | ||
if (queue.length === 0) { | ||
this.saveQueues.delete(guildId); | ||
} | ||
setTimeout(() => this.processNextQueue(guildId), this.saveInterval); | ||
/** Processes the collected player state events */ | ||
processBatchEvents() { | ||
if (this.eventBatchInterval) { | ||
clearTimeout(this.eventBatchInterval); | ||
this.eventBatchInterval = null; | ||
} | ||
else { | ||
this.lastProcessedGuilds.delete(guildId); | ||
} | ||
// Save the latest player states for each guild | ||
this.latestPlayerStates.forEach((player, guildId) => { | ||
this.savePlayerState(guildId); // Perform a single write operation | ||
}); | ||
// Clear the latest player states after processing | ||
this.latestPlayerStates.clear(); | ||
} | ||
@@ -323,0 +303,0 @@ /** |
{ | ||
"name": "magmastream", | ||
"version": "2.6.0-beta.4", | ||
"version": "2.6.0-beta.5", | ||
"description": "A user-friendly Lavalink client designed for NodeJS.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155263
3784