mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 13:04:23 +00:00
add backend for feeding information to main ui
This commit is contained in:
@@ -122,7 +122,7 @@ app.get( '/mainNotifier', ( req, res ) => {
|
|||||||
} );
|
} );
|
||||||
res.status( 200 );
|
res.status( 200 );
|
||||||
res.flushHeaders();
|
res.flushHeaders();
|
||||||
let det = { 'type': 'basics', 'data': currentDetails };
|
let det = { 'type': 'basics', 'data': connectedClients };
|
||||||
res.write( `data: ${ JSON.stringify( det ) }\n\n` );
|
res.write( `data: ${ JSON.stringify( det ) }\n\n` );
|
||||||
connectedMain = res;
|
connectedMain = res;
|
||||||
} else {
|
} else {
|
||||||
@@ -197,19 +197,25 @@ app.post( '/statusUpdate', ( req, res ) => {
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// STATUS UPDATE from the client display to send to main ui
|
||||||
|
const allowedMainUpdates = [ 'disconnect', 'fullScreenStatus', 'visibility' ];
|
||||||
app.get( '/clientStatusUpdate/:status', ( req, res ) => {
|
app.get( '/clientStatusUpdate/:status', ( req, res ) => {
|
||||||
if ( req.params.status === 'disconnect' ) {
|
if ( allowedTypes.includes( req.body.type ) ) {
|
||||||
|
const ipRetrieved = req.headers[ 'x-forwarded-for' ];
|
||||||
} else if ( req.params.status === 'fullScreenExit' ) {
|
const ip = ipRetrieved ? ipRetrieved.split( /, / )[ 0 ] : req.connection.remoteAddress;
|
||||||
|
sendClientUpdate( req.body.type, req.body.data, ip );
|
||||||
} else if ( req.params.status === 'inactive' ) {
|
res.send( 'ok' );
|
||||||
|
} else {
|
||||||
} else if ( req.params.status === 'reactivated' ) {
|
res.status( 400 ).send( 'ERR_UNKNOWN_TYPE' );
|
||||||
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
const sendClientUpdate = ( update, data, ip ) => {
|
||||||
|
for ( let main in connectedMain ) {
|
||||||
|
connectedMain[ main ].write( 'data: ' + JSON.stringify( { 'type': update, 'ip': ip, 'data': data } ) + '\n\n' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.get( '/indexDirs', ( req, res ) => {
|
app.get( '/indexDirs', ( req, res ) => {
|
||||||
if ( req.query.dir ) {
|
if ( req.query.dir ) {
|
||||||
indexer.index( req ).then( dirIndex => {
|
indexer.index( req ).then( dirIndex => {
|
||||||
|
|||||||
@@ -88,6 +88,17 @@ const app = Vue.createApp( {
|
|||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
this.sendUpdate( 'pos' );
|
this.sendUpdate( 'pos' );
|
||||||
}, 500 );
|
}, 500 );
|
||||||
|
const minuteCounts = Math.floor( ( this.playingSong.duration ) / 60 );
|
||||||
|
this.durationBeautified = String( minuteCounts ) + ':';
|
||||||
|
if ( ( '' + minuteCounts ).length === 1 ) {
|
||||||
|
this.durationBeautified = '0' + minuteCounts + ':';
|
||||||
|
}
|
||||||
|
const secondCounts = Math.floor( ( this.playingSong.duration ) - minuteCounts * 60 );
|
||||||
|
if ( ( '' + secondCounts ).length === 1 ) {
|
||||||
|
this.durationBeautified += '0' + secondCounts;
|
||||||
|
} else {
|
||||||
|
this.durationBeautified += secondCounts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
this.apiGetRequest( 'https://api.music.apple.com/v1/me/library/playlists', this.playlistHandler );
|
this.apiGetRequest( 'https://api.music.apple.com/v1/me/library/playlists', this.playlistHandler );
|
||||||
@@ -405,6 +416,9 @@ const app = Vue.createApp( {
|
|||||||
console.log( err );
|
console.log( err );
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
toggleShowMode() {
|
||||||
|
this.isShowingRemainingTime = !this.isShowingRemainingTime;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
pos() {
|
pos() {
|
||||||
|
|||||||
Reference in New Issue
Block a user