Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dunctebot-custom
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Mar 2, 2021
2 parents f01c41d + 3b17422 commit 9266249
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
14 changes: 14 additions & 0 deletions IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
Expand Down
17 changes: 9 additions & 8 deletions LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class WebSocketHandlers(private val contextMap: Map<String, SocketContext>) {
//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) {
Expand Down Expand Up @@ -70,7 +73,7 @@ class WebSocketHandlers(private val contextMap: Map<String, SocketContext>) {

player.play(track)

val conn = context.getVoiceConnection(player.guildId.toLong())
val conn = context.getVoiceConnection(player)
context.getPlayer(json.getString("guildId")).provideTo(conn)
}

Expand Down

0 comments on commit 9266249

Please sign in to comment.