mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 04:54: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.flushHeaders();
|
||||
let det = { 'type': 'basics', 'data': currentDetails };
|
||||
let det = { 'type': 'basics', 'data': connectedClients };
|
||||
res.write( `data: ${ JSON.stringify( det ) }\n\n` );
|
||||
connectedMain = res;
|
||||
} 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 ) => {
|
||||
if ( req.params.status === 'disconnect' ) {
|
||||
|
||||
} else if ( req.params.status === 'fullScreenExit' ) {
|
||||
|
||||
} else if ( req.params.status === 'inactive' ) {
|
||||
|
||||
} else if ( req.params.status === 'reactivated' ) {
|
||||
|
||||
if ( allowedTypes.includes( req.body.type ) ) {
|
||||
const ipRetrieved = req.headers[ 'x-forwarded-for' ];
|
||||
const ip = ipRetrieved ? ipRetrieved.split( /, / )[ 0 ] : req.connection.remoteAddress;
|
||||
sendClientUpdate( req.body.type, req.body.data, ip );
|
||||
res.send( 'ok' );
|
||||
} else {
|
||||
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 ) => {
|
||||
if ( req.query.dir ) {
|
||||
indexer.index( req ).then( dirIndex => {
|
||||
|
||||
@@ -88,6 +88,17 @@ const app = Vue.createApp( {
|
||||
setTimeout( () => {
|
||||
this.sendUpdate( 'pos' );
|
||||
}, 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 );
|
||||
@@ -405,6 +416,9 @@ const app = Vue.createApp( {
|
||||
console.log( err );
|
||||
} );
|
||||
},
|
||||
toggleShowMode() {
|
||||
this.isShowingRemainingTime = !this.isShowingRemainingTime;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
pos() {
|
||||
|
||||
Reference in New Issue
Block a user