2020-02-04 05:26:54 -09:00
|
|
|
import 'react-jinke-music-player/assets/index.css'
|
2020-02-07 08:36:26 -09:00
|
|
|
import { subsonicUrl } from '../subsonic'
|
2020-02-04 05:26:54 -09:00
|
|
|
|
|
|
|
|
const PLAYER_ADD_TRACK = 'PLAYER_ADD_TRACK'
|
|
|
|
|
const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
|
|
|
|
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
2020-02-05 06:11:42 -09:00
|
|
|
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
|
2020-02-04 05:26:54 -09:00
|
|
|
|
|
|
|
|
const mapToAudioLists = (item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
name: item.title,
|
|
|
|
|
singer: item.artist,
|
2020-02-07 12:51:14 -09:00
|
|
|
cover: subsonicUrl('getCoverArt', item.id, 'size=300'),
|
2020-02-06 16:37:31 -09:00
|
|
|
musicSrc: subsonicUrl('stream', item.id),
|
|
|
|
|
scrobble: (submit) => subsonicUrl('scrobble', item.id, `submission=${submit}`)
|
2020-02-04 05:26:54 -09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const addTrack = (data) => ({
|
|
|
|
|
type: PLAYER_ADD_TRACK,
|
|
|
|
|
data
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const setTrack = (data) => ({
|
|
|
|
|
type: PLAYER_SET_TRACK,
|
|
|
|
|
data
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const syncQueue = (data) => ({
|
|
|
|
|
type: PLAYER_SYNC_QUEUE,
|
|
|
|
|
data
|
|
|
|
|
})
|
|
|
|
|
|
2020-02-05 14:16:00 -09:00
|
|
|
const scrobble = (id) => ({
|
2020-02-05 06:11:42 -09:00
|
|
|
type: PLAYER_SCROBBLE,
|
2020-02-05 14:16:00 -09:00
|
|
|
data: id
|
2020-02-05 06:11:42 -09:00
|
|
|
})
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const playQueueReducer = (
|
|
|
|
|
previousState = { queue: [], clear: true },
|
|
|
|
|
{ type, data }
|
|
|
|
|
) => {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case PLAYER_ADD_TRACK:
|
|
|
|
|
const queue = previousState.queue
|
|
|
|
|
queue.push(mapToAudioLists(data))
|
|
|
|
|
return { queue, clear: false }
|
|
|
|
|
case PLAYER_SET_TRACK:
|
|
|
|
|
return { queue: [mapToAudioLists(data)], clear: true }
|
|
|
|
|
case PLAYER_SYNC_QUEUE:
|
|
|
|
|
return { queue: data, clear: false }
|
2020-02-05 06:11:42 -09:00
|
|
|
case PLAYER_SCROBBLE:
|
|
|
|
|
const newQueue = previousState.queue.map((item) => {
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
2020-02-06 08:54:27 -09:00
|
|
|
scrobbled: item.scrobbled || item.id === data
|
2020-02-05 06:11:42 -09:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return { queue: newQueue, clear: false }
|
2020-02-04 05:26:54 -09:00
|
|
|
default:
|
|
|
|
|
return previousState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 14:16:00 -09:00
|
|
|
export { addTrack, setTrack, syncQueue, scrobble, playQueueReducer }
|