some small updates

This commit is contained in:
2024-06-28 15:27:11 +02:00
parent 7a42ab8b4e
commit f314732f3f
4 changed files with 59 additions and 40 deletions

View File

@@ -99,11 +99,11 @@
if ( isPlaying.value ) { if ( isPlaying.value ) {
player.control( 'play' ); player.control( 'play' );
startProgressTracker(); startProgressTracker();
} else { } else {
player.control( 'pause' ); player.control( 'pause' );
stopProgressTracker(); stopProgressTracker();
} }
notificationHandler.emit( 'playback', isPlaying.value );
} }
const toggleRemaining = () => { const toggleRemaining = () => {
@@ -115,10 +115,12 @@
isPlaying.value = false; isPlaying.value = false;
player.control( 'pause' ); player.control( 'pause' );
stopProgressTracker(); stopProgressTracker();
notificationHandler.emit( 'playback', isPlaying.value );
} else if ( action === 'play' ) { } else if ( action === 'play' ) {
isPlaying.value = true; isPlaying.value = true;
player.control( 'play' ); player.control( 'play' );
startProgressTracker(); startProgressTracker();
notificationHandler.emit( 'playback', isPlaying.value );
} else if ( action === 'repeat' ) { } else if ( action === 'repeat' ) {
if ( repeatMode.value === '' ) { if ( repeatMode.value === '' ) {
repeatMode.value = '_on'; repeatMode.value = '_on';
@@ -135,18 +137,30 @@
shuffleMode.value = '_on'; shuffleMode.value = '_on';
player.setShuffle( true ); player.setShuffle( true );
getDetails(); getDetails();
notificationHandler.emit( 'playlist', playlist.value );
} else { } else {
shuffleMode.value = ''; shuffleMode.value = '';
player.setShuffle( false ); player.setShuffle( false );
getDetails(); getDetails();
notificationHandler.emit( 'playlist', playlist.value );
} }
getDetails(); getDetails();
} else if ( action === 'forward' ) { } else if ( action === 'forward' ) {
clickCountForward.value += 1; clickCountForward.value += 1;
player.control( 'skip-10' ); if( player.control( 'skip-10' ) ) {
setTimeout( () => {
startProgressTracker();
getDetails();
}, 2000 );
}
} else if ( action === 'back' ) { } else if ( action === 'back' ) {
clickCountBack.value += 1; clickCountBack.value += 1;
player.control( 'back-10' ); if( player.control( 'back-10' ) ) {
setTimeout( () => {
startProgressTracker();
getDetails();
}, 2000 );
}
} else if ( action === 'next' ) { } else if ( action === 'next' ) {
stopProgressTracker(); stopProgressTracker();
player.control( 'next' ); player.control( 'next' );
@@ -170,6 +184,10 @@
} else if ( action === 'start-share' ) { } else if ( action === 'start-share' ) {
// TODO: Open popup, then send data with popup returns // TODO: Open popup, then send data with popup returns
notificationHandler.connect( 'test' ); notificationHandler.connect( 'test' );
} else if ( action === 'stop-share' ) {
if ( confirm( 'Do you really want to stop sharing?' ) ) {
notificationHandler.disconnect();
}
} }
} }
@@ -215,6 +233,8 @@
setTimeout( () => { setTimeout( () => {
startProgressTracker(); startProgressTracker();
getDetails(); getDetails();
notificationHandler.emit( 'playlist', playlist.value );
// TODO: Add playback-start emit as well. For every time elapsed before starting to play current section, move start time back
}, 2000 ); }, 2000 );
} ); } );
} }
@@ -330,6 +350,9 @@
} }
if ( pos.value > 0 && !hasStarted ) { if ( pos.value > 0 && !hasStarted ) {
notificationHandler.emit( 'playlist-index', currentlyPlayingSongIndex.value );
notificationHandler.emit( 'playback', isPlaying.value );
notificationHandler.emit( 'playback-start', new Date().getTime() - pos.value * 1000 );
hasStarted = true; hasStarted = true;
} }

View File

@@ -83,7 +83,7 @@ class NotificationHandler {
*/ */
disconnect (): void { disconnect (): void {
this.socket.disconnect(); this.socket.disconnect();
this.socket.emit( 'create-room', { this.socket.emit( 'delete-room', {
name: this.roomName, name: this.roomName,
token: this.roomToken token: this.roomToken
}, ( res: { status: boolean, msg: string } ) => { }, ( res: { status: boolean, msg: string } ) => {

View File

@@ -61,7 +61,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Song } from '@/scripts/song'; import type { Song } from '@/scripts/song';
import { ref, type Ref } from 'vue'; import { computed, ref, type Ref } from 'vue';
import { ColorThief } from 'colorthief'; import { ColorThief } from 'colorthief';
const hasLoaded = ref( false ); const hasLoaded = ref( false );
@@ -75,46 +75,42 @@
const visualizationSettings = ref( 'mic' ); const visualizationSettings = ref( 'mic' );
const micAnalyzer = ref( 0 ); const micAnalyzer = ref( 0 );
const beatDetected = ref( false ); const beatDetected = ref( false );
colorThief: null, const colorThief = new ColorThief();
lastDispatch: new Date().getTime() - 5000, const songQueue = computed( () => {
isReconnecting: false, let ret = [];
computed: { let pos = 0;
songQueue() { for ( let song in songs.value ) {
let ret = []; if ( pos >= playingSong.value ) {
let pos = 0; ret.push( songs.value[ song ] );
for ( let song in this.songs ) {
if ( pos >= this.queuePos ) {
ret.push( this.songs[ song ] );
}
pos += 1;
} }
return ret; pos += 1;
}, }
getTimeUntil() { return ret;
return ( song ) => { } );
let timeRemaining = 0; const getTimeUntil = computed( () => {
for ( let i = this.queuePos; i < Object.keys( this.songs ).length - 1; i++ ) { return ( song ) => {
if ( this.songs[ i ] == song ) { let timeRemaining = 0;
break; for ( let i = this.queuePos; i < Object.keys( this.songs ).length - 1; i++ ) {
} if ( this.songs[ i ] == song ) {
timeRemaining += parseInt( this.songs[ i ].duration ); break;
} }
if ( this.isPlaying ) { timeRemaining += parseInt( this.songs[ i ].duration );
if ( timeRemaining === 0 ) { }
return 'Currently playing'; if ( isPlaying.value ) {
} else { if ( timeRemaining === 0 ) {
return 'Playing in less than ' + Math.ceil( timeRemaining / 60 - this.pos / 60 ) + 'min'; return 'Currently playing';
}
} else { } else {
if ( timeRemaining === 0 ) { return 'Playing in less than ' + Math.ceil( timeRemaining / 60 - this.pos / 60 ) + 'min';
return 'Plays next'; }
} else { } else {
return 'Playing less than ' + Math.ceil( timeRemaining / 60 - this.pos / 60 ) + 'min after starting to play'; if ( timeRemaining === 0 ) {
} return 'Plays next';
} else {
return 'Playing less than ' + Math.ceil( timeRemaining / 60 - this.pos / 60 ) + 'min after starting to play';
} }
} }
} }
}, } );
methods: { methods: {
startTimeTracker () { startTimeTracker () {
this.timeTracker = setInterval( () => { this.timeTracker = setInterval( () => {

View File

@@ -12,7 +12,7 @@ const fs = require( 'fs' );
const path = require( 'path' ); const path = require( 'path' );
// TODO: deploy non-secret version // TODO: deploy non-secret version
const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/config/apple-music-api.config.json' ) ) ); const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/config/apple-music-api.config.secret.json' ) ) );
const music = new MusicKit( { const music = new MusicKit( {
key: fs.readFileSync( path.join( __dirname + '/config/apple_private_key.p8' ) ).toString(), key: fs.readFileSync( path.join( __dirname + '/config/apple_private_key.p8' ) ).toString(),