aqualink 2.20.1 → 3.1.0
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/README.md +174 -184
- package/build/handlers/autoplay.js +5 -1
- package/build/index.d.ts +1 -1
- package/build/structures/Aqua.js +235 -540
- package/build/structures/AquaRecovery.js +905 -0
- package/build/structures/Connection.js +84 -262
- package/build/structures/ConnectionRecovery.js +425 -0
- package/build/structures/Filters.js +96 -13
- package/build/structures/Node.js +175 -72
- package/build/structures/Player.js +344 -338
- package/build/structures/PlayerLifecycle.js +584 -0
- package/build/structures/PlayerLifecycleState.js +42 -0
- package/build/structures/Queue.js +5 -1
- package/build/structures/Reporting.js +32 -0
- package/build/structures/Rest.js +51 -11
- package/build/structures/Track.js +2 -2
- package/package.json +1 -1
package/build/structures/Rest.js
CHANGED
|
@@ -134,6 +134,7 @@ class Rest {
|
|
|
134
134
|
this.aqua = aqua
|
|
135
135
|
this.node = node
|
|
136
136
|
this.sessionId = node.sessionId
|
|
137
|
+
this._sessionGeneration = 0
|
|
137
138
|
this.timeout = node.timeout || 30000
|
|
138
139
|
|
|
139
140
|
const protocol = node.ssl ? 'https:' : 'http:'
|
|
@@ -172,6 +173,7 @@ class Rest {
|
|
|
172
173
|
|
|
173
174
|
this._headerPool = []
|
|
174
175
|
this._tlsOptions = null
|
|
176
|
+
this._autoplayAgent = null
|
|
175
177
|
this._setupAgent(node)
|
|
176
178
|
this.useHttp2 = !!aqua?.options?.useHttp2
|
|
177
179
|
this._h2 = null
|
|
@@ -207,8 +209,21 @@ class Rest {
|
|
|
207
209
|
this.agent = new (node.ssl ? HttpsAgent : HttpAgent)(opts)
|
|
208
210
|
this.request = node.ssl ? httpsRequest : httpRequest
|
|
209
211
|
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
+
if (autoplayModule?.setSharedAgent) {
|
|
213
|
+
if (node.ssl) {
|
|
214
|
+
this._autoplayAgent = this.agent
|
|
215
|
+
} else {
|
|
216
|
+
this._autoplayAgent = new HttpsAgent({
|
|
217
|
+
keepAlive: true,
|
|
218
|
+
maxSockets: node.maxSockets || 128,
|
|
219
|
+
maxFreeSockets: node.maxFreeSockets || 64,
|
|
220
|
+
freeSocketTimeout: node.freeSocketTimeout || 15000,
|
|
221
|
+
keepAliveMsecs: node.keepAliveMsecs || 500,
|
|
222
|
+
scheduling: 'lifo',
|
|
223
|
+
timeout: this.timeout
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
autoplayModule.setSharedAgent(this._autoplayAgent)
|
|
212
227
|
}
|
|
213
228
|
|
|
214
229
|
const origCreate = this.agent.createConnection.bind(this.agent)
|
|
@@ -222,10 +237,18 @@ class Rest {
|
|
|
222
237
|
|
|
223
238
|
setSessionId(sessionId) {
|
|
224
239
|
this.sessionId = sessionId
|
|
240
|
+
this._sessionGeneration++
|
|
225
241
|
}
|
|
226
242
|
|
|
227
|
-
_getSessionPath() {
|
|
243
|
+
_getSessionPath(generation) {
|
|
228
244
|
if (!this.sessionId) throw ERRORS.NO_SESSION
|
|
245
|
+
if (generation != null && generation !== this._sessionGeneration) {
|
|
246
|
+
const staleErr = new Error(
|
|
247
|
+
`Stale session: sessionId was updated (expected gen ${generation}, current ${this._sessionGeneration}) for session ${this.sessionId}`
|
|
248
|
+
)
|
|
249
|
+
staleErr.statusCode = 404
|
|
250
|
+
throw staleErr
|
|
251
|
+
}
|
|
229
252
|
return `${this._apiBase}/sessions/${this.sessionId}`
|
|
230
253
|
}
|
|
231
254
|
|
|
@@ -625,28 +648,33 @@ class Rest {
|
|
|
625
648
|
}
|
|
626
649
|
|
|
627
650
|
async updatePlayer({ guildId, data, noReplace = false }) {
|
|
651
|
+
const gen = this._sessionGeneration
|
|
628
652
|
return this.makeRequest(
|
|
629
653
|
'PATCH',
|
|
630
|
-
`${this._getSessionPath()}/players/${guildId}?noReplace=${noReplace}`,
|
|
654
|
+
`${this._getSessionPath(gen)}/players/${guildId}?noReplace=${noReplace}`,
|
|
631
655
|
data
|
|
632
656
|
)
|
|
633
657
|
}
|
|
634
658
|
|
|
635
659
|
async getPlayer(guildId) {
|
|
660
|
+
const gen = this._sessionGeneration
|
|
636
661
|
return this.makeRequest(
|
|
637
662
|
'GET',
|
|
638
|
-
`${this._getSessionPath()}/players/${guildId}`
|
|
663
|
+
`${this._getSessionPath(gen)}/players/${guildId}`
|
|
639
664
|
)
|
|
640
665
|
}
|
|
641
666
|
|
|
642
667
|
async getPlayers() {
|
|
643
|
-
|
|
668
|
+
const gen = this._sessionGeneration
|
|
669
|
+
return this.makeRequest('GET', `${this._getSessionPath(gen)}/players`)
|
|
644
670
|
}
|
|
645
671
|
|
|
646
|
-
async destroyPlayer(guildId) {
|
|
672
|
+
async destroyPlayer(guildId, abortSignal) {
|
|
673
|
+
const gen = this._sessionGeneration
|
|
674
|
+
if (abortSignal?.aborted) return null
|
|
647
675
|
return this.makeRequest(
|
|
648
676
|
'DELETE',
|
|
649
|
-
`${this._getSessionPath()}/players/${guildId}`
|
|
677
|
+
`${this._getSessionPath(gen)}/players/${guildId}`
|
|
650
678
|
)
|
|
651
679
|
}
|
|
652
680
|
|
|
@@ -719,9 +747,10 @@ class Rest {
|
|
|
719
747
|
|
|
720
748
|
if (guildId) {
|
|
721
749
|
try {
|
|
750
|
+
const gen = this._sessionGeneration
|
|
722
751
|
const lyrics = await this.makeRequest(
|
|
723
752
|
'GET',
|
|
724
|
-
`${this._getSessionPath()}/players/${guildId}/track/lyrics?skipTrackSource=${skip}`
|
|
753
|
+
`${this._getSessionPath(gen)}/players/${guildId}/track/lyrics?skipTrackSource=${skip}`
|
|
725
754
|
)
|
|
726
755
|
if (this._validLyrics(lyrics)) return lyrics
|
|
727
756
|
} catch {}
|
|
@@ -762,10 +791,11 @@ class Rest {
|
|
|
762
791
|
|
|
763
792
|
async subscribeLiveLyrics(guildId, skipTrackSource = false) {
|
|
764
793
|
try {
|
|
794
|
+
const gen = this._sessionGeneration
|
|
765
795
|
return (
|
|
766
796
|
(await this.makeRequest(
|
|
767
797
|
'POST',
|
|
768
|
-
`${this._getSessionPath()}/players/${guildId}/lyrics/subscribe?skipTrackSource=${skipTrackSource ? 'true' : 'false'}`
|
|
798
|
+
`${this._getSessionPath(gen)}/players/${guildId}/lyrics/subscribe?skipTrackSource=${skipTrackSource ? 'true' : 'false'}`
|
|
769
799
|
)) === null
|
|
770
800
|
)
|
|
771
801
|
} catch {
|
|
@@ -775,10 +805,11 @@ class Rest {
|
|
|
775
805
|
|
|
776
806
|
async unsubscribeLiveLyrics(guildId) {
|
|
777
807
|
try {
|
|
808
|
+
const gen = this._sessionGeneration
|
|
778
809
|
return (
|
|
779
810
|
(await this.makeRequest(
|
|
780
811
|
'DELETE',
|
|
781
|
-
`${this._getSessionPath()}/players/${guildId}/lyrics/subscribe`
|
|
812
|
+
`${this._getSessionPath(gen)}/players/${guildId}/lyrics/subscribe`
|
|
782
813
|
)) === null
|
|
783
814
|
)
|
|
784
815
|
} catch {
|
|
@@ -845,10 +876,18 @@ class Rest {
|
|
|
845
876
|
}
|
|
846
877
|
|
|
847
878
|
destroy() {
|
|
879
|
+
const autoplayAgent = this._autoplayAgent
|
|
880
|
+
const primaryAgent = this.agent
|
|
848
881
|
if (this.agent) {
|
|
849
882
|
this.agent.destroy()
|
|
850
883
|
this.agent = null
|
|
851
884
|
}
|
|
885
|
+
if (autoplayAgent && autoplayAgent !== primaryAgent) {
|
|
886
|
+
autoplayAgent.destroy?.()
|
|
887
|
+
}
|
|
888
|
+
if (autoplayModule?.setSharedAgent && autoplayAgent) {
|
|
889
|
+
autoplayModule.setSharedAgent(null)
|
|
890
|
+
}
|
|
852
891
|
this._closeH2()
|
|
853
892
|
if (this._headerPool) {
|
|
854
893
|
this._headerPool.length = 0
|
|
@@ -859,6 +898,7 @@ class Rest {
|
|
|
859
898
|
this.request =
|
|
860
899
|
this.defaultHeaders =
|
|
861
900
|
this._endpoints =
|
|
901
|
+
this._autoplayAgent =
|
|
862
902
|
null
|
|
863
903
|
this.calls = 0
|
|
864
904
|
}
|
|
@@ -65,7 +65,7 @@ class Track {
|
|
|
65
65
|
|
|
66
66
|
const platform =
|
|
67
67
|
opts.platform || aqua?.options?.defaultSearchPlatform || 'ytsearch'
|
|
68
|
-
const node = opts.node || this.node || this.nodes
|
|
68
|
+
const node = opts.nodes || opts.node || this.node || this.nodes
|
|
69
69
|
|
|
70
70
|
let query = this.uri
|
|
71
71
|
if (!query) {
|
|
@@ -83,7 +83,7 @@ class Track {
|
|
|
83
83
|
if (!query) return null
|
|
84
84
|
|
|
85
85
|
const payload = { query, source: platform, requester: this.requester }
|
|
86
|
-
if (node) payload.
|
|
86
|
+
if (node) payload.nodes = node
|
|
87
87
|
|
|
88
88
|
let result
|
|
89
89
|
try {
|