web: add error surfacing

This commit is contained in:
2025-11-15 17:58:29 -08:00
parent 04d23bec1e
commit bc54735d1f
5 changed files with 74 additions and 13 deletions

View File

@@ -37,6 +37,7 @@ enum UserEvent {
FavoritesUpdate = "favorites_update",
MetadataUpdate = "metadata_update",
MPDUpdate = "mpd_update",
PlaybackError = "playback_error",
}
export interface Features {
@@ -57,6 +58,9 @@ export class MediaPlayer {
private dataBuffer: string = '';
private metadata: Map<string, LinkMetadata> = new Map();
private bonjourInstance: Bonjour | null = null;
private playbackErrors: Map<string, string> = new Map();
private currentFile: string | null = null;
private lastLoadCandidate: string | null = null;
constructor() {
this.socket = this.tryRespawnPlayerProcess();
@@ -152,7 +156,8 @@ export class MediaPlayer {
const playlist = response.data as PlaylistItem[];
return playlist.map((item: PlaylistItem) => ({
...item,
metadata: this.metadata.get(item.filename) || {}
metadata: this.metadata.get(item.filename) || {},
playbackError: this.playbackErrors.get(item.filename)
}));
});
}
@@ -352,6 +357,8 @@ export class MediaPlayer {
}
private async loadFile(url: string, mode: string, fetchMetadata: boolean = true, options: string[] = []) {
this.lastLoadCandidate = url;
this.playbackErrors.delete(url);
this.modify(UserEvent.PlaylistUpdate, () => this.writeCommand("loadfile", [url, mode, "-1", options.join(',')]));
if (fetchMetadata) {
@@ -470,6 +477,24 @@ export class MediaPlayer {
this.pendingCommands.delete(response.request_id);
}
} else if (response.event) {
if (response.event === "start-file") {
// Clear any previous error for the file that is starting
const file = response.file || this.lastLoadCandidate;
if (file) {
this.currentFile = file;
this.playbackErrors.delete(file);
}
} else if (response.event === "end-file" && response.reason === "error") {
const file = response.file || this.currentFile || this.lastLoadCandidate || "Unknown file";
const errorMessage = response.error || response["file-error"] || "Unknown playback error";
this.playbackErrors.set(file, errorMessage);
this.handleEvent(UserEvent.PlaybackError, {
filename: file,
error: errorMessage
});
}
this.handleEvent(UserEvent.MPDUpdate, response);
} else {
console.log(response);

View File

@@ -29,4 +29,5 @@ export interface PlaylistItem {
playing?: boolean;
current?: boolean;
metadata?: LinkMetadata;
}
playbackError?: string;
}