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,17 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Player = void 0;
|
|
4
|
+
const AdvancedAudioRecovery_1 = require("../players/AdvancedAudioRecovery");
|
|
5
|
+
const OpenTelemetry_1 = require("../observability/OpenTelemetry");
|
|
6
|
+
const NodeLinkContracts_1 = require("../backends/NodeLinkContracts");
|
|
7
|
+
const ProtocolContracts_1 = require("../backends/ProtocolContracts");
|
|
8
|
+
const PlayerMigration_1 = require("../players/PlayerMigration");
|
|
4
9
|
const PlayerCommandQueue_1 = require("../players/PlayerCommandQueue");
|
|
5
10
|
const PlaybackGuard_1 = require("../players/PlaybackGuard");
|
|
11
|
+
const PlaybackAttempt_1 = require("../players/PlaybackAttempt");
|
|
12
|
+
const NodeSelector_1 = require("../nodes/NodeSelector");
|
|
6
13
|
const Util_1 = require("../Util");
|
|
7
14
|
const Voice_1 = require("./Voice");
|
|
8
15
|
const Track_1 = require("./Track");
|
|
9
16
|
const TrackCodec_1 = require("../tracks/TrackCodec");
|
|
10
17
|
const TrackResolver_1 = require("../tracks/TrackResolver");
|
|
11
18
|
const VoiceReceiver_1 = require("./VoiceReceiver");
|
|
19
|
+
const PlayerSnapshot_1 = require("../database/PlayerSnapshot");
|
|
20
|
+
const NodeLinkMixContracts_1 = require("../backends/NodeLinkMixContracts");
|
|
21
|
+
const PlayerOperationCancelledError_1 = require("../errors/PlayerOperationCancelledError");
|
|
22
|
+
const QueuePreload_1 = require("../players/QueuePreload");
|
|
12
23
|
class Player {
|
|
13
24
|
manager;
|
|
14
25
|
node;
|
|
26
|
+
nodeSelection;
|
|
15
27
|
guildId;
|
|
16
28
|
queue;
|
|
17
29
|
filters;
|
|
@@ -36,11 +48,19 @@ class Player {
|
|
|
36
48
|
historySize = 10;
|
|
37
49
|
lastActivityTime = Date.now();
|
|
38
50
|
commands = new PlayerCommandQueue_1.PlayerCommandQueue();
|
|
51
|
+
get pendingCommands() { return this.commands.pending; }
|
|
39
52
|
destructionPromise;
|
|
53
|
+
pendingPlayTicket;
|
|
54
|
+
lastSuccessfulExplicitPlayTicket;
|
|
40
55
|
volumeRevision = 0;
|
|
41
56
|
optimisticVolumeRevision = 0;
|
|
42
57
|
fading;
|
|
58
|
+
crossfade;
|
|
43
59
|
nextTrack;
|
|
60
|
+
preloadOptions;
|
|
61
|
+
queuePreload;
|
|
62
|
+
preloadScheduler = new QueuePreload_1.QueuePreloadScheduler();
|
|
63
|
+
get preloadJob() { return this.preloadScheduler.pending; }
|
|
44
64
|
audioTrackId;
|
|
45
65
|
loudnessNormalizer;
|
|
46
66
|
endTime;
|
|
@@ -53,6 +73,14 @@ class Player {
|
|
|
53
73
|
isResumeInProgress = false;
|
|
54
74
|
lastResumeAttempt = 0;
|
|
55
75
|
constructor(manager, node, config) {
|
|
76
|
+
NodeSelector_1.NodeSelector.validate(config.nodeSelection);
|
|
77
|
+
const requirements = config.nodeSelection ?? {};
|
|
78
|
+
this.nodeSelection = Object.freeze({
|
|
79
|
+
...(requirements.backend !== undefined ? { backend: requirements.backend } : {}),
|
|
80
|
+
...(requirements.requiredCapabilities !== undefined ? { requiredCapabilities: Object.freeze([...requirements.requiredCapabilities]) } : {}),
|
|
81
|
+
...(requirements.region !== undefined ? { region: requirements.region } : {}),
|
|
82
|
+
...(requirements.regionPolicy !== undefined ? { regionPolicy: requirements.regionPolicy } : {}),
|
|
83
|
+
});
|
|
56
84
|
this.manager = manager;
|
|
57
85
|
this.node = node;
|
|
58
86
|
this.guildId = config.guildId;
|
|
@@ -71,10 +99,7 @@ class Player {
|
|
|
71
99
|
this.voice = new Voice_1.Voice(this);
|
|
72
100
|
if (config.current) {
|
|
73
101
|
this.current = TrackCodec_1.TrackCodec.restore(config.current);
|
|
74
|
-
|
|
75
|
-
this.current.position = config.current.position;
|
|
76
|
-
this.lastPosition = this.current.position;
|
|
77
|
-
}
|
|
102
|
+
this.lastPosition = this.current.getInfo().position;
|
|
78
103
|
}
|
|
79
104
|
if (config.queue && Array.isArray(config.queue)) {
|
|
80
105
|
for (const track of config.queue) {
|
|
@@ -86,7 +111,7 @@ class Player {
|
|
|
86
111
|
this.previous.push(TrackCodec_1.TrackCodec.restore(track));
|
|
87
112
|
}
|
|
88
113
|
}
|
|
89
|
-
this.manager.emit("debug", `
|
|
114
|
+
this.manager.emit("debug", `NyxLink > Player#constructor >> Player created for guild ${this.guildId} on node ${this.node.identifier} | autoPlay: ${this.autoPlay}, autoLeave: ${this.autoLeave}, loop: ${this.loop}`);
|
|
90
115
|
this.startHealthCheck();
|
|
91
116
|
}
|
|
92
117
|
startHealthCheck() {
|
|
@@ -113,11 +138,11 @@ class Player {
|
|
|
113
138
|
const currentPosition = this.current.position ?? 0;
|
|
114
139
|
const positionDelta = Math.abs(currentPosition - this.lastPosition);
|
|
115
140
|
const timeDelta = now - this.lastPositionTime;
|
|
116
|
-
if (positionDelta < 1000 && timeDelta > 30000 && !this.current.isStream) {
|
|
141
|
+
if (positionDelta < 1000 && timeDelta > 30000 && !this.current.getInfo().isStream) {
|
|
117
142
|
this.stuckDetectionCount++;
|
|
118
|
-
this.manager.emit("debug", `
|
|
143
|
+
this.manager.emit("debug", `NyxLink > Player#healthCheck >> Player ${this.guildId} appears stuck. Position: ${currentPosition}, Delta: ${positionDelta}, Stuck count: ${this.stuckDetectionCount}/${maxStuckCount}`);
|
|
119
144
|
if (this.stuckDetectionCount >= maxStuckCount) {
|
|
120
|
-
this.manager.emit("debug", `
|
|
145
|
+
this.manager.emit("debug", `NyxLink > Player#healthCheck >> Player ${this.guildId} stuck for too long, attempting recovery.`);
|
|
121
146
|
await this.recoverFromStuck();
|
|
122
147
|
this.stuckDetectionCount = 0;
|
|
123
148
|
return;
|
|
@@ -125,16 +150,16 @@ class Player {
|
|
|
125
150
|
}
|
|
126
151
|
else {
|
|
127
152
|
if (this.stuckDetectionCount > 0) {
|
|
128
|
-
this.manager.emit("debug", `
|
|
153
|
+
this.manager.emit("debug", `NyxLink > Player#healthCheck >> Player ${this.guildId} position advanced (Delta: ${positionDelta}). Resetting stuck count.`);
|
|
129
154
|
}
|
|
130
155
|
this.stuckDetectionCount = 0;
|
|
131
156
|
}
|
|
132
157
|
const activityDelta = now - this.lastActivityTime;
|
|
133
158
|
if (activityDelta > silenceTimeout) {
|
|
134
159
|
this.silentDetectionCount++;
|
|
135
|
-
this.manager.emit("debug", `
|
|
160
|
+
this.manager.emit("debug", `NyxLink > Player#healthCheck >> Player ${this.guildId} silent for ${Math.round(activityDelta / 1000)}s. Silent count: ${this.silentDetectionCount}/${maxSilentCount}`);
|
|
136
161
|
if (this.silentDetectionCount >= maxSilentCount) {
|
|
137
|
-
this.manager.emit("debug", `
|
|
162
|
+
this.manager.emit("debug", `NyxLink > Player#healthCheck >> Player ${this.guildId} silent for too long, attempting soft restart.`);
|
|
138
163
|
await this.softRestart("Silent player detected");
|
|
139
164
|
this.silentDetectionCount = 0;
|
|
140
165
|
return;
|
|
@@ -157,9 +182,9 @@ class Player {
|
|
|
157
182
|
let ticket = (0, PlaybackGuard_1.playbackGuard)(this).ticket;
|
|
158
183
|
this.manager.emit("playerRecoveryStarted", this);
|
|
159
184
|
try {
|
|
160
|
-
if (this.current && this.current.isSeekable) {
|
|
185
|
+
if (this.current && this.current.getInfo().isSeekable) {
|
|
161
186
|
const seekPos = Math.max(0, (this.current.position ?? 0) + 2000);
|
|
162
|
-
this.manager.emit("debug", `
|
|
187
|
+
this.manager.emit("debug", `NyxLink > Player#recoverFromStuck >> Seeking forward 2s for player ${this.guildId}.`);
|
|
163
188
|
await this.seek(seekPos);
|
|
164
189
|
}
|
|
165
190
|
else {
|
|
@@ -174,19 +199,19 @@ class Player {
|
|
|
174
199
|
this.manager.emit("playerRecoverySuccess", this);
|
|
175
200
|
}
|
|
176
201
|
catch (error) {
|
|
177
|
-
this.manager.emit("debug", `
|
|
202
|
+
this.manager.emit("debug", `NyxLink > Player#recoverFromStuck >> Recovery failed: ${error.message}`);
|
|
178
203
|
this.manager.emit("playerRecoveryFailed", this);
|
|
179
204
|
}
|
|
180
205
|
}
|
|
181
206
|
async softRestart(reason) {
|
|
182
207
|
if (this.destroyed)
|
|
183
208
|
return false;
|
|
184
|
-
this.manager.emit("debug", `
|
|
209
|
+
this.manager.emit("debug", `NyxLink > Player#softRestart >> Soft restart triggered for player ${this.guildId}. Reason: ${reason}`);
|
|
185
210
|
const currentTrack = this.current;
|
|
186
211
|
const currentPosition = currentTrack?.position ?? 0;
|
|
187
212
|
const wasPaused = this.paused;
|
|
188
213
|
if (!currentTrack) {
|
|
189
|
-
this.manager.emit("debug", `
|
|
214
|
+
this.manager.emit("debug", `NyxLink > Player#softRestart >> No current track, skipping soft restart for player ${this.guildId}.`);
|
|
190
215
|
return false;
|
|
191
216
|
}
|
|
192
217
|
try {
|
|
@@ -230,11 +255,11 @@ class Player {
|
|
|
230
255
|
this.lastPosition = currentPosition;
|
|
231
256
|
this.lastPositionTime = Date.now();
|
|
232
257
|
this.updateActivity();
|
|
233
|
-
this.manager.emit("debug", `
|
|
258
|
+
this.manager.emit("debug", `NyxLink > Player#softRestart >> Soft restart completed for player ${this.guildId}.`);
|
|
234
259
|
return true;
|
|
235
260
|
}
|
|
236
261
|
catch (error) {
|
|
237
|
-
this.manager.emit("debug", `
|
|
262
|
+
this.manager.emit("debug", `NyxLink > Player#softRestart >> Soft restart failed: ${error.message}`);
|
|
238
263
|
return false;
|
|
239
264
|
}
|
|
240
265
|
}
|
|
@@ -254,6 +279,16 @@ class Player {
|
|
|
254
279
|
void operation.catch(error => this.manager.emit('debug', `NyxLink > Storage > Write failed for ${dbPath}: ${error.message}`));
|
|
255
280
|
return operation;
|
|
256
281
|
}
|
|
282
|
+
exportSnapshot() {
|
|
283
|
+
return this.commands.enqueue(async () => {
|
|
284
|
+
if (this.destroyed)
|
|
285
|
+
throw new Error('Cannot export a destroyed player');
|
|
286
|
+
const record = await this.manager.database.get(`players.${this.guildId}`);
|
|
287
|
+
if (this.destroyed)
|
|
288
|
+
throw new Error('Cannot export a destroyed player');
|
|
289
|
+
return PlayerSnapshot_1.PlayerSnapshotCodec.capture(this, (0, PlayerSnapshot_1.recordRevision)(record));
|
|
290
|
+
});
|
|
291
|
+
}
|
|
257
292
|
assertNodeLinkFeature(feature) {
|
|
258
293
|
this.node.assertFeature(feature);
|
|
259
294
|
}
|
|
@@ -264,30 +299,48 @@ class Player {
|
|
|
264
299
|
return track;
|
|
265
300
|
throw new Error("Invalid track input. Provide a Track instance or encoded string.");
|
|
266
301
|
}
|
|
267
|
-
async sendPlayerUpdate(payload, noReplace) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
payload
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
302
|
+
async sendPlayerUpdate(payload, noReplace, reservedTrack) {
|
|
303
|
+
await this.manager.guildOwnership?.assertCurrent(this.guildId);
|
|
304
|
+
const finalPayload = this.node.backend
|
|
305
|
+
? this.node.backend.preparePlayerUpdate(payload, this.voiceChannelId)
|
|
306
|
+
: (0, ProtocolContracts_1.preparePlayerUpdate)(this.node.isNodeLink ? 'nodelink' : 'unknown', payload, this.voiceChannelId);
|
|
307
|
+
const attempts = (0, PlaybackAttempt_1.playbackAttempt)(this);
|
|
308
|
+
const attempt = typeof payload.track?.encoded === 'string' ? attempts.begin(this.node, { ...payload.track, encoded: payload.track.encoded }, typeof payload.paused === 'boolean') : undefined;
|
|
309
|
+
if (attempt)
|
|
310
|
+
finalPayload.track = attempt.track;
|
|
311
|
+
const preload = typeof payload.nextTrack?.encoded === 'string' || payload.nextTrack === null ? attempts.preload(this.node, payload.nextTrack) : undefined;
|
|
312
|
+
if (preload)
|
|
313
|
+
finalPayload.nextTrack = preload.track;
|
|
314
|
+
const previousReservation = this.queuePreload;
|
|
315
|
+
const reservation = reservedTrack ? { track: reservedTrack, node: this.node, session: this.node.sessionId } : undefined;
|
|
316
|
+
if (preload)
|
|
317
|
+
this.queuePreload = reservation;
|
|
318
|
+
let acknowledged = false;
|
|
319
|
+
try {
|
|
320
|
+
const response = await this.node.rest.updatePlayer(this.guildId, finalPayload, noReplace);
|
|
321
|
+
if (response == null)
|
|
322
|
+
throw new Error("Backend did not acknowledge player update");
|
|
323
|
+
acknowledged = true;
|
|
324
|
+
if (attempt && !attempt.accepted(response))
|
|
325
|
+
throw new Error("Backend did not accept the requested track");
|
|
326
|
+
if (preload && !this.destroyed) {
|
|
327
|
+
if (payload.nextTrack === null)
|
|
328
|
+
this.nextTrack = undefined;
|
|
329
|
+
else if (preload.pending() && payload.nextTrack)
|
|
330
|
+
this.nextTrack = structuredClone(payload.nextTrack);
|
|
281
331
|
}
|
|
282
|
-
|
|
283
|
-
|
|
332
|
+
return response;
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
attempt?.rollback();
|
|
336
|
+
if (!acknowledged) {
|
|
337
|
+
const restoreReservation = preload && this.queuePreload === reservation && (!reservation || preload.pending());
|
|
338
|
+
preload?.rollback();
|
|
339
|
+
if (restoreReservation)
|
|
340
|
+
this.queuePreload = previousReservation;
|
|
284
341
|
}
|
|
285
|
-
|
|
342
|
+
throw error;
|
|
286
343
|
}
|
|
287
|
-
const response = await this.node.rest.updatePlayer(this.guildId, finalPayload, noReplace);
|
|
288
|
-
if (response == null)
|
|
289
|
-
throw new Error("Backend did not acknowledge player update");
|
|
290
|
-
return response;
|
|
291
344
|
}
|
|
292
345
|
async updatePlayer(payload, noReplace) {
|
|
293
346
|
return this.commands.enqueue(() => {
|
|
@@ -302,8 +355,10 @@ class Player {
|
|
|
302
355
|
return this.sendPlayerUpdate({ voice }, true);
|
|
303
356
|
}
|
|
304
357
|
async connect({ selfDeaf, selfMute } = {}) {
|
|
358
|
+
await this.manager.guildOwnership?.assertCurrent(this.guildId);
|
|
359
|
+
this.node.cancelVoiceReconnect?.(this);
|
|
305
360
|
const connectStack = new Error().stack?.split("\n").slice(2, 8).join("\n");
|
|
306
|
-
this.manager.emit("debug", `
|
|
361
|
+
this.manager.emit("debug", `NyxLink > Player#connect -> Connect requested for guild ${this.guildId}. Stack: ${connectStack || "unavailable"}`);
|
|
307
362
|
this.set("userInitiatedConnect", true);
|
|
308
363
|
if (selfDeaf !== undefined)
|
|
309
364
|
this.set("selfDeaf", selfDeaf);
|
|
@@ -313,20 +368,56 @@ class Player {
|
|
|
313
368
|
return this;
|
|
314
369
|
}
|
|
315
370
|
async disconnect() {
|
|
371
|
+
this.node.cancelVoiceReconnect?.(this);
|
|
316
372
|
const disconnectStack = new Error().stack?.split("\n").slice(2, 8).join("\n");
|
|
317
|
-
this.manager.emit("debug", `
|
|
373
|
+
this.manager.emit("debug", `NyxLink > Player#disconnect -> Disconnect requested for guild ${this.guildId}. Stack: ${disconnectStack || "unavailable"}`);
|
|
318
374
|
this.set("userInitiatedConnect", false);
|
|
319
375
|
await this.voice.disconnect();
|
|
320
376
|
return this;
|
|
321
377
|
}
|
|
322
378
|
async play(options = {}) {
|
|
323
379
|
const ticket = (0, PlaybackGuard_1.playbackGuard)(this).invalidate();
|
|
324
|
-
|
|
380
|
+
this.pendingPlayTicket = ticket;
|
|
381
|
+
return this.commands.enqueue(async () => {
|
|
382
|
+
const played = await (0, OpenTelemetry_1.observeOperation)(this.manager, 'nyxlink.player.play', () => this.playNext(options, ticket), result => result ? 'success' : 'resolved');
|
|
383
|
+
if (played)
|
|
384
|
+
this.lastSuccessfulExplicitPlayTicket = ticket;
|
|
385
|
+
return played;
|
|
386
|
+
}).finally(() => {
|
|
387
|
+
if (this.pendingPlayTicket === ticket)
|
|
388
|
+
this.pendingPlayTicket = undefined;
|
|
389
|
+
});
|
|
325
390
|
}
|
|
326
391
|
async playAutoPlay(track, ticket, automaticTicket) {
|
|
327
|
-
return this.commands.enqueue(() =>
|
|
392
|
+
return this.commands.enqueue(async () => {
|
|
393
|
+
if (this.queue.size > 0)
|
|
394
|
+
return false;
|
|
395
|
+
let automaticTrackQueued = false;
|
|
396
|
+
const markAutomaticQueue = (queued) => { automaticTrackQueued = queued; };
|
|
397
|
+
try {
|
|
398
|
+
return await (0, OpenTelemetry_1.observeOperation)(this.manager, 'nyxlink.autoplay', () => this.playNext({ track }, ticket, () => this.autoPlay && (0, PlaybackGuard_1.playbackGuard)(this).isAutoCurrent(automaticTicket) &&
|
|
399
|
+
(automaticTrackQueued
|
|
400
|
+
? this.queue.size === 1 && this.queue.first === track
|
|
401
|
+
: this.queue.size === 0), markAutomaticQueue), result => result ? 'success' : 'resolved');
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
if (automaticTrackQueued) {
|
|
405
|
+
const index = this.queue.tracks.indexOf(track);
|
|
406
|
+
if (index >= 0)
|
|
407
|
+
this.queue.remove(index);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
328
411
|
}
|
|
329
|
-
async playNext(options, ticket, allowed = () => true) {
|
|
412
|
+
async playNext(options, ticket, allowed = () => true, onInjectedQueueChange, suppressHistory = false) {
|
|
413
|
+
try {
|
|
414
|
+
return await this.applyPlayback(options, ticket, allowed, onInjectedQueueChange, suppressHistory);
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
(0, PlaybackAttempt_1.playbackAttempt)(this).retain(ticket);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async applyPlayback(options, ticket, allowed, onInjectedQueueChange, suppressHistory = false) {
|
|
330
421
|
const guard = (0, PlaybackGuard_1.playbackGuard)(this);
|
|
331
422
|
if (this.destroyed || !guard.isCurrent(ticket) || !allowed())
|
|
332
423
|
return false;
|
|
@@ -341,14 +432,16 @@ class Player {
|
|
|
341
432
|
else {
|
|
342
433
|
finalOptions = options;
|
|
343
434
|
}
|
|
344
|
-
|
|
435
|
+
if (finalOptions.audioTrackId !== undefined && !(0, AdvancedAudioRecovery_1.canSendNativeAudio)(this.node, 'audioTrackId'))
|
|
436
|
+
return false;
|
|
437
|
+
this.manager.emit("debug", `NyxLink > Player#play -> Playback requested for guild ${this.guildId}. Explicit track: ${Boolean(finalOptions.track || finalOptions.encoded)}`);
|
|
345
438
|
if (!this.voice.sessionId || !this.voice.endpoint) {
|
|
346
|
-
this.manager.emit("debug", `
|
|
439
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Voice not ready for guild ${this.guildId}, attempting to connect...`);
|
|
347
440
|
try {
|
|
348
441
|
await this.connect();
|
|
349
442
|
}
|
|
350
443
|
catch (e) {
|
|
351
|
-
this.manager.emit("debug", `
|
|
444
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Failed to connect voice: ${e}`);
|
|
352
445
|
return false;
|
|
353
446
|
}
|
|
354
447
|
}
|
|
@@ -358,52 +451,58 @@ class Player {
|
|
|
358
451
|
if (finalOptions.encoded) {
|
|
359
452
|
try {
|
|
360
453
|
const decoded = (0, Util_1.decodeTrack)(finalOptions.encoded);
|
|
361
|
-
track = new Track_1.Track(decoded, finalOptions.requester);
|
|
454
|
+
track = new Track_1.Track(decoded, finalOptions.requester, undefined, this.manager.options.trackPartial ?? []);
|
|
362
455
|
}
|
|
363
456
|
catch (e) {
|
|
364
|
-
this.manager.emit("debug", `
|
|
457
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Error decoding track for guild ${this.guildId}. Error: ${e}`);
|
|
365
458
|
return false;
|
|
366
459
|
}
|
|
367
460
|
}
|
|
368
461
|
if (track && !(track instanceof Track_1.Track)) {
|
|
369
462
|
try {
|
|
370
|
-
track = new Track_1.Track(track, finalOptions.requester);
|
|
463
|
+
track = new Track_1.Track(track, finalOptions.requester, undefined, this.manager.options.trackPartial ?? []);
|
|
371
464
|
}
|
|
372
465
|
catch (e) {
|
|
373
|
-
this.manager.emit("debug", `
|
|
466
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Invalid track object for guild ${this.guildId}. Error: ${e}`);
|
|
374
467
|
return false;
|
|
375
468
|
}
|
|
376
469
|
}
|
|
377
470
|
if (track) {
|
|
378
471
|
this.queue.unshift(track);
|
|
379
|
-
|
|
472
|
+
onInjectedQueueChange?.(true);
|
|
473
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Added track "${track.title}" to front of queue for guild ${this.guildId}`);
|
|
380
474
|
}
|
|
381
475
|
if (this.queue.size === 0) {
|
|
382
|
-
this.manager.emit("debug", `
|
|
476
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Queue is empty, cannot start playback for guild ${this.guildId}`);
|
|
383
477
|
return false;
|
|
384
478
|
}
|
|
385
479
|
const previousTrack = this.current;
|
|
386
480
|
const queuedTrack = this.queue.first;
|
|
387
481
|
let nextTrack = queuedTrack;
|
|
388
|
-
if (!nextTrack || !nextTrack.encoded) {
|
|
389
|
-
this.manager.emit("debug", `
|
|
482
|
+
if (!queuedTrack || !nextTrack || !nextTrack.encoded) {
|
|
483
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Invalid track data for guild ${this.guildId}.`);
|
|
390
484
|
return false;
|
|
391
485
|
}
|
|
486
|
+
let selectedPlaybackTrack;
|
|
392
487
|
try {
|
|
393
|
-
nextTrack = await TrackResolver_1.TrackResolver.resolve(nextTrack, this.node);
|
|
488
|
+
nextTrack = await TrackResolver_1.TrackResolver.resolve(nextTrack, this.node, undefined, guard.signal);
|
|
489
|
+
selectedPlaybackTrack = nextTrack instanceof Track_1.Track ? nextTrack :
|
|
490
|
+
new Track_1.Track(nextTrack, undefined, undefined, this.manager.options.trackPartial ?? []);
|
|
394
491
|
}
|
|
395
492
|
catch (error) {
|
|
396
|
-
this.manager.emit('debug', `NyxLink > TrackResolver > ${error.message}`);
|
|
493
|
+
this.manager.emit('debug', `NyxLink > TrackResolver > ${error instanceof Error ? error.message : String(error)}`);
|
|
397
494
|
return false;
|
|
398
495
|
}
|
|
399
496
|
if (this.destroyed || !guard.isCurrent(ticket) || !allowed() || this.queue.first !== queuedTrack)
|
|
400
497
|
return false;
|
|
401
498
|
this.queue.shift();
|
|
499
|
+
onInjectedQueueChange?.(false);
|
|
402
500
|
const oldTrackTitle = this.current?.title ?? "null";
|
|
403
|
-
|
|
501
|
+
const positionBeforePlayback = selectedPlaybackTrack.position;
|
|
502
|
+
this.current = selectedPlaybackTrack;
|
|
404
503
|
this.current.position = finalOptions.position || 0;
|
|
405
504
|
this.updateData("current", TrackCodec_1.TrackCodec.serialize(this.current));
|
|
406
|
-
this.manager.emit("debug", `
|
|
505
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Player state changed: current track: ${oldTrackTitle} -> ${this.current.title}`);
|
|
407
506
|
const oldPlaying = this.playing;
|
|
408
507
|
const oldPaused = this.paused;
|
|
409
508
|
this.playing = true;
|
|
@@ -419,72 +518,95 @@ class Player {
|
|
|
419
518
|
position: finalOptions.position || this.current.position,
|
|
420
519
|
volume: this.volume
|
|
421
520
|
};
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (this.nextTrack)
|
|
428
|
-
payload.nextTrack = this.nextTrack;
|
|
429
|
-
if (this.loudnessNormalizer !== undefined) {
|
|
430
|
-
payload.loudnessNormalizer = this.loudnessNormalizer;
|
|
431
|
-
}
|
|
521
|
+
(0, AdvancedAudioRecovery_1.projectAdvancedAudio)(payload, this.node, {
|
|
522
|
+
audioTrackId, fading: this.fading, crossfade: this.crossfade,
|
|
523
|
+
loudnessNormalizer: this.loudnessNormalizer,
|
|
524
|
+
nextTrack: this.queuePreload ? null : this.nextTrack
|
|
525
|
+
});
|
|
432
526
|
this.manager.emit("playerTriggeredPlay", this, this.current);
|
|
433
|
-
this.manager.emit("debug", `
|
|
527
|
+
this.manager.emit("debug", `NyxLink > Player#play -> Sending play request to node ${this.node.identifier} for guild ${this.guildId}.`);
|
|
434
528
|
try {
|
|
435
529
|
const response = await this.sendPlayerUpdate(payload, finalOptions.noReplace ?? this.manager.options.noReplace);
|
|
436
530
|
if (response == null)
|
|
437
531
|
throw new Error("Backend did not acknowledge playback");
|
|
438
532
|
if (!guard.isCurrent(ticket) || this.destroyed)
|
|
439
533
|
return false;
|
|
440
|
-
this.manager.emit("debug", `
|
|
534
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Successfully sent play request for track "${this.current.title}" for guild ${this.guildId}`);
|
|
441
535
|
}
|
|
442
536
|
catch (e) {
|
|
443
|
-
this.manager.emit("debug", `
|
|
537
|
+
this.manager.emit("debug", `NyxLink > Player#play >> CRITICAL: Failed to send play request for guild ${this.guildId}. Reverting state. Error: ${e.message}`);
|
|
444
538
|
this.playing = oldPlaying;
|
|
445
539
|
this.paused = oldPaused;
|
|
540
|
+
selectedPlaybackTrack.position = positionBeforePlayback;
|
|
446
541
|
this.current = previousTrack;
|
|
447
|
-
this.
|
|
542
|
+
this.updateData("current", previousTrack ? TrackCodec_1.TrackCodec.serialize(previousTrack) : null);
|
|
543
|
+
this.updateData("playing", oldPlaying);
|
|
544
|
+
this.updateData("paused", oldPaused);
|
|
545
|
+
this.queue.unshift(queuedTrack);
|
|
546
|
+
onInjectedQueueChange?.(true);
|
|
448
547
|
return false;
|
|
449
548
|
}
|
|
450
|
-
if (previousTrack && !this.get("isBackPlay")) {
|
|
549
|
+
if (previousTrack && !suppressHistory && !this.get("isBackPlay")) {
|
|
451
550
|
this.previous.push(previousTrack);
|
|
452
551
|
const historyLimit = this.manager.options.queue?.historyLimit ?? this.historySize;
|
|
453
552
|
if (this.previous.length > historyLimit) {
|
|
454
553
|
this.previous.shift();
|
|
455
554
|
}
|
|
456
555
|
this.updateData("previous", this.previous.map(t => TrackCodec_1.TrackCodec.serialize(t)));
|
|
457
|
-
this.manager.emit("debug", `
|
|
556
|
+
this.manager.emit("debug", `NyxLink > Player#play << Added track "${previousTrack.title}" to history for guild ${this.guildId}. History size: ${this.previous.length}`);
|
|
458
557
|
}
|
|
459
558
|
this.set("isBackPlay", false);
|
|
460
559
|
this.playing = true;
|
|
461
560
|
this.paused = false;
|
|
462
|
-
this.manager.emit("debug", `
|
|
561
|
+
this.manager.emit("debug", `NyxLink > Player#play >> Player state changed: playing: ${oldPlaying} -> ${this.playing}, paused: ${oldPaused} -> ${this.paused}`);
|
|
463
562
|
this.node.updateRecommendations(this).catch(() => { });
|
|
464
563
|
return true;
|
|
465
564
|
}
|
|
466
565
|
async addMix(track, options) {
|
|
467
566
|
this.assertNodeLinkFeature("mix:add");
|
|
468
567
|
const encoded = this.resolveEncodedTrack(track);
|
|
469
|
-
|
|
568
|
+
const body = (0, NodeLinkMixContracts_1.mixCreateBody)({
|
|
470
569
|
track: { encoded, userData: options?.userData },
|
|
471
570
|
volume: options?.volume
|
|
472
571
|
});
|
|
572
|
+
return this.mixCommand('mix:add', node => node.rest.addMixLayer(this.guildId, body));
|
|
473
573
|
}
|
|
474
574
|
async getMixes() {
|
|
475
575
|
this.assertNodeLinkFeature("mix:list");
|
|
476
|
-
return this.node.rest.getMixLayers(this.guildId);
|
|
576
|
+
return this.mixCommand('mix:list', node => node.rest.getMixLayers(this.guildId));
|
|
477
577
|
}
|
|
478
578
|
async updateMixVolume(mixId, volume) {
|
|
479
579
|
this.assertNodeLinkFeature("mix:update");
|
|
480
|
-
await this.node.rest.updateMixLayerVolume(this.guildId, mixId, volume);
|
|
580
|
+
await this.mixCommand('mix:update', node => node.rest.updateMixLayerVolume(this.guildId, mixId, volume));
|
|
481
581
|
return this;
|
|
482
582
|
}
|
|
483
583
|
async removeMix(mixId) {
|
|
484
584
|
this.assertNodeLinkFeature("mix:remove");
|
|
485
|
-
await this.node.rest.removeMixLayer(this.guildId, mixId);
|
|
585
|
+
await this.mixCommand('mix:remove', node => node.rest.removeMixLayer(this.guildId, mixId));
|
|
486
586
|
return this;
|
|
487
587
|
}
|
|
588
|
+
mixCommand(operation, execute) {
|
|
589
|
+
const node = this.node, session = node.sessionId, socket = node.socket, backend = node.backend;
|
|
590
|
+
const guard = (0, PlaybackGuard_1.playbackGuard)(this), ticket = guard.ticket;
|
|
591
|
+
const active = () => !this.destroyed && !this.manager.destroyed && !node.destroyed && node.connected &&
|
|
592
|
+
this.node === node && node.sessionId === session && node.socket === socket && node.backend === backend && guard.isCurrent(ticket);
|
|
593
|
+
return this.commands.enqueue(async () => {
|
|
594
|
+
if (!active())
|
|
595
|
+
throw new PlayerOperationCancelledError_1.PlayerOperationCancelledError(operation);
|
|
596
|
+
let result;
|
|
597
|
+
try {
|
|
598
|
+
result = await execute(node);
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
if (!active())
|
|
602
|
+
throw new PlayerOperationCancelledError_1.PlayerOperationCancelledError(operation);
|
|
603
|
+
throw error;
|
|
604
|
+
}
|
|
605
|
+
if (!active())
|
|
606
|
+
throw new PlayerOperationCancelledError_1.PlayerOperationCancelledError(operation);
|
|
607
|
+
return result;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
488
610
|
async subscribeLyrics(options) {
|
|
489
611
|
this.assertNodeLinkFeature("lyrics:subscribe");
|
|
490
612
|
await this.node.rest.subscribeLyrics(this.guildId, options?.skipTrackSource);
|
|
@@ -528,40 +650,151 @@ class Player {
|
|
|
528
650
|
return this.node.getDirectStream(target, itag);
|
|
529
651
|
}
|
|
530
652
|
async setFading(fading) {
|
|
531
|
-
|
|
532
|
-
this.
|
|
533
|
-
|
|
534
|
-
|
|
653
|
+
const config = structuredClone(fading);
|
|
654
|
+
return this.commands.enqueue(async () => {
|
|
655
|
+
if (this.destroyed)
|
|
656
|
+
throw new Error("Cannot update a destroyed player");
|
|
657
|
+
this.assertNodeLinkFeature("fading");
|
|
658
|
+
await this.sendPlayerUpdate({ fading: config });
|
|
659
|
+
if (!this.destroyed)
|
|
660
|
+
this.fading = config;
|
|
661
|
+
return this;
|
|
662
|
+
});
|
|
535
663
|
}
|
|
536
664
|
async clearFading() {
|
|
537
|
-
this.
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
return this;
|
|
665
|
+
return this.setFading({ enabled: false });
|
|
666
|
+
}
|
|
667
|
+
getCrossfade() {
|
|
668
|
+
return this.crossfade ? { ...this.crossfade } : undefined;
|
|
669
|
+
}
|
|
670
|
+
async setCrossfade(options) {
|
|
671
|
+
const config = (0, NodeLinkContracts_1.normalizeCrossfade)(options);
|
|
672
|
+
return this.commands.enqueue(async () => {
|
|
673
|
+
if (this.destroyed)
|
|
674
|
+
throw new Error("Cannot update a destroyed player");
|
|
675
|
+
this.assertNodeLinkFeature("crossfade");
|
|
676
|
+
await (0, OpenTelemetry_1.observeOperation)(this.manager, 'nyxlink.crossfade', () => this.sendPlayerUpdate({ crossfade: config }));
|
|
677
|
+
if (!this.destroyed) {
|
|
678
|
+
this.crossfade = config;
|
|
679
|
+
this.requestQueuePreload();
|
|
680
|
+
}
|
|
681
|
+
return this;
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
async clearCrossfade() {
|
|
685
|
+
return this.setCrossfade({ enabled: false });
|
|
541
686
|
}
|
|
542
687
|
async setNextTrack(track, userData) {
|
|
543
|
-
this.assertNodeLinkFeature("nextTrack");
|
|
544
688
|
const encoded = this.resolveEncodedTrack(track);
|
|
545
|
-
this.
|
|
546
|
-
|
|
547
|
-
|
|
689
|
+
return this.commands.enqueue(async () => {
|
|
690
|
+
if (this.destroyed)
|
|
691
|
+
throw new Error("Cannot update a destroyed player");
|
|
692
|
+
this.assertNodeLinkFeature("nextTrack");
|
|
693
|
+
const nextTrack = { encoded, userData: userData ?? (track instanceof Track_1.Track ? track.userData : undefined) };
|
|
694
|
+
await this.sendPlayerUpdate({ nextTrack });
|
|
695
|
+
return this;
|
|
696
|
+
});
|
|
548
697
|
}
|
|
549
698
|
async clearNextTrack() {
|
|
550
|
-
this.
|
|
551
|
-
|
|
552
|
-
|
|
699
|
+
return this.commands.enqueue(async () => {
|
|
700
|
+
if (this.destroyed)
|
|
701
|
+
throw new Error("Cannot update a destroyed player");
|
|
702
|
+
this.assertNodeLinkFeature("nextTrack");
|
|
703
|
+
await this.sendPlayerUpdate({ nextTrack: null });
|
|
704
|
+
return this;
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
getNextTrack() {
|
|
708
|
+
return this.nextTrack ? structuredClone(this.nextTrack) : undefined;
|
|
709
|
+
}
|
|
710
|
+
setQueuePreload(options) {
|
|
711
|
+
if (!options || typeof options.enabled !== 'boolean' ||
|
|
712
|
+
options.leadMs !== undefined && (!Number.isSafeInteger(options.leadMs) || options.leadMs < 1000 || options.leadMs > 120000)) {
|
|
713
|
+
throw new TypeError('Invalid queue preload options');
|
|
714
|
+
}
|
|
715
|
+
this.preloadOptions = { enabled: options.enabled, leadMs: options.leadMs ?? 35000 };
|
|
716
|
+
this.requestQueuePreload();
|
|
553
717
|
return this;
|
|
554
718
|
}
|
|
719
|
+
requestQueuePreload() {
|
|
720
|
+
if (this.destroyed || this.manager.destroyed || (!this.preloadOptions?.enabled && !this.queuePreload))
|
|
721
|
+
return;
|
|
722
|
+
const ticket = (0, PlaybackGuard_1.playbackGuard)(this).ticket;
|
|
723
|
+
const node = this.node;
|
|
724
|
+
const session = node.sessionId;
|
|
725
|
+
const active = () => !this.destroyed && !this.manager.destroyed && this.node === node &&
|
|
726
|
+
node.connected && !node.destroyed && node.sessionId === session && (0, PlaybackGuard_1.playbackGuard)(this).isCurrent(ticket);
|
|
727
|
+
const desired = () => active() ? (0, QueuePreload_1.desiredPreload)(this, this.preloadOptions, !!this.crossfade?.enabled) : undefined;
|
|
728
|
+
this.preloadScheduler.request(operation => this.commands.enqueue(operation), async () => {
|
|
729
|
+
if (!active())
|
|
730
|
+
return;
|
|
731
|
+
const reservation = this.queuePreload;
|
|
732
|
+
if (reservation && (reservation.node !== node || reservation.session !== session)) {
|
|
733
|
+
this.queuePreload = undefined;
|
|
734
|
+
this.nextTrack = undefined;
|
|
735
|
+
}
|
|
736
|
+
if (!node.isNodeLink)
|
|
737
|
+
return;
|
|
738
|
+
let candidate = desired();
|
|
739
|
+
if (this.queuePreload) {
|
|
740
|
+
if (this.queuePreload.track === candidate)
|
|
741
|
+
return;
|
|
742
|
+
await this.sendPlayerUpdate({ nextTrack: null });
|
|
743
|
+
candidate = desired();
|
|
744
|
+
}
|
|
745
|
+
if (!candidate || this.paused || this.nextTrack)
|
|
746
|
+
return;
|
|
747
|
+
const current = this.current;
|
|
748
|
+
const resolved = await TrackResolver_1.TrackResolver.resolve(candidate, node, undefined, (0, PlaybackGuard_1.playbackGuard)(this).signal);
|
|
749
|
+
if (this.current !== current || desired() !== candidate || this.paused || this.nextTrack)
|
|
750
|
+
return;
|
|
751
|
+
await this.sendPlayerUpdate({ nextTrack: { encoded: resolved.encoded, userData: resolved.userData } }, undefined, candidate);
|
|
752
|
+
}, () => {
|
|
753
|
+
this.manager.emit('debug', 'NyxLink > Queue preload request failed');
|
|
754
|
+
}, () => this.requestQueuePreload());
|
|
755
|
+
}
|
|
756
|
+
completeAudioMigration() {
|
|
757
|
+
const manualPreloadDiscarded = !!this.nextTrack && !this.queuePreload;
|
|
758
|
+
this.nextTrack = undefined;
|
|
759
|
+
this.queuePreload = undefined;
|
|
760
|
+
(0, PlaybackAttempt_1.playbackAttempt)(this).preload(this.node, null);
|
|
761
|
+
this.requestQueuePreload();
|
|
762
|
+
return manualPreloadDiscarded;
|
|
763
|
+
}
|
|
764
|
+
consumePreloadedTrack() {
|
|
765
|
+
const reservation = this.queuePreload;
|
|
766
|
+
this.queuePreload = undefined;
|
|
767
|
+
this.nextTrack = undefined;
|
|
768
|
+
if (reservation && reservation.node === this.node && reservation.session === this.node.sessionId) {
|
|
769
|
+
const index = this.queue.tracks.indexOf(reservation.track);
|
|
770
|
+
if (index !== -1)
|
|
771
|
+
this.queue.remove(index);
|
|
772
|
+
if (this.current) {
|
|
773
|
+
this.previous.push(this.current);
|
|
774
|
+
const limit = this.manager.options.queue?.historyLimit ?? this.historySize;
|
|
775
|
+
if (this.previous.length > limit)
|
|
776
|
+
this.previous.shift();
|
|
777
|
+
this.updateData('previous', this.previous.map(track => TrackCodec_1.TrackCodec.serialize(track)));
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
555
781
|
setAudioTrackId(audioTrackId) {
|
|
556
782
|
this.assertNodeLinkFeature("audioTrackId");
|
|
557
783
|
this.audioTrackId = audioTrackId;
|
|
558
784
|
return this;
|
|
559
785
|
}
|
|
560
786
|
async setLoudnessNormalizer(enabled) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
787
|
+
if (typeof enabled !== 'boolean')
|
|
788
|
+
throw new TypeError('Invalid loudness normalizer state');
|
|
789
|
+
return this.commands.enqueue(async () => {
|
|
790
|
+
if (this.destroyed)
|
|
791
|
+
throw new Error("Cannot update a destroyed player");
|
|
792
|
+
this.assertNodeLinkFeature("loudnessNormalizer");
|
|
793
|
+
await this.sendPlayerUpdate({ loudnessNormalizer: enabled });
|
|
794
|
+
if (!this.destroyed)
|
|
795
|
+
this.loudnessNormalizer = enabled;
|
|
796
|
+
return this;
|
|
797
|
+
});
|
|
565
798
|
}
|
|
566
799
|
createVoiceReceiver(options) {
|
|
567
800
|
this.assertNodeLinkFeature("voiceReceive");
|
|
@@ -574,17 +807,17 @@ class Player {
|
|
|
574
807
|
if (this.destroyed)
|
|
575
808
|
return this;
|
|
576
809
|
if (this.paused) {
|
|
577
|
-
this.manager.emit("debug", `
|
|
810
|
+
this.manager.emit("debug", `NyxLink > Player#pause >> Player is already paused for guild ${this.guildId}`);
|
|
578
811
|
return this;
|
|
579
812
|
}
|
|
580
|
-
this.manager.emit("debug", `
|
|
813
|
+
this.manager.emit("debug", `NyxLink > Player#pause -> Sending pause request to node ${this.node.identifier} for guild ${this.guildId}`);
|
|
581
814
|
this.manager.emit("playerTriggeredPause", this);
|
|
582
815
|
await this.sendPlayerUpdate({ paused: true });
|
|
583
816
|
const oldPaused = this.paused;
|
|
584
817
|
this.paused = true;
|
|
585
818
|
this.updateData("paused", this.paused);
|
|
586
|
-
this.manager.emit("debug", `
|
|
587
|
-
this.manager.emit("debug", `
|
|
819
|
+
this.manager.emit("debug", `NyxLink > Player#pause >> Player state changed: paused: ${oldPaused} -> ${this.paused}`);
|
|
820
|
+
this.manager.emit("debug", `NyxLink > Player#pause >> Player paused for guild ${this.guildId}`);
|
|
588
821
|
return this;
|
|
589
822
|
}
|
|
590
823
|
async resume(options) {
|
|
@@ -610,29 +843,29 @@ class Player {
|
|
|
610
843
|
const now = Date.now();
|
|
611
844
|
const minResumeInterval = this.manager.options.playerHealth?.resumeDebounce ?? 1000;
|
|
612
845
|
if (this.isResumeInProgress) {
|
|
613
|
-
this.manager.emit("debug", `
|
|
846
|
+
this.manager.emit("debug", `NyxLink > Player#resume >> Resume already in progress for guild ${this.guildId}, skipping.`);
|
|
614
847
|
return this;
|
|
615
848
|
}
|
|
616
849
|
if (now - this.lastResumeAttempt < minResumeInterval) {
|
|
617
|
-
this.manager.emit("debug", `
|
|
850
|
+
this.manager.emit("debug", `NyxLink > Player#resume >> Resume debounced for guild ${this.guildId} (last attempt ${now - this.lastResumeAttempt}ms ago).`);
|
|
618
851
|
return this;
|
|
619
852
|
}
|
|
620
853
|
this.updateActivity();
|
|
621
854
|
if (!this.paused) {
|
|
622
|
-
this.manager.emit("debug", `
|
|
855
|
+
this.manager.emit("debug", `NyxLink > Player#resume >> Player is not paused for guild ${this.guildId}`);
|
|
623
856
|
return this;
|
|
624
857
|
}
|
|
625
858
|
this.isResumeInProgress = true;
|
|
626
859
|
this.lastResumeAttempt = now;
|
|
627
|
-
this.manager.emit("debug", `
|
|
860
|
+
this.manager.emit("debug", `NyxLink > Player#resume -> Sending resume request to node ${this.node.identifier} for guild ${this.guildId}`);
|
|
628
861
|
this.manager.emit("playerTriggeredResume", this);
|
|
629
862
|
try {
|
|
630
863
|
await this.sendPlayerUpdate({ paused: false });
|
|
631
864
|
const oldPaused = this.paused;
|
|
632
865
|
this.paused = false;
|
|
633
866
|
this.updateData("paused", this.paused);
|
|
634
|
-
this.manager.emit("debug", `
|
|
635
|
-
this.manager.emit("debug", `
|
|
867
|
+
this.manager.emit("debug", `NyxLink > Player#resume >> Player state changed: paused: ${oldPaused} -> ${this.paused}`);
|
|
868
|
+
this.manager.emit("debug", `NyxLink > Player#resume >> Player resumed for guild ${this.guildId}`);
|
|
636
869
|
}
|
|
637
870
|
finally {
|
|
638
871
|
this.isResumeInProgress = false;
|
|
@@ -642,13 +875,13 @@ class Player {
|
|
|
642
875
|
async forward(ms) {
|
|
643
876
|
if (!this.current)
|
|
644
877
|
return this;
|
|
645
|
-
const newPosition = Math.min(this.current.
|
|
878
|
+
const newPosition = Math.min(this.current.getInfo().length, this.current.getInfo().position + ms);
|
|
646
879
|
return this.seek(newPosition);
|
|
647
880
|
}
|
|
648
881
|
async rewind(ms) {
|
|
649
882
|
if (!this.current)
|
|
650
883
|
return this;
|
|
651
|
-
const newPosition = Math.max(0, this.current.position - ms);
|
|
884
|
+
const newPosition = Math.max(0, this.current.getInfo().position - ms);
|
|
652
885
|
return this.seek(newPosition);
|
|
653
886
|
}
|
|
654
887
|
async setVoiceState(state) {
|
|
@@ -677,79 +910,139 @@ class Player {
|
|
|
677
910
|
}
|
|
678
911
|
async stop() {
|
|
679
912
|
(0, PlaybackGuard_1.playbackGuard)(this).invalidate();
|
|
680
|
-
return this.commands.enqueue(() => this.stopPlayback());
|
|
913
|
+
return this.commands.enqueue(() => (0, OpenTelemetry_1.observeOperation)(this.manager, 'nyxlink.player.stop', () => this.stopPlayback()));
|
|
681
914
|
}
|
|
682
915
|
async stopPlayback() {
|
|
683
916
|
if (this.destroyed)
|
|
684
917
|
return this;
|
|
685
|
-
this.manager.emit("debug", `
|
|
918
|
+
this.manager.emit("debug", `NyxLink > Player#stop -> Sending stop request to node ${this.node.identifier} for guild ${this.guildId}`);
|
|
686
919
|
this.manager.emit("playerTriggeredStop", this);
|
|
687
|
-
await this.sendPlayerUpdate({
|
|
920
|
+
await this.sendPlayerUpdate({
|
|
921
|
+
track: { encoded: null },
|
|
922
|
+
...(this.node.isNodeLink && this.nextTrack ? { nextTrack: null } : {})
|
|
923
|
+
});
|
|
688
924
|
const oldPlaying = this.playing;
|
|
689
|
-
|
|
690
|
-
this.updateData("playing", this.playing);
|
|
691
|
-
this.manager.emit("debug", `Moonlink.js > Player#stop >> Player state changed: playing: ${oldPlaying} -> ${this.playing}`);
|
|
925
|
+
const oldPaused = this.paused;
|
|
692
926
|
const oldTrackTitle = this.current?.title ?? "null";
|
|
927
|
+
this.playing = false;
|
|
928
|
+
this.paused = false;
|
|
693
929
|
this.current = null;
|
|
694
|
-
this.updateData("
|
|
695
|
-
this.
|
|
696
|
-
this.
|
|
930
|
+
await this.updateData("playing", false);
|
|
931
|
+
await this.updateData("paused", false);
|
|
932
|
+
await this.updateData("current", null);
|
|
933
|
+
this.manager.emit("debug", `NyxLink > Player#stop >> State changed: playing: ${oldPlaying} -> ${this.playing}, paused: ${oldPaused} -> ${this.paused}`);
|
|
934
|
+
this.manager.emit("debug", `NyxLink > Player#stop >> Player state changed: current: ${oldTrackTitle} -> null`);
|
|
935
|
+
this.manager.emit("debug", `NyxLink > Player#stop >> Player stopped for guild ${this.guildId}`);
|
|
697
936
|
this.manager.emit("playerStop", this);
|
|
698
937
|
return this;
|
|
699
938
|
}
|
|
700
939
|
async skip(position) {
|
|
701
940
|
const oldTrack = this.current;
|
|
702
941
|
if (position !== undefined) {
|
|
703
|
-
|
|
704
|
-
const track = this.queue.remove(position);
|
|
705
|
-
if (!track) {
|
|
706
|
-
this.manager.emit("debug", `Moonlink.js > Player#skip >> Invalid queue position for guild ${this.guildId}`);
|
|
942
|
+
if (!Number.isInteger(position) || position < 0 || !this.queue.get(position))
|
|
707
943
|
return false;
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
return
|
|
944
|
+
const guard = (0, PlaybackGuard_1.playbackGuard)(this);
|
|
945
|
+
const ticket = guard.invalidate();
|
|
946
|
+
return this.commands.enqueue(async () => {
|
|
947
|
+
try {
|
|
948
|
+
if (this.destroyed || !guard.isCurrent(ticket))
|
|
949
|
+
return false;
|
|
950
|
+
const track = this.queue.get(position);
|
|
951
|
+
if (!track)
|
|
952
|
+
return false;
|
|
953
|
+
this.manager.emit("playerTriggeredSkip", this, this.current, track, position);
|
|
954
|
+
if (this.destroyed || !guard.isCurrent(ticket) || this.queue.get(position) !== track)
|
|
955
|
+
return false;
|
|
956
|
+
let playbackTrack;
|
|
957
|
+
try {
|
|
958
|
+
playbackTrack = track instanceof Track_1.Track ? track :
|
|
959
|
+
new Track_1.Track(track, undefined, undefined, this.manager.options.trackPartial ?? []);
|
|
960
|
+
}
|
|
961
|
+
catch (error) {
|
|
962
|
+
this.manager.emit("debug", `NyxLink > Player#skip >> Invalid queued track: ${error instanceof Error ? error.name : "unknown"}`);
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
const selected = this.queue.remove(position);
|
|
966
|
+
if (!selected)
|
|
967
|
+
return false;
|
|
968
|
+
const originalPosition = playbackTrack.position;
|
|
969
|
+
let injectedTrackQueued = false;
|
|
970
|
+
let played = false;
|
|
971
|
+
try {
|
|
972
|
+
played = await this.playNext({ track: playbackTrack }, ticket, () => true, queued => { injectedTrackQueued = queued; });
|
|
973
|
+
return played;
|
|
974
|
+
}
|
|
975
|
+
finally {
|
|
976
|
+
if (!played) {
|
|
977
|
+
playbackTrack.position = originalPosition;
|
|
978
|
+
if (injectedTrackQueued) {
|
|
979
|
+
const injectedIndex = this.queue.tracks.indexOf(playbackTrack);
|
|
980
|
+
if (injectedIndex >= 0)
|
|
981
|
+
this.queue.remove(injectedIndex);
|
|
982
|
+
}
|
|
983
|
+
if (!this.destroyed && !this.manager.destroyed) {
|
|
984
|
+
this.queue.insert(Math.min(position, this.queue.size), selected);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
finally {
|
|
990
|
+
(0, PlaybackAttempt_1.playbackAttempt)(this).retain(ticket);
|
|
991
|
+
}
|
|
992
|
+
});
|
|
711
993
|
}
|
|
712
994
|
if (!this.queue.size) {
|
|
713
995
|
if (this.autoPlay) {
|
|
714
996
|
if (!this.current) {
|
|
715
|
-
this.manager.emit("debug", `
|
|
997
|
+
this.manager.emit("debug", `NyxLink > Player#skip >> Queue is empty and no current track, cannot trigger autoPlay for guild ${this.guildId}`);
|
|
716
998
|
return false;
|
|
717
999
|
}
|
|
718
|
-
this.manager.emit("debug", `
|
|
1000
|
+
this.manager.emit("debug", `NyxLink > Player#skip >> Queue empty, triggering autoPlay for guild ${this.guildId}`);
|
|
719
1001
|
return await this.node.handleAutoPlay(this, this.current);
|
|
720
1002
|
}
|
|
721
|
-
this.manager.emit("debug", `
|
|
1003
|
+
this.manager.emit("debug", `NyxLink > Player#skip >> Queue is empty, stopping player for guild ${this.guildId}`);
|
|
722
1004
|
await this.stop();
|
|
723
1005
|
return true;
|
|
724
1006
|
}
|
|
725
1007
|
const nextTrack = this.queue.first;
|
|
1008
|
+
if (!nextTrack)
|
|
1009
|
+
return false;
|
|
726
1010
|
this.manager.emit("playerTriggeredSkip", this, oldTrack, nextTrack, 0);
|
|
727
|
-
this.manager.emit("debug", `
|
|
1011
|
+
this.manager.emit("debug", `NyxLink > Player#skip -> Skipping to next track in queue for guild ${this.guildId}`);
|
|
728
1012
|
return await this.play();
|
|
729
1013
|
}
|
|
730
1014
|
async seek(position) {
|
|
731
|
-
|
|
1015
|
+
const ticket = (0, PlaybackGuard_1.playbackGuard)(this).ticket;
|
|
1016
|
+
const track = this.current;
|
|
1017
|
+
const afterPendingPlay = this.pendingPlayTicket === ticket;
|
|
1018
|
+
return this.commands.enqueue(() => (0, OpenTelemetry_1.observeOperation)(this.manager, 'nyxlink.player.seek', () => this.seekPlayback(position, ticket, track, afterPendingPlay)));
|
|
732
1019
|
}
|
|
733
|
-
async seekPlayback(position) {
|
|
1020
|
+
async seekPlayback(position, ticket, track, afterPendingPlay) {
|
|
734
1021
|
if (this.destroyed)
|
|
735
1022
|
return this;
|
|
736
|
-
(0, Util_1.validate)(position, (v) => typeof v === "number" &&
|
|
737
|
-
|
|
1023
|
+
(0, Util_1.validate)(position, (v) => typeof v === "number" && Number.isFinite(v) && v >= 0, "Player#seek > Position must be a valid number.");
|
|
1024
|
+
const guard = (0, PlaybackGuard_1.playbackGuard)(this);
|
|
1025
|
+
if (!guard.isCurrent(ticket) ||
|
|
1026
|
+
(afterPendingPlay && this.lastSuccessfulExplicitPlayTicket !== ticket) ||
|
|
1027
|
+
(!afterPendingPlay && track !== null && this.current !== track))
|
|
1028
|
+
return this;
|
|
1029
|
+
const activeTrack = this.current;
|
|
1030
|
+
this.manager.emit("debug", `NyxLink > Player#seek -> Seeking to position ${position}ms for guild ${this.guildId}`);
|
|
738
1031
|
this.manager.emit("playerTriggeredSeek", this, position);
|
|
739
1032
|
await this.sendPlayerUpdate({ position });
|
|
740
|
-
if (this.current) {
|
|
741
|
-
|
|
1033
|
+
if (guard.isCurrent(ticket) && !this.destroyed && this.current === activeTrack && activeTrack) {
|
|
1034
|
+
activeTrack.position = position;
|
|
742
1035
|
}
|
|
743
|
-
this.manager.emit("debug", `
|
|
1036
|
+
this.manager.emit("debug", `NyxLink > Player#seek >> Sent seek request to node ${this.node.identifier}`);
|
|
744
1037
|
return this;
|
|
745
1038
|
}
|
|
746
1039
|
setVolume(volume) {
|
|
747
|
-
(0, Util_1.validate)(volume, (v) => typeof v === "number" &&
|
|
1040
|
+
(0, Util_1.validate)(volume, (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1000, "Player#setVolume > Volume must be between 0 and 1000.");
|
|
748
1041
|
this.optimisticVolumeRevision = ++this.volumeRevision;
|
|
749
1042
|
const oldVolume = this.volume;
|
|
750
1043
|
this.volume = volume;
|
|
751
1044
|
this.manager.emit("playerChangedVolume", this, oldVolume, volume);
|
|
752
|
-
this.manager.emit("debug", `
|
|
1045
|
+
this.manager.emit("debug", `NyxLink > Player#setVolume -> Changing volume from ${oldVolume} to ${volume} for guild ${this.guildId}`);
|
|
753
1046
|
void this.commands.enqueue(async () => {
|
|
754
1047
|
if (this.destroyed)
|
|
755
1048
|
return;
|
|
@@ -759,7 +1052,7 @@ class Player {
|
|
|
759
1052
|
this.manager.emit("debug", `NyxLink > Player#setVolume >> Volume update failed for guild ${this.guildId}: ${error.message}`);
|
|
760
1053
|
});
|
|
761
1054
|
this.updateData("volume", this.volume);
|
|
762
|
-
this.manager.emit("debug", `
|
|
1055
|
+
this.manager.emit("debug", `NyxLink > Player#setVolume >> Volume updated for guild ${this.guildId}`);
|
|
763
1056
|
return this;
|
|
764
1057
|
}
|
|
765
1058
|
async setVolumeAsync(volume) {
|
|
@@ -768,7 +1061,21 @@ class Player {
|
|
|
768
1061
|
return this.commands.enqueue(async () => {
|
|
769
1062
|
if (this.destroyed)
|
|
770
1063
|
throw new Error("Cannot update volume on a destroyed player");
|
|
771
|
-
|
|
1064
|
+
const node = this.node, session = node.sessionId, socket = node.socket, backend = node.backend;
|
|
1065
|
+
const active = () => !this.destroyed && !this.manager.destroyed && !node.destroyed && node.connected &&
|
|
1066
|
+
this.node === node && node.sessionId === session && node.socket === socket && node.backend === backend;
|
|
1067
|
+
if (!active())
|
|
1068
|
+
throw new PlayerOperationCancelledError_1.PlayerOperationCancelledError('volume');
|
|
1069
|
+
try {
|
|
1070
|
+
await this.sendPlayerUpdate({ volume });
|
|
1071
|
+
}
|
|
1072
|
+
catch (error) {
|
|
1073
|
+
if (!active())
|
|
1074
|
+
throw new PlayerOperationCancelledError_1.PlayerOperationCancelledError('volume');
|
|
1075
|
+
throw error;
|
|
1076
|
+
}
|
|
1077
|
+
if (!active())
|
|
1078
|
+
throw new PlayerOperationCancelledError_1.PlayerOperationCancelledError('volume');
|
|
772
1079
|
if (this.optimisticVolumeRevision > revision)
|
|
773
1080
|
return this;
|
|
774
1081
|
const oldVolume = this.volume;
|
|
@@ -786,7 +1093,7 @@ class Player {
|
|
|
786
1093
|
this.manager.emit("playerChangedLoop", this, oldLoop, this.loop, oldLoopCount, this.loopCount);
|
|
787
1094
|
this.updateData("loop", this.loop);
|
|
788
1095
|
this.updateData("loopCount", this.loopCount);
|
|
789
|
-
this.manager.emit("debug", `
|
|
1096
|
+
this.manager.emit("debug", `NyxLink > Player#setLoop >> Loop mode changed from "${oldLoop}" to "${loop}"${count ? ` (count: ${count})` : ""} for guild ${this.guildId}`);
|
|
790
1097
|
return this;
|
|
791
1098
|
}
|
|
792
1099
|
setAutoPlay(autoPlay) {
|
|
@@ -795,26 +1102,26 @@ class Player {
|
|
|
795
1102
|
this.autoPlay = autoPlay;
|
|
796
1103
|
this.manager.emit("playerAutoPlaySet", this, autoPlay);
|
|
797
1104
|
this.updateData("autoPlay", this.autoPlay);
|
|
798
|
-
this.manager.emit("debug", `
|
|
1105
|
+
this.manager.emit("debug", `NyxLink > Player#setAutoPlay >> AutoPlay set to ${autoPlay} for guild ${this.guildId}`);
|
|
799
1106
|
return this;
|
|
800
1107
|
}
|
|
801
1108
|
setAutoLeave(autoLeave) {
|
|
802
1109
|
this.autoLeave = autoLeave;
|
|
803
1110
|
this.manager.emit("playerAutoLeaveSet", this, autoLeave);
|
|
804
1111
|
this.updateData("autoLeave", this.autoLeave);
|
|
805
|
-
this.manager.emit("debug", `
|
|
1112
|
+
this.manager.emit("debug", `NyxLink > Player#setAutoLeave >> AutoLeave set to ${autoLeave} for guild ${this.guildId}`);
|
|
806
1113
|
return this;
|
|
807
1114
|
}
|
|
808
1115
|
shuffle() {
|
|
809
1116
|
if (this.queue.size < 2) {
|
|
810
|
-
this.manager.emit("debug", `
|
|
1117
|
+
this.manager.emit("debug", `NyxLink > Player#shuffle >> Queue has less than 2 tracks, cannot shuffle for guild ${this.guildId}`);
|
|
811
1118
|
return this;
|
|
812
1119
|
}
|
|
813
1120
|
const oldQueue = [...this.queue.tracks];
|
|
814
|
-
this.manager.emit("debug", `
|
|
1121
|
+
this.manager.emit("debug", `NyxLink > Player#shuffle -> Shuffling queue with ${this.queue.size} tracks for guild ${this.guildId}`);
|
|
815
1122
|
this.queue.shuffle();
|
|
816
1123
|
this.manager.emit("playerTriggeredShuffle", this, oldQueue, this.queue.tracks);
|
|
817
|
-
this.manager.emit("debug", `
|
|
1124
|
+
this.manager.emit("debug", `NyxLink > Player#shuffle >> Queue shuffled for guild ${this.guildId}`);
|
|
818
1125
|
return this;
|
|
819
1126
|
}
|
|
820
1127
|
async destroy(reason) {
|
|
@@ -825,8 +1132,15 @@ class Player {
|
|
|
825
1132
|
}
|
|
826
1133
|
(0, PlaybackGuard_1.playbackGuard)(this).invalidate();
|
|
827
1134
|
this.destroyed = true;
|
|
828
|
-
this.
|
|
829
|
-
this.
|
|
1135
|
+
this.node.cancelVoiceReconnect?.(this);
|
|
1136
|
+
const leased = this.manager.guildOwnership?.localLease(this.guildId);
|
|
1137
|
+
this.destructionPromise = this.commands.enqueue(() => this.destroyPlayback(reason))
|
|
1138
|
+
.finally(async () => {
|
|
1139
|
+
if (leased)
|
|
1140
|
+
await this.manager.guildOwnership?.release(this.guildId, leased);
|
|
1141
|
+
});
|
|
1142
|
+
if (!this.manager.guildOwnership)
|
|
1143
|
+
this.voice.destroy();
|
|
830
1144
|
this.stopHealthCheck();
|
|
831
1145
|
return this.destructionPromise;
|
|
832
1146
|
}
|
|
@@ -837,49 +1151,62 @@ class Player {
|
|
|
837
1151
|
}
|
|
838
1152
|
if (!reason) {
|
|
839
1153
|
const stack = new Error().stack?.split("\n").slice(2, 8).join("\n");
|
|
840
|
-
this.manager.emit("debug", `
|
|
1154
|
+
this.manager.emit("debug", `NyxLink > Player#destroy >> Destroy called without reason for guild ${this.guildId}. Stack: ${stack || "unavailable"}`);
|
|
841
1155
|
}
|
|
842
1156
|
const destroyReason = reason ?? "No reason provided";
|
|
843
|
-
this.manager.emit("debug", `
|
|
1157
|
+
this.manager.emit("debug", `NyxLink > Player#destroy -> Destroying player for guild ${this.guildId}. Reason: ${destroyReason}`);
|
|
844
1158
|
this.playing = false;
|
|
845
1159
|
this.paused = false;
|
|
846
|
-
|
|
847
|
-
await this.
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1160
|
+
const owner = !this.manager.guildOwnership ||
|
|
1161
|
+
await this.manager.guildOwnership.isCurrent(this.guildId);
|
|
1162
|
+
if (owner)
|
|
1163
|
+
try {
|
|
1164
|
+
await this.disconnect();
|
|
1165
|
+
}
|
|
1166
|
+
catch (e) {
|
|
1167
|
+
this.manager.emit("debug", `NyxLink > Player#destroy >> Voice disconnection failed for guild ${this.guildId}: ${e.message}`);
|
|
1168
|
+
}
|
|
1169
|
+
if (owner)
|
|
1170
|
+
try {
|
|
1171
|
+
await this.node.rest.destroyPlayer(this.guildId);
|
|
1172
|
+
}
|
|
1173
|
+
catch (e) {
|
|
1174
|
+
this.manager.emit("debug", `NyxLink > Player#destroy >> Failed to destroy player on node: ${e.message}`);
|
|
1175
|
+
}
|
|
858
1176
|
this.current = null;
|
|
859
1177
|
this.queue.clear();
|
|
860
1178
|
this.previous = [];
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1179
|
+
if (owner)
|
|
1180
|
+
this.updateData("previous", []);
|
|
1181
|
+
if (this.manager.players.get(this.guildId) === this) {
|
|
1182
|
+
this.manager.players.players.delete(this.guildId);
|
|
1183
|
+
}
|
|
1184
|
+
if (owner && (!this.manager.guildOwnership ||
|
|
1185
|
+
await this.manager.guildOwnership.isCurrent(this.guildId))) {
|
|
1186
|
+
await this.manager.database.remove(`players.${this.guildId}`);
|
|
1187
|
+
}
|
|
864
1188
|
this.manager.emit('playerDestroyed', this, reason);
|
|
865
|
-
this.manager.emit("debug", `
|
|
1189
|
+
this.manager.emit("debug", `NyxLink > Player#destroy >> Player destroyed for guild ${this.guildId}.`);
|
|
866
1190
|
}
|
|
867
1191
|
async restart(options = {}) {
|
|
868
1192
|
const guard = (0, PlaybackGuard_1.playbackGuard)(this);
|
|
869
1193
|
const ticket = guard.ticket;
|
|
1194
|
+
const run = (operation) => options[PlayerMigration_1.migrationRestart] ? operation() : this.commands.enqueue(operation);
|
|
870
1195
|
if (this.destroyed)
|
|
871
1196
|
return false;
|
|
872
|
-
this.manager.emit("debug", `
|
|
1197
|
+
this.manager.emit("debug", `NyxLink > Player#restart -> Restarting player for guild ${this.guildId}`);
|
|
873
1198
|
this.manager.emit("playerResuming", this);
|
|
1199
|
+
if (this.destroyed || !guard.isCurrent(ticket))
|
|
1200
|
+
return false;
|
|
874
1201
|
if (!this.voiceChannelId) {
|
|
875
|
-
this.manager.emit("debug", `
|
|
1202
|
+
this.manager.emit("debug", `NyxLink > Player#restart >> Cannot restart player without a voiceChannelId for guild ${this.guildId}`);
|
|
876
1203
|
return false;
|
|
877
1204
|
}
|
|
878
1205
|
try {
|
|
879
1206
|
await this.connect();
|
|
880
1207
|
}
|
|
881
1208
|
catch (error) {
|
|
882
|
-
this.manager.emit("debug", `
|
|
1209
|
+
this.manager.emit("debug", `NyxLink > Player#restart >> Voice connection failed for guild ${this.guildId}. Error: ${error.message}`);
|
|
883
1210
|
if (this.destroyed || !guard.isCurrent(ticket))
|
|
884
1211
|
return false;
|
|
885
1212
|
if (options.destroyOnFailure !== false)
|
|
@@ -893,34 +1220,31 @@ class Player {
|
|
|
893
1220
|
const lastState = this.get("lastState");
|
|
894
1221
|
const currentLavalinkPos = lastState?.position ?? 0;
|
|
895
1222
|
const isResumedSync = this.node.resumed && this.playing && currentLavalinkPos > 0;
|
|
896
|
-
const isAlreadySync = isResumedSync || (lastState?.connected && Math.abs(currentLavalinkPos - (this.current.position ?? 0)) < 2000);
|
|
1223
|
+
const isAlreadySync = !options[PlayerMigration_1.migrationRestart] && (isResumedSync || (lastState?.connected && Math.abs(currentLavalinkPos - (this.current.position ?? 0)) < 2000));
|
|
897
1224
|
if (isAlreadySync && this.playing) {
|
|
898
|
-
this.manager.emit("debug", `
|
|
1225
|
+
this.manager.emit("debug", `NyxLink > Player#restart >> Player already in sync for guild ${this.guildId}, skipping track restoration. (Resumed: ${this.node.resumed}, Sync: ${isAlreadySync})`);
|
|
899
1226
|
this.manager.emit("playerResumed", this);
|
|
900
1227
|
return true;
|
|
901
1228
|
}
|
|
902
|
-
const
|
|
903
|
-
|
|
1229
|
+
const observed = this.current.position ?? 0;
|
|
1230
|
+
const resumePosition = options[PlayerMigration_1.migrationRestart] ? observed : Math.max(Number.isFinite(lastKnownPosition) ? lastKnownPosition : 0, Number.isFinite(currentLavalinkPos) ? currentLavalinkPos : 0, observed);
|
|
1231
|
+
this.manager.emit("debug", `NyxLink > Player#restart -> Restoring current track "${this.current.title}" for guild ${this.guildId} at ${resumePosition}ms. AlreadySync: ${isAlreadySync}`);
|
|
904
1232
|
const payload = {
|
|
905
1233
|
track: { encoded: this.current.encoded, userData: this.current.userData },
|
|
906
1234
|
volume: this.volume,
|
|
907
1235
|
playing: this.playing,
|
|
908
|
-
paused: this.paused
|
|
1236
|
+
paused: this.paused,
|
|
1237
|
+
filters: this.filters.toPayload({ compatibleOnly: true, suspended: options.suspendedFeatures })
|
|
909
1238
|
};
|
|
910
|
-
if (resumePosition > 0 && this.current.isSeekable && !isAlreadySync) {
|
|
1239
|
+
if (resumePosition > 0 && this.current.getInfo().isSeekable && !isAlreadySync) {
|
|
911
1240
|
payload.position = resumePosition;
|
|
912
1241
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
payload.nextTrack = this.nextTrack;
|
|
920
|
-
if (this.loudnessNormalizer !== undefined) {
|
|
921
|
-
payload.loudnessNormalizer = this.loudnessNormalizer;
|
|
922
|
-
}
|
|
923
|
-
const restored = await this.commands.enqueue(async () => {
|
|
1242
|
+
(0, AdvancedAudioRecovery_1.projectAdvancedAudio)(payload, this.node, {
|
|
1243
|
+
audioTrackId: this.audioTrackId, fading: this.fading, crossfade: this.crossfade,
|
|
1244
|
+
loudnessNormalizer: this.loudnessNormalizer,
|
|
1245
|
+
nextTrack: options[PlayerMigration_1.migrationRestart] ? undefined : this.queuePreload ? null : this.nextTrack
|
|
1246
|
+
}, options.suspendedFeatures);
|
|
1247
|
+
const restored = await run(async () => {
|
|
924
1248
|
if (this.destroyed || !guard.isCurrent(ticket))
|
|
925
1249
|
return false;
|
|
926
1250
|
if (!await this.restoreVoiceForRestart(ticket))
|
|
@@ -932,8 +1256,8 @@ class Player {
|
|
|
932
1256
|
return false;
|
|
933
1257
|
}
|
|
934
1258
|
else if (this.queue.size > 0 && options.startQueued !== false) {
|
|
935
|
-
this.manager.emit("debug", `
|
|
936
|
-
if (!await
|
|
1259
|
+
this.manager.emit("debug", `NyxLink > Player#restart -> No current track, playing first from queue for guild ${this.guildId}`);
|
|
1260
|
+
if (!await run(async () => {
|
|
937
1261
|
if (!await this.restoreVoiceForRestart(ticket))
|
|
938
1262
|
return false;
|
|
939
1263
|
return this.playNext({}, ticket);
|
|
@@ -941,10 +1265,22 @@ class Player {
|
|
|
941
1265
|
return false;
|
|
942
1266
|
}
|
|
943
1267
|
else {
|
|
944
|
-
|
|
1268
|
+
if (options[PlayerMigration_1.migrationRestart]) {
|
|
1269
|
+
if (!await this.restoreVoiceForRestart(ticket))
|
|
1270
|
+
return false;
|
|
1271
|
+
const payload = { filters: this.filters.toPayload({ compatibleOnly: true, suspended: options.suspendedFeatures }), volume: this.volume, paused: this.paused };
|
|
1272
|
+
(0, AdvancedAudioRecovery_1.projectAdvancedAudio)(payload, this.node, {
|
|
1273
|
+
fading: this.fading, crossfade: this.crossfade, loudnessNormalizer: this.loudnessNormalizer
|
|
1274
|
+
}, options.suspendedFeatures);
|
|
1275
|
+
await this.sendPlayerUpdate(payload);
|
|
1276
|
+
if (this.destroyed || !guard.isCurrent(ticket))
|
|
1277
|
+
return false;
|
|
1278
|
+
}
|
|
1279
|
+
this.manager.emit("debug", `NyxLink > Player#restart >> No track to restore and queue is empty for guild ${this.guildId}`);
|
|
945
1280
|
return true;
|
|
946
1281
|
}
|
|
947
|
-
|
|
1282
|
+
if (!options[PlayerMigration_1.migrationRestart])
|
|
1283
|
+
this.manager.emit("playerResumed", this);
|
|
948
1284
|
return true;
|
|
949
1285
|
}
|
|
950
1286
|
async restoreVoiceForRestart(ticket) {
|
|
@@ -958,125 +1294,116 @@ class Player {
|
|
|
958
1294
|
}
|
|
959
1295
|
async transferNode(node) {
|
|
960
1296
|
const targetNode = typeof node === "string" ? this.manager.nodes.nodes.get(node) : node;
|
|
961
|
-
if (this.destroyed || !targetNode || !targetNode.
|
|
1297
|
+
if (this.destroyed || !targetNode || targetNode.manager !== this.manager || !NodeSelector_1.NodeSelector.matches(targetNode, this.nodeSelection) || targetNode.identifier === this.node.identifier)
|
|
962
1298
|
return false;
|
|
963
|
-
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
const report = (status, reason) => {
|
|
967
|
-
this.manager.emit("playerNodeFailover", this, {
|
|
968
|
-
source: oldNode.identifier, target: targetNode.identifier, status,
|
|
969
|
-
positionMs: this.current?.position, reason
|
|
970
|
-
});
|
|
971
|
-
};
|
|
972
|
-
report('in-progress');
|
|
973
|
-
try {
|
|
974
|
-
const moved = await this.commands.enqueue(async () => {
|
|
975
|
-
if (this.destroyed || !guard.isCurrent(ticket) || !targetNode.connected)
|
|
976
|
-
return false;
|
|
977
|
-
const resolved = this.current ? await TrackResolver_1.TrackResolver.resolve(this.current, targetNode, oldNode) : null;
|
|
978
|
-
if (this.destroyed || !guard.isCurrent(ticket) || !targetNode.connected)
|
|
979
|
-
return false;
|
|
980
|
-
try {
|
|
981
|
-
await oldNode.rest.destroyPlayer(this.guildId);
|
|
982
|
-
}
|
|
983
|
-
catch (error) {
|
|
984
|
-
this.manager.emit("debug", `NyxLink > Player#transferNode >> Old node cleanup failed: ${error.message}`);
|
|
985
|
-
}
|
|
986
|
-
if (this.destroyed || !guard.isCurrent(ticket))
|
|
987
|
-
return false;
|
|
988
|
-
for (const track of [...this.queue.tracks, ...this.previous]) {
|
|
989
|
-
track.backend ??= oldNode.backend?.kind;
|
|
990
|
-
}
|
|
991
|
-
this.updateData('queue', this.queue.tracks.map(track => TrackCodec_1.TrackCodec.serialize(track)));
|
|
992
|
-
this.updateData('previous', this.previous.map(track => TrackCodec_1.TrackCodec.serialize(track)));
|
|
993
|
-
this.node = targetNode;
|
|
994
|
-
if (resolved) {
|
|
995
|
-
this.current = resolved;
|
|
996
|
-
this.updateData('current', TrackCodec_1.TrackCodec.serialize(resolved));
|
|
997
|
-
}
|
|
998
|
-
this.set("lastState", undefined);
|
|
999
|
-
return true;
|
|
1000
|
-
});
|
|
1001
|
-
if (!moved || !await this.restart({ destroyOnFailure: false, startQueued: false }) || this.destroyed || !guard.isCurrent(ticket)) {
|
|
1002
|
-
report(guard.isCurrent(ticket) ? 'failed' : 'cancelled');
|
|
1003
|
-
return false;
|
|
1004
|
-
}
|
|
1005
|
-
this.manager.emit("playerSwitchedNode", this, oldNode, targetNode);
|
|
1006
|
-
report('recovered');
|
|
1007
|
-
return true;
|
|
1008
|
-
}
|
|
1009
|
-
catch (error) {
|
|
1010
|
-
report(guard.isCurrent(ticket) ? 'failed' : 'cancelled', error.message);
|
|
1011
|
-
return false;
|
|
1012
|
-
}
|
|
1299
|
+
this.node.cancelVoiceReconnect?.(this);
|
|
1300
|
+
const ticket = (0, PlaybackGuard_1.playbackGuard)(this).invalidate();
|
|
1301
|
+
return this.commands.enqueue(() => (0, PlayerMigration_1.migratePlayer)(this, targetNode, ticket));
|
|
1013
1302
|
}
|
|
1014
1303
|
setVoiceChannelId(voiceChannelId) {
|
|
1015
1304
|
(0, Util_1.validate)(voiceChannelId, (v) => typeof v === "string" && v.length > 0, "Player#setVoiceChannelId > Voice channel ID must be a non-empty string.");
|
|
1016
1305
|
if (this.voiceChannelId === voiceChannelId) {
|
|
1017
|
-
this.manager.emit("debug", `
|
|
1306
|
+
this.manager.emit("debug", `NyxLink > Player#setVoiceChannelId >> Voice channel already set to ${voiceChannelId} for guild ${this.guildId}`);
|
|
1018
1307
|
return this;
|
|
1019
1308
|
}
|
|
1309
|
+
this.node.cancelVoiceReconnect?.(this);
|
|
1020
1310
|
const oldChannel = this.voiceChannelId;
|
|
1021
1311
|
this.voiceChannelId = voiceChannelId;
|
|
1022
1312
|
this.updateData("voiceChannelId", this.voiceChannelId);
|
|
1023
|
-
this.manager.emit("debug", `
|
|
1313
|
+
this.manager.emit("debug", `NyxLink > Player#setVoiceChannel >> Voice channel changed from ${oldChannel} to ${voiceChannelId} for guild ${this.guildId}`);
|
|
1024
1314
|
this.manager.emit("playerVoiceChannelIdSet", this, oldChannel, voiceChannelId);
|
|
1025
1315
|
return this;
|
|
1026
1316
|
}
|
|
1027
1317
|
setTextChannelId(textChannelId) {
|
|
1028
1318
|
(0, Util_1.validate)(textChannelId, (v) => typeof v === "string" && v.length > 0, "Player#setTextChannelId > Text channel ID must be a non-empty string.");
|
|
1029
1319
|
if (this.textChannelId === textChannelId) {
|
|
1030
|
-
this.manager.emit("debug", `
|
|
1320
|
+
this.manager.emit("debug", `NyxLink > Player#setTextChannelId >> Text channel already set to ${textChannelId} for guild ${this.guildId}`);
|
|
1031
1321
|
return this;
|
|
1032
1322
|
}
|
|
1033
1323
|
const oldChannel = this.textChannelId;
|
|
1034
1324
|
this.textChannelId = textChannelId;
|
|
1035
1325
|
this.updateData("textChannelId", this.textChannelId);
|
|
1036
|
-
this.manager.emit("debug", `
|
|
1326
|
+
this.manager.emit("debug", `NyxLink > Player#setTextChannel >> Text channel changed from ${oldChannel} to ${textChannelId} for guild ${this.guildId}`);
|
|
1037
1327
|
this.manager.emit("playerTextChannelIdSet", this, oldChannel, textChannelId);
|
|
1038
1328
|
return this;
|
|
1039
1329
|
}
|
|
1040
1330
|
async replay() {
|
|
1041
|
-
if (!this.current?.encoded)
|
|
1042
|
-
this.manager.emit("debug", `Moonlink.js > Player#replay >> No current track to replay for guild ${this.guildId}`);
|
|
1331
|
+
if (!this.current?.encoded || this.destroyed)
|
|
1043
1332
|
return false;
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1333
|
+
const guard = (0, PlaybackGuard_1.playbackGuard)(this);
|
|
1334
|
+
const ticket = guard.invalidate();
|
|
1335
|
+
this.pendingPlayTicket = ticket;
|
|
1336
|
+
return this.commands.enqueue(async () => {
|
|
1337
|
+
if (this.destroyed || !guard.isCurrent(ticket))
|
|
1338
|
+
return false;
|
|
1339
|
+
const original = this.current;
|
|
1340
|
+
if (!original?.encoded)
|
|
1341
|
+
return false;
|
|
1342
|
+
const copy = new Track_1.Track(original.toJSON(), original.requester, original.origin, this.manager.options.trackPartial ?? []);
|
|
1343
|
+
let injectedTrackQueued = false;
|
|
1344
|
+
try {
|
|
1345
|
+
const played = await this.playNext({ track: copy, position: 0 }, ticket, () => true, queued => { injectedTrackQueued = queued; }, true);
|
|
1346
|
+
if (played)
|
|
1347
|
+
this.lastSuccessfulExplicitPlayTicket = ticket;
|
|
1348
|
+
return played;
|
|
1349
|
+
}
|
|
1350
|
+
finally {
|
|
1351
|
+
if (injectedTrackQueued) {
|
|
1352
|
+
const index = this.queue.tracks.indexOf(copy);
|
|
1353
|
+
if (index >= 0)
|
|
1354
|
+
this.queue.remove(index);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
}).finally(() => {
|
|
1358
|
+
if (this.pendingPlayTicket === ticket)
|
|
1359
|
+
this.pendingPlayTicket = undefined;
|
|
1049
1360
|
});
|
|
1050
1361
|
}
|
|
1051
1362
|
async back() {
|
|
1052
|
-
if (this.previous.length === 0)
|
|
1053
|
-
this.manager.emit("debug", `Moonlink.js > Player#back >> No previous tracks available for guild ${this.guildId}`);
|
|
1054
|
-
return false;
|
|
1055
|
-
}
|
|
1056
|
-
const lastTrack = this.previous.pop();
|
|
1057
|
-
if (!lastTrack) {
|
|
1058
|
-
this.manager.emit("debug", `Moonlink.js > Player#back >> Popped an invalid track from history for guild ${this.guildId}`);
|
|
1363
|
+
if (this.destroyed || this.previous.length === 0)
|
|
1059
1364
|
return false;
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
this.
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
position
|
|
1365
|
+
const guard = (0, PlaybackGuard_1.playbackGuard)(this);
|
|
1366
|
+
const ticket = guard.invalidate();
|
|
1367
|
+
return this.commands.enqueue(async () => {
|
|
1368
|
+
if (this.destroyed || !guard.isCurrent(ticket))
|
|
1369
|
+
return false;
|
|
1370
|
+
const lastTrack = this.previous.at(-1);
|
|
1371
|
+
if (!lastTrack)
|
|
1372
|
+
return false;
|
|
1373
|
+
const outgoing = this.current;
|
|
1374
|
+
const priorBackFlag = this.get("isBackPlay") ?? false;
|
|
1375
|
+
const originalPreviousPosition = lastTrack.position;
|
|
1376
|
+
let injectedTrackQueued = false;
|
|
1377
|
+
let played = false;
|
|
1378
|
+
let committed = false;
|
|
1379
|
+
this.set("isBackPlay", true);
|
|
1380
|
+
try {
|
|
1381
|
+
played = await this.playNext({ track: lastTrack, position: 0 }, ticket, () => true, queued => { injectedTrackQueued = queued; });
|
|
1382
|
+
if (!played || !guard.isCurrent(ticket) || this.destroyed)
|
|
1383
|
+
return false;
|
|
1384
|
+
const index = this.previous.lastIndexOf(lastTrack);
|
|
1385
|
+
if (index >= 0) {
|
|
1386
|
+
this.previous.splice(index, 1);
|
|
1387
|
+
this.updateData("previous", this.previous.map(track => TrackCodec_1.TrackCodec.serialize(track)));
|
|
1388
|
+
}
|
|
1389
|
+
if (outgoing)
|
|
1390
|
+
this.queue.unshift(outgoing);
|
|
1391
|
+
committed = true;
|
|
1392
|
+
this.manager.emit("playerTriggeredBack", this, lastTrack);
|
|
1393
|
+
return true;
|
|
1394
|
+
}
|
|
1395
|
+
finally {
|
|
1396
|
+
if (injectedTrackQueued) {
|
|
1397
|
+
const index = this.queue.tracks.indexOf(lastTrack);
|
|
1398
|
+
if (index >= 0)
|
|
1399
|
+
this.queue.remove(index);
|
|
1400
|
+
}
|
|
1401
|
+
if (!committed) {
|
|
1402
|
+
lastTrack.position = originalPreviousPosition;
|
|
1403
|
+
this.set("isBackPlay", priorBackFlag);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1071
1406
|
});
|
|
1072
|
-
if (played) {
|
|
1073
|
-
this.manager.emit("playerTriggeredBack", this, lastTrack);
|
|
1074
|
-
this.manager.emit("debug", `Moonlink.js > Player#back >> Successfully went back for guild ${this.guildId}`);
|
|
1075
|
-
}
|
|
1076
|
-
else {
|
|
1077
|
-
this.manager.emit("debug", `Moonlink.js > Player#back >> Failed to play previous track for guild ${this.guildId}.`);
|
|
1078
|
-
}
|
|
1079
|
-
return played;
|
|
1080
1407
|
}
|
|
1081
1408
|
}
|
|
1082
1409
|
exports.Player = Player;
|