aqualink 2.12.0 → 2.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/structures/Aqua.js +37 -10
- package/build/structures/Connection.js +25 -11
- package/build/structures/Player.js +61 -36
- package/build/structures/Track.js +10 -1
- package/package.json +1 -1
package/build/structures/Aqua.js
CHANGED
|
@@ -142,6 +142,7 @@ class Aqua extends EventEmitter {
|
|
|
142
142
|
this._onNodeConnect = async node => {
|
|
143
143
|
this._invalidateCache()
|
|
144
144
|
await this._rebuildBrokenPlayers(node)
|
|
145
|
+
this._performCleanup()
|
|
145
146
|
}
|
|
146
147
|
this._onNodeDisconnect = node => {
|
|
147
148
|
this._invalidateCache()
|
|
@@ -759,33 +760,59 @@ class Aqua extends EventEmitter {
|
|
|
759
760
|
|
|
760
761
|
_performCleanup() {
|
|
761
762
|
const now = Date.now();
|
|
763
|
+
|
|
762
764
|
const expiredPlayers = [];
|
|
763
765
|
for (const [guildId, state] of this._brokenPlayers) {
|
|
764
|
-
if (now - state.brokenAt > BROKEN_PLAYER_TTL)
|
|
766
|
+
if (now - state.brokenAt > BROKEN_PLAYER_TTL) {
|
|
767
|
+
expiredPlayers.push(guildId);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
for (const guildId of expiredPlayers) {
|
|
771
|
+
this._brokenPlayers.delete(guildId);
|
|
765
772
|
}
|
|
766
|
-
|
|
773
|
+
|
|
767
774
|
const expiredNodes = [];
|
|
768
775
|
for (const [nodeId, ts] of this._lastFailoverAttempt) {
|
|
769
|
-
if (now - ts > FAILOVER_CLEANUP_TTL)
|
|
776
|
+
if (now - ts > FAILOVER_CLEANUP_TTL) {
|
|
777
|
+
expiredNodes.push(nodeId);
|
|
778
|
+
}
|
|
770
779
|
}
|
|
771
780
|
for (const nodeId of expiredNodes) {
|
|
772
781
|
this._lastFailoverAttempt.delete(nodeId);
|
|
773
782
|
this._failoverQueue.delete(nodeId);
|
|
774
783
|
}
|
|
775
|
-
|
|
784
|
+
|
|
785
|
+
if (this._brokenPlayers.size > 100) {
|
|
776
786
|
const oldest = [...this._brokenPlayers.entries()]
|
|
777
787
|
.sort((a, b) => a[1].brokenAt - b[1].brokenAt)
|
|
778
788
|
.slice(0, this._brokenPlayers.size - 50);
|
|
779
|
-
for (const [guildId] of oldest)
|
|
789
|
+
for (const [guildId] of oldest) {
|
|
790
|
+
this._brokenPlayers.delete(guildId);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (this._failoverQueue.size > 50) {
|
|
795
|
+
this._failoverQueue.clear();
|
|
780
796
|
}
|
|
781
|
-
|
|
782
|
-
if (this._lastFailoverAttempt.size >
|
|
783
|
-
|
|
784
|
-
|
|
797
|
+
|
|
798
|
+
if (this._lastFailoverAttempt.size > 50) {
|
|
799
|
+
this._lastFailoverAttempt.clear();
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
for (const [nodeId, state] of this._nodeStates) {
|
|
803
|
+
if (!this.nodeMap.has(nodeId)) {
|
|
804
|
+
this._nodeStates.delete(nodeId);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
this._invalidateCache();
|
|
809
|
+
|
|
810
|
+
if (this._nodeLoadCache.size > 20) {
|
|
785
811
|
this._nodeLoadCache.clear();
|
|
786
812
|
this._nodeLoadCacheTime.clear();
|
|
787
813
|
}
|
|
788
|
-
|
|
814
|
+
|
|
815
|
+
this.emit("debug", `Cleanup: broken=${this._brokenPlayers.size}, failover=${this._failoverQueue.size}, players=${this.players.size}`);
|
|
789
816
|
}
|
|
790
817
|
|
|
791
818
|
_getAvailableNodes(excludeNode) {
|
|
@@ -31,10 +31,10 @@ const _functions = {
|
|
|
31
31
|
|
|
32
32
|
class OptimizedPayloadPool {
|
|
33
33
|
constructor() {
|
|
34
|
-
this.pool = new Array(POOL_SIZE)
|
|
35
|
-
this.size = POOL_SIZE
|
|
34
|
+
this.pool = new Array(POOL_SIZE);
|
|
35
|
+
this.size = POOL_SIZE;
|
|
36
36
|
for (let i = 0; i < POOL_SIZE; i++) {
|
|
37
|
-
this.pool[i] = this._createPayload()
|
|
37
|
+
this.pool[i] = this._createPayload();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -51,22 +51,36 @@ class OptimizedPayloadPool {
|
|
|
51
51
|
},
|
|
52
52
|
volume: null
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
acquire() {
|
|
58
|
-
return this.size > 0 ? this.pool[--this.size] : this._createPayload()
|
|
58
|
+
return this.size > 0 ? this.pool[--this.size] : this._createPayload();
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
release(payload) {
|
|
62
|
-
if (!payload || this.size >= POOL_SIZE) return
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
payload.data.
|
|
66
|
-
|
|
62
|
+
if (!payload || this.size >= POOL_SIZE) return;
|
|
63
|
+
|
|
64
|
+
payload.guildId = null;
|
|
65
|
+
const voice = payload.data.voice;
|
|
66
|
+
voice.token = null;
|
|
67
|
+
voice.endpoint = null;
|
|
68
|
+
voice.sessionId = null;
|
|
69
|
+
voice.resume = undefined;
|
|
70
|
+
voice.sequence = undefined;
|
|
71
|
+
payload.data.volume = null;
|
|
72
|
+
|
|
73
|
+
this.pool[this.size++] = payload;
|
|
67
74
|
}
|
|
68
|
-
}
|
|
69
75
|
|
|
76
|
+
destroy() {
|
|
77
|
+
for (let i = 0; i < this.size; i++) {
|
|
78
|
+
this.pool[i] = null;
|
|
79
|
+
}
|
|
80
|
+
this.pool = null;
|
|
81
|
+
this.size = 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
70
84
|
const sharedPool = new OptimizedPayloadPool()
|
|
71
85
|
|
|
72
86
|
class Connection {
|
|
@@ -283,53 +283,78 @@ class Player extends EventEmitter {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
destroy({ preserveClient = true, skipRemote = false } = {}) {
|
|
286
|
-
if (this.destroyed) return this
|
|
286
|
+
if (this.destroyed) return this;
|
|
287
|
+
|
|
288
|
+
this.destroyed = true;
|
|
289
|
+
|
|
287
290
|
if (this._voiceWatchdogTimer) {
|
|
288
|
-
clearInterval(this._voiceWatchdogTimer)
|
|
289
|
-
this._voiceWatchdogTimer = null
|
|
291
|
+
clearInterval(this._voiceWatchdogTimer);
|
|
292
|
+
this._voiceWatchdogTimer = null;
|
|
290
293
|
}
|
|
291
|
-
|
|
292
|
-
this.connected = this.playing = this.paused = this.isAutoplay = false
|
|
293
|
-
this.isAutoplay = false
|
|
294
|
-
this.autoplayRetries = this.reconnectionRetries = 0
|
|
295
|
-
this.voiceChannel = null
|
|
296
|
-
this.nowPlayingMessage = null
|
|
297
|
-
|
|
298
|
-
this.
|
|
294
|
+
|
|
295
|
+
this.connected = this.playing = this.paused = this.isAutoplay = false;
|
|
296
|
+
this.isAutoplay = false;
|
|
297
|
+
this.autoplayRetries = this.reconnectionRetries = 0;
|
|
298
|
+
this.voiceChannel = null;
|
|
299
|
+
this.nowPlayingMessage = null;
|
|
300
|
+
|
|
301
|
+
this.removeAllListeners();
|
|
302
|
+
this.off('playerUpdate', this._boundPlayerUpdate);
|
|
303
|
+
this.off('event', this._boundEvent);
|
|
304
|
+
|
|
299
305
|
if (this.aqua && this._boundAquaPlayerMove) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
} catch (error) {
|
|
303
|
-
this.aqua.emit('debug', new Error(`Failed to remove aqua playerMove listener: ${error.message}`))
|
|
304
|
-
}
|
|
306
|
+
this.aqua.removeListener('playerMove', this._boundAquaPlayerMove);
|
|
307
|
+
this.aqua.off('playerMove', this._boundAquaPlayerMove);
|
|
305
308
|
}
|
|
306
309
|
|
|
307
|
-
this._updateBatcher
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
this.removeAllListeners()
|
|
312
|
-
this._updateBatcher?.destroy()
|
|
313
|
-
this._updateBatcher = null
|
|
310
|
+
if (this._updateBatcher) {
|
|
311
|
+
this._updateBatcher.destroy();
|
|
312
|
+
this._updateBatcher = null;
|
|
313
|
+
}
|
|
314
314
|
|
|
315
|
-
this.connection
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
this.
|
|
315
|
+
if (this.connection) {
|
|
316
|
+
this.connection.destroy();
|
|
317
|
+
this.connection = null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (this.queue) {
|
|
321
|
+
this.queue.clear();
|
|
322
|
+
this.queue = null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (this.previousTracks) {
|
|
326
|
+
this.previousTracks.clear();
|
|
327
|
+
this.previousTracks = null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (this.previousIdentifiers) {
|
|
331
|
+
this.previousIdentifiers.clear();
|
|
332
|
+
this.previousIdentifiers = null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
this.filters = null;
|
|
336
|
+
this._dataStore = null;
|
|
337
|
+
this.current = null;
|
|
338
|
+
this.autoplaySeed = null;
|
|
339
|
+
|
|
340
|
+
this._boundPlayerUpdate = null;
|
|
341
|
+
this._boundEvent = null;
|
|
342
|
+
this._boundAquaPlayerMove = null;
|
|
321
343
|
|
|
322
344
|
if (!skipRemote) {
|
|
323
345
|
try {
|
|
324
|
-
this.send({ guild_id: this.guildId, channel_id: null })
|
|
325
|
-
this.aqua?.destroyPlayer?.(this.guildId)
|
|
326
|
-
this.nodes?.connected && this.nodes?.rest?.destroyPlayer?.(this.guildId).catch(
|
|
327
|
-
} catch { }
|
|
346
|
+
this.send({ guild_id: this.guildId, channel_id: null });
|
|
347
|
+
this.aqua?.destroyPlayer?.(this.guildId);
|
|
348
|
+
this.nodes?.connected && this.nodes?.rest?.destroyPlayer?.(this.guildId).catch(() => { });
|
|
349
|
+
} catch (e) { }
|
|
328
350
|
}
|
|
329
|
-
this.clearData()
|
|
330
|
-
if (!preserveClient) this.aqua = this.nodes = null
|
|
331
|
-
return this
|
|
332
351
|
|
|
352
|
+
if (!preserveClient) {
|
|
353
|
+
this.aqua = null;
|
|
354
|
+
this.nodes = null;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return this;
|
|
333
358
|
}
|
|
334
359
|
|
|
335
360
|
pause(paused) {
|
|
@@ -107,7 +107,7 @@ class Track {
|
|
|
107
107
|
|
|
108
108
|
isValid() {
|
|
109
109
|
return (typeof this.track === 'string' && this.track.length > 0)
|
|
110
|
-
|
|
110
|
+
|| (typeof this.uri === 'string' && this.uri.length > 0);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
dispose() {
|
|
@@ -115,6 +115,15 @@ class Track {
|
|
|
115
115
|
this.requester = null;
|
|
116
116
|
this.node = null;
|
|
117
117
|
this.nodes = null;
|
|
118
|
+
this.playlist = null;
|
|
119
|
+
|
|
120
|
+
this.track = null;
|
|
121
|
+
this.identifier = '';
|
|
122
|
+
this.author = '';
|
|
123
|
+
this.title = '';
|
|
124
|
+
this.uri = '';
|
|
125
|
+
this.sourceName = '';
|
|
126
|
+
this.artworkUrl = '';
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
_computeArtworkFromKnownSources() {
|