diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index 5f2e547..b3a897f 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -122,6 +122,18 @@ The position is in milliseconds. } ``` +#### Set player volume + +Volume may range from 0 to 1000. 100 is default. + +```json +{ + "op": "volume", + "guildId": "...", + "volume": 125 +} +``` + #### Using filters The `filters` op sets the filters. All the filters are optional, and leaving them out of this message will disable them. @@ -132,6 +144,8 @@ normally require very little processing. This is often the case with YouTube vid JSON comments are for illustration purposes only, and will not be accepted by the server. +Note that filters may take a moment to apply. + ```yaml { "op": "filters", diff --git a/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt b/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt index ee3ba11..0fb9276 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt @@ -105,11 +105,12 @@ class SocketContext internal constructor( /** * Gets or creates a voice connection */ - fun getVoiceConnection(guild: Long): VoiceConnection { - var conn = koe.getConnection(guild) + fun getVoiceConnection(player: Player): VoiceConnection { + val guildId = player.guildId.toLong() + var conn = koe.getConnection(guildId) if (conn == null) { - conn = koe.createConnection(guild) - conn.registerListener(EventHandler(guild.toString())) + conn = koe.createConnection(guildId) + conn.registerListener(EventHandler(player)) } return conn } @@ -181,23 +182,23 @@ class SocketContext internal constructor( koe.close() } - private inner class EventHandler(private val guildId: String) : KoeEventAdapter() { + private inner class EventHandler(private val player: Player) : KoeEventAdapter() { override fun gatewayClosed(code: Int, reason: String?, byRemote: Boolean) { val out = JSONObject() out.put("op", "event") out.put("type", "WebSocketClosedEvent") - out.put("guildId", guildId) + out.put("guildId", player.guildId) out.put("reason", reason ?: "") out.put("code", code) out.put("byRemote", byRemote) send(out) - SocketServer.sendPlayerUpdate(this@SocketContext, this@SocketContext.getPlayer(guildId)) + SocketServer.sendPlayerUpdate(this@SocketContext, player) } override fun gatewayReady(target: InetSocketAddress?, ssrc: Int) { - SocketServer.sendPlayerUpdate(this@SocketContext, this@SocketContext.getPlayer(guildId)) + SocketServer.sendPlayerUpdate(this@SocketContext, player) } } } diff --git a/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt b/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt index 6add0da..42f8e75 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt @@ -57,7 +57,7 @@ class SocketServer( val json = JSONObject() val state = player.state - val connected = socketContext.getVoiceConnection(player.guildId.toLong()).gatewayConnection?.isOpen == true + val connected = socketContext.getVoiceConnection(player).gatewayConnection?.isOpen == true state.put("connected", connected) json.put("op", "playerUpdate") diff --git a/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandlers.kt b/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandlers.kt index b173b57..070eead 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandlers.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandlers.kt @@ -30,7 +30,10 @@ class WebSocketHandlers(private val contextMap: Map) { //discord sometimes send a partial server update missing the endpoint, which can be ignored. endpoint ?: return - context.getVoiceConnection(guildId).connect(VoiceServerInfo(sessionId, endpoint, token)) + val player = context.getPlayer(guildId) + val conn = context.getVoiceConnection(player) + conn.connect(VoiceServerInfo(sessionId, endpoint, token)) + player.provideTo(conn) } fun play(context: SocketContext, json: JSONObject) { @@ -70,7 +73,7 @@ class WebSocketHandlers(private val contextMap: Map) { player.play(track) - val conn = context.getVoiceConnection(player.guildId.toLong()) + val conn = context.getVoiceConnection(player) context.getPlayer(json.getString("guildId")).provideTo(conn) }