Skip to content
Snippets Groups Projects
Select Git revision
  • fix-index.html-encoding
  • develop default protected
  • document-loglevel
  • master
  • 1.0.1
  • 1121-download
  • plugins-v3
  • 876-http-signature
  • plugins-v2
  • plugins
  • 1.0.1
  • 1.0
  • 1.0-rc1
  • 0.21.2
  • 0.21.1
  • 0.21
  • 0.21-rc2
  • 0.21-rc1
  • 0.20.1
  • 0.20.0
  • 0.20.0-rc1
  • 0.19.1
  • 0.19.0
  • 0.19.0-rc2
  • 0.19.0-rc1
  • 0.18.3
  • 0.18.2
  • 0.18.1
  • 0.18
  • 0.17
30 results

radios.js

Blame
  • Forked from funkwhale / funkwhale
    3953 commits behind the upstream repository.
    radios.js 1.59 KiB
    import axios from "axios"
    import logger from '@/logging'
    
    // import axios from 'axios'
    
    const RADIOS = {
      // some radios are client side only, so we have to implement the populateQueue
      // method by hand
      account: {
        offset: 1,
        populateQueue({current, dispatch, playNow}) {
          let params = {scope: `actor:${current.objectId.fullUsername}`, ordering: '-creation_date', page_size: 1, page: this.offset}
          axios.get('history/listenings', {params}).then((response) => {
            let latest = response.data.results[0]
            if (!latest) {
              logger.default.error('No more tracks')
              dispatch('stop')
            }
            this.offset += 1
            let append = dispatch('queue/append', {track: latest.track}, {root: true})
            if (playNow) {
              append.then(() => {
                dispatch('queue/last', null, {root: true})
              })
            }
          }, (error) => {
            logger.default.error('Error while fetching listenings', error)
            dispatch('stop')
          })
        },
        stop () {
          this.offset = 1
        },
        handleListen (current, event, store) {
          // XXX: handle actors from other pods
          if (event.actor.local_id === current.objectId.username) {
            axios.get(`tracks/${event.object.local_id}`).then((response) => {
              if (response.data.uploads.length > 0) {
                store.dispatch('queue/append', {track: response.data})
                this.offset += 1
              }
            }, (error) => {
              logger.default.error('Cannot retrieve track info', error)
            })
          }
        }
      }
    }
    export function getClientOnlyRadio({type}) {
      return RADIOS[type]
    }