Skip to content

Commit e98de0e

Browse files
committed
Add option to set session ID on connection
1 parent ba381d7 commit e98de0e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkNode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LavalinkNode(
4444
val regionFilter = nodeOptions.regionFilter
4545
val password = nodeOptions.password
4646

47-
var sessionId: String? = null
47+
var sessionId: String? = nodeOptions.sessionId
4848
internal set
4949

5050
internal val httpClient = OkHttpClient.Builder().callTimeout(nodeOptions.httpTimeout, TimeUnit.MILLISECONDS).build()

src/main/kotlin/dev/arbjerg/lavalink/client/NodeOptions.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ data class NodeOptions private constructor(val name: String,
88
val serverUri: URI,
99
val password: String,
1010
val regionFilter: IRegionFilter?,
11-
val httpTimeout: Long) {
11+
val httpTimeout: Long,
12+
val sessionId: String?) {
1213
data class Builder(
1314
private var name: String? = null,
1415
private var serverUri: URI? = null,
1516
private var password: String? = null,
1617
private var regionFilter: IRegionFilter? = null,
1718
private var httpTimeout: Long = TIMEOUT_MS,
19+
private var sessionId: String? = null
1820
) {
1921
fun setName(name: String) = apply { this.name = name }
2022

@@ -53,6 +55,14 @@ data class NodeOptions private constructor(val name: String,
5355
*/
5456
fun setHttpTimeout(httpTimeout: Long) = apply { this.httpTimeout = httpTimeout }
5557

58+
/**
59+
* Sets the session ID that the client will use when first connecting to Lavalink. If the given session is still
60+
* running on the Lavalink server, the session will be resumed.
61+
*
62+
* Defaults to null, which means no attempt to resume will be made.
63+
*/
64+
fun setSessionId(sessionId: String?) = apply { this.sessionId = sessionId }
65+
5666
fun build(): NodeOptions {
5767
requireNotNull(name) { "name is required" }
5868
requireNotNull(serverUri) { "serverUri is required" }
@@ -63,7 +73,8 @@ data class NodeOptions private constructor(val name: String,
6373
serverUri!!,
6474
password!!,
6575
regionFilter,
66-
httpTimeout)
76+
httpTimeout,
77+
sessionId)
6778
}
6879
}
6980
}

0 commit comments

Comments
 (0)