diff --git a/backend/src/manager/rooms/index.ts b/backend/src/manager/rooms/index.ts index a159521..30f223b 100644 --- a/backend/src/manager/rooms/index.ts +++ b/backend/src/manager/rooms/index.ts @@ -152,9 +152,9 @@ const sendUpdate = ( room: string, kind: 'state' | 'playlist' ) => { if ( !roomObject ) return false; - roomObject.clients.forEach( client => client.response.write( `data: ${ JSON.stringify( { + roomObject.clients.forEach( client => client.response.write( `data: json:${ JSON.stringify( { 'type': kind, - 'data': JSON.stringify( roomObject[kind] ) + 'data': roomObject[kind] } ) }\n\n` ) ); return true; diff --git a/backend/src/routes/room/update.ts b/backend/src/routes/room/update.ts index 6c8838f..5aa75ae 100644 --- a/backend/src/routes/room/update.ts +++ b/backend/src/routes/room/update.ts @@ -32,7 +32,7 @@ const routes = ( app: express.Application, foss: boolean, config: Config ) => { response.send( JSON.stringify( { 'state': room?.state, - 'playlist': lastRequest < room!.playlist!.lastUpdate ? room!.playlist : undefined + 'playlist': ( lastRequest < room!.playlist!.lastUpdate || isNaN( lastRequest ) ) ? room!.playlist.playlist : undefined } ) ); } ); diff --git a/web/src/components/shared/SharedQueue.vue b/web/src/components/shared/SharedQueue.vue index b534fcc..0444426 100644 --- a/web/src/components/shared/SharedQueue.vue +++ b/web/src/components/shared/SharedQueue.vue @@ -3,17 +3,27 @@ computed, ref } from 'vue'; - import type { - Song - } from '@/ts/dtype/playlist'; + import { + currentQueue, + currentQueueIdx + } from '@/ts/shared/state'; - const props = defineProps<{ - 'songs': Song[], - 'idx': number - }>(); - const songs = computed( () => props.songs?.slice( props.idx + 1 ) ?? [] ); + const songs = computed( () => currentQueue.value?.slice( currentQueueIdx.value + 1 ) ?? [] ); // TODO: Move this out of this file const showArtworks = ref( false ); + const timeToPlay = computed( () => { + return ( idx: number ) => { + let total = 0; + + for ( let i = 0; i < idx; i++ ) { + total += songs.value[ i ]!.duration; + } + + total += currentQueue.value[ currentQueueIdx.value ]?.duration ?? 0; + + return Math.round( total / 60 ); + }; + } );