nyxlink 0.1.0-dev.2 → 5.3.0-rc.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/NOTICE.md +39 -0
- package/README.md +306 -36
- package/dist/index.d.ts +77 -3
- package/dist/index.js +72 -3
- package/dist/index.js.map +1 -1
- package/dist/src/Util.d.ts +13 -5
- package/dist/src/Util.js +158 -81
- package/dist/src/Util.js.map +1 -1
- package/dist/src/autoplay/AutoPlayManager.js +19 -9
- package/dist/src/autoplay/AutoPlayManager.js.map +1 -1
- package/dist/src/autoplay/RecommendationDiscovery.d.ts +27 -0
- package/dist/src/autoplay/RecommendationDiscovery.js +67 -0
- package/dist/src/autoplay/RecommendationDiscovery.js.map +1 -0
- package/dist/src/autoplay/RecommendationPreference.d.ts +15 -0
- package/dist/src/autoplay/RecommendationPreference.js +31 -0
- package/dist/src/autoplay/RecommendationPreference.js.map +1 -0
- package/dist/src/autoplay/RecommendationResolver.js +129 -91
- package/dist/src/autoplay/RecommendationResolver.js.map +1 -1
- package/dist/src/backends/BackendAdapter.d.ts +16 -3
- package/dist/src/backends/BackendAdapter.js +27 -9
- package/dist/src/backends/BackendAdapter.js.map +1 -1
- package/dist/src/backends/BackendDetector.js +36 -8
- package/dist/src/backends/BackendDetector.js.map +1 -1
- package/dist/src/backends/BackendInventory.d.ts +16 -0
- package/dist/src/backends/BackendInventory.js +3 -0
- package/dist/src/backends/BackendInventory.js.map +1 -0
- package/dist/src/backends/CapabilityRegistry.d.ts +17 -0
- package/dist/src/backends/CapabilityRegistry.js +39 -0
- package/dist/src/backends/CapabilityRegistry.js.map +1 -0
- package/dist/src/backends/ClientPCMSeek.d.ts +5 -0
- package/dist/src/backends/ClientPCMSeek.js +46 -0
- package/dist/src/backends/ClientPCMSeek.js.map +1 -0
- package/dist/src/backends/ExtensionRoutes.d.ts +202 -0
- package/dist/src/backends/ExtensionRoutes.js +57 -0
- package/dist/src/backends/ExtensionRoutes.js.map +1 -0
- package/dist/src/backends/HoloTrackMetadata.d.ts +24 -0
- package/dist/src/backends/HoloTrackMetadata.js +50 -0
- package/dist/src/backends/HoloTrackMetadata.js.map +1 -0
- package/dist/src/backends/LavaDSPXContracts.d.ts +27 -0
- package/dist/src/backends/LavaDSPXContracts.js +54 -0
- package/dist/src/backends/LavaDSPXContracts.js.map +1 -0
- package/dist/src/backends/LavaLyricsContracts.d.ts +21 -0
- package/dist/src/backends/LavaLyricsContracts.js +45 -0
- package/dist/src/backends/LavaLyricsContracts.js.map +1 -0
- package/dist/src/backends/LavaSearchContracts.d.ts +33 -0
- package/dist/src/backends/LavaSearchContracts.js +67 -0
- package/dist/src/backends/LavaSearchContracts.js.map +1 -0
- package/dist/src/backends/LavaSrcMetadata.d.ts +18 -0
- package/dist/src/backends/LavaSrcMetadata.js +38 -0
- package/dist/src/backends/LavaSrcMetadata.js.map +1 -0
- package/dist/src/backends/LavalinkAdapter.d.ts +2 -1
- package/dist/src/backends/LavalinkAdapter.js +3 -0
- package/dist/src/backends/LavalinkAdapter.js.map +1 -1
- package/dist/src/backends/LavalinkSponsorBlockContracts.d.ts +8 -0
- package/dist/src/backends/LavalinkSponsorBlockContracts.js +41 -0
- package/dist/src/backends/LavalinkSponsorBlockContracts.js.map +1 -0
- package/dist/src/backends/NodeLinkAdapter.d.ts +2 -1
- package/dist/src/backends/NodeLinkAdapter.js +3 -0
- package/dist/src/backends/NodeLinkAdapter.js.map +1 -1
- package/dist/src/backends/NodeLinkContracts.d.ts +99 -0
- package/dist/src/backends/NodeLinkContracts.js +146 -0
- package/dist/src/backends/NodeLinkContracts.js.map +1 -0
- package/dist/src/backends/NodeLinkMixContracts.d.ts +34 -0
- package/dist/src/backends/NodeLinkMixContracts.js +51 -0
- package/dist/src/backends/NodeLinkMixContracts.js.map +1 -0
- package/dist/src/backends/NodeLinkOrchestration.d.ts +69 -0
- package/dist/src/backends/NodeLinkOrchestration.js +123 -0
- package/dist/src/backends/NodeLinkOrchestration.js.map +1 -0
- package/dist/src/backends/NodeLinkSearchContracts.d.ts +9 -0
- package/dist/src/backends/NodeLinkSearchContracts.js +25 -0
- package/dist/src/backends/NodeLinkSearchContracts.js.map +1 -0
- package/dist/src/backends/NodeLinkStreamResponse.d.ts +1 -0
- package/dist/src/backends/NodeLinkStreamResponse.js +32 -0
- package/dist/src/backends/NodeLinkStreamResponse.js.map +1 -0
- package/dist/src/backends/ProtocolContracts.d.ts +56 -0
- package/dist/src/backends/ProtocolContracts.js +31 -0
- package/dist/src/backends/ProtocolContracts.js.map +1 -0
- package/dist/src/backends/ProtocolValidation.d.ts +13 -0
- package/dist/src/backends/ProtocolValidation.js +119 -0
- package/dist/src/backends/ProtocolValidation.js.map +1 -0
- package/dist/src/backends/SessionPath.d.ts +3 -0
- package/dist/src/backends/SessionPath.js +19 -0
- package/dist/src/backends/SessionPath.js.map +1 -0
- package/dist/src/backends/SponsorBlockEvents.d.ts +31 -0
- package/dist/src/backends/SponsorBlockEvents.js +56 -0
- package/dist/src/backends/SponsorBlockEvents.js.map +1 -0
- package/dist/src/cluster/GuildOwnership.d.ts +30 -0
- package/dist/src/cluster/GuildOwnership.js +190 -0
- package/dist/src/cluster/GuildOwnership.js.map +1 -0
- package/dist/src/cluster/RedisGuildIpcRouter.d.ts +34 -0
- package/dist/src/cluster/RedisGuildIpcRouter.js +150 -0
- package/dist/src/cluster/RedisGuildIpcRouter.js.map +1 -0
- package/dist/src/connectors/Connector.d.ts +3 -1
- package/dist/src/connectors/Connector.js +7 -1
- package/dist/src/connectors/Connector.js.map +1 -1
- package/dist/src/core/Manager.d.ts +26 -8
- package/dist/src/core/Manager.js +93 -25
- package/dist/src/core/Manager.js.map +1 -1
- package/dist/src/database/Local.d.ts +6 -2
- package/dist/src/database/Local.js +49 -14
- package/dist/src/database/Local.js.map +1 -1
- package/dist/src/database/Memory.d.ts +4 -0
- package/dist/src/database/Memory.js +17 -3
- package/dist/src/database/Memory.js.map +1 -1
- package/dist/src/database/PlayerSnapshot.d.ts +35 -0
- package/dist/src/database/PlayerSnapshot.js +176 -0
- package/dist/src/database/PlayerSnapshot.js.map +1 -0
- package/dist/src/database/RedisGuildLeaseCoordinator.d.ts +30 -0
- package/dist/src/database/RedisGuildLeaseCoordinator.js +134 -0
- package/dist/src/database/RedisGuildLeaseCoordinator.js.map +1 -0
- package/dist/src/database/RedisPlayerFence.d.ts +15 -0
- package/dist/src/database/RedisPlayerFence.js +44 -0
- package/dist/src/database/RedisPlayerFence.js.map +1 -0
- package/dist/src/database/RedisStorage.d.ts +32 -0
- package/dist/src/database/RedisStorage.js +209 -0
- package/dist/src/database/RedisStorage.js.map +1 -0
- package/dist/src/database/StorageAdapter.d.ts +1 -0
- package/dist/src/entities/Filters.d.ts +10 -1
- package/dist/src/entities/Filters.js +119 -56
- package/dist/src/entities/Filters.js.map +1 -1
- package/dist/src/entities/Node.d.ts +67 -6
- package/dist/src/entities/Node.js +568 -348
- package/dist/src/entities/Node.js.map +1 -1
- package/dist/src/entities/Player.d.ts +34 -11
- package/dist/src/entities/Player.js +607 -280
- package/dist/src/entities/Player.js.map +1 -1
- package/dist/src/entities/Queue.d.ts +1 -0
- package/dist/src/entities/Queue.js +76 -25
- package/dist/src/entities/Queue.js.map +1 -1
- package/dist/src/entities/Rest.d.ts +52 -9
- package/dist/src/entities/Rest.js +511 -124
- package/dist/src/entities/Rest.js.map +1 -1
- package/dist/src/entities/Track.d.ts +19 -12
- package/dist/src/entities/Track.js +44 -22
- package/dist/src/entities/Track.js.map +1 -1
- package/dist/src/entities/Voice.js +13 -6
- package/dist/src/entities/Voice.js.map +1 -1
- package/dist/src/entities/VoicePacketHandler.js +2 -2
- package/dist/src/entities/VoicePacketHandler.js.map +1 -1
- package/dist/src/entities/VoiceReceiver.d.ts +5 -0
- package/dist/src/entities/VoiceReceiver.js +117 -13
- package/dist/src/entities/VoiceReceiver.js.map +1 -1
- package/dist/src/entities/YouTubeLiveChat.d.ts +1 -0
- package/dist/src/entities/YouTubeLiveChat.js +53 -8
- package/dist/src/entities/YouTubeLiveChat.js.map +1 -1
- package/dist/src/errors/CircuitOpenError.d.ts +5 -0
- package/dist/src/errors/CircuitOpenError.js +14 -0
- package/dist/src/errors/CircuitOpenError.js.map +1 -0
- package/dist/src/errors/FeatureUnavailableError.d.ts +2 -2
- package/dist/src/errors/FeatureUnavailableError.js +1 -1
- package/dist/src/errors/FeatureUnavailableError.js.map +1 -1
- package/dist/src/errors/HttpError.d.ts +3 -2
- package/dist/src/errors/HttpError.js +11 -1
- package/dist/src/errors/HttpError.js.map +1 -1
- package/dist/src/errors/HttpPolicyError.d.ts +6 -0
- package/dist/src/errors/HttpPolicyError.js +14 -0
- package/dist/src/errors/HttpPolicyError.js.map +1 -0
- package/dist/src/errors/NoEligibleNodeError.d.ts +6 -0
- package/dist/src/errors/NoEligibleNodeError.js +14 -0
- package/dist/src/errors/NoEligibleNodeError.js.map +1 -0
- package/dist/src/errors/PlayerOperationCancelledError.d.ts +5 -0
- package/dist/src/errors/PlayerOperationCancelledError.js +14 -0
- package/dist/src/errors/PlayerOperationCancelledError.js.map +1 -0
- package/dist/src/extensions/ExtensionHost.d.ts +33 -0
- package/dist/src/extensions/ExtensionHost.js +156 -0
- package/dist/src/extensions/ExtensionHost.js.map +1 -0
- package/dist/src/http/RequestPolicy.d.ts +6 -0
- package/dist/src/http/RequestPolicy.js +52 -0
- package/dist/src/http/RequestPolicy.js.map +1 -0
- package/dist/src/logging/AuroraBootstrap.d.ts +22 -0
- package/dist/src/logging/AuroraBootstrap.js +89 -0
- package/dist/src/logging/AuroraBootstrap.js.map +1 -0
- package/dist/src/logging/AuroraDiagnostics.d.ts +56 -0
- package/dist/src/logging/AuroraDiagnostics.js +152 -0
- package/dist/src/logging/AuroraDiagnostics.js.map +1 -0
- package/dist/src/logging/AuroraEvents.d.ts +423 -0
- package/dist/src/logging/AuroraEvents.js +305 -0
- package/dist/src/logging/AuroraEvents.js.map +1 -0
- package/dist/src/logging/AuroraInspector.d.ts +55 -0
- package/dist/src/logging/AuroraInspector.js +117 -0
- package/dist/src/logging/AuroraInspector.js.map +1 -0
- package/dist/src/logging/AuroraPresentation.d.ts +35 -0
- package/dist/src/logging/AuroraPresentation.js +108 -0
- package/dist/src/logging/AuroraPresentation.js.map +1 -0
- package/dist/src/logging/ErrorDiagnostics.d.ts +11 -0
- package/dist/src/logging/ErrorDiagnostics.js +32 -0
- package/dist/src/logging/ErrorDiagnostics.js.map +1 -0
- package/dist/src/logging/LogFormatter.d.ts +1 -0
- package/dist/src/logging/LogFormatter.js +70 -20
- package/dist/src/logging/LogFormatter.js.map +1 -1
- package/dist/src/logging/LogLevels.d.ts +0 -2
- package/dist/src/logging/LogLevels.js +1 -9
- package/dist/src/logging/LogLevels.js.map +1 -1
- package/dist/src/logging/ManagerLogRoute.d.ts +4 -0
- package/dist/src/logging/ManagerLogRoute.js +18 -0
- package/dist/src/logging/ManagerLogRoute.js.map +1 -0
- package/dist/src/logging/ObservedFields.d.ts +1 -0
- package/dist/src/logging/ObservedFields.js +16 -0
- package/dist/src/logging/ObservedFields.js.map +1 -0
- package/dist/src/logging/PinoEngine.d.ts +13 -0
- package/dist/src/logging/PinoEngine.js +38 -0
- package/dist/src/logging/PinoEngine.js.map +1 -0
- package/dist/src/logging/SafeDiagnostics.d.ts +3 -0
- package/dist/src/logging/SafeDiagnostics.js +71 -0
- package/dist/src/logging/SafeDiagnostics.js.map +1 -0
- package/dist/src/logging/TerminalCoordinator.d.ts +64 -0
- package/dist/src/logging/TerminalCoordinator.js +237 -0
- package/dist/src/logging/TerminalCoordinator.js.map +1 -0
- package/dist/src/logging/index.d.ts +4 -6
- package/dist/src/logging/index.js +5 -8
- package/dist/src/logging/index.js.map +1 -1
- package/dist/src/managers/DatabaseManager.d.ts +10 -0
- package/dist/src/managers/DatabaseManager.js +192 -1
- package/dist/src/managers/DatabaseManager.js.map +1 -1
- package/dist/src/managers/NodeManager.d.ts +17 -8
- package/dist/src/managers/NodeManager.js +153 -16
- package/dist/src/managers/NodeManager.js.map +1 -1
- package/dist/src/managers/PlayerManager.d.ts +5 -0
- package/dist/src/managers/PlayerManager.js +52 -4
- package/dist/src/managers/PlayerManager.js.map +1 -1
- package/dist/src/nodes/NodeCircuitBreaker.d.ts +23 -0
- package/dist/src/nodes/NodeCircuitBreaker.js +107 -0
- package/dist/src/nodes/NodeCircuitBreaker.js.map +1 -0
- package/dist/src/nodes/NodeFailover.d.ts +2 -0
- package/dist/src/nodes/NodeFailover.js +68 -13
- package/dist/src/nodes/NodeFailover.js.map +1 -1
- package/dist/src/nodes/NodeHealthMonitor.d.ts +1 -1
- package/dist/src/nodes/NodeHealthMonitor.js +5 -1
- package/dist/src/nodes/NodeHealthMonitor.js.map +1 -1
- package/dist/src/nodes/NodeScoring.d.ts +4 -0
- package/dist/src/nodes/NodeScoring.js +52 -0
- package/dist/src/nodes/NodeScoring.js.map +1 -0
- package/dist/src/nodes/NodeSelector.d.ts +26 -2
- package/dist/src/nodes/NodeSelector.js +108 -3
- package/dist/src/nodes/NodeSelector.js.map +1 -1
- package/dist/src/nodes/RecoveryQueue.d.ts +8 -0
- package/dist/src/nodes/RecoveryQueue.js +36 -0
- package/dist/src/nodes/RecoveryQueue.js.map +1 -0
- package/dist/src/nodes/RetryDelay.d.ts +2 -0
- package/dist/src/nodes/RetryDelay.js +15 -0
- package/dist/src/nodes/RetryDelay.js.map +1 -0
- package/dist/src/nodes/SessionRecovery.d.ts +2 -0
- package/dist/src/nodes/SessionRecovery.js +168 -0
- package/dist/src/nodes/SessionRecovery.js.map +1 -0
- package/dist/src/nodes/SourceHealthMonitor.d.ts +16 -0
- package/dist/src/nodes/SourceHealthMonitor.js +47 -0
- package/dist/src/nodes/SourceHealthMonitor.js.map +1 -0
- package/dist/src/observability/OpenTelemetry.d.ts +64 -0
- package/dist/src/observability/OpenTelemetry.js +183 -0
- package/dist/src/observability/OpenTelemetry.js.map +1 -0
- package/dist/src/observability/PerformanceMonitor.d.ts +69 -0
- package/dist/src/observability/PerformanceMonitor.js +164 -0
- package/dist/src/observability/PerformanceMonitor.js.map +1 -0
- package/dist/src/observability/PrivateMetricsServer.d.ts +47 -0
- package/dist/src/observability/PrivateMetricsServer.js +221 -0
- package/dist/src/observability/PrivateMetricsServer.js.map +1 -0
- package/dist/src/observability/TerminalDashboard.d.ts +60 -0
- package/dist/src/observability/TerminalDashboard.js +111 -0
- package/dist/src/observability/TerminalDashboard.js.map +1 -0
- package/dist/src/players/AdvancedAudioRecovery.d.ts +18 -0
- package/dist/src/players/AdvancedAudioRecovery.js +38 -0
- package/dist/src/players/AdvancedAudioRecovery.js.map +1 -0
- package/dist/src/players/MixRecovery.d.ts +24 -0
- package/dist/src/players/MixRecovery.js +89 -0
- package/dist/src/players/MixRecovery.js.map +1 -0
- package/dist/src/players/PlaybackAttempt.d.ts +34 -0
- package/dist/src/players/PlaybackAttempt.js +171 -0
- package/dist/src/players/PlaybackAttempt.js.map +1 -0
- package/dist/src/players/PlaybackGuard.d.ts +4 -0
- package/dist/src/players/PlaybackGuard.js +15 -2
- package/dist/src/players/PlaybackGuard.js.map +1 -1
- package/dist/src/players/PlayerCommandQueue.d.ts +2 -0
- package/dist/src/players/PlayerCommandQueue.js +4 -1
- package/dist/src/players/PlayerCommandQueue.js.map +1 -1
- package/dist/src/players/PlayerMigration.d.ts +20 -0
- package/dist/src/players/PlayerMigration.js +217 -0
- package/dist/src/players/PlayerMigration.js.map +1 -0
- package/dist/src/players/QueuePreload.d.ts +10 -0
- package/dist/src/players/QueuePreload.js +46 -0
- package/dist/src/players/QueuePreload.js.map +1 -0
- package/dist/src/players/VoiceRecovery.d.ts +7 -0
- package/dist/src/players/VoiceRecovery.js +56 -0
- package/dist/src/players/VoiceRecovery.js.map +1 -0
- package/dist/src/search/SearchService.d.ts +6 -2
- package/dist/src/search/SearchService.js +91 -44
- package/dist/src/search/SearchService.js.map +1 -1
- package/dist/src/search/SharedSearchRequests.d.ts +6 -0
- package/dist/src/search/SharedSearchRequests.js +61 -0
- package/dist/src/search/SharedSearchRequests.js.map +1 -0
- package/dist/src/search/SourceRouting.d.ts +4 -0
- package/dist/src/search/SourceRouting.js +36 -0
- package/dist/src/search/SourceRouting.js.map +1 -0
- package/dist/src/services/WebSocket.d.ts +3 -0
- package/dist/src/services/WebSocket.js +75 -48
- package/dist/src/services/WebSocket.js.map +1 -1
- package/dist/src/sources/deezer.d.ts +2 -0
- package/dist/src/sources/deezer.js +35 -22
- package/dist/src/sources/deezer.js.map +1 -1
- package/dist/src/sources/spotify.d.ts +2 -0
- package/dist/src/sources/spotify.js +27 -18
- package/dist/src/sources/spotify.js.map +1 -1
- package/dist/src/structures/SearchResult.d.ts +6 -3
- package/dist/src/structures/SearchResult.js +13 -4
- package/dist/src/structures/SearchResult.js.map +1 -1
- package/dist/src/tracks/AbortableLookup.d.ts +1 -0
- package/dist/src/tracks/AbortableLookup.js +14 -0
- package/dist/src/tracks/AbortableLookup.js.map +1 -0
- package/dist/src/tracks/MetadataTrackResolver.d.ts +11 -0
- package/dist/src/tracks/MetadataTrackResolver.js +90 -0
- package/dist/src/tracks/MetadataTrackResolver.js.map +1 -0
- package/dist/src/tracks/TrackCodec.js +1 -1
- package/dist/src/tracks/TrackCodec.js.map +1 -1
- package/dist/src/tracks/TrackResolver.d.ts +1 -1
- package/dist/src/tracks/TrackResolver.js +75 -27
- package/dist/src/tracks/TrackResolver.js.map +1 -1
- package/dist/src/typings/Interfaces.d.ts +31 -6
- package/examples/aurora-bootstrap.d.mts +2 -0
- package/examples/aurora-bootstrap.mjs +77 -0
- package/examples/aurora-demo.mjs +63 -0
- package/examples/aurora-diagnostics.d.mts +5 -0
- package/examples/aurora-diagnostics.mjs +73 -0
- package/examples/aurora-file.d.mts +2 -0
- package/examples/aurora-file.mjs +55 -0
- package/examples/aurora-inspector.d.mts +7 -0
- package/examples/aurora-inspector.mjs +173 -0
- package/examples/aurora-otel.d.mts +4 -0
- package/examples/aurora-otel.mjs +4 -0
- package/examples/aurora-pipeline.d.mts +22 -0
- package/examples/aurora-pipeline.mjs +91 -0
- package/examples/aurora-sdk.cjs +73 -0
- package/examples/aurora-sdk.d.cts +2 -0
- package/examples/aurora-terminal-tools.mjs +44 -0
- package/examples/aurora-visual.mjs +55 -0
- package/package.json +112 -10
- package/dist/src/logging/ConsoleReporter.d.ts +0 -8
- package/dist/src/logging/ConsoleReporter.js +0 -25
- package/dist/src/logging/ConsoleReporter.js.map +0 -1
- package/dist/src/logging/Logger.d.ts +0 -37
- package/dist/src/logging/Logger.js +0 -122
- package/dist/src/logging/Logger.js.map +0 -1
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Rest = exports.RestError = void 0;
|
|
4
|
+
const SessionPath_1 = require("../backends/SessionPath");
|
|
5
|
+
const NodeLinkSearchContracts_1 = require("../backends/NodeLinkSearchContracts");
|
|
6
|
+
const LavaSearchContracts_1 = require("../backends/LavaSearchContracts");
|
|
7
|
+
const OpenTelemetry_1 = require("../observability/OpenTelemetry");
|
|
8
|
+
const ManagerLogRoute_1 = require("../logging/ManagerLogRoute");
|
|
9
|
+
const NodeLinkOrchestration_1 = require("../backends/NodeLinkOrchestration");
|
|
10
|
+
const NodeLinkContracts_1 = require("../backends/NodeLinkContracts");
|
|
11
|
+
const LavaLyricsContracts_1 = require("../backends/LavaLyricsContracts");
|
|
12
|
+
const LavalinkSponsorBlockContracts_1 = require("../backends/LavalinkSponsorBlockContracts");
|
|
13
|
+
const ProtocolValidation_1 = require("../backends/ProtocolValidation");
|
|
4
14
|
const HttpError_1 = require("../errors/HttpError");
|
|
15
|
+
const ExtensionRoutes_1 = require("../backends/ExtensionRoutes");
|
|
16
|
+
const ProtocolContracts_1 = require("../backends/ProtocolContracts");
|
|
5
17
|
const FeatureUnavailableError_1 = require("../errors/FeatureUnavailableError");
|
|
6
18
|
const Util_1 = require("../Util");
|
|
7
19
|
const PlaybackGuard_1 = require("../players/PlaybackGuard");
|
|
20
|
+
const NodeLinkStreamResponse_1 = require("../backends/NodeLinkStreamResponse");
|
|
21
|
+
const ClientPCMSeek_1 = require("../backends/ClientPCMSeek");
|
|
22
|
+
const NodeLinkMixContracts_1 = require("../backends/NodeLinkMixContracts");
|
|
8
23
|
class RestError extends Error {
|
|
9
24
|
statusCode;
|
|
10
25
|
isSessionExpired;
|
|
@@ -21,34 +36,77 @@ class Rest {
|
|
|
21
36
|
authHeaders;
|
|
22
37
|
jsonHeaders;
|
|
23
38
|
userAgentHeaders;
|
|
24
|
-
|
|
39
|
+
sessionRecoveries = new WeakSet();
|
|
40
|
+
request;
|
|
41
|
+
streamRequest;
|
|
25
42
|
constructor(node) {
|
|
26
43
|
this.node = node;
|
|
44
|
+
this.request = this.observeTransport(Util_1.makeRequest, 'REST.http');
|
|
45
|
+
this.streamRequest = this.observeTransport(Util_1.makeStreamRequest, 'REST.stream.open');
|
|
27
46
|
this.authHeaders = {
|
|
28
47
|
"Authorization": this.node.password,
|
|
29
|
-
"User-Agent": this.node.manager.options?.userAgent
|
|
48
|
+
"User-Agent": this.node.manager.options?.userAgent ?? "NyxLink"
|
|
30
49
|
};
|
|
31
50
|
this.jsonHeaders = {
|
|
32
51
|
...this.authHeaders,
|
|
33
52
|
"Content-Type": "application/json"
|
|
34
53
|
};
|
|
35
54
|
this.userAgentHeaders = {
|
|
36
|
-
"User-Agent": this.node.manager.options?.userAgent
|
|
55
|
+
"User-Agent": this.node.manager.options?.userAgent ?? "NyxLink"
|
|
37
56
|
};
|
|
38
57
|
}
|
|
39
58
|
get url() {
|
|
40
59
|
return `http${this.node.secure ? "s" : ""}://${this.node.host}:${this.node.port}`;
|
|
41
60
|
}
|
|
61
|
+
observeTransport(transport, operation) {
|
|
62
|
+
return new Proxy(transport, { apply: (target, receiver, args) => {
|
|
63
|
+
const monitor = this.node.manager.performanceMonitor;
|
|
64
|
+
const execute = () => monitor ? monitor.measure(operation === 'REST.http' ? 'rest' : 'streamOpen', () => Reflect.apply(target, receiver, args)) : Reflect.apply(target, receiver, args);
|
|
65
|
+
const run = () => (0, OpenTelemetry_1.observeOperation)(this.node.manager, 'nyxlink.rest', async () => {
|
|
66
|
+
const aurora = (0, ManagerLogRoute_1.getManagerLogRoute)(this.node.manager);
|
|
67
|
+
return aurora ? aurora.observe(operation === 'REST.http' ? 'rest' : 'stream', async () => execute(), { backend: this.node.backend?.kind }, result => {
|
|
68
|
+
if (operation === 'REST.http' && typeof result === 'object' && result !== null && result.loadType === 'error') {
|
|
69
|
+
try {
|
|
70
|
+
if (new URL(args[0]).pathname === '/v4/loadtracks')
|
|
71
|
+
return 'failed';
|
|
72
|
+
}
|
|
73
|
+
catch { }
|
|
74
|
+
}
|
|
75
|
+
return 'completed';
|
|
76
|
+
}) : execute();
|
|
77
|
+
}, result => {
|
|
78
|
+
if (result == null)
|
|
79
|
+
return 'empty';
|
|
80
|
+
let pathname = '';
|
|
81
|
+
try {
|
|
82
|
+
pathname = new URL(args[0]).pathname;
|
|
83
|
+
}
|
|
84
|
+
catch { }
|
|
85
|
+
if (pathname === '/v4/loadtracks' && typeof result === 'object') {
|
|
86
|
+
const type = result.loadType;
|
|
87
|
+
if (type === 'error' || type === 'empty')
|
|
88
|
+
return type;
|
|
89
|
+
}
|
|
90
|
+
return 'resolved';
|
|
91
|
+
});
|
|
92
|
+
return run();
|
|
93
|
+
} });
|
|
94
|
+
}
|
|
42
95
|
async triggerPlayerRecovery(player) {
|
|
43
|
-
if (player.destroyed)
|
|
96
|
+
if (player.destroyed || this.node.destroyed || player.node !== this.node)
|
|
44
97
|
return;
|
|
45
98
|
player.stuckDetectionCount = 0;
|
|
46
99
|
player.silentDetectionCount = 0;
|
|
100
|
+
const guard = (0, PlaybackGuard_1.playbackGuard)(player);
|
|
101
|
+
let ticket = guard.ticket;
|
|
102
|
+
const active = () => !player.destroyed && !this.node.destroyed &&
|
|
103
|
+
player.node === this.node && this.node.manager.players.get(player.guildId) === player &&
|
|
104
|
+
guard.isCurrent(ticket);
|
|
47
105
|
try {
|
|
48
106
|
const recovering = player.softRestart("Session expired (404)");
|
|
49
|
-
|
|
107
|
+
ticket = guard.ticket;
|
|
50
108
|
const recovered = await recovering;
|
|
51
|
-
if (
|
|
109
|
+
if (!active())
|
|
52
110
|
return;
|
|
53
111
|
if (recovered) {
|
|
54
112
|
this.node.manager.emit("playerRecoverySuccess", player);
|
|
@@ -57,129 +115,306 @@ class Rest {
|
|
|
57
115
|
await player.destroy("Session expired and recovery failed");
|
|
58
116
|
}
|
|
59
117
|
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
this.node.manager.emit("debug", `Moonlink.js > Rest >> Recovery error: ${e.message}`);
|
|
62
|
-
await player.destroy("Session recovery error");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async featureRequest(feature, url, options) {
|
|
66
|
-
this.node.assertFeature(feature);
|
|
67
|
-
try {
|
|
68
|
-
const result = await (0, Util_1.makeRequest)(url, { ...options, throwOnError: true }, 10000, 0);
|
|
69
|
-
this.node.backend?.recordFeature(feature, 'available');
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
118
|
catch (error) {
|
|
73
|
-
|
|
119
|
+
if (!active())
|
|
120
|
+
return;
|
|
121
|
+
this.node.manager.emit("debug", `NyxLink > Rest > Recovery error: ${error.message}`);
|
|
122
|
+
if (active())
|
|
123
|
+
await player.destroy("Session recovery error");
|
|
74
124
|
}
|
|
75
125
|
}
|
|
76
|
-
|
|
126
|
+
extensionRoute(operation, params = {}) {
|
|
127
|
+
const parameters = { ...params, sessionId: this.node.sessionId };
|
|
128
|
+
return this.node.backend ? this.node.backend.resolveExtension(operation, parameters)
|
|
129
|
+
: (0, ExtensionRoutes_1.resolveExtensionRoute)(this.node.isNodeLink ? 'nodelink' : 'unknown', operation, parameters);
|
|
130
|
+
}
|
|
131
|
+
async featureRequest(operation, params, options, validate) {
|
|
132
|
+
return this.runFeatureRequest(operation, params, options, validate);
|
|
133
|
+
}
|
|
134
|
+
async runFeatureRequest(operation, params, options, validate) {
|
|
135
|
+
const route = this.extensionRoute(operation, params);
|
|
136
|
+
if (params.guildId && route.method !== 'GET') {
|
|
137
|
+
await this.node.manager.guildOwnership?.assertCurrent(params.guildId);
|
|
138
|
+
}
|
|
139
|
+
const feature = route.feature;
|
|
140
|
+
this.node.assertFeature(feature);
|
|
141
|
+
if (route.transport !== 'json')
|
|
142
|
+
throw new TypeError('Extension requires stream transport');
|
|
143
|
+
const backend = this.node.backend;
|
|
144
|
+
const socket = this.node.socket;
|
|
145
|
+
const session = this.node.sessionId;
|
|
146
|
+
const current = () => !this.node.destroyed && this.node.backend === backend &&
|
|
147
|
+
this.node.socket === socket && this.node.sessionId === session;
|
|
148
|
+
const result = await this.node.circuit.run(async () => {
|
|
149
|
+
try {
|
|
150
|
+
return await this.request(this.url + route.path, { ...options, method: route.method, throwOnError: true }, 10000, 0);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
this.featureError(feature, error, backend, current);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (result === undefined)
|
|
157
|
+
throw new Error('Backend did not acknowledge feature request');
|
|
158
|
+
validate?.(result);
|
|
159
|
+
if (current())
|
|
160
|
+
backend?.recordFeature(feature, 'available');
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
featureError(feature, error, backend, current) {
|
|
77
164
|
const body = error instanceof HttpError_1.HttpError ? error.body : undefined;
|
|
78
165
|
const message = body && typeof body === 'object' && 'message' in body ? String(body.message) : '';
|
|
79
166
|
const unavailable = error instanceof HttpError_1.HttpError && (error.statusCode === 501 ||
|
|
80
167
|
[403, 404].includes(error.statusCode) && /requested route was not found|unknown (?:route|endpoint)|(?:endpoint|feature).*disabled/i.test(message));
|
|
81
168
|
if (unavailable) {
|
|
82
|
-
|
|
83
|
-
|
|
169
|
+
if (current())
|
|
170
|
+
backend?.recordFeature(feature, 'unavailable');
|
|
171
|
+
throw new FeatureUnavailableError_1.FeatureUnavailableError(feature, backend?.kind ?? 'unknown', error.statusCode);
|
|
84
172
|
}
|
|
85
173
|
throw error;
|
|
86
174
|
}
|
|
175
|
+
async getGroups() {
|
|
176
|
+
return this.featureRequest('groups:list', {}, { headers: this.authHeaders }, NodeLinkOrchestration_1.validateGroups);
|
|
177
|
+
}
|
|
178
|
+
async getGroup(groupId) {
|
|
179
|
+
(0, NodeLinkOrchestration_1.requireGroupId)(groupId);
|
|
180
|
+
return this.featureRequest('groups:get', { groupId }, { headers: this.authHeaders }, value => (0, NodeLinkOrchestration_1.validateGroup)(value, groupId));
|
|
181
|
+
}
|
|
182
|
+
async createGroup(options) {
|
|
183
|
+
const body = (0, NodeLinkOrchestration_1.groupCreateBody)(options);
|
|
184
|
+
return this.featureRequest('groups:create', {}, { headers: this.jsonHeaders, body }, value => (0, NodeLinkOrchestration_1.validateGroup)(value, body.id));
|
|
185
|
+
}
|
|
186
|
+
async updateGroup(groupId, options) {
|
|
187
|
+
(0, NodeLinkOrchestration_1.requireGroupId)(groupId);
|
|
188
|
+
return this.featureRequest('groups:update', { groupId }, { headers: this.jsonHeaders, body: (0, NodeLinkOrchestration_1.groupPatchBody)(options) }, value => (0, NodeLinkOrchestration_1.validateGroupPatch)(value, groupId));
|
|
189
|
+
}
|
|
190
|
+
async deleteGroup(groupId) {
|
|
191
|
+
(0, NodeLinkOrchestration_1.requireGroupId)(groupId);
|
|
192
|
+
await this.featureRequest('groups:delete', { groupId }, { headers: this.authHeaders });
|
|
193
|
+
}
|
|
194
|
+
async lavalinkSponsorBlockRequest(method, guildId, categories) {
|
|
195
|
+
if (method !== 'GET')
|
|
196
|
+
await this.node.manager.guildOwnership?.assertCurrent(guildId);
|
|
197
|
+
const path = (0, LavalinkSponsorBlockContracts_1.lavalinkSponsorBlockPath)(this.node.sessionId, guildId);
|
|
198
|
+
const body = method === 'PUT' ? (0, LavalinkSponsorBlockContracts_1.sponsorBlockCategoryBody)(categories) : undefined;
|
|
199
|
+
const backend = this.node.backend;
|
|
200
|
+
if (backend?.kind !== 'lavalink' || !(0, LavalinkSponsorBlockContracts_1.hasLavalinkSponsorBlockPlugin)(backend.plugins) ||
|
|
201
|
+
backend.featureStatus('lavalink:sponsorblock') === 'unavailable') {
|
|
202
|
+
throw new FeatureUnavailableError_1.FeatureUnavailableError('lavalink:sponsorblock', backend?.kind ?? 'unknown');
|
|
203
|
+
}
|
|
204
|
+
const socket = this.node.socket;
|
|
205
|
+
const session = this.node.sessionId;
|
|
206
|
+
const current = () => !this.node.destroyed && this.node.backend === backend &&
|
|
207
|
+
this.node.socket === socket && this.node.sessionId === session;
|
|
208
|
+
const result = await this.node.circuit.run(async () => {
|
|
209
|
+
try {
|
|
210
|
+
return await this.request(this.url + path, {
|
|
211
|
+
method, headers: method === 'PUT' ? this.jsonHeaders : this.authHeaders,
|
|
212
|
+
...(method === 'PUT' ? { body } : {}), throwOnError: true
|
|
213
|
+
}, 10000, 0);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
this.featureError('lavalink:sponsorblock', error, backend, current);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (method === 'GET')
|
|
220
|
+
(0, LavalinkSponsorBlockContracts_1.validateSponsorBlockCategories)(result);
|
|
221
|
+
if (result === undefined)
|
|
222
|
+
throw new ProtocolValidation_1.ProtocolResponseError('Lavalink SponsorBlock', 'response');
|
|
223
|
+
if (current())
|
|
224
|
+
backend.recordFeature('lavalink:sponsorblock', 'available');
|
|
225
|
+
return method === 'GET' ? [...result] : undefined;
|
|
226
|
+
}
|
|
227
|
+
getLavalinkSponsorBlockCategories(guildId) {
|
|
228
|
+
return this.lavalinkSponsorBlockRequest('GET', guildId);
|
|
229
|
+
}
|
|
230
|
+
async setLavalinkSponsorBlockCategories(guildId, categories) {
|
|
231
|
+
await this.lavalinkSponsorBlockRequest('PUT', guildId, categories);
|
|
232
|
+
}
|
|
233
|
+
async clearLavalinkSponsorBlockCategories(guildId) {
|
|
234
|
+
await this.lavalinkSponsorBlockRequest('DELETE', guildId);
|
|
235
|
+
}
|
|
236
|
+
async getSponsorBlock(guildId) {
|
|
237
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
238
|
+
return this.featureRequest('sponsorblock:get', { guildId }, { headers: this.authHeaders }, NodeLinkOrchestration_1.validateSponsorState);
|
|
239
|
+
}
|
|
240
|
+
async updateSponsorBlock(guildId, options) {
|
|
241
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
242
|
+
return this.featureRequest('sponsorblock:update', { guildId }, { headers: this.jsonHeaders, body: (0, NodeLinkOrchestration_1.sponsorOptionsBody)(options) }, NodeLinkOrchestration_1.validateSponsorState);
|
|
243
|
+
}
|
|
244
|
+
async setSponsorBlockSegments(guildId, segments) {
|
|
245
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
246
|
+
return this.featureRequest('sponsorblock:segments', { guildId }, { headers: this.jsonHeaders, body: (0, NodeLinkOrchestration_1.sponsorSegmentsBody)(segments) }, NodeLinkOrchestration_1.validateSponsorState);
|
|
247
|
+
}
|
|
248
|
+
async clearSponsorBlock(guildId) {
|
|
249
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
250
|
+
await this.featureRequest('sponsorblock:clear', { guildId }, { headers: this.authHeaders });
|
|
251
|
+
}
|
|
87
252
|
async getPlayers() {
|
|
88
|
-
const res = await
|
|
253
|
+
const res = await this.request(`${this.url}${(0, SessionPath_1.sessionPath)(this.node.sessionId)}/players`, {
|
|
89
254
|
method: "GET",
|
|
90
255
|
headers: this.authHeaders
|
|
91
256
|
});
|
|
92
|
-
|
|
257
|
+
if (res === undefined || res === null)
|
|
258
|
+
return null;
|
|
259
|
+
if (!Array.isArray(res))
|
|
260
|
+
throw new ProtocolValidation_1.ProtocolResponseError('get players', 'player array');
|
|
261
|
+
const players = [];
|
|
262
|
+
for (const row of res) {
|
|
263
|
+
(0, ProtocolValidation_1.validatePlayerRead)(row);
|
|
264
|
+
players.push(row);
|
|
265
|
+
}
|
|
266
|
+
return players;
|
|
93
267
|
}
|
|
94
268
|
async getPlayer(guildId) {
|
|
95
|
-
const res = await
|
|
269
|
+
const res = await this.request(`${this.url}${(0, SessionPath_1.playerPath)(this.node.sessionId, guildId)}`, {
|
|
96
270
|
method: "GET",
|
|
97
271
|
headers: this.authHeaders
|
|
98
272
|
});
|
|
99
|
-
|
|
273
|
+
if (res === undefined || res === null)
|
|
274
|
+
return null;
|
|
275
|
+
(0, ProtocolValidation_1.validatePlayerRead)(res, guildId);
|
|
276
|
+
return res;
|
|
100
277
|
}
|
|
101
278
|
async updatePlayer(guildId, data, noReplace = false) {
|
|
279
|
+
return this.updatePlayerRequest(guildId, data, noReplace);
|
|
280
|
+
}
|
|
281
|
+
async updatePlayerRequest(guildId, data, noReplace) {
|
|
282
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
283
|
+
const requestSession = this.node.sessionId;
|
|
284
|
+
const requestBackend = this.node.backend;
|
|
285
|
+
const requestSocket = this.node.socket;
|
|
286
|
+
(0, SessionPath_1.playerPath)(requestSession, guildId);
|
|
287
|
+
await this.node.manager.guildOwnership?.assertCurrent(guildId);
|
|
288
|
+
if (this.node.destroyed || this.node.sessionId !== requestSession ||
|
|
289
|
+
this.node.backend !== requestBackend || this.node.socket !== requestSocket)
|
|
290
|
+
throw new Error('Player update session changed');
|
|
291
|
+
const payload = this.node.backend ? this.node.backend.preparePlayerUpdate(data) : (0, ProtocolContracts_1.preparePlayerUpdate)(this.node.isNodeLink ? 'nodelink' : 'unknown', data);
|
|
102
292
|
const params = new URLSearchParams();
|
|
103
293
|
if (noReplace) {
|
|
104
294
|
params.append("noReplace", "true");
|
|
105
295
|
}
|
|
296
|
+
const owner = this.node.manager.players.get(guildId);
|
|
297
|
+
const intent = owner ? (0, PlaybackGuard_1.playbackGuard)(owner).ticket : undefined;
|
|
298
|
+
const session = this.node.sessionId;
|
|
106
299
|
try {
|
|
107
|
-
const res = await (
|
|
300
|
+
const res = await this.node.circuit.run(() => this.request(`${this.url}${(0, SessionPath_1.playerPath)(session, guildId)}?${params.toString()}`, {
|
|
108
301
|
method: "PATCH",
|
|
109
302
|
headers: this.jsonHeaders,
|
|
110
|
-
body:
|
|
303
|
+
body: payload,
|
|
111
304
|
throwOnError: true
|
|
112
|
-
}, undefined, 0);
|
|
113
|
-
|
|
305
|
+
}, undefined, 0));
|
|
306
|
+
if (this.node.destroyed || this.node.sessionId !== requestSession ||
|
|
307
|
+
this.node.backend !== requestBackend || this.node.socket !== requestSocket)
|
|
308
|
+
throw new Error('Player update session changed');
|
|
309
|
+
if (res === undefined || res === null)
|
|
310
|
+
return null;
|
|
311
|
+
(0, ProtocolValidation_1.validatePlayerAcknowledgement)(res, guildId);
|
|
312
|
+
return res;
|
|
114
313
|
}
|
|
115
314
|
catch (error) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.node.manager.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
.finally(() => { this.sessionRecoveryInProgress = false; });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
315
|
+
if (error instanceof HttpError_1.HttpError && error.statusCode === 404 &&
|
|
316
|
+
owner && !owner.destroyed && !this.node.destroyed && owner.node === this.node &&
|
|
317
|
+
this.node.manager.players.get(guildId) === owner && this.node.sessionId === session &&
|
|
318
|
+
this.node.backend === requestBackend && this.node.socket === requestSocket &&
|
|
319
|
+
(0, PlaybackGuard_1.playbackGuard)(owner).isCurrent(intent) && !this.sessionRecoveries.has(owner)) {
|
|
320
|
+
this.sessionRecoveries.add(owner);
|
|
321
|
+
void this.triggerPlayerRecovery(owner)
|
|
322
|
+
.catch(error => this.node.manager.emit("debug", `NyxLink > Rest > Recovery failed: ${error.message}`))
|
|
323
|
+
.finally(() => { this.sessionRecoveries.delete(owner); });
|
|
128
324
|
}
|
|
129
325
|
throw error;
|
|
130
326
|
}
|
|
131
327
|
}
|
|
132
|
-
async destroyPlayer(guildId) {
|
|
328
|
+
async destroyPlayer(guildId, options) {
|
|
329
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
330
|
+
const session = this.node.sessionId, backend = this.node.backend, socket = this.node.socket;
|
|
331
|
+
const path = (0, SessionPath_1.playerPath)(session, guildId);
|
|
332
|
+
await this.node.manager.guildOwnership?.assertCurrent(guildId);
|
|
333
|
+
if (this.node.sessionId !== session || this.node.backend !== backend || this.node.socket !== socket)
|
|
334
|
+
throw new Error('Player cleanup session changed');
|
|
335
|
+
const timeout = options?.timeoutMs ?? 10000;
|
|
336
|
+
if (options && (!Number.isFinite(timeout) || timeout <= 0 || timeout > 60000))
|
|
337
|
+
throw new TypeError('Cleanup timeout must be within 1..60000 ms');
|
|
133
338
|
try {
|
|
134
|
-
await
|
|
339
|
+
await this.request(`${this.url}${path}`, {
|
|
135
340
|
method: "DELETE",
|
|
136
|
-
headers: this.authHeaders
|
|
137
|
-
|
|
341
|
+
headers: this.authHeaders,
|
|
342
|
+
signal: options?.signal,
|
|
343
|
+
throwOnError: options !== undefined
|
|
344
|
+
}, options ? timeout : undefined, options ? 0 : undefined);
|
|
138
345
|
}
|
|
139
346
|
catch (error) {
|
|
140
|
-
|
|
141
|
-
if (!err.message.includes('status 404')) {
|
|
347
|
+
if (!(error instanceof HttpError_1.HttpError) || error.statusCode !== 404)
|
|
142
348
|
throw error;
|
|
143
|
-
}
|
|
144
349
|
}
|
|
145
350
|
}
|
|
351
|
+
async loadNodeLinkSearch(query, options = {}) {
|
|
352
|
+
const identifier = (0, NodeLinkSearchContracts_1.nodeLinkDiscoveryIdentifier)(query, options);
|
|
353
|
+
const backend = this.node.backend;
|
|
354
|
+
if (backend?.kind !== 'nodelink')
|
|
355
|
+
throw new FeatureUnavailableError_1.FeatureUnavailableError('nodelink:discovery', backend?.kind ?? 'unknown');
|
|
356
|
+
const session = this.node.sessionId;
|
|
357
|
+
const socket = this.node.socket;
|
|
358
|
+
options.signal?.throwIfAborted();
|
|
359
|
+
const result = await this.loadTracks(identifier, { timeoutMs: options.timeoutMs ?? 10000, signal: options.signal });
|
|
360
|
+
options.signal?.throwIfAborted();
|
|
361
|
+
if (this.node.destroyed || this.node.backend !== backend || this.node.sessionId !== session || this.node.socket !== socket) {
|
|
362
|
+
throw new Error('NodeLink discovery session changed');
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
146
366
|
async loadTracks(identifier, options) {
|
|
147
367
|
const params = new URLSearchParams();
|
|
148
368
|
params.append("identifier", identifier);
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
369
|
+
const protectedRequest = this.node.circuit.enabled;
|
|
370
|
+
return this.node.circuit.run(async () => {
|
|
371
|
+
const res = await this.request(`${this.url}/v4/loadtracks?${params}`, {
|
|
372
|
+
method: "GET",
|
|
373
|
+
headers: this.authHeaders,
|
|
374
|
+
throwOnError: protectedRequest || options !== undefined,
|
|
375
|
+
signal: options?.signal
|
|
376
|
+
}, options?.timeoutMs ?? 10000, protectedRequest || options ? 0 : 3);
|
|
377
|
+
if (res === undefined || res === null)
|
|
378
|
+
return { loadType: "empty", data: {} };
|
|
379
|
+
(0, ProtocolValidation_1.validateLoadResponse)(res);
|
|
380
|
+
return res;
|
|
381
|
+
});
|
|
156
382
|
}
|
|
157
383
|
async decodeTrack(encodedTrack) {
|
|
158
384
|
const params = new URLSearchParams();
|
|
159
385
|
params.append("encodedTrack", encodedTrack);
|
|
160
|
-
const res = await
|
|
386
|
+
const res = await this.request(`${this.url}/v4/decodetrack?${params}`, {
|
|
161
387
|
method: "GET",
|
|
162
388
|
headers: this.authHeaders
|
|
163
389
|
});
|
|
164
|
-
|
|
390
|
+
if (res === undefined || res === null)
|
|
391
|
+
return null;
|
|
392
|
+
(0, ProtocolValidation_1.validateTrackResponse)(res);
|
|
393
|
+
return res;
|
|
165
394
|
}
|
|
166
395
|
async decodeTracks(encodedTracks) {
|
|
167
|
-
const res = await
|
|
396
|
+
const res = await this.request(`${this.url}/v4/decodetracks`, {
|
|
168
397
|
method: "POST",
|
|
169
398
|
headers: this.jsonHeaders,
|
|
170
399
|
body: encodedTracks
|
|
171
400
|
});
|
|
172
|
-
|
|
401
|
+
if (res === undefined || res === null)
|
|
402
|
+
return null;
|
|
403
|
+
if (!Array.isArray(res))
|
|
404
|
+
throw new ProtocolValidation_1.ProtocolResponseError('decode tracks', 'track array');
|
|
405
|
+
for (const track of res)
|
|
406
|
+
(0, ProtocolValidation_1.validateTrackResponse)(track, 'decode tracks');
|
|
407
|
+
return res;
|
|
173
408
|
}
|
|
174
409
|
async getInfo() {
|
|
175
|
-
const res = await
|
|
410
|
+
const res = await this.request(`${this.url}/v4/info`, {
|
|
176
411
|
method: "GET",
|
|
177
412
|
headers: this.authHeaders
|
|
178
413
|
});
|
|
179
414
|
return res || null;
|
|
180
415
|
}
|
|
181
416
|
async getInfoWithHeaders() {
|
|
182
|
-
const res = await
|
|
417
|
+
const res = await this.request(`${this.url}/v4/info`, {
|
|
183
418
|
method: "GET",
|
|
184
419
|
headers: this.authHeaders,
|
|
185
420
|
returnHeaders: true,
|
|
@@ -188,41 +423,50 @@ class Rest {
|
|
|
188
423
|
return res || null;
|
|
189
424
|
}
|
|
190
425
|
async getVersion(timeout, retries) {
|
|
191
|
-
const res = await
|
|
426
|
+
const res = await this.request(`${this.url}/version`, {
|
|
192
427
|
method: "GET",
|
|
193
428
|
headers: this.authHeaders
|
|
194
429
|
}, timeout, retries);
|
|
195
430
|
return res || null;
|
|
196
431
|
}
|
|
197
432
|
async getStats() {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
433
|
+
const protectedRequest = this.node.circuit.enabled;
|
|
434
|
+
const res = await this.node.circuit.run(async () => {
|
|
435
|
+
const stats = await this.request(`${this.url}/v4/stats`, {
|
|
436
|
+
method: "GET", headers: this.authHeaders, throwOnError: protectedRequest
|
|
437
|
+
}, protectedRequest ? 10000 : undefined, protectedRequest ? 0 : undefined);
|
|
438
|
+
if (protectedRequest) {
|
|
439
|
+
const measurements = [stats?.players, stats?.cpu?.systemLoad, stats?.memory?.used, stats?.memory?.allocated];
|
|
440
|
+
if (!stats?.memory?.allocated || !measurements.every(value => typeof value === 'number' && Number.isFinite(value) && value >= 0)) {
|
|
441
|
+
throw new TypeError('Invalid node statistics');
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return stats;
|
|
201
445
|
});
|
|
202
446
|
return res || null;
|
|
203
447
|
}
|
|
204
448
|
async getRoutePlannerStatus() {
|
|
205
|
-
const res = await
|
|
449
|
+
const res = await this.request(`${this.url}/v4/routeplanner/status`, {
|
|
206
450
|
method: "GET",
|
|
207
451
|
headers: this.authHeaders
|
|
208
452
|
});
|
|
209
453
|
return res || null;
|
|
210
454
|
}
|
|
211
455
|
async freeFailedAddress(address) {
|
|
212
|
-
await
|
|
456
|
+
await this.request(`${this.url}/v4/routeplanner/free/address`, {
|
|
213
457
|
method: "POST",
|
|
214
458
|
headers: this.jsonHeaders,
|
|
215
459
|
body: { address }
|
|
216
460
|
});
|
|
217
461
|
}
|
|
218
462
|
async freeAllFailedAddresses() {
|
|
219
|
-
await
|
|
463
|
+
await this.request(`${this.url}/v4/routeplanner/free/all`, {
|
|
220
464
|
method: "POST",
|
|
221
465
|
headers: this.authHeaders
|
|
222
466
|
});
|
|
223
467
|
}
|
|
224
468
|
async updateSession(resuming, timeout) {
|
|
225
|
-
const res = await
|
|
469
|
+
const res = await this.request(`${this.url}${(0, SessionPath_1.sessionPath)(this.node.sessionId)}`, {
|
|
226
470
|
method: "PATCH",
|
|
227
471
|
headers: this.jsonHeaders,
|
|
228
472
|
body: {
|
|
@@ -230,58 +474,126 @@ class Rest {
|
|
|
230
474
|
timeout
|
|
231
475
|
}
|
|
232
476
|
});
|
|
233
|
-
|
|
477
|
+
if (res === undefined || res === null)
|
|
478
|
+
return null;
|
|
479
|
+
(0, ProtocolValidation_1.validateSessionResponse)(res);
|
|
480
|
+
return res;
|
|
234
481
|
}
|
|
235
482
|
async addMixLayer(guildId, data) {
|
|
236
483
|
this.node.assertFeature("mix:add");
|
|
237
|
-
|
|
238
|
-
|
|
484
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
485
|
+
const body = (0, NodeLinkMixContracts_1.mixCreateBody)(data);
|
|
486
|
+
const res = await this.featureRequest("mix:add", { guildId }, {
|
|
239
487
|
headers: this.jsonHeaders,
|
|
240
|
-
body
|
|
241
|
-
});
|
|
242
|
-
return res
|
|
488
|
+
body
|
|
489
|
+
}, NodeLinkMixContracts_1.validateMixCreated);
|
|
490
|
+
return res == null ? null : res;
|
|
243
491
|
}
|
|
244
492
|
async getMixLayers(guildId) {
|
|
245
493
|
this.node.assertFeature("mix:list");
|
|
246
|
-
|
|
247
|
-
|
|
494
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
495
|
+
const res = await this.featureRequest("mix:list", { guildId }, {
|
|
248
496
|
headers: this.authHeaders
|
|
249
|
-
});
|
|
250
|
-
return res
|
|
497
|
+
}, NodeLinkMixContracts_1.validateMixLayers);
|
|
498
|
+
return res == null ? null : res;
|
|
251
499
|
}
|
|
252
500
|
async updateMixLayerVolume(guildId, mixId, volume) {
|
|
253
501
|
this.node.assertFeature("mix:update");
|
|
254
|
-
|
|
255
|
-
|
|
502
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
503
|
+
(0, NodeLinkMixContracts_1.requireMixId)(mixId);
|
|
504
|
+
(0, NodeLinkMixContracts_1.requireMixVolume)(volume);
|
|
505
|
+
await this.featureRequest("mix:update", { guildId, mixId }, {
|
|
256
506
|
headers: this.jsonHeaders,
|
|
257
507
|
body: { volume }
|
|
258
508
|
});
|
|
259
509
|
}
|
|
260
510
|
async removeMixLayer(guildId, mixId) {
|
|
261
511
|
this.node.assertFeature("mix:remove");
|
|
262
|
-
|
|
263
|
-
|
|
512
|
+
(0, NodeLinkOrchestration_1.requireGuildId)(guildId);
|
|
513
|
+
(0, NodeLinkMixContracts_1.requireMixId)(mixId);
|
|
514
|
+
await this.featureRequest("mix:remove", { guildId, mixId }, {
|
|
264
515
|
headers: this.authHeaders
|
|
265
516
|
});
|
|
266
517
|
}
|
|
267
|
-
async
|
|
518
|
+
async loadSearch(query, options = {}) {
|
|
519
|
+
const params = (0, LavaSearchContracts_1.lavaSearchParameters)(query, options);
|
|
520
|
+
const backend = this.node.backend;
|
|
521
|
+
if (backend?.kind !== 'lavalink' || !(0, LavaSearchContracts_1.hasLavaSearchPlugin)(backend.plugins) ||
|
|
522
|
+
backend.featureStatus('lavasearch') === 'unavailable') {
|
|
523
|
+
throw new FeatureUnavailableError_1.FeatureUnavailableError('lavasearch', backend?.kind ?? 'unknown');
|
|
524
|
+
}
|
|
525
|
+
const socket = this.node.socket;
|
|
526
|
+
const session = this.node.sessionId;
|
|
527
|
+
const current = () => !this.node.destroyed && this.node.backend === backend &&
|
|
528
|
+
this.node.socket === socket && this.node.sessionId === session;
|
|
529
|
+
options.signal?.throwIfAborted();
|
|
530
|
+
const result = await this.node.circuit.run(async () => {
|
|
531
|
+
try {
|
|
532
|
+
return await this.request(this.url + '/v4/loadsearch?' + params.toString(), {
|
|
533
|
+
method: 'GET', headers: this.authHeaders, throwOnError: true,
|
|
534
|
+
noContentAsNull: true, signal: options.signal
|
|
535
|
+
}, options.timeoutMs ?? 10000, 0);
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
this.featureError('lavasearch', error, backend, current);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
options.signal?.throwIfAborted();
|
|
542
|
+
if (!current())
|
|
543
|
+
throw new Error('LavaSearch backend session changed');
|
|
544
|
+
if (result !== null)
|
|
545
|
+
(0, LavaSearchContracts_1.validateLavaSearch)(result);
|
|
546
|
+
backend.recordFeature('lavasearch', 'available');
|
|
547
|
+
return result;
|
|
548
|
+
}
|
|
549
|
+
async getLavaLyrics(encodedTrack, options) {
|
|
550
|
+
const params = (0, LavaLyricsContracts_1.lavaLyricsParameters)(encodedTrack, options);
|
|
551
|
+
const backend = this.node.backend;
|
|
552
|
+
if (backend?.kind !== 'lavalink' || !(0, LavaLyricsContracts_1.hasLavaLyricsPlugin)(backend.plugins) ||
|
|
553
|
+
backend.featureStatus('lavalyrics') === 'unavailable') {
|
|
554
|
+
throw new FeatureUnavailableError_1.FeatureUnavailableError('lavalyrics', backend?.kind ?? 'unknown');
|
|
555
|
+
}
|
|
556
|
+
const socket = this.node.socket;
|
|
557
|
+
const session = this.node.sessionId;
|
|
558
|
+
const current = () => !this.node.destroyed && this.node.backend === backend &&
|
|
559
|
+
this.node.socket === socket && this.node.sessionId === session;
|
|
560
|
+
const result = await this.node.circuit.run(async () => {
|
|
561
|
+
try {
|
|
562
|
+
return await this.request(this.url + '/v4/lyrics?' + params.toString(), {
|
|
563
|
+
method: 'GET', headers: this.authHeaders, throwOnError: true,
|
|
564
|
+
noContentAsNull: true
|
|
565
|
+
}, 10000, 0);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
this.featureError('lavalyrics', error, backend, current);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
if (result === null) {
|
|
572
|
+
if (current())
|
|
573
|
+
backend.recordFeature('lavalyrics', 'available');
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
(0, LavaLyricsContracts_1.validateLavaLyrics)(result);
|
|
577
|
+
if (current())
|
|
578
|
+
backend.recordFeature('lavalyrics', 'available');
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
async loadLyrics(encodedTrack, options) {
|
|
268
582
|
this.node.assertFeature("lyrics");
|
|
269
|
-
const params =
|
|
270
|
-
|
|
271
|
-
if (lang)
|
|
272
|
-
params.append("lang", lang);
|
|
273
|
-
const res = await this.featureRequest("lyrics", `${this.url}/v4/loadlyrics?${params}`, {
|
|
274
|
-
method: "GET",
|
|
583
|
+
const params = (0, NodeLinkContracts_1.lyricsParameters)(encodedTrack, options);
|
|
584
|
+
const res = await this.featureRequest("lyrics", { query: params }, {
|
|
275
585
|
headers: this.authHeaders
|
|
276
586
|
});
|
|
277
587
|
return res ? (0, Util_1.normalizeNodeLinkResponse)(res, res.loadType) : null;
|
|
278
588
|
}
|
|
589
|
+
async getSourceHealth() {
|
|
590
|
+
return this.featureRequest('source-health', {}, { headers: this.authHeaders }, NodeLinkContracts_1.validateSourceHealth);
|
|
591
|
+
}
|
|
279
592
|
async loadChapters(encodedTrack) {
|
|
280
593
|
this.node.assertFeature("chapters");
|
|
281
594
|
const params = new URLSearchParams();
|
|
282
595
|
params.append("encodedTrack", encodedTrack);
|
|
283
|
-
const res = await this.featureRequest("chapters",
|
|
284
|
-
method: "GET",
|
|
596
|
+
const res = await this.featureRequest("chapters", { query: params }, {
|
|
285
597
|
headers: this.authHeaders
|
|
286
598
|
});
|
|
287
599
|
return res ? (0, Util_1.normalizeNodeLinkResponse)(res, "chapters") : null;
|
|
@@ -292,40 +604,35 @@ class Rest {
|
|
|
292
604
|
params.append("encodedTrack", encodedTrack);
|
|
293
605
|
if (lang)
|
|
294
606
|
params.append("lang", lang);
|
|
295
|
-
const res = await this.featureRequest("meaning",
|
|
296
|
-
method: "GET",
|
|
607
|
+
const res = await this.featureRequest("meaning", { query: params }, {
|
|
297
608
|
headers: this.authHeaders
|
|
298
609
|
});
|
|
299
610
|
return res ? (0, Util_1.normalizeNodeLinkResponse)(res, res.loadType) : null;
|
|
300
611
|
}
|
|
301
612
|
async getConnectionStatus() {
|
|
302
613
|
this.node.assertFeature("connection");
|
|
303
|
-
const res = await this.featureRequest("connection",
|
|
304
|
-
method: "GET",
|
|
614
|
+
const res = await this.featureRequest("connection", {}, {
|
|
305
615
|
headers: this.authHeaders
|
|
306
616
|
});
|
|
307
617
|
return res ? (0, Util_1.normalizeNodeLinkResponse)(res, "connection") : null;
|
|
308
618
|
}
|
|
309
619
|
async getMetrics() {
|
|
310
620
|
this.node.assertFeature("metrics");
|
|
311
|
-
const res = await this.featureRequest("metrics",
|
|
312
|
-
method: "GET",
|
|
621
|
+
const res = await this.featureRequest("metrics", {}, {
|
|
313
622
|
headers: this.authHeaders
|
|
314
623
|
});
|
|
315
624
|
return res || null;
|
|
316
625
|
}
|
|
317
626
|
async getWorkers() {
|
|
318
627
|
this.node.assertFeature("workers:get");
|
|
319
|
-
const res = await this.featureRequest("workers:get",
|
|
320
|
-
method: "GET",
|
|
628
|
+
const res = await this.featureRequest("workers:get", {}, {
|
|
321
629
|
headers: this.authHeaders
|
|
322
630
|
});
|
|
323
631
|
return res ? (0, Util_1.normalizeNodeLinkResponse)(res, "workers") : null;
|
|
324
632
|
}
|
|
325
633
|
async patchWorker(payload) {
|
|
326
634
|
this.node.assertFeature("workers:patch");
|
|
327
|
-
const res = await this.featureRequest("workers:patch",
|
|
328
|
-
method: "PATCH",
|
|
635
|
+
const res = await this.featureRequest("workers:patch", {}, {
|
|
329
636
|
headers: this.jsonHeaders,
|
|
330
637
|
body: payload
|
|
331
638
|
});
|
|
@@ -336,16 +643,14 @@ class Rest {
|
|
|
336
643
|
const params = new URLSearchParams();
|
|
337
644
|
if (validate)
|
|
338
645
|
params.append("validate", "true");
|
|
339
|
-
const res = await this.featureRequest("youtube:config",
|
|
340
|
-
method: "GET",
|
|
646
|
+
const res = await this.featureRequest("youtube:config:get", { query: params }, {
|
|
341
647
|
headers: this.authHeaders
|
|
342
648
|
});
|
|
343
649
|
return res || null;
|
|
344
650
|
}
|
|
345
651
|
async updateYoutubeConfig(payload) {
|
|
346
652
|
this.node.assertFeature("youtube:config");
|
|
347
|
-
const res = await this.featureRequest("youtube:config",
|
|
348
|
-
method: "PATCH",
|
|
653
|
+
const res = await this.featureRequest("youtube:config:update", {}, {
|
|
349
654
|
headers: this.jsonHeaders,
|
|
350
655
|
body: payload
|
|
351
656
|
});
|
|
@@ -355,8 +660,7 @@ class Rest {
|
|
|
355
660
|
this.node.assertFeature("youtube:oauth");
|
|
356
661
|
const params = new URLSearchParams();
|
|
357
662
|
params.append("refreshToken", refreshToken);
|
|
358
|
-
const res = await this.featureRequest("youtube:oauth",
|
|
359
|
-
method: "GET",
|
|
663
|
+
const res = await this.featureRequest("youtube:oauth", { query: params }, {
|
|
360
664
|
headers: this.authHeaders
|
|
361
665
|
});
|
|
362
666
|
return res || null;
|
|
@@ -365,16 +669,14 @@ class Rest {
|
|
|
365
669
|
this.node.assertFeature("encodetrack");
|
|
366
670
|
const params = new URLSearchParams();
|
|
367
671
|
params.append("track", track);
|
|
368
|
-
const res = await this.featureRequest("encodetrack",
|
|
369
|
-
method: "GET",
|
|
672
|
+
const res = await this.featureRequest("encodetrack", { query: params }, {
|
|
370
673
|
headers: this.authHeaders
|
|
371
674
|
});
|
|
372
675
|
return res || null;
|
|
373
676
|
}
|
|
374
677
|
async encodeTracksRemote(tracks) {
|
|
375
678
|
this.node.assertFeature("encodedtracks");
|
|
376
|
-
const res = await this.featureRequest("encodedtracks",
|
|
377
|
-
method: "POST",
|
|
679
|
+
const res = await this.featureRequest("encodedtracks", {}, {
|
|
378
680
|
headers: this.jsonHeaders,
|
|
379
681
|
body: tracks
|
|
380
682
|
});
|
|
@@ -387,23 +689,110 @@ class Rest {
|
|
|
387
689
|
if (itag !== undefined && itag !== null) {
|
|
388
690
|
params.append("itag", String(itag));
|
|
389
691
|
}
|
|
390
|
-
const res = await this.featureRequest("trackstream",
|
|
391
|
-
method: "GET",
|
|
692
|
+
const res = await this.featureRequest("trackstream", { query: params }, {
|
|
392
693
|
headers: this.authHeaders
|
|
393
694
|
});
|
|
394
695
|
return res || null;
|
|
395
696
|
}
|
|
697
|
+
async getStreamFormats(encodedTrack, options = {}) {
|
|
698
|
+
this.node.assertFeature('loadstream');
|
|
699
|
+
if (typeof encodedTrack !== 'string' || !encodedTrack.trim())
|
|
700
|
+
throw new TypeError('Stream formats require an encoded track');
|
|
701
|
+
if (options.itag !== undefined && (!Number.isSafeInteger(options.itag) || options.itag <= 0))
|
|
702
|
+
throw new TypeError('itag must be a positive integer');
|
|
703
|
+
if (options.timeoutMs !== undefined && (!Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 30000))
|
|
704
|
+
throw new RangeError('Invalid stream formats timeout');
|
|
705
|
+
const route = this.extensionRoute('loadstream');
|
|
706
|
+
const backend = this.node.backend;
|
|
707
|
+
const socket = this.node.socket;
|
|
708
|
+
const session = this.node.sessionId;
|
|
709
|
+
const current = () => !this.node.destroyed && this.node.backend === backend &&
|
|
710
|
+
this.node.socket === socket && this.node.sessionId === session;
|
|
711
|
+
try {
|
|
712
|
+
const response = await this.request(this.url + route.path, {
|
|
713
|
+
method: route.method, headers: this.jsonHeaders,
|
|
714
|
+
body: { encodedTrack, format: 'formats', ...(options.itag !== undefined ? { itag: options.itag } : {}) },
|
|
715
|
+
signal: options.signal, throwOnError: true,
|
|
716
|
+
}, options.timeoutMs ?? 10000, 0);
|
|
717
|
+
(0, NodeLinkContracts_1.validateNodeLinkStreamFormats)(response);
|
|
718
|
+
if (current())
|
|
719
|
+
backend?.recordFeature('loadstream', 'available');
|
|
720
|
+
return response;
|
|
721
|
+
}
|
|
722
|
+
catch (error) {
|
|
723
|
+
this.featureError('loadstream', error, backend, current);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
396
726
|
async loadStream(payload, options = {}) {
|
|
397
727
|
this.node.assertFeature('loadstream');
|
|
728
|
+
if (!payload || typeof payload !== 'object' || typeof payload.encodedTrack !== 'string' || !payload.encodedTrack.trim()) {
|
|
729
|
+
throw new TypeError('LoadStream requires an encoded track');
|
|
730
|
+
}
|
|
731
|
+
if (payload.format !== undefined && !['raw', 'pcm', 'wav', 'passthrough', 'original', 'source'].includes(payload.format)) {
|
|
732
|
+
throw new TypeError('LoadStream format must be raw, wav or passthrough (formats JSON uses getStreamFormats)');
|
|
733
|
+
}
|
|
734
|
+
const passthrough = ['passthrough', 'original', 'source'].includes(payload.format ?? '');
|
|
735
|
+
if (payload.itag !== undefined && (!passthrough || !Number.isSafeInteger(payload.itag) || payload.itag <= 0)) {
|
|
736
|
+
throw new TypeError('itag is only valid for passthrough and must be positive');
|
|
737
|
+
}
|
|
738
|
+
if (options.range !== undefined && (!passthrough ||
|
|
739
|
+
!/^bytes=(?:\d+-\d*|-\d+)$/.test(options.range) || options.range.length > 64)) {
|
|
740
|
+
throw new TypeError('HTTP Range requires passthrough and a valid single byte range');
|
|
741
|
+
}
|
|
742
|
+
if (payload.volume !== undefined && (!Number.isFinite(payload.volume) || payload.volume < 0 || payload.volume > 1000) ||
|
|
743
|
+
payload.position !== undefined && (!Number.isFinite(payload.position) || payload.position < 0) ||
|
|
744
|
+
payload.filters !== undefined && (!payload.filters || typeof payload.filters !== 'object' || Array.isArray(payload.filters))) {
|
|
745
|
+
throw new TypeError('Invalid LoadStream playback options');
|
|
746
|
+
}
|
|
747
|
+
if (options.seekMode !== undefined && !['server', 'pcm-trim'].includes(options.seekMode)) {
|
|
748
|
+
throw new TypeError('LoadStream seekMode must be server or pcm-trim');
|
|
749
|
+
}
|
|
750
|
+
const clientTrim = options.seekMode === 'pcm-trim';
|
|
751
|
+
if (clientTrim) {
|
|
752
|
+
if (payload.format !== undefined && !['raw', 'pcm'].includes(payload.format))
|
|
753
|
+
throw new TypeError('Client PCM seeking supports raw/pcm only; original bytes cannot be trimmed as PCM');
|
|
754
|
+
(0, ClientPCMSeek_1.assertClientPcmSeekPosition)(payload.position ?? 0);
|
|
755
|
+
}
|
|
756
|
+
const requestPayload = clientTrim
|
|
757
|
+
? { ...payload, position: 0, format: 'raw' }
|
|
758
|
+
: payload.format === 'pcm' ? { ...payload, format: 'raw' }
|
|
759
|
+
: passthrough ? { ...payload, format: 'passthrough' } : payload;
|
|
760
|
+
const route = this.extensionRoute('loadstream');
|
|
761
|
+
const backend = this.node.backend;
|
|
762
|
+
const socket = this.node.socket;
|
|
763
|
+
const session = this.node.sessionId;
|
|
764
|
+
const current = () => !this.node.destroyed && this.node.backend === backend &&
|
|
765
|
+
this.node.socket === socket && this.node.sessionId === session;
|
|
398
766
|
try {
|
|
399
|
-
const res = await
|
|
400
|
-
method:
|
|
767
|
+
const res = await this.streamRequest(this.url + route.path, {
|
|
768
|
+
method: route.method,
|
|
769
|
+
headers: options.range ? { ...this.jsonHeaders, Range: options.range } : this.jsonHeaders,
|
|
770
|
+
body: requestPayload, signal: options.signal,
|
|
401
771
|
}, options.timeoutMs ?? 100000);
|
|
402
|
-
|
|
403
|
-
|
|
772
|
+
try {
|
|
773
|
+
(0, NodeLinkStreamResponse_1.validateNodeLinkStreamResponse)(res.headers, passthrough ? 'passthrough' :
|
|
774
|
+
requestPayload.format === 'wav' ? 'wav' : 'raw');
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
res.stream.destroy();
|
|
778
|
+
throw error;
|
|
779
|
+
}
|
|
780
|
+
if (current())
|
|
781
|
+
backend?.recordFeature('loadstream', 'available');
|
|
782
|
+
if (!clientTrim)
|
|
783
|
+
return { stream: res.stream, headers: res.headers, statusCode: res.statusCode };
|
|
784
|
+
const headers = { ...res.headers };
|
|
785
|
+
delete headers['content-length'];
|
|
786
|
+
delete headers['content-range'];
|
|
787
|
+
delete headers['transfer-encoding'];
|
|
788
|
+
delete headers['accept-ranges'];
|
|
789
|
+
return {
|
|
790
|
+
stream: (0, ClientPCMSeek_1.createClientPcmSeekStream)(res.stream, payload.position ?? 0),
|
|
791
|
+
headers, statusCode: res.statusCode,
|
|
792
|
+
};
|
|
404
793
|
}
|
|
405
794
|
catch (error) {
|
|
406
|
-
this.featureError('loadstream', error);
|
|
795
|
+
this.featureError('loadstream', error, backend, current);
|
|
407
796
|
}
|
|
408
797
|
}
|
|
409
798
|
async subscribeLyrics(guildId, skipTrackSource) {
|
|
@@ -411,15 +800,13 @@ class Rest {
|
|
|
411
800
|
const params = new URLSearchParams();
|
|
412
801
|
if (skipTrackSource)
|
|
413
802
|
params.append("skipTrackSource", "true");
|
|
414
|
-
await this.featureRequest("lyrics:subscribe",
|
|
415
|
-
method: "POST",
|
|
803
|
+
await this.featureRequest("lyrics:subscribe", { guildId, query: params }, {
|
|
416
804
|
headers: this.authHeaders
|
|
417
805
|
});
|
|
418
806
|
}
|
|
419
807
|
async unsubscribeLyrics(guildId) {
|
|
420
808
|
this.node.assertFeature("lyrics:unsubscribe");
|
|
421
|
-
await this.featureRequest("lyrics:unsubscribe",
|
|
422
|
-
method: "DELETE",
|
|
809
|
+
await this.featureRequest("lyrics:unsubscribe", { guildId }, {
|
|
423
810
|
headers: this.authHeaders
|
|
424
811
|
});
|
|
425
812
|
}
|