Skip to content

Commit

Permalink
Add some logging for links
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Sep 1, 2024
1 parent 2a7e651 commit 531ffb3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/kotlin/dev/arbjerg/lavalink/client/Link.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.arbjerg.lavalink.client
import dev.arbjerg.lavalink.client.player.LavalinkPlayer
import dev.arbjerg.lavalink.client.player.PlayerUpdateBuilder
import dev.arbjerg.lavalink.protocol.v4.VoiceState
import org.slf4j.LoggerFactory
import java.time.Duration
import java.util.function.Consumer

Expand All @@ -15,6 +16,8 @@ class Link(
val guildId: Long,
node: LavalinkNode
) {
private var logger = LoggerFactory.getLogger(Link::class.java)

var node = node
private set

Expand Down Expand Up @@ -58,11 +61,15 @@ class Link(
val player = node.getCachedPlayer(guildId)

if (player != null) {
node.removeCachedPlayer(guildId)
newNode.createOrUpdatePlayer(guildId)
.applyBuilder(player.stateToBuilder())
.delaySubscription(delay)
.subscribe()
.subscribe({
node.removeCachedPlayer(guildId)
}) {
state = LinkState.DISCONNECTED
logger.error("Failed to transfer player to new node: ${newNode.name}", it)
}
}

node = newNode
Expand All @@ -73,7 +80,10 @@ class Link(
state = LinkState.CONNECTING
node.createOrUpdatePlayer(guildId)
.setVoiceState(newVoiceState)
.subscribe()
.subscribe(null) {
state = LinkState.DISCONNECTED
logger.error("Failed to update voice state to $newVoiceState", it)
}
}
}

Expand Down

0 comments on commit 531ffb3

Please sign in to comment.