2018-08-11 01:47:10 -04:00
|
|
|
<template>
|
|
|
|
<div id="app">
|
|
|
|
<navbar-top />
|
|
|
|
<vue-progress-bar class="fd-progress-bar" />
|
|
|
|
<transition name="fade">
|
2019-07-06 04:21:37 -04:00
|
|
|
<!-- Setting v-show to true on the router-view tag avoids jumpiness during transitions -->
|
|
|
|
<router-view v-show="true" />
|
2018-08-11 01:47:10 -04:00
|
|
|
</transition>
|
2020-03-15 05:00:16 -04:00
|
|
|
<modal-dialog-remote-pairing :show="pairing_active" @close="pairing_active = false" />
|
2018-08-11 01:47:10 -04:00
|
|
|
<notifications v-show="!show_burger_menu" />
|
2020-04-18 00:57:55 -04:00
|
|
|
<navbar-bottom />
|
2020-05-16 00:29:02 -04:00
|
|
|
<div class="fd-overlay-fullscreen" v-show="show_burger_menu || show_player_menu"
|
2020-04-18 00:57:55 -04:00
|
|
|
@click="show_burger_menu = show_player_menu = false"></div>
|
2018-08-11 01:47:10 -04:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import NavbarTop from '@/components/NavbarTop'
|
|
|
|
import NavbarBottom from '@/components/NavbarBottom'
|
|
|
|
import Notifications from '@/components/Notifications'
|
2020-03-15 05:00:16 -04:00
|
|
|
import ModalDialogRemotePairing from '@/components/ModalDialogRemotePairing'
|
2018-08-11 01:47:10 -04:00
|
|
|
import webapi from '@/webapi'
|
|
|
|
import * as types from '@/store/mutation_types'
|
|
|
|
import ReconnectingWebSocket from 'reconnectingwebsocket'
|
2020-05-11 08:40:52 -04:00
|
|
|
import moment from 'moment'
|
2018-08-11 01:47:10 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
2020-03-15 05:00:16 -04:00
|
|
|
components: { NavbarTop, NavbarBottom, Notifications, ModalDialogRemotePairing },
|
2018-08-11 01:47:10 -04:00
|
|
|
template: '<App/>',
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
2018-10-26 14:14:30 -04:00
|
|
|
token_timer_id: 0,
|
2020-03-15 05:00:16 -04:00
|
|
|
reconnect_attempts: 0,
|
|
|
|
pairing_active: false
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-04-18 00:57:55 -04:00
|
|
|
show_burger_menu: {
|
|
|
|
get () {
|
|
|
|
return this.$store.state.show_burger_menu
|
|
|
|
},
|
|
|
|
set (value) {
|
|
|
|
this.$store.commit(types.SHOW_BURGER_MENU, value)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
show_player_menu: {
|
|
|
|
get () {
|
|
|
|
return this.$store.state.show_player_menu
|
|
|
|
},
|
|
|
|
set (value) {
|
|
|
|
this.$store.commit(types.SHOW_PLAYER_MENU, value)
|
|
|
|
}
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created: function () {
|
2020-05-11 08:40:52 -04:00
|
|
|
moment.locale(navigator.language)
|
2018-08-11 01:47:10 -04:00
|
|
|
this.connect()
|
|
|
|
|
|
|
|
// Start the progress bar on app start
|
|
|
|
this.$Progress.start()
|
|
|
|
|
|
|
|
// Hook the progress bar to start before we move router-view
|
|
|
|
this.$router.beforeEach((to, from, next) => {
|
|
|
|
if (to.meta.show_progress) {
|
|
|
|
if (to.meta.progress !== undefined) {
|
2020-04-11 13:43:53 -04:00
|
|
|
const meta = to.meta.progress
|
2018-08-11 01:47:10 -04:00
|
|
|
this.$Progress.parseMeta(meta)
|
|
|
|
}
|
|
|
|
this.$Progress.start()
|
|
|
|
}
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
|
|
|
// hook the progress bar to finish after we've finished moving router-view
|
|
|
|
this.$router.afterEach((to, from) => {
|
|
|
|
if (to.meta.show_progress) {
|
|
|
|
this.$Progress.finish()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
connect: function () {
|
2021-05-13 10:03:10 -04:00
|
|
|
this.$store.dispatch('add_notification', { text: 'Connecting to OwnTone server', type: 'info', topic: 'connection', timeout: 2000 })
|
2018-08-11 01:47:10 -04:00
|
|
|
|
|
|
|
webapi.config().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_CONFIG, data)
|
|
|
|
this.$store.commit(types.HIDE_SINGLES, data.hide_singles)
|
|
|
|
document.title = data.library_name
|
|
|
|
|
|
|
|
this.open_ws()
|
|
|
|
this.$Progress.finish()
|
|
|
|
}).catch(() => {
|
2021-05-13 10:03:10 -04:00
|
|
|
this.$store.dispatch('add_notification', { text: 'Failed to connect to OwnTone server', type: 'danger', topic: 'connection' })
|
2018-08-11 01:47:10 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
open_ws: function () {
|
|
|
|
if (this.$store.state.config.websocket_port <= 0) {
|
|
|
|
this.$store.dispatch('add_notification', { text: 'Missing websocket port', type: 'danger' })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const vm = this
|
|
|
|
|
2021-01-10 01:51:50 -05:00
|
|
|
let protocol = 'ws://'
|
2019-01-15 13:46:37 -05:00
|
|
|
if (window.location.protocol === 'https:') {
|
|
|
|
protocol = 'wss://'
|
|
|
|
}
|
|
|
|
|
2021-01-10 01:51:50 -05:00
|
|
|
let wsUrl = protocol + window.location.hostname + ':' + vm.$store.state.config.websocket_port
|
2020-05-02 02:43:10 -04:00
|
|
|
if (process.env.NODE_ENV === 'development' && process.env.VUE_APP_WEBSOCKET_SERVER) {
|
|
|
|
// If we are running in the development server, use the websocket url configured in .env.development
|
|
|
|
wsUrl = process.env.VUE_APP_WEBSOCKET_SERVER
|
|
|
|
}
|
|
|
|
|
2021-01-10 01:51:50 -05:00
|
|
|
const socket = new ReconnectingWebSocket(
|
2020-05-02 02:43:10 -04:00
|
|
|
wsUrl,
|
2018-08-11 01:47:10 -04:00
|
|
|
'notify',
|
2018-10-26 14:14:30 -04:00
|
|
|
{ reconnectInterval: 3000 }
|
2018-08-11 01:47:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
socket.onopen = function () {
|
|
|
|
vm.$store.dispatch('add_notification', { text: 'Connection to server established', type: 'primary', topic: 'connection', timeout: 2000 })
|
2018-10-26 14:14:30 -04:00
|
|
|
vm.reconnect_attempts = 0
|
2021-05-13 16:54:11 -04:00
|
|
|
socket.send(JSON.stringify({ notify: ['update', 'database', 'player', 'options', 'outputs', 'volume', 'queue', 'spotify', 'lastfm', 'pairing'] }))
|
2018-08-11 01:47:10 -04:00
|
|
|
|
|
|
|
vm.update_outputs()
|
|
|
|
vm.update_player_status()
|
|
|
|
vm.update_library_stats()
|
2019-07-07 02:22:56 -04:00
|
|
|
vm.update_settings()
|
2018-08-11 01:47:10 -04:00
|
|
|
vm.update_queue()
|
|
|
|
vm.update_spotify()
|
2020-01-04 12:53:27 -05:00
|
|
|
vm.update_lastfm()
|
|
|
|
vm.update_pairing()
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
socket.onclose = function () {
|
|
|
|
// vm.$store.dispatch('add_notification', { text: 'Connection closed', type: 'danger', timeout: 2000 })
|
|
|
|
}
|
|
|
|
socket.onerror = function () {
|
2018-10-26 14:14:30 -04:00
|
|
|
vm.reconnect_attempts++
|
|
|
|
vm.$store.dispatch('add_notification', { text: 'Connection lost. Reconnecting ... (' + vm.reconnect_attempts + ')', type: 'danger', topic: 'connection' })
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
socket.onmessage = function (response) {
|
2021-01-10 01:51:50 -05:00
|
|
|
const data = JSON.parse(response.data)
|
2018-12-30 03:14:23 -05:00
|
|
|
if (data.notify.includes('update') || data.notify.includes('database')) {
|
2018-08-11 01:47:10 -04:00
|
|
|
vm.update_library_stats()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('player') || data.notify.includes('options') || data.notify.includes('volume')) {
|
|
|
|
vm.update_player_status()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('outputs') || data.notify.includes('volume')) {
|
|
|
|
vm.update_outputs()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('queue')) {
|
|
|
|
vm.update_queue()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('spotify')) {
|
|
|
|
vm.update_spotify()
|
|
|
|
}
|
2020-01-04 12:53:27 -05:00
|
|
|
if (data.notify.includes('lastfm')) {
|
|
|
|
vm.update_lastfm()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('pairing')) {
|
|
|
|
vm.update_pairing()
|
|
|
|
}
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
update_library_stats: function () {
|
|
|
|
webapi.library_stats().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_STATS, data)
|
|
|
|
})
|
|
|
|
webapi.library_count('media_kind is audiobook').then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_AUDIOBOOKS_COUNT, data)
|
|
|
|
})
|
|
|
|
webapi.library_count('media_kind is podcast').then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_PODCASTS_COUNT, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
update_outputs: function () {
|
|
|
|
webapi.outputs().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_OUTPUTS, data.outputs)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
update_player_status: function () {
|
|
|
|
webapi.player_status().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_PLAYER_STATUS, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
update_queue: function () {
|
|
|
|
webapi.queue().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_QUEUE, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2019-07-07 02:22:56 -04:00
|
|
|
update_settings: function () {
|
|
|
|
webapi.settings().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_SETTINGS, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-01-04 12:53:27 -05:00
|
|
|
update_lastfm: function () {
|
|
|
|
webapi.lastfm().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LASTFM, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2018-08-11 01:47:10 -04:00
|
|
|
update_spotify: function () {
|
|
|
|
webapi.spotify().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_SPOTIFY, data)
|
|
|
|
|
|
|
|
if (this.token_timer_id > 0) {
|
|
|
|
window.clearTimeout(this.token_timer_id)
|
|
|
|
this.token_timer_id = 0
|
|
|
|
}
|
|
|
|
if (data.webapi_token_expires_in > 0 && data.webapi_token) {
|
|
|
|
this.token_timer_id = window.setTimeout(this.update_spotify, 1000 * data.webapi_token_expires_in)
|
|
|
|
}
|
|
|
|
})
|
2020-01-04 12:53:27 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
update_pairing: function () {
|
|
|
|
webapi.pairing().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_PAIRING, data)
|
2020-03-15 05:00:16 -04:00
|
|
|
this.pairing_active = data.active
|
2020-01-04 12:53:27 -05:00
|
|
|
})
|
2020-04-18 00:57:55 -04:00
|
|
|
},
|
2018-08-11 01:47:10 -04:00
|
|
|
|
2020-04-18 00:57:55 -04:00
|
|
|
update_is_clipped: function () {
|
|
|
|
if (this.show_burger_menu || this.show_player_menu) {
|
2018-08-11 01:47:10 -04:00
|
|
|
document.querySelector('html').classList.add('is-clipped')
|
|
|
|
} else {
|
|
|
|
document.querySelector('html').classList.remove('is-clipped')
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 00:57:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
'show_burger_menu' () {
|
|
|
|
this.update_is_clipped()
|
|
|
|
},
|
|
|
|
'show_player_menu' () {
|
|
|
|
this.update_is_clipped()
|
|
|
|
}
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
</style>
|