Files
enigFM/frontend/src/stores/player.js
mamonov.ep f77a453158 Add global mini-player and improve configuration
- Add global activeRoom store for persistent WebSocket connection
- Add MiniPlayer component for playback controls across pages
- Add chunked S3 streaming with 64KB chunks and Range support
- Add queue item removal button
- Move DB credentials to environment variables
- Update .env.example with DB configuration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-12 15:02:02 +03:00

81 lines
1.5 KiB
JavaScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
export const usePlayerStore = defineStore('player', () => {
const isPlaying = ref(false)
const currentTrack = ref(null)
const currentTrackUrl = ref(null)
const position = ref(0)
const duration = ref(0)
const volume = ref(100)
function setPlayerState(state) {
isPlaying.value = state.is_playing
position.value = state.position
if (state.current_track_id) {
currentTrack.value = { id: state.current_track_id }
}
if (state.track_url) {
currentTrackUrl.value = state.track_url
}
}
function setTrack(track, url) {
currentTrack.value = track
currentTrackUrl.value = url
position.value = 0
}
function setPosition(pos) {
position.value = pos
}
function setDuration(dur) {
duration.value = dur
}
function setVolume(vol) {
volume.value = vol
localStorage.setItem('volume', vol)
}
function play() {
isPlaying.value = true
}
function pause() {
isPlaying.value = false
}
function reset() {
isPlaying.value = false
currentTrack.value = null
currentTrackUrl.value = null
position.value = 0
duration.value = 0
}
// Load saved volume
const savedVolume = localStorage.getItem('volume')
if (savedVolume) {
volume.value = parseInt(savedVolume)
}
return {
isPlaying,
currentTrack,
currentTrackUrl,
position,
duration,
volume,
setPlayerState,
setTrack,
setPosition,
setDuration,
setVolume,
play,
pause,
reset,
}
})