From 5a9b8c3b1535b94f0708794afdd80021ae0c9528 Mon Sep 17 00:00:00 2001 From: topi314 Date: Mon, 25 Dec 2023 22:31:09 +0100 Subject: [PATCH] update plugin-api --- .../main/java/lavalink/server/io/SocketContext.kt | 5 +++-- .../src/main/java/lavalink/server/io/SocketServer.kt | 12 +++++++----- plugin-api/build.gradle.kts | 1 + .../java/dev/arbjerg/lavalink/api/ISocketContext.kt | 6 ++++++ .../java/dev/arbjerg/lavalink/api/ISocketServer.kt | 9 +++++++++ 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketServer.kt diff --git a/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt b/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt index 874e0d2e8..121590107 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt @@ -24,6 +24,7 @@ package lavalink.server.io import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager import dev.arbjerg.lavalink.api.AudioPluginInfoModifier +import dev.arbjerg.lavalink.api.IPlayer import dev.arbjerg.lavalink.api.ISocketContext import dev.arbjerg.lavalink.api.PluginEventHandler import dev.arbjerg.lavalink.protocol.v4.Message @@ -115,7 +116,7 @@ class SocketContext( /** * Gets or creates a media connection */ - fun getMediaConnection(player: LavalinkPlayer): MediaConnection { + override fun getMediaConnection(player: IPlayer): MediaConnection { val guildId = player.guildId var conn = koe.getConnection(guildId) if (conn == null) { @@ -216,7 +217,7 @@ class SocketContext( session.close() } - private inner class WsEventHandler(private val player: LavalinkPlayer) : KoeEventAdapter() { + private inner class WsEventHandler(private val player: IPlayer) : KoeEventAdapter() { override fun gatewayClosed(code: Int, reason: String?, byRemote: Boolean) { val event = Message.EmittedEvent.WebSocketClosedEvent( player.guildId.toString(), diff --git a/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt b/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt index 5cf087783..d47a04081 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt @@ -24,6 +24,8 @@ package lavalink.server.io import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager import dev.arbjerg.lavalink.api.AudioPluginInfoModifier +import dev.arbjerg.lavalink.api.IPlayer +import dev.arbjerg.lavalink.api.ISocketServer import dev.arbjerg.lavalink.api.PluginEventHandler import dev.arbjerg.lavalink.protocol.v4.Message import dev.arbjerg.lavalink.protocol.v4.PlayerState @@ -46,19 +48,19 @@ final class SocketServer( koeOptions: KoeOptions, private val eventHandlers: List, private val pluginInfoModifiers: List -) : TextWebSocketHandler() { +) : TextWebSocketHandler(), ISocketServer { // sessionID <-> Session - val contextMap = ConcurrentHashMap() - private val resumableSessions = mutableMapOf() - private val koe = Koe.koe(koeOptions) + override val contextMap = ConcurrentHashMap() + override val resumableSessions = mutableMapOf() + override val koe = Koe.koe(koeOptions) private val statsCollector = StatsCollector(this) private val charPool = ('a'..'z') + ('0'..'9') companion object { private val log = LoggerFactory.getLogger(SocketServer::class.java) - fun sendPlayerUpdate(socketContext: SocketContext, player: LavalinkPlayer) { + fun sendPlayerUpdate(socketContext: SocketContext, player: IPlayer) { if (socketContext.sessionPaused) return val connection = socketContext.getMediaConnection(player).gatewayConnection diff --git a/plugin-api/build.gradle.kts b/plugin-api/build.gradle.kts index f0fe1556c..b1162bb63 100644 --- a/plugin-api/build.gradle.kts +++ b/plugin-api/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { api(libs.spring.boot.web) api(libs.lavaplayer) api(libs.kotlinx.serialization.json) + api(libs.koe) } java { diff --git a/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketContext.kt b/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketContext.kt index 4ed52075e..e9569085c 100644 --- a/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketContext.kt +++ b/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketContext.kt @@ -2,6 +2,7 @@ package dev.arbjerg.lavalink.api import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.json.JsonElement +import moe.kyokobot.koe.MediaConnection /** * Represents a WebSocket connection @@ -35,6 +36,11 @@ interface ISocketContext { */ fun getPlayer(guildId: Long): IPlayer + /** + * Gets or creates a media connection + */ + fun getMediaConnection(player: IPlayer): MediaConnection + /** * Destroys the player for the Guild corresponding to [guildId]. */ diff --git a/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketServer.kt b/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketServer.kt new file mode 100644 index 000000000..abb7a20bf --- /dev/null +++ b/plugin-api/src/main/java/dev/arbjerg/lavalink/api/ISocketServer.kt @@ -0,0 +1,9 @@ +package dev.arbjerg.lavalink.api + +import moe.kyokobot.koe.Koe + +interface ISocketServer { + val contextMap: Map + val resumableSessions: Map + val koe: Koe +} \ No newline at end of file