feat: basic rendering of queue on share screen

This commit is contained in:
2026-09-07 20:24:23 +02:00
parent 054fda2fb9
commit 6d9853f2c1
8 changed files with 158 additions and 34 deletions
+46
View File
@@ -0,0 +1,46 @@
import {
currentQueue,
currentQueueIdx,
isPlaying,
startTime
} from './state';
import type {
Song
} from '../dtype/playlist';
interface ReceivedJSONMessage {
'type': 'state' | 'playlist';
'data': unknown;
}
export interface StateUpdate {
'playing': boolean;
'index': number;
'start': number;
}
export const messageHandler = ( msg: string ) => {
if ( msg.startsWith( 'json:' ) ) {
try {
const data = JSON.parse( msg.substring( 5 ) ) as ReceivedJSONMessage;
if ( data.type === 'playlist' ) {
currentQueue.value = ( data.data as {
'playlist': Song[]
} ?? {
'playlist': []
} ).playlist;
} else if ( data.type === 'state' ) {
const state = data.data as StateUpdate;
currentQueueIdx.value = state.index;
isPlaying.value = state.playing;
startTime.value = state.start;
} else {
console.log( '[SSE] Received unknown data', data.type );
}
} catch ( err ) {
console.error( 'JSON DECODE failed with error', err );
}
}
};