Skip to content

Commit

Permalink
[lastfm] fix connection dropping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Jan 2, 2025
1 parent 454f18b commit f9435cb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion plugins/lastfm/listenbrainz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,22 @@ export class LbWebsocket {
path: "/https://listenbrainz.org/socket.io",
transports: ["websocket"],
});
this.#pendingSocket.on("connect", () => this.#onConnect(nextUser));
this.#pendingSocket.once("connect", () => this.#onConnect(nextUser));
this.#pendingSocket.on("playing_now", (pn) => this.#playingNowHandler(pn));

const s = this.#pendingSocket;

// screw it, maybe this will fix connection issues
const intCode = setInterval(() => {
if (s !== this.#pendingSocket && s !== this.#socket)
return clearInterval(intCode);

//console.log("connected: ", s.connected, "active: ", s.active);
if (!s.connected) {
s.connect();
s.once("connect", () => s.emit("json", { user: nextUser }));
}
}, 10_000);
}

#onConnect(nextUser: string) {
Expand Down

0 comments on commit f9435cb

Please sign in to comment.