Skip to content

Commit 610dab3

Browse files
committed
Merge branch 'dev'
2 parents 6c2afbf + b8dd3c8 commit 610dab3

25 files changed

+559
-709
lines changed

IMPLEMENTATION.md

Lines changed: 27 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ How to write your own client. The Java client will serve as an example implement
1010
* Hybi 10
1111
* Hixie 76
1212
* Hixie 75
13+
14+
## Changes v1.3 -> v2.0
15+
With the release of v2.0 many unnecessary ops were removed:
16+
17+
* `connect`
18+
* `disconnect`
19+
* `validationRes`
20+
* `isConnectedRes`
21+
* `validationReq`
22+
* `isConnectedReq`
23+
* `sendWS`
24+
25+
With Lavalink 1.x the server had the responsibility of handling Discord VOICE_SERVER_UPDATEs as well as its own internal ratelimiting.
26+
This remote handling makes things unnecessarily complicated and adds a lot og points where things could go wrong.
27+
One problem we noticed is that since JDAA is unaware of ratelimits on the bot's gateway connection, it would keep adding
28+
to the ratelimit queue to the gateway. With this update this is now the responsibility of the Lavalink client or the
29+
Discord client.
30+
31+
A voice connection is now initiated by forwarding a `voiceUpdate` (VOICE_SERVER_UPDATE) to the server. When you want to
32+
disconnect or move to a different voice channel you must send Discord a new VOICE_STATE_UPDATE. If you want to move your
33+
connection to a new Lavalink server you can simply send the VOICE_SERVER_UPDATE to the new node, and the other node
34+
will be disconnected by Discord.
35+
36+
Depending on your Discord library, it may be possible to take advantage of the library's OP 4 handling. For instance,
37+
the JDA client takes advantage of JDA's websocket write thread to send OP 4s for connects, disconnects and reconnects.
1338

1439
## Protocol
1540
### Opening a connection
@@ -21,16 +46,7 @@ User-Id: The user id of the bot you are playing music with
2146
```
2247

2348
### Outgoing messages
24-
Make the server queue a voice connection
25-
```json
26-
{
27-
"op": "connect",
28-
"guildId": "...",
29-
"channelId": "..."
30-
}
31-
```
32-
33-
Provide an intercepted voice server update
49+
Provide an intercepted voice server update. This causes the server to connect to the voice channel
3450
```json
3551
{
3652
"op": "voiceUpdate",
@@ -40,33 +56,6 @@ Provide an intercepted voice server update
4056
}
4157
```
4258

43-
Close a voice connection
44-
```json
45-
{
46-
"op": "disconnect",
47-
"guildId": "123"
48-
}
49-
```
50-
51-
Response to `validationReq`. `channelId` is omitted if the request does not display the channel id.
52-
```json
53-
{
54-
"op": "validationRes",
55-
"guildId": "...",
56-
"channelId": "...",
57-
"valid": true
58-
}
59-
```
60-
61-
Response to `isConnectedRes`.
62-
```json
63-
{
64-
"op": "isConnectedRes",
65-
"shardId": 1337,
66-
"connected": true
67-
}
68-
```
69-
7059
Cause the player to play a track.
7160
`startTime` is an optional setting that determines the number of milliseconds to offset the track by. Defaults to 0.
7261
`endTime` is an optional setting that determines at the number of milliseconds at which point the track should stop playing. Helpful if you only want to play a snippet of a bigger track. By default the track plays until it's end as per the encoded data.
@@ -117,35 +106,9 @@ Set player volume. Volume may range from 0 to 150. 100 is default.
117106

118107
### Incoming messages
119108
See
120-
[LavalinkSocket.java](https://github.com/Frederikam/Lavalink/blob/91bc0ef4dab6ca5d5efcba12203ee4054bb55ae9/LavalinkClient/src/main/java/lavalink/client/io/LavalinkSocket.java)
109+
[LavalinkSocket.java](https://github.com/Frederikam/Lavalink/blob/dev/LavalinkClient/src/main/java/lavalink/client/io/LavalinkSocket.java)
121110
for client implementation
122111

123-
Incoming message to forward to mainWS
124-
```json
125-
{
126-
"op": "sendWS",
127-
"shardId": 1337,
128-
"message": "..."
129-
}
130-
```
131-
132-
Request to check if the VC or Guild exists, and that we have access to the VC. Note that the channelId may be omitted, in which case you should only check if we are in the guild.
133-
```json
134-
{
135-
"op": "validationReq",
136-
"guildId": "...",
137-
"channelId": "..."
138-
}
139-
```
140-
141-
Request to check if a shard's mainWS is connected
142-
```json
143-
{
144-
"op": "isConnectedReq",
145-
"shardId": 1337
146-
}
147-
```
148-
149112
Position information about a player. Includes unix timestamp.
150113
```json
151114
{

LavalinkClient/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/logs/
33
/target/
44
/dependency-reduced-pom.xml
5-
build/*
5+
build/*
6+
/out/

LavalinkClient/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
description = 'JDA based client for the Lavalink-Server'
2-
version System.getenv('dev') == 'true' ? '-SNAPSHOT' : '1.3'
2+
version System.getenv('dev') == 'true' ? '-SNAPSHOT' : '2.0'
33
ext {
44
moduleName = 'Lavalink-Client'
55
}
66
dependencies {
77
compile group: 'com.sedmelluq', name: 'lavaplayer', version: '1.2.45'
8-
compile group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.3.4'
8+
compile group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.3.7'
99
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
10-
compile group: 'org.json', name: 'json', version: '20170516'
11-
compile group: 'net.dv8tion', name: 'JDA', version: '3.3.1_307'
10+
compile group: 'org.json', name: 'json', version: '20171018'
11+
compile group: 'net.dv8tion', name: 'JDA', version: '3.5.0_328'
12+
compileOnly group: 'io.prometheus', name: 'simpleclient', version: '0.1.0'
1213
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-M4'
1314
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.0-M4'
1415
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.0.0-M4'

LavalinkClient/src/main/java/lavalink/client/LavalinkUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class LavalinkUtil {
4545

4646
static {
4747
PLAYER_MANAGER = new DefaultAudioPlayerManager();
48-
PLAYER_MANAGER.enableGcMonitoring();
4948

5049
/* These are only to encode/decode messages */
5150
PLAYER_MANAGER.registerSourceManager(new YoutubeAudioSourceManager());
@@ -65,7 +64,7 @@ public static AudioTrack toAudioTrack(String message) throws IOException {
6564
public static String toMessage(AudioTrack track) throws IOException {
6665
ByteArrayOutputStream baos = new ByteArrayOutputStream();
6766
PLAYER_MANAGER.encodeTrack(new MessageOutput(baos), track);
68-
return new String(Base64.encodeBytesToBytes(baos.toByteArray()));
67+
return Base64.encodeBytes(baos.toByteArray());
6968
}
7069

7170
public static int getShardFromSnowflake(String snowflake, int numShards) {

0 commit comments

Comments
 (0)