@@ -9,13 +9,15 @@ import dev.arbjerg.lavalink.internal.ReconnectTask
9
9
import dev.arbjerg.lavalink.protocol.v4.VoiceState
10
10
import reactor.core.Disposable
11
11
import reactor.core.publisher.Flux
12
+ import reactor.core.publisher.Mono
12
13
import reactor.core.publisher.Sinks
13
14
import java.io.Closeable
14
15
import java.time.Duration
15
16
import java.util.concurrent.ConcurrentHashMap
16
17
import java.util.concurrent.CopyOnWriteArrayList
17
18
import java.util.concurrent.Executors
18
19
import java.util.concurrent.TimeUnit
20
+ import kotlin.time.toJavaDuration
19
21
20
22
/* *
21
23
* @param userId ID of the bot for authenticating with Discord
@@ -169,6 +171,21 @@ class LavalinkClient(val userId: Long) : Closeable, Disposable {
169
171
return
170
172
}
171
173
174
+ val session = node.cachedSession
175
+ val canResume = session != null && session.resuming && session.timeoutSeconds > 0
176
+ if (canResume) {
177
+ node.resumeTimer = Mono .delay(Duration .ofSeconds(session!! .timeoutSeconds))
178
+ .subscribe() { transferNodes(node) }
179
+ } else {
180
+ transferNodes(node)
181
+ }
182
+ }
183
+
184
+ internal fun onNodeConnected (node : LavalinkNode ) {
185
+ node.resumeTimer?.dispose()
186
+ }
187
+
188
+ private fun transferNodes (node : LavalinkNode ) {
172
189
linkMap.forEach { (_, link) ->
173
190
if (link.node == node) {
174
191
val voiceRegion = link.cachedPlayer?.voiceRegion
0 commit comments