Skip to content

Commit afc7dc3

Browse files
committed
Avoid duplicate connection ID + URL decode
1 parent 5839d5b commit afc7dc3

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/connectstate/DeviceStateHandler.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
import xyz.gianlu.librespot.dealer.DealerClient;
2222
import xyz.gianlu.librespot.dealer.DealerClient.RequestResult;
2323
import xyz.gianlu.librespot.mercury.MercuryClient;
24-
import xyz.gianlu.librespot.mercury.SubListener;
2524

2625
import java.io.Closeable;
2726
import java.io.IOException;
27+
import java.io.UnsupportedEncodingException;
28+
import java.net.URLDecoder;
2829
import java.util.*;
2930

3031
/**
3132
* @author Gianlu
3233
*/
33-
public final class DeviceStateHandler implements Closeable, DealerClient.MessageListener, DealerClient.RequestListener, SubListener {
34+
public final class DeviceStateHandler implements Closeable, DealerClient.MessageListener, DealerClient.RequestListener {
3435
private static final Logger LOGGER = LogManager.getLogger(DeviceStateHandler.class);
3536

3637
static {
@@ -60,7 +61,6 @@ public DeviceStateHandler(@NotNull Session session) {
6061

6162
session.dealer().addMessageListener(this, "hm://pusher/v1/connections/", "hm://connect-state/v1/connect/volume", "hm://connect-state/v1/cluster");
6263
session.dealer().addRequestListener(this, "hm://connect-state/v1/");
63-
session.mercury().interestedIn("hm://pusher/v1/connections/", this);
6464
}
6565

6666
@NotNull
@@ -122,15 +122,12 @@ private void notifyNotActive() {
122122
listener.notActive();
123123
}
124124

125-
@Override
126-
public void event(@NotNull MercuryClient.Response resp) {
127-
if (resp.uri.startsWith("hm://pusher/v1/connections/")) {
128-
int index = resp.uri.lastIndexOf('/');
129-
updateConnectionId(resp.uri.substring(index + 1));
125+
private synchronized void updateConnectionId(@NotNull String newer) {
126+
try {
127+
newer = URLDecoder.decode(newer, "UTF-8");
128+
} catch (UnsupportedEncodingException ignored) {
130129
}
131-
}
132130

133-
private synchronized void updateConnectionId(@NotNull String newer) {
134131
if (connectionId == null || !connectionId.equals(newer)) {
135132
connectionId = newer;
136133
LOGGER.debug("Updated Spotify-Connection-Id: " + connectionId);
@@ -234,7 +231,6 @@ public void setVolume(int val) {
234231
public void close() {
235232
session.dealer().removeMessageListener(this);
236233
session.dealer().removeRequestListener(this);
237-
session.mercury().notInterested(this);
238234

239235
putStateWorker.close();
240236
listeners.clear();

0 commit comments

Comments
 (0)