Skip to content

Commit

Permalink
update plugin-api
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Apr 19, 2024
1 parent 96e65bf commit 5a9b8c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(),
Expand Down
12 changes: 7 additions & 5 deletions LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,19 +48,19 @@ final class SocketServer(
koeOptions: KoeOptions,
private val eventHandlers: List<PluginEventHandler>,
private val pluginInfoModifiers: List<AudioPluginInfoModifier>
) : TextWebSocketHandler() {
) : TextWebSocketHandler(), ISocketServer {

// sessionID <-> Session
val contextMap = ConcurrentHashMap<String, SocketContext>()
private val resumableSessions = mutableMapOf<String, SocketContext>()
private val koe = Koe.koe(koeOptions)
override val contextMap = ConcurrentHashMap<String, SocketContext>()
override val resumableSessions = mutableMapOf<String, SocketContext>()
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
Expand Down
1 change: 1 addition & 0 deletions plugin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
api(libs.spring.boot.web)
api(libs.lavaplayer)
api(libs.kotlinx.serialization.json)
api(libs.koe)
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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].
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.arbjerg.lavalink.api

import moe.kyokobot.koe.Koe

interface ISocketServer {
val contextMap: Map<String, ISocketContext>
val resumableSessions: Map<String, ISocketContext>
val koe: Koe
}

0 comments on commit 5a9b8c3

Please sign in to comment.