File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
src/main/kotlin/dev/arbjerg/lavalink Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import reactor.core.publisher.Sinks.Many
2525import reactor.kotlin.core.publisher.toMono
2626import java.io.Closeable
2727import java.io.IOException
28+ import java.time.Duration
2829import java.util.concurrent.ConcurrentHashMap
2930import java.util.concurrent.TimeUnit
3031import java.util.function.Consumer
@@ -234,6 +235,22 @@ class LavalinkNode(
234235 return rest.getNodeInfo()
235236 }
236237
238+ /* *
239+ * Enables resuming. This causes Lavalink to continue playing for a certain duration of time, during which
240+ * we can reconnect without losing our session data. */
241+ fun enableResuming (timeout : Duration ): Mono <Session > {
242+ return rest.patchSession(Session (resuming = true , timeout.seconds))
243+ }
244+
245+ /* *
246+ * Disables resuming, causing Lavalink to immediately drop all players upon this client disconnecting from it.
247+ *
248+ * This is the default behavior, reversing calls to [enableResuming].
249+ */
250+ fun disableResuming (): Mono <Session > {
251+ return rest.patchSession(Session (resuming = false , timeoutSeconds = 0 ))
252+ }
253+
237254 /* *
238255 * Send a custom request to the lavalink node. Any host and port you set will be replaced with the node host automatically.
239256 * The scheme must match your node's scheme, however.
Original file line number Diff line number Diff line change @@ -69,6 +69,13 @@ class LavalinkRestClient(val node: LavalinkNode) {
6969 }.toMono()
7070 }
7171
72+ fun patchSession (session : Session ): Mono <Session > {
73+ return newRequest {
74+ path(" /v4/sessions/${node.sessionId} " )
75+ patch(json.encodeToString(session).toRequestBody(" application/json" .toMediaType()))
76+ }.toMono()
77+ }
78+
7279 /* *
7380 * Make a request to the lavalink node. This is internal to keep it looking nice in kotlin. Java compatibility is in the node class.
7481 */
You can’t perform that action at this time.
0 commit comments