Skip to content

Commit e25fc2f

Browse files
committed
Trying to fix issue where client doesn't appear after dealer has reconnected
1 parent 4abb7fa commit e25fc2f

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public void onMessage(@NotNull String uri, @NotNull Map<String, String> headers,
150150
}
151151
}
152152

153+
@Override
154+
public void onConnectionRestarted() {
155+
// Do nothing (already handled by StateWrapper)
156+
}
157+
153158
@NotNull
154159
@Override
155160
public RequestResult onRequest(@NotNull String mid, int pid, @NotNull String sender, @NotNull JsonObject command) {

core/src/main/java/xyz/gianlu/librespot/dealer/DealerClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,21 @@ private void connectionInvalided() {
196196

197197
try {
198198
connect();
199+
notifyConnectionRestarted();
199200
} catch (IOException | MercuryClient.MercuryException ex) {
200201
LOGGER.error("Failed reconnecting, retrying...", ex);
201202
connectionInvalided();
202203
}
203204
}, 10, TimeUnit.SECONDS);
204205
}
205206

207+
private void notifyConnectionRestarted() {
208+
synchronized (msgListeners) {
209+
for (MessageListener listener : msgListeners.keySet())
210+
listener.onConnectionRestarted();
211+
}
212+
}
213+
206214
public enum RequestResult {
207215
UNKNOWN_SEND_COMMAND_RESULT, SUCCESS,
208216
DEVICE_NOT_FOUND, CONTEXT_PLAYER_ERROR,
@@ -217,6 +225,8 @@ public interface RequestListener {
217225

218226
public interface MessageListener {
219227
void onMessage(@NotNull String uri, @NotNull Map<String, String> headers, @NotNull String[] payloads) throws IOException;
228+
229+
void onConnectionRestarted();
220230
}
221231

222232
private static class Looper implements Runnable, Closeable {

core/src/main/java/xyz/gianlu/librespot/player/StateWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ else if (op.getKind() == Playlist4ApiProto.Op.Kind.REM)
654654
}
655655
}
656656

657+
@Override
658+
public void onConnectionRestarted() {
659+
updated();
660+
}
661+
657662
private synchronized void performCollectionUpdate(@NotNull List<String> uris, boolean inCollection) {
658663
for (String uri : uris)
659664
tracksKeeper.updateMetadataFor(uri, "collection.in_collection", String.valueOf(inCollection));

0 commit comments

Comments
 (0)