From 9107620b3ca731a64532b7942cb59073914ecb86 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 12 Sep 2021 16:10:12 -0500 Subject: [PATCH] Add socket event to remove download, fix clearInterval on stream loop --- client/package.json | 2 +- package.json | 2 +- server/DownloadManager.js | 9 +++++++++ server/Server.js | 9 +++++++++ server/objects/Stream.js | 7 ++++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/client/package.json b/client/package.json index 0f3118d5..b553d2d4 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf-client", - "version": "1.1.4", + "version": "1.1.5", "description": "Audiobook manager and player", "main": "index.js", "scripts": { diff --git a/package.json b/package.json index 58898552..7cfc02bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf", - "version": "1.1.4", + "version": "1.1.5", "description": "Self-hosted audiobook server for managing and playing audiobooks.", "main": "index.js", "scripts": { diff --git a/server/DownloadManager.js b/server/DownloadManager.js index b6abd4ee..6ed42173 100644 --- a/server/DownloadManager.js +++ b/server/DownloadManager.js @@ -49,6 +49,15 @@ class DownloadManager { 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 = {}) { var downloadId = (Math.trunc(Math.random() * 1000) + Date.now()).toString(36) var dlpath = Path.join(this.downloadDirPath, downloadId) diff --git a/server/Server.js b/server/Server.js index 8a948dc4..7423db4f 100644 --- a/server/Server.js +++ b/server/Server.js @@ -199,14 +199,23 @@ class Server { Logger.info('[SOCKET] Socket Connected', socket.id) socket.on('auth', (token) => this.authenticateSocket(socket, token)) + + // Scanning socket.on('scan', this.scan.bind(this)) socket.on('scan_covers', this.scanCovers.bind(this)) socket.on('cancel_scan', this.cancelScan.bind(this)) + + // Streaming socket.on('open_stream', (audiobookId) => this.streamManager.openStreamSocketRequest(socket, audiobookId)) socket.on('close_stream', () => this.streamManager.closeStreamRequest(socket)) socket.on('stream_update', (payload) => this.streamManager.streamUpdate(socket, payload)) + socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket.sheepClient, payload)) + + // Downloading socket.on('download', (payload) => this.downloadManager.downloadSocketRequest(socket, payload)) + socket.on('remove_download', (downloadId) => this.downloadManager.removeSocketRequest(socket, downloadId)) + socket.on('test', () => { socket.emit('test_received', socket.id) }) diff --git a/server/objects/Stream.js b/server/objects/Stream.js index 8beb12bc..4c76355a 100644 --- a/server/objects/Stream.js +++ b/server/objects/Stream.js @@ -43,6 +43,10 @@ class Stream extends EventEmitter { return this.audiobook.id } + get audiobookTitle() { + return this.audiobook ? this.audiobook.title : null + } + get totalDuration() { return this.audiobook.totalDuration } @@ -206,8 +210,9 @@ class Stream extends EventEmitter { if (!this.isTranscodeComplete) { this.checkFiles() } else { + Logger.info(`[Stream] ${this.audiobookTitle} sending stream_ready`) this.socket.emit('stream_ready') - clearTimeout(this.loop) + clearInterval(this.loop) } }, 2000) }