Skip to content

Commit 39a171c

Browse files
authored
Expose voice connection ping in player stats. (#738)
* expose gateway ping in player stats * document ping in IMPLEMENTATION.md
1 parent 9962ff4 commit 39a171c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

IMPLEMENTATION.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,16 @@ This event includes:
251251
* Unix timestamp in milliseconds.
252252
* Track position in milliseconds. Omitted if not playing anything.
253253
* `connected` is true when connected to the voice gateway.
254+
* `ping` represents the number of milliseconds between heartbeat and ack. Could be `-1` if not connected.
254255
```json
255256
{
256257
"op": "playerUpdate",
257258
"guildId": "...",
258259
"state": {
259260
"time": 1500467109,
260261
"position": 60000,
261-
"connected": true
262+
"connected": true,
263+
"ping": 0
262264
}
263265
}
264266
```

LavalinkServer/src/main/java/lavalink/server/io/SocketServer.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class SocketServer(
6161
val json = JSONObject()
6262

6363
val state = player.state
64-
val connected = socketContext.getMediaConnection(player).gatewayConnection?.isOpen == true
65-
state.put("connected", connected)
64+
val connection = socketContext.getMediaConnection(player).gatewayConnection
65+
state.put("connected", connection?.isOpen == true)
66+
state.put("ping", connection?.ping ?: -1)
6667

6768
json.put("op", "playerUpdate")
6869
json.put("guildId", player.guildId.toString())

0 commit comments

Comments
 (0)