Skip to content

Commit

Permalink
fix player info widget
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Feb 17, 2024
1 parent 9b34e08 commit 1ee7043
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/MediaWidget/PlaylistController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export class PlaylistController {

constructor(recipientId: string, widgetId: string, conf: any) {
this.recipientId = recipientId;
const requested = new Playlist(PLAYLIST_TYPE.REQUESTED);
const requested = new Playlist(PLAYLIST_TYPE.REQUESTED, conf.topic.player);
this.current = requested;
this.playlists.set(PLAYLIST_TYPE.REQUESTED, requested);
this.playlists.set(
PLAYLIST_TYPE.PERSONAL,
new Playlist(PLAYLIST_TYPE.PERSONAL),
new Playlist(PLAYLIST_TYPE.PERSONAL, conf.topic.player),
);

log.info(`Loading playlist for ${recipientId}`);
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlayerInfo/PlayerInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function PlayerInfo() {
subscribe(widgetId, conf.topic.player, (message) => {
log.debug(`Received: ${message.body}`);
let json = JSON.parse(message.body);
if (json.title) {
if (json.title !== null) {
setTitle(json.title);
}
if (json.count != null && json.number != null) {
Expand Down
9 changes: 8 additions & 1 deletion src/logic/playlist/Playlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { markListened } from "../../components/MediaWidget/api";
import { Song } from "../../components/MediaWidget/types";
import { log } from "../../logging";
import { publish } from "../../socket";
import { IPlaylistChangesListener } from "./PlaylistChangesListener";

enum PLAYLIST_TYPE {
Expand All @@ -13,9 +14,11 @@ class Playlist {
_index: number | null = null;
_type: PLAYLIST_TYPE;
_listeners: IPlaylistChangesListener[] = [];
topic: string;

constructor(type: PLAYLIST_TYPE) {
constructor(type: PLAYLIST_TYPE, topic: string) {
this._type = type;
this.topic = topic;
}

addSong(song: Song) {
Expand Down Expand Up @@ -131,6 +134,10 @@ class Playlist {
}

triggerListeners() {
publish(this.topic, {
count: this._index === null ? 0 : this._songs.length,
number: this._index === null ? 0 : this._index
});
this._listeners.forEach((listener) => listener.trigger(this));
}
}
Expand Down

0 comments on commit 1ee7043

Please sign in to comment.