Skip to content

Commit

Permalink
feat(plugin-api): userId & clientName getters (lavalink-devs#743)
Browse files Browse the repository at this point in the history
* feat(plugin-api): userId & clientName getters

* fix: remove trailing space from javadoc

* chore: convert user id to long in getter
  • Loading branch information
viztea authored Oct 12, 2022
1 parent 5f23a15 commit 4524f67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class SocketContext(
val serverConfig: ServerConfig,
private var session: WebSocketSession,
private val socketServer: SocketServer,
val userId: String,
private val userId: String,
private val clientName: String?,
val koe: KoeClient,
eventHandlers: Collection<PluginEventHandler>,
webSocketExtensions: List<WebSocketExtension>,
Expand Down Expand Up @@ -105,6 +106,14 @@ class SocketContext(

fun getPlayer(guildId: String) = getPlayer(guildId.toLong())

override fun getUserId(): Long {
return userId.toLong()
}

override fun getClientName(): String? {
return clientName
}

override fun getPlayer(guildId: Long) = players.computeIfAbsent(guildId) {
val player = Player(this, guildId, audioPlayerManager, serverConfig)
eventEmitter.onNewPlayer(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class SocketServer(
session,
this,
userId,
clientName,
koe.newClient(userId.toLong()),
eventHandlers,
webSocketExtensions,
Expand Down Expand Up @@ -176,4 +177,4 @@ class SocketServer(
}

internal fun canResume(key: String) = resumableSessions[key]?.stopResumeTimeout() ?: false
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package dev.arbjerg.lavalink.api;

import org.json.JSONObject;
import org.springframework.lang.Nullable;

import java.util.Map;

/**
* Represents a WebSocket connection
*/
public interface ISocketContext {
/**
* @return the User ID of the Client.
*/
long getUserId();

/**
* @return the name of the Client, or null if it was not specified.
*/
@Nullable
String getClientName();

/**
* Returns the player of a guild. Never returns null.
*
Expand Down

0 comments on commit 4524f67

Please sign in to comment.