Skip to content

Commit b9875d8

Browse files
committed
Merge branch 'dev'
2 parents e846411 + 2b3b09b commit b9875d8

File tree

16 files changed

+321
-181
lines changed

16 files changed

+321
-181
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
Each release usually includes various fixes and improvements.
44
The most noteworthy of these, as well as any features and breaking changes, are listed here.
55

6+
## v3.2.0.1
7+
* Bumped to Java 11. Treating this as a patch version, as v3.2 still requires Java 11 due to a Magma update.
8+
9+
Contributor:
10+
[@Frederikam](https://github.com/Frederikam/)
11+
12+
## v3.2
13+
* Added resuming
14+
15+
Contributor:
16+
[@Frederikam](https://github.com/Frederikam/)
17+
618
## v3.1.2
719
* Add API version header to all responses
820

IMPLEMENTATION.md

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ User-Id: The user id of the bot you are playing music with
5252
```
5353

5454
### Outgoing messages
55-
Provide an intercepted voice server update. This causes the server to connect to the voice channel
55+
Provide an intercepted voice server update. This causes the server to connect to the voice channel.
5656
```json
5757
{
5858
"op": "voiceUpdate",
@@ -65,13 +65,15 @@ Provide an intercepted voice server update. This causes the server to connect to
6565
Cause the player to play a track.
6666
`startTime` is an optional setting that determines the number of milliseconds to offset the track by. Defaults to 0.
6767
`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.
68+
`noReplace` if set to true, this operation will be ignored if a track is already playing or paused.
6869
```json
6970
{
7071
"op": "play",
7172
"guildId": "...",
7273
"track": "...",
7374
"startTime": "60000",
74-
"endTime": "120000"
75+
"endTime": "120000",
76+
"noReplace": false
7577
}
7678
```
7779

@@ -139,9 +141,8 @@ and you can send the same VOICE_SERVER_UPDATE to a new node.
139141
```
140142

141143
### Incoming messages
142-
See
143-
[LavalinkSocket.java](https://github.com/FredBoat/Lavalink-Client/blob/master/src/main/java/lavalink/client/io/LavalinkSocket.java)
144-
for client implementation
144+
145+
See [LavalinkSocket.java](https://github.com/FredBoat/Lavalink-Client/blob/master/src/main/java/lavalink/client/io/LavalinkSocket.java) for client implementation
145146

146147
Position information about a player. Includes unix timestamp.
147148
```json
@@ -156,6 +157,7 @@ Position information about a player. Includes unix timestamp.
156157
```
157158

158159
A collection of stats sent every minute.
160+
159161
```json
160162
{
161163
"op": "stats",
@@ -309,10 +311,46 @@ Additionally, in every `/loadtracks` response, a `loadType` property is returned
309311

310312
All REST responses from Lavalink include a `Lavalink-Api-Version` header.
311313

314+
### Resuming Lavalink sessions
315+
316+
What happens after your client disconnects is dependent on whether or not the session has been configured for resuming.
317+
318+
* If resuming is disabled all voice connections are closed immediately.
319+
* If resuming is enabled all music will continue playing. You will then be able to resume your session, allowing you to control the players again.
320+
321+
To enable resuming, you must send a `configureResuming` message.
322+
323+
* `key` is the string you will need to send when resuming the session. Set to null to disable resuming altogether. Defaults to null.
324+
* `timeout` is the number of seconds after disconnecting before the session is closed anyways. This is useful for avoiding accidental leaks. Defaults to `60` (seconds).
325+
326+
```json
327+
{
328+
"op": "configureResuming",
329+
"key": "myResumeKey",
330+
"timeout": 60
331+
}
332+
```
333+
334+
To resume a session, specify the resume key in your WebSocket handshake request headers:
335+
336+
```
337+
Resume-Key: The resume key of the session you want to resume.
338+
```
339+
340+
You can tell if your session was resumed by looking at the handshake response header `Session-Resumed` which is either `true` or `false`:
341+
342+
```
343+
Session-Resumed: true
344+
```
345+
346+
When a session is paused, any events that would normally have been sent is queued up. When the session is resumed, this
347+
queue is then emptied and the events are then replayed.
348+
312349
### Special notes
313-
* When your shard's mainWS connection dies, so does all your lavalink audio connections.
314-
* This also includes resumes
315-
* When a client connection to Lavalink-Server disconnects, all connections and players for that session are shut down.
350+
351+
* When your shard's main WS connection dies, so does all your lavalink audio connections.
352+
* This also includes resumes
353+
316354
* If Lavalink-Server suddenly dies (think SIGKILL) the client will have to terminate any audio connections by sending this event:
317355
```json
318356
{"op":4,"d":{"self_deaf":false,"guild_id":"GUILD_ID_HERE","channel_id":null,"self_mute":false}}

LavalinkServer/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ bootJar {
1818
archiveName = "Lavalink.jar"
1919
}
2020

21-
sourceCompatibility = 10
22-
targetCompatibility = 10
21+
sourceCompatibility = 11
22+
targetCompatibility = 11
2323

2424
bootRun {
2525
//compiling tests during bootRun increases the likelihood of catching broken tests locally instead of on the CI

LavalinkServer/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM openjdk:10-jre-slim
1+
FROM openjdk:11-jre-slim
22

33
WORKDIR /opt/Lavalink
44

LavalinkServer/src/main/java/lavalink/server/config/SentryConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121

2222
@Configuration
23-
@SuppressWarnings("WeakerAccess")
2423
public class SentryConfiguration {
2524

2625
private static final Logger log = LoggerFactory.getLogger(SentryConfiguration.class);
@@ -59,6 +58,7 @@ public void turnOn(String dsn, Map<String, String> tags) {
5958
// set the git commit hash this was build on as the release
6059
Properties gitProps = new Properties();
6160
try {
61+
//noinspection ConstantConditions
6262
gitProps.load(Launcher.class.getClassLoader().getResourceAsStream("git.properties"));
6363
} catch (NullPointerException | IOException e) {
6464
log.error("Failed to load git repo information", e);

LavalinkServer/src/main/java/lavalink/server/io/HandshakeInterceptorImpl.java

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package lavalink.server.io
2+
3+
import lavalink.server.config.ServerConfig
4+
import org.slf4j.Logger
5+
import org.slf4j.LoggerFactory
6+
import org.springframework.beans.factory.annotation.Autowired
7+
import org.springframework.http.server.ServerHttpRequest
8+
import org.springframework.http.server.ServerHttpResponse
9+
import org.springframework.stereotype.Controller
10+
import org.springframework.web.socket.WebSocketHandler
11+
import org.springframework.web.socket.server.HandshakeInterceptor
12+
import java.util.Objects
13+
14+
@Controller
15+
class HandshakeInterceptorImpl @Autowired
16+
constructor(private val serverConfig: ServerConfig, private val socketServer: SocketServer) : HandshakeInterceptor {
17+
18+
companion object {
19+
private val log = LoggerFactory.getLogger(HandshakeInterceptorImpl::class.java)
20+
}
21+
22+
/**
23+
* Checks credentials and sets the Lavalink version header
24+
*
25+
* @return true if authenticated
26+
*/
27+
override fun beforeHandshake(request: ServerHttpRequest, response: ServerHttpResponse, wsHandler: WebSocketHandler,
28+
attributes: Map<String, Any>): Boolean {
29+
response.headers.add("Lavalink-Major-Version", "3")
30+
31+
val password = request.headers.getFirst("Authorization")
32+
val matches = password == serverConfig.password
33+
34+
if (matches) {
35+
log.info("Incoming connection from " + request.remoteAddress)
36+
} else {
37+
log.error("Authentication failed from " + request.remoteAddress)
38+
}
39+
40+
val resumeKey = request.headers.getFirst("Resume-Key")
41+
val resuming = resumeKey != null && socketServer.canResume(resumeKey)
42+
response.headers.add("Session-Resumed", resuming.toString())
43+
44+
return matches
45+
}
46+
47+
// No action required
48+
override fun afterHandshake(request: ServerHttpRequest, response: ServerHttpResponse, wsHandler: WebSocketHandler,
49+
exception: Exception?) {
50+
}
51+
}

LavalinkServer/src/main/java/lavalink/server/io/ResponseHeaderFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package lavalink.server.io;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.springframework.stereotype.Component;
45
import org.springframework.web.filter.OncePerRequestFilter;
56

@@ -13,8 +14,8 @@
1314
public class ResponseHeaderFilter extends OncePerRequestFilter {
1415

1516
@Override
16-
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
17-
FilterChain filterChain) throws IOException, ServletException {
17+
protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response,
18+
@NotNull FilterChain filterChain) throws IOException, ServletException {
1819
response.addHeader("Lavalink-Api-Version", "3");
1920
filterChain.doFilter(request, response);
2021
}

0 commit comments

Comments
 (0)