2021-09-01 20:07:11 -05:00
|
|
|
<template>
|
2021-12-31 16:57:53 -06:00
|
|
|
<div class="w-full layout-wrapper bg-bg text-white">
|
2021-09-01 20:07:11 -05:00
|
|
|
<app-appbar />
|
2021-12-31 16:57:53 -06:00
|
|
|
<div id="content" class="overflow-hidden relative" :class="playerIsOpen ? 'playerOpen' : ''">
|
2021-09-01 20:07:11 -05:00
|
|
|
<Nuxt />
|
|
|
|
</div>
|
2021-11-01 21:06:51 -05:00
|
|
|
<app-audio-player-container ref="streamContainer" />
|
2021-10-06 07:24:15 -05:00
|
|
|
<modals-libraries-modal />
|
2021-11-14 19:59:34 -06:00
|
|
|
<app-side-drawer />
|
2021-10-17 20:20:00 -05:00
|
|
|
<readers-reader />
|
2021-09-01 20:07:11 -05:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-09-12 18:37:08 -05:00
|
|
|
import { Capacitor } from '@capacitor/core'
|
2021-09-04 12:31:00 -05:00
|
|
|
import { AppUpdate } from '@robingenz/capacitor-app-update'
|
2021-09-12 18:37:08 -05:00
|
|
|
import AudioDownloader from '@/plugins/audio-downloader'
|
2021-10-28 09:37:31 -05:00
|
|
|
import StorageManager from '@/plugins/storage-manager'
|
2021-09-04 12:31:00 -05:00
|
|
|
|
2021-09-01 20:07:11 -05:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
2021-11-14 19:59:34 -06:00
|
|
|
watch: {
|
|
|
|
networkConnected: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.attemptConnection()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-09-01 20:07:11 -05:00
|
|
|
computed: {
|
2021-09-12 18:37:08 -05:00
|
|
|
playerIsOpen() {
|
|
|
|
return this.$store.getters['playerIsOpen']
|
2021-09-01 20:07:11 -05:00
|
|
|
},
|
|
|
|
routeName() {
|
|
|
|
return this.$route.name
|
2021-11-14 19:59:34 -06:00
|
|
|
},
|
|
|
|
networkConnected() {
|
|
|
|
return this.$store.state.networkConnected
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
|
|
|
isSocketConnected() {
|
|
|
|
return this.$store.state.socketConnected
|
2021-09-01 20:07:11 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-06 07:24:15 -05:00
|
|
|
async connected(isConnected) {
|
2021-10-25 21:13:10 -05:00
|
|
|
if (isConnected) {
|
2021-11-19 20:00:34 -06:00
|
|
|
console.log('[Default] Connected socket sync user ab data')
|
2022-03-23 17:59:14 -05:00
|
|
|
// this.$store.dispatch('user/syncUserAudiobookData')
|
2021-10-06 07:24:15 -05:00
|
|
|
|
2021-12-05 18:31:47 -06:00
|
|
|
this.initSocketListeners()
|
|
|
|
|
2021-10-25 21:13:10 -05:00
|
|
|
// Load libraries
|
2022-01-16 14:14:02 -06:00
|
|
|
await this.$store.dispatch('libraries/load')
|
|
|
|
this.$eventBus.$emit('library-changed')
|
2021-12-04 19:56:29 -06:00
|
|
|
this.$store.dispatch('libraries/fetch', this.currentLibraryId)
|
2021-12-05 18:31:47 -06:00
|
|
|
} else {
|
|
|
|
this.removeSocketListeners()
|
2021-10-25 21:13:10 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
socketConnectionFailed(err) {
|
|
|
|
this.$toast.error('Socket connection error: ' + err.message)
|
2021-09-12 18:37:08 -05:00
|
|
|
},
|
2021-10-25 21:13:10 -05:00
|
|
|
currentUserAudiobookUpdate({ id, data }) {
|
|
|
|
if (data) {
|
2021-11-02 19:44:42 -05:00
|
|
|
console.log(`Current User Audiobook Updated ${id} ${JSON.stringify(data)}`)
|
2021-11-19 20:00:34 -06:00
|
|
|
this.$sqlStore.setUserAudiobookData(data)
|
2021-10-25 21:13:10 -05:00
|
|
|
} else {
|
2021-11-19 20:00:34 -06:00
|
|
|
this.$sqlStore.removeUserAudiobookData(id)
|
2021-10-25 21:13:10 -05:00
|
|
|
}
|
|
|
|
},
|
2021-09-01 20:07:11 -05:00
|
|
|
initialStream(stream) {
|
|
|
|
if (this.$refs.streamContainer && this.$refs.streamContainer.audioPlayerReady) {
|
|
|
|
this.$refs.streamContainer.streamOpen(stream)
|
|
|
|
}
|
2021-09-02 12:19:26 -05:00
|
|
|
},
|
2021-09-04 12:31:00 -05:00
|
|
|
async clickUpdateToast() {
|
|
|
|
var immediateUpdateAllowed = this.$store.state.appUpdateInfo.immediateUpdateAllowed
|
|
|
|
if (immediateUpdateAllowed) {
|
|
|
|
await AppUpdate.performImmediateUpdate()
|
2021-09-02 12:19:26 -05:00
|
|
|
} else {
|
2021-09-04 12:31:00 -05:00
|
|
|
await AppUpdate.openAppStore()
|
2021-09-02 12:19:26 -05:00
|
|
|
}
|
|
|
|
},
|
2021-09-04 12:31:00 -05:00
|
|
|
async checkForUpdate() {
|
2021-10-16 10:08:13 -05:00
|
|
|
console.log('Checking for app update')
|
2021-09-04 12:31:00 -05:00
|
|
|
const result = await AppUpdate.getAppUpdateInfo()
|
|
|
|
if (!result) {
|
|
|
|
console.error('Invalid version check')
|
2021-09-02 12:19:26 -05:00
|
|
|
return
|
|
|
|
}
|
2021-10-16 10:08:13 -05:00
|
|
|
console.log('App Update Info', JSON.stringify(result))
|
2021-09-04 12:31:00 -05:00
|
|
|
this.$store.commit('setAppUpdateInfo', result)
|
2021-09-12 18:37:08 -05:00
|
|
|
if (result.updateAvailability === 2) {
|
|
|
|
setTimeout(() => {
|
2021-09-19 18:44:10 -05:00
|
|
|
this.$toast.info(`Update is available! Click to update.`, {
|
2021-09-12 18:37:08 -05:00
|
|
|
draggable: false,
|
|
|
|
hideProgressBar: false,
|
2021-09-19 18:44:10 -05:00
|
|
|
timeout: 20000,
|
|
|
|
closeButton: true,
|
|
|
|
onClick: this.clickUpdateToast
|
2021-09-12 18:37:08 -05:00
|
|
|
})
|
|
|
|
}, 5000)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onDownloadProgress(data) {
|
|
|
|
var progress = data.progress
|
2021-09-19 18:44:10 -05:00
|
|
|
var audiobookId = data.audiobookId
|
2021-09-04 12:31:00 -05:00
|
|
|
|
2021-09-12 18:37:08 -05:00
|
|
|
var downloadObj = this.$store.getters['downloads/getDownload'](audiobookId)
|
|
|
|
if (downloadObj) {
|
|
|
|
this.$toast.update(downloadObj.toastId, { content: `${progress}% Downloading ${downloadObj.audiobook.book.title}` })
|
|
|
|
}
|
|
|
|
},
|
2021-09-19 18:44:10 -05:00
|
|
|
onDownloadFailed(data) {
|
|
|
|
if (!data.audiobookId) {
|
|
|
|
console.error('Download failed invalid audiobook id', data)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var downloadObj = this.$store.getters['downloads/getDownload'](data.audiobookId)
|
|
|
|
if (!downloadObj) {
|
|
|
|
console.error('Failed to find download for audiobook', data.audiobookId)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var message = data.error || 'Unknown Error'
|
|
|
|
this.$toast.update(downloadObj.toastId, { content: `Failed. ${message}.`, options: { timeout: 5000, type: 'error' } }, true)
|
|
|
|
this.$store.commit('downloads/removeDownload', downloadObj)
|
|
|
|
},
|
2021-09-12 18:37:08 -05:00
|
|
|
onDownloadComplete(data) {
|
2021-09-19 18:44:10 -05:00
|
|
|
if (!data.audiobookId) {
|
|
|
|
console.error('Download compelte invalid audiobook id', data)
|
|
|
|
return
|
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
var downloadId = data.downloadId
|
|
|
|
var contentUrl = data.contentUrl
|
2021-09-19 18:44:10 -05:00
|
|
|
var folderUrl = data.folderUrl
|
|
|
|
var folderName = data.folderName
|
|
|
|
var storageId = data.storageId
|
|
|
|
var storageType = data.storageType
|
|
|
|
var simplePath = data.simplePath
|
2021-09-12 18:37:08 -05:00
|
|
|
var filename = data.filename
|
2021-09-19 18:44:10 -05:00
|
|
|
var audiobookId = data.audiobookId
|
|
|
|
var size = data.size || 0
|
|
|
|
var isCover = !!data.isCover
|
|
|
|
|
2021-10-18 19:40:05 -05:00
|
|
|
console.log(`Download complete "${contentUrl}" | ${filename} | DlId: ${downloadId} | Is Cover? ${isCover}`)
|
2021-09-19 18:44:10 -05:00
|
|
|
var downloadObj = this.$store.getters['downloads/getDownload'](audiobookId)
|
|
|
|
if (!downloadObj) {
|
|
|
|
console.error('Failed to find download for audiobook', audiobookId)
|
|
|
|
return
|
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
|
2021-09-19 18:44:10 -05:00
|
|
|
if (!isCover) {
|
2021-09-12 18:37:08 -05:00
|
|
|
// Notify server to remove prepared download
|
|
|
|
if (this.$server.socket) {
|
2021-09-16 19:58:04 -05:00
|
|
|
this.$server.socket.emit('remove_download', audiobookId)
|
2021-09-12 18:37:08 -05:00
|
|
|
}
|
|
|
|
|
2021-09-19 18:44:10 -05:00
|
|
|
this.$toast.update(downloadObj.toastId, { content: `Success! ${downloadObj.audiobook.book.title} downloaded.`, options: { timeout: 5000, type: 'success' } }, true)
|
2021-09-12 18:37:08 -05:00
|
|
|
|
2021-09-19 18:44:10 -05:00
|
|
|
delete downloadObj.isDownloading
|
|
|
|
delete downloadObj.isPreparing
|
|
|
|
downloadObj.contentUrl = contentUrl
|
|
|
|
downloadObj.simplePath = simplePath
|
|
|
|
downloadObj.folderUrl = folderUrl
|
|
|
|
downloadObj.folderName = folderName
|
|
|
|
downloadObj.storageType = storageType
|
|
|
|
downloadObj.storageId = storageId
|
|
|
|
downloadObj.basePath = data.basePath || null
|
|
|
|
downloadObj.size = size
|
|
|
|
this.$store.commit('downloads/addUpdateDownload', downloadObj)
|
|
|
|
} else {
|
|
|
|
downloadObj.coverUrl = contentUrl
|
|
|
|
downloadObj.cover = Capacitor.convertFileSrc(contentUrl)
|
|
|
|
downloadObj.coverSize = size
|
|
|
|
downloadObj.coverBasePath = data.basePath || null
|
|
|
|
console.log('Updating download with cover', downloadObj.cover)
|
|
|
|
this.$store.commit('downloads/addUpdateDownload', downloadObj)
|
2021-09-12 18:37:08 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
async checkLoadCurrent() {
|
|
|
|
var currentObj = await this.$localStore.getCurrent()
|
|
|
|
if (!currentObj) return
|
|
|
|
|
|
|
|
console.log('Has Current playing', currentObj.audiobookId)
|
|
|
|
var download = this.$store.getters['downloads/getDownload'](currentObj.audiobookId)
|
|
|
|
if (download) {
|
|
|
|
this.$store.commit('setPlayingDownload', download)
|
|
|
|
} else {
|
|
|
|
console.warn('Download not available for previous current playing', currentObj.audiobookId)
|
|
|
|
this.$localStore.setCurrent(null)
|
|
|
|
}
|
|
|
|
},
|
2021-10-28 09:37:31 -05:00
|
|
|
async searchFolder(downloadFolder) {
|
|
|
|
try {
|
|
|
|
var response = await StorageManager.searchFolder({ folderUrl: downloadFolder.uri })
|
|
|
|
var searchResults = response
|
|
|
|
searchResults.folders = JSON.parse(searchResults.folders)
|
|
|
|
searchResults.files = JSON.parse(searchResults.files)
|
|
|
|
|
|
|
|
console.log('Search folders results length', searchResults.folders.length)
|
|
|
|
searchResults.folders = searchResults.folders.map((sr) => {
|
|
|
|
if (sr.files) {
|
|
|
|
sr.files = JSON.parse(sr.files)
|
|
|
|
}
|
|
|
|
return sr
|
|
|
|
})
|
|
|
|
|
|
|
|
return searchResults
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.$toast.error('Failed to search downloads folder')
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async syncDownloads(downloads, downloadFolder) {
|
|
|
|
console.log('Syncing downloads ' + downloads.length)
|
|
|
|
var mediaScanResults = await this.searchFolder(downloadFolder)
|
|
|
|
|
2021-11-20 10:59:34 -06:00
|
|
|
this.$store.commit('downloads/setMediaScanResults', mediaScanResults)
|
2021-10-28 09:37:31 -05:00
|
|
|
|
|
|
|
// Filter out media folders without any audio files
|
|
|
|
var mediaFolders = mediaScanResults.folders.filter((sr) => {
|
|
|
|
if (!sr.files) return false
|
|
|
|
var audioFiles = sr.files.filter((mf) => !!mf.isAudio)
|
|
|
|
return audioFiles.length
|
2021-09-12 18:37:08 -05:00
|
|
|
})
|
|
|
|
|
2021-10-28 09:37:31 -05:00
|
|
|
downloads.forEach((download) => {
|
|
|
|
var mediaFolder = mediaFolders.find((mf) => mf.name === download.folderName)
|
|
|
|
if (mediaFolder) {
|
|
|
|
console.log('Found download ' + download.folderName)
|
2021-12-04 19:56:29 -06:00
|
|
|
if (download.isMissing) {
|
|
|
|
download.isMissing = false
|
|
|
|
this.$store.commit('downloads/addUpdateDownload', download)
|
2021-10-28 09:37:31 -05:00
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
} else {
|
2021-10-28 09:37:31 -05:00
|
|
|
console.error('Download not found ' + download.folderName)
|
2021-12-04 19:56:29 -06:00
|
|
|
if (!download.isMissing) {
|
|
|
|
download.isMissing = true
|
|
|
|
this.$store.commit('downloads/addUpdateDownload', download)
|
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
}
|
2021-10-28 09:37:31 -05:00
|
|
|
})
|
2021-12-04 19:56:29 -06:00
|
|
|
|
|
|
|
// Match media scanned folders with books from server
|
|
|
|
if (this.isSocketConnected) {
|
|
|
|
await this.$store.dispatch('downloads/linkOrphanDownloads')
|
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
},
|
2022-04-02 19:43:43 -05:00
|
|
|
onItemDownloadUpdate(data) {
|
|
|
|
console.log('ON ITEM DOWNLOAD UPDATE', JSON.stringify(data))
|
|
|
|
},
|
|
|
|
onItemDownloadComplete(data) {
|
|
|
|
console.log('ON ITEM DOWNLOAD COMPLETE', JSON.stringify(data))
|
|
|
|
},
|
2021-09-19 18:44:10 -05:00
|
|
|
async initMediaStore() {
|
2021-09-12 18:37:08 -05:00
|
|
|
// Request and setup listeners for media files on native
|
2022-04-02 19:43:43 -05:00
|
|
|
AudioDownloader.addListener('onItemDownloadUpdate', (data) => {
|
|
|
|
this.onItemDownloadUpdate(data)
|
2021-09-19 18:44:10 -05:00
|
|
|
})
|
2022-04-02 19:43:43 -05:00
|
|
|
AudioDownloader.addListener('onItemDownloadComplete', (data) => {
|
|
|
|
this.onItemDownloadComplete(data)
|
2021-09-12 18:37:08 -05:00
|
|
|
})
|
2022-04-02 19:43:43 -05:00
|
|
|
// AudioDownloader.addListener('onDownloadFailed', (data) => {
|
|
|
|
// this.onDownloadFailed(data)
|
|
|
|
// })
|
|
|
|
// AudioDownloader.addListener('onDownloadProgress', (data) => {
|
|
|
|
// this.onDownloadProgress(data)
|
|
|
|
// })
|
2021-09-19 18:44:10 -05:00
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
var downloads = await this.$store.dispatch('downloads/loadFromStorage')
|
2021-10-28 09:37:31 -05:00
|
|
|
var downloadFolder = await this.$localStore.getDownloadFolder()
|
|
|
|
|
2021-11-20 10:59:34 -06:00
|
|
|
if (downloadFolder) {
|
2022-03-28 19:53:53 -05:00
|
|
|
// await this.syncDownloads(downloads, downloadFolder)
|
2021-10-28 09:37:31 -05:00
|
|
|
}
|
2021-12-05 18:31:47 -06:00
|
|
|
this.$eventBus.$emit('downloads-loaded')
|
2021-09-19 18:44:10 -05:00
|
|
|
|
2021-10-28 09:37:31 -05:00
|
|
|
var checkPermission = await StorageManager.checkStoragePermission()
|
2021-10-18 19:40:05 -05:00
|
|
|
console.log('Storage Permission is' + checkPermission.value)
|
2021-09-19 18:44:10 -05:00
|
|
|
if (!checkPermission.value) {
|
|
|
|
console.log('Will require permissions')
|
|
|
|
} else {
|
|
|
|
console.log('Has Storage Permission')
|
|
|
|
this.$store.commit('setHasStoragePermission', true)
|
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
},
|
2021-12-05 18:31:47 -06:00
|
|
|
async loadSavedSettings() {
|
|
|
|
var userSavedServerSettings = await this.$localStore.getServerSettings()
|
|
|
|
if (userSavedServerSettings) {
|
|
|
|
this.$store.commit('setServerSettings', userSavedServerSettings)
|
|
|
|
}
|
|
|
|
|
|
|
|
var userSavedSettings = await this.$localStore.getUserSettings()
|
|
|
|
if (userSavedSettings) {
|
|
|
|
this.$store.commit('user/setSettings', userSavedSettings)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Loading offline user audiobook data')
|
|
|
|
await this.$store.dispatch('user/loadOfflineUserAudiobookData')
|
|
|
|
},
|
2021-11-02 19:44:42 -05:00
|
|
|
showErrorToast(message) {
|
|
|
|
this.$toast.error(message)
|
|
|
|
},
|
|
|
|
showSuccessToast(message) {
|
|
|
|
this.$toast.success(message)
|
2021-11-14 19:59:34 -06:00
|
|
|
},
|
|
|
|
async attemptConnection() {
|
|
|
|
if (!this.$server) return
|
|
|
|
if (!this.networkConnected) {
|
|
|
|
console.warn('No network connection')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var localServerUrl = await this.$localStore.getServerUrl()
|
|
|
|
var localUserToken = await this.$localStore.getToken()
|
|
|
|
if (localServerUrl) {
|
|
|
|
// Server and Token are stored
|
|
|
|
if (localUserToken) {
|
|
|
|
var isSocketAlreadyEstablished = this.$server.socket
|
|
|
|
var success = await this.$server.connect(localServerUrl, localUserToken)
|
|
|
|
if (!success && !this.$server.url) {
|
|
|
|
// Bad URL
|
|
|
|
} else if (!success) {
|
|
|
|
// Failed to connect
|
|
|
|
} else if (isSocketAlreadyEstablished) {
|
|
|
|
// No need to wait for connect event
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 18:31:47 -06:00
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
// audiobookAdded(audiobook) {
|
|
|
|
// this.$store.commit('libraries/updateFilterDataWithAudiobook', audiobook)
|
|
|
|
// },
|
|
|
|
// audiobookUpdated(audiobook) {
|
|
|
|
// this.$store.commit('libraries/updateFilterDataWithAudiobook', audiobook)
|
|
|
|
// },
|
|
|
|
itemRemoved(libraryItem) {
|
|
|
|
if (this.$route.name.startsWith('item')) {
|
|
|
|
if (this.$route.params.id === libraryItem.id) {
|
2021-12-05 18:31:47 -06:00
|
|
|
this.$router.replace(`/bookshelf`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
// audiobooksAdded(audiobooks) {
|
|
|
|
// audiobooks.forEach((ab) => {
|
|
|
|
// this.audiobookAdded(ab)
|
|
|
|
// })
|
|
|
|
// },
|
|
|
|
// audiobooksUpdated(audiobooks) {
|
|
|
|
// audiobooks.forEach((ab) => {
|
|
|
|
// this.audiobookUpdated(ab)
|
|
|
|
// })
|
|
|
|
// },
|
2021-12-05 18:31:47 -06:00
|
|
|
userLoggedOut() {
|
|
|
|
// Only cancels stream if streamining not playing downloaded
|
2022-04-02 12:12:00 -05:00
|
|
|
this.$eventBus.$emit('close-stream')
|
2021-12-05 18:31:47 -06:00
|
|
|
},
|
|
|
|
initSocketListeners() {
|
|
|
|
if (this.$server.socket) {
|
2022-03-23 17:59:14 -05:00
|
|
|
// this.$server.socket.on('audiobook_updated', this.audiobookUpdated)
|
|
|
|
// this.$server.socket.on('audiobook_added', this.audiobookAdded)
|
|
|
|
this.$server.socket.on('item_removed', this.itemRemoved)
|
|
|
|
// this.$server.socket.on('audiobooks_updated', this.audiobooksUpdated)
|
|
|
|
// this.$server.socket.on('audiobooks_added', this.audiobooksAdded)
|
2021-12-05 18:31:47 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
removeSocketListeners() {
|
|
|
|
if (this.$server.socket) {
|
2022-03-23 17:59:14 -05:00
|
|
|
// this.$server.socket.off('audiobook_updated', this.audiobookUpdated)
|
|
|
|
// this.$server.socket.off('audiobook_added', this.audiobookAdded)
|
|
|
|
this.$server.socket.off('item_removed', this.itemRemoved)
|
|
|
|
// this.$server.socket.off('audiobooks_updated', this.audiobooksUpdated)
|
|
|
|
// this.$server.socket.off('audiobooks_added', this.audiobooksAdded)
|
2021-12-05 18:31:47 -06:00
|
|
|
}
|
2021-09-12 18:37:08 -05:00
|
|
|
}
|
2021-09-01 20:07:11 -05:00
|
|
|
},
|
2021-11-14 19:59:34 -06:00
|
|
|
async mounted() {
|
2021-09-01 20:07:11 -05:00
|
|
|
if (!this.$server) return console.error('No Server')
|
2021-10-25 21:13:10 -05:00
|
|
|
// console.log(`Default Mounted set SOCKET listeners ${this.$server.connected}`)
|
2021-09-01 20:07:11 -05:00
|
|
|
|
2021-11-20 19:25:01 -06:00
|
|
|
if (this.$server.connected) {
|
2021-11-19 20:00:34 -06:00
|
|
|
console.log('Syncing on default mount')
|
2021-12-06 18:40:42 -06:00
|
|
|
this.connected(true)
|
2021-11-19 20:00:34 -06:00
|
|
|
}
|
2022-03-23 17:59:14 -05:00
|
|
|
|
2021-12-05 18:31:47 -06:00
|
|
|
this.$server.on('logout', this.userLoggedOut)
|
2021-09-01 20:07:11 -05:00
|
|
|
this.$server.on('connected', this.connected)
|
2021-10-25 21:13:10 -05:00
|
|
|
this.$server.on('connectionFailed', this.socketConnectionFailed)
|
2021-09-01 20:07:11 -05:00
|
|
|
this.$server.on('initialStream', this.initialStream)
|
2021-10-25 21:13:10 -05:00
|
|
|
this.$server.on('currentUserAudiobookUpdate', this.currentUserAudiobookUpdate)
|
2021-11-02 19:44:42 -05:00
|
|
|
this.$server.on('show_error_toast', this.showErrorToast)
|
|
|
|
this.$server.on('show_success_toast', this.showSuccessToast)
|
2021-09-01 20:07:11 -05:00
|
|
|
|
2021-09-19 18:44:10 -05:00
|
|
|
if (this.$store.state.isFirstLoad) {
|
|
|
|
this.$store.commit('setIsFirstLoad', false)
|
2021-11-21 06:54:10 -06:00
|
|
|
await this.$store.dispatch('setupNetworkListener')
|
2021-11-14 19:59:34 -06:00
|
|
|
this.attemptConnection()
|
2021-09-19 18:44:10 -05:00
|
|
|
this.checkForUpdate()
|
2021-12-05 18:31:47 -06:00
|
|
|
this.loadSavedSettings()
|
2021-09-19 18:44:10 -05:00
|
|
|
this.initMediaStore()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (!this.$server) {
|
|
|
|
console.error('No Server beforeDestroy')
|
|
|
|
return
|
|
|
|
}
|
2021-12-05 18:31:47 -06:00
|
|
|
this.removeSocketListeners()
|
|
|
|
this.$server.off('logout', this.userLoggedOut)
|
2021-09-19 18:44:10 -05:00
|
|
|
this.$server.off('connected', this.connected)
|
2021-10-25 21:13:10 -05:00
|
|
|
this.$server.off('connectionFailed', this.socketConnectionFailed)
|
2021-09-19 18:44:10 -05:00
|
|
|
this.$server.off('initialStream', this.initialStream)
|
2021-11-02 19:44:42 -05:00
|
|
|
this.$server.off('show_error_toast', this.showErrorToast)
|
|
|
|
this.$server.off('show_success_toast', this.showSuccessToast)
|
2021-09-01 20:07:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|