diff --git a/frontend/src/app.js b/frontend/src/app.js index a2249e2..329d442 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -16,6 +16,7 @@ let coverArtIndex = {}; const allowedFileTypes = [ '.mp3', '.wav', '.flac' ]; let connectedClients = []; +let changedStatus = []; let currentDetails = { 'songQueue': [], @@ -71,18 +72,20 @@ app.get( '/mainNotifier', ( req, res ) => { } } ); +const sendUpdate = () => { + console.log( currentDetails ); +} +const allowedTypes = [ 'playingSong', 'isPlaying', 'songQueue', 'pos' ]; app.post( '/statusUpdate', ( req, res ) => { - if ( req.body.status === 'playingSong' ) { - - } else if ( req.body.status === 'isPlaying' ) { - - } else if ( req.body.status === 'songQueue' ) { - - } else if ( req.body.status === 'pos' ) { - + if ( allowedTypes.includes( req.body.type ) ) { + currentDetails[ req.body.type ] = req.body.data; + changedStatus.push( req.body.type ); + sendUpdate(); + res.send( 'ok' ); + } else { + res.status( 400 ).send( 'ERR_UNKNOWN_TYPE' ); } - res.send( 'ok' ); } ); @@ -99,8 +102,8 @@ app.get( '/clientStatusUpdate/:status', ( req, res ) => { } ); app.get( '/openSongs', ( req, res ) => { - res.send( '{ "data": [ "/home/janis/Music/KB2022" ] }' ); - // res.send( '{ "data": [ "/mnt/storage/SORTED/Music/audio/KB2022" ] }' ); + // res.send( '{ "data": [ "/home/janis/Music/KB2022" ] }' ); + res.send( '{ "data": [ "/mnt/storage/SORTED/Music/audio/KB2022" ] }' ); // res.send( { 'data': dialog.showOpenDialogSync( { properties: [ 'openDirectory' ], title: 'Open music library folder' } ) } ); } ); diff --git a/frontend/src/components/player.vue b/frontend/src/components/player.vue index 6e6dd5f..0978817 100644 --- a/frontend/src/components/player.vue +++ b/frontend/src/components/player.vue @@ -156,9 +156,8 @@ export default { if ( autoplay ) { this.control( 'play' ); this.isPlaying = true; - this.sendUpdate( 'isPLaying' ); + this.sendUpdate( 'isPlaying' ); this.sendUpdate( 'playingSong' ); - this.sendUpdate( 'songQueue' ); this.sendUpdate( 'pos' ); } const minuteCount = Math.floor( this.playingSong.duration / 60 ); @@ -191,10 +190,8 @@ export default { data = this.playbackPos; } else if ( update === 'playingSong' ) { data = this.playingSong; - } else if ( update === 'songQueue' ) { - data = this.playbackPos; - } else if ( update === 'pos' ) { - data = this.playbackPos; + } else if ( update === 'isPlaying' ) { + data = this.isPlaying; } let fetchOptions = { method: 'post', @@ -204,7 +201,7 @@ export default { 'charset': 'utf-8' }, }; - fetch( '/statusUpdate', fetchOptions ).then( res => { + fetch( 'http://localhost:8081/statusUpdate', fetchOptions ).then( res => { console.log( res ); } ); },