mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Add socket event to remove download, fix clearInterval on stream loop
This commit is contained in:
parent
c30955f909
commit
9107620b3c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "audiobookshelf-client",
|
"name": "audiobookshelf-client",
|
||||||
"version": "1.1.4",
|
"version": "1.1.5",
|
||||||
"description": "Audiobook manager and player",
|
"description": "Audiobook manager and player",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "audiobookshelf",
|
"name": "audiobookshelf",
|
||||||
"version": "1.1.4",
|
"version": "1.1.5",
|
||||||
"description": "Self-hosted audiobook server for managing and playing audiobooks.",
|
"description": "Self-hosted audiobook server for managing and playing audiobooks.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -49,6 +49,15 @@ class DownloadManager {
|
|||||||
this.prepareDownload(client, audiobook, options)
|
this.prepareDownload(client, audiobook, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeSocketRequest(socket, downloadId) {
|
||||||
|
var download = this.downloads.find(d => d.id === downloadId)
|
||||||
|
if (!download) {
|
||||||
|
Logger.error('Remove download request download not found ' + downloadId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.removeDownload(download)
|
||||||
|
}
|
||||||
|
|
||||||
async prepareDownload(client, audiobook, options = {}) {
|
async prepareDownload(client, audiobook, options = {}) {
|
||||||
var downloadId = (Math.trunc(Math.random() * 1000) + Date.now()).toString(36)
|
var downloadId = (Math.trunc(Math.random() * 1000) + Date.now()).toString(36)
|
||||||
var dlpath = Path.join(this.downloadDirPath, downloadId)
|
var dlpath = Path.join(this.downloadDirPath, downloadId)
|
||||||
|
@ -199,14 +199,23 @@ class Server {
|
|||||||
Logger.info('[SOCKET] Socket Connected', socket.id)
|
Logger.info('[SOCKET] Socket Connected', socket.id)
|
||||||
|
|
||||||
socket.on('auth', (token) => this.authenticateSocket(socket, token))
|
socket.on('auth', (token) => this.authenticateSocket(socket, token))
|
||||||
|
|
||||||
|
// Scanning
|
||||||
socket.on('scan', this.scan.bind(this))
|
socket.on('scan', this.scan.bind(this))
|
||||||
socket.on('scan_covers', this.scanCovers.bind(this))
|
socket.on('scan_covers', this.scanCovers.bind(this))
|
||||||
socket.on('cancel_scan', this.cancelScan.bind(this))
|
socket.on('cancel_scan', this.cancelScan.bind(this))
|
||||||
|
|
||||||
|
// Streaming
|
||||||
socket.on('open_stream', (audiobookId) => this.streamManager.openStreamSocketRequest(socket, audiobookId))
|
socket.on('open_stream', (audiobookId) => this.streamManager.openStreamSocketRequest(socket, audiobookId))
|
||||||
socket.on('close_stream', () => this.streamManager.closeStreamRequest(socket))
|
socket.on('close_stream', () => this.streamManager.closeStreamRequest(socket))
|
||||||
socket.on('stream_update', (payload) => this.streamManager.streamUpdate(socket, payload))
|
socket.on('stream_update', (payload) => this.streamManager.streamUpdate(socket, payload))
|
||||||
|
|
||||||
socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket.sheepClient, payload))
|
socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket.sheepClient, payload))
|
||||||
|
|
||||||
|
// Downloading
|
||||||
socket.on('download', (payload) => this.downloadManager.downloadSocketRequest(socket, payload))
|
socket.on('download', (payload) => this.downloadManager.downloadSocketRequest(socket, payload))
|
||||||
|
socket.on('remove_download', (downloadId) => this.downloadManager.removeSocketRequest(socket, downloadId))
|
||||||
|
|
||||||
socket.on('test', () => {
|
socket.on('test', () => {
|
||||||
socket.emit('test_received', socket.id)
|
socket.emit('test_received', socket.id)
|
||||||
})
|
})
|
||||||
|
@ -43,6 +43,10 @@ class Stream extends EventEmitter {
|
|||||||
return this.audiobook.id
|
return this.audiobook.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get audiobookTitle() {
|
||||||
|
return this.audiobook ? this.audiobook.title : null
|
||||||
|
}
|
||||||
|
|
||||||
get totalDuration() {
|
get totalDuration() {
|
||||||
return this.audiobook.totalDuration
|
return this.audiobook.totalDuration
|
||||||
}
|
}
|
||||||
@ -206,8 +210,9 @@ class Stream extends EventEmitter {
|
|||||||
if (!this.isTranscodeComplete) {
|
if (!this.isTranscodeComplete) {
|
||||||
this.checkFiles()
|
this.checkFiles()
|
||||||
} else {
|
} else {
|
||||||
|
Logger.info(`[Stream] ${this.audiobookTitle} sending stream_ready`)
|
||||||
this.socket.emit('stream_ready')
|
this.socket.emit('stream_ready')
|
||||||
clearTimeout(this.loop)
|
clearInterval(this.loop)
|
||||||
}
|
}
|
||||||
}, 2000)
|
}, 2000)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user