|
21 | 21 | import xyz.gianlu.librespot.dealer.DealerClient; |
22 | 22 | import xyz.gianlu.librespot.dealer.DealerClient.RequestResult; |
23 | 23 | import xyz.gianlu.librespot.mercury.MercuryClient; |
24 | | -import xyz.gianlu.librespot.mercury.SubListener; |
25 | 24 |
|
26 | 25 | import java.io.Closeable; |
27 | 26 | import java.io.IOException; |
| 27 | +import java.io.UnsupportedEncodingException; |
| 28 | +import java.net.URLDecoder; |
28 | 29 | import java.util.*; |
29 | 30 |
|
30 | 31 | /** |
31 | 32 | * @author Gianlu |
32 | 33 | */ |
33 | | -public final class DeviceStateHandler implements Closeable, DealerClient.MessageListener, DealerClient.RequestListener, SubListener { |
| 34 | +public final class DeviceStateHandler implements Closeable, DealerClient.MessageListener, DealerClient.RequestListener { |
34 | 35 | private static final Logger LOGGER = LogManager.getLogger(DeviceStateHandler.class); |
35 | 36 |
|
36 | 37 | static { |
@@ -60,7 +61,6 @@ public DeviceStateHandler(@NotNull Session session) { |
60 | 61 |
|
61 | 62 | session.dealer().addMessageListener(this, "hm://pusher/v1/connections/", "hm://connect-state/v1/connect/volume", "hm://connect-state/v1/cluster"); |
62 | 63 | session.dealer().addRequestListener(this, "hm://connect-state/v1/"); |
63 | | - session.mercury().interestedIn("hm://pusher/v1/connections/", this); |
64 | 64 | } |
65 | 65 |
|
66 | 66 | @NotNull |
@@ -122,15 +122,12 @@ private void notifyNotActive() { |
122 | 122 | listener.notActive(); |
123 | 123 | } |
124 | 124 |
|
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) { |
130 | 129 | } |
131 | | - } |
132 | 130 |
|
133 | | - private synchronized void updateConnectionId(@NotNull String newer) { |
134 | 131 | if (connectionId == null || !connectionId.equals(newer)) { |
135 | 132 | connectionId = newer; |
136 | 133 | LOGGER.debug("Updated Spotify-Connection-Id: " + connectionId); |
@@ -234,7 +231,6 @@ public void setVolume(int val) { |
234 | 231 | public void close() { |
235 | 232 | session.dealer().removeMessageListener(this); |
236 | 233 | session.dealer().removeRequestListener(this); |
237 | | - session.mercury().notInterested(this); |
238 | 234 |
|
239 | 235 | putStateWorker.close(); |
240 | 236 | listeners.clear(); |
|
0 commit comments